tofu.plugins.ITER.Struct._core — tofu v1.1

# Source code for tofu.plugins.ITER.Struct._core

    # -*- coding: utf-8 -*-
    """
    Created on Wed Mar  5 10:42:24 2014

    @author: didiervezinet
    """

    import os
    import numpy as np
    import datetime as dtm
    import warnings

    # ToFu-specific
    import tofu.defaults as tfd
    import tofu.pathfile as tfpf
    import tofu.geom as tfg
    from .. import _path as _tfiter_path
    from .. import Ves as tfiterVes

    __author__ = "Didier Vezinet"
    __all__ = ["plot"]

    _Exp = 'ITER'

    SavePathInp = '/afs/ipp-garching.mpg.de/home/d/didiv/Python/tofu/tofu/plugins/ITER/Struct/Inputs/'
    SavePathObj = '/afs/ipp-garching.mpg.de/home/d/didiv/Python/tofu/tofu/plugins/ITER/Struct/Objects/'

    ############################################################################
    ############################################################################
    ############################################################################
    #                   Struct creation and plotting
    ############################################################################

    def plot(Elt='BPV', EltStruct='P', EltVes='P', Lax=None, Proj="Cross", shot=0, SavePathInp=SavePathInp, SavePathObj=SavePathObj,
             Ves=None, NameVes=None, SavePathVes=None,
             skiprows=0, comments='#', units='mm',
             dtime=None, dtFormat=tfd.dtmFormat, dtimeIn=False, Test=True):
        """ Create and plot the required Struct object on the required axes

        The coordinates of the polygons of the Struct objects are taken from SavePathInp

        Parameters
        ----------
        Elt :           str
            Flag indicating which elements to plot, one capital letter per element
                - 'B' : the Beams
                - 'P' : the ports
                - 'V' : the associated Ves object
        Lax :           None / plt.Axes / list
            If provided, the axes or list of axes on which the poloidal and / or horizontal projections of the structure elements shall be plotted
        shot :          int
            A shot number, to be used as a reference point in time, marking from when the provided geometry is valid
        SavePathInp :   None / str
            If provided, forces the routine to search for the input file at SavePathInp, if not provided SavePathInp is automatically set to default (i.e. tofu/plugin/Ves/Inputs/)
        SavePathObj :   None / str
            (optional) Absolute path where the created object will be saved
        Ves :           None / :class:`tofu.geom.Ves`
            If provided, associates the Struct objects with this Ves object, otherwise a default Ves is loaded from SavePathVes if provided
        NameVes :       str
            Use if Ves is not provided, fed to tofu.plugins.ITER.Ves.load() for loading a default Ves
        SavePathVes :   None / str
            If provided, path from which a default Ves object can be loaded
        skiprows :      int
            Parameter fed to np.loadtxt() for reading the polygon from a txt file
        comments :      str
            Parameter fed to np.loadtxt() for reading the polygon from a txt file
        units :         str
            Flag indicating in which units the input polygon is provided (in ['m','cm','mm'])
        dtime :         None / dtm.datetime
            A datetime instance used for labelling the created instance (mostly used for debugging)
        dtFormat :      str
            The format of the labelling (mostly used for debugging)
        dtimeIn :       bool
            Flag indicating whether to include the label in the file name (mostly used for debugging)
        Test :          bool
            Flag indicating whether the inpurts should be checked for conformity

        Returns
        -------
        LS :            list
            The list of all created :class:`tofu.geom.Struct` instances

        """

        if Test:
            assert type(Elt) is str, "Arg Elt must be a str !"
            assert type(shot) is int, "Arg shot must be a int !"
            assert all([ss is None or type(ss) is str for ss in [SavePathInp]]), "Args [SavePathInp] must be str !"
            assert type(units) is str and units in ['m','cm','mm'], "Arg units must be in ['m','cm','mm'] !"
            assert dtime is None or type(dtime) is dtm.datetime, "Arg dtime must be a dtm.datetime !"
            assert type(dtFormat) is str, "Arg dtFormat must be a str !"
            assert type(dtimeIn) is bool, "Arg dtimeIn must be a bool !"

        # Get default path for loading inputs and saving object
        if SavePathInp is None:
            SavePathInp = Root + '/tofu/plugins/'+_Exp+'/Struct/Inputs/'

        # Load Ves if necessary
        if Ves is None:
            Ves = tfiterVes.load(Name=NameVes, SavePathObj=SavePathVes)

        # Get polygons and info
        LS = []
        ld = os.listdir(SavePathInp)
        if 'P' in Elt:
            L = sorted([ll for ll in ld if all([ss in ll for ss in ['PoloidalCurvesCoordinates_','.csv']]) and not any([ss in ll for ss in ['_Poloidal','_BM']])])
            NB = len(L)
            for ii in range(0,NB):
                ind1 = L[ii].index('PoloidalCurvesCoordinates_')+len('PoloidalCurvesCoordinates_')
                ind2 = L[ii].index('.csv')
                name = L[ii][ind1:ind2]
                Poly, addInfo = tfpf.get_PolyFromPolyFileObj(L[ii], SavePathInp=SavePathInp, units=units, comments='#', skiprows=0, shape0=2)
                ss = tfg.Struct(name, Poly, Type='Tor', Ves=Ves, Exp='ITER', shot=shot, SavePath=SavePathObj)
                for dd in addInfo.keys():
                    ss.Id._USRdict[dd] = addInfo[dd]
                LS.append(ss)
        if 'B' in Elt:
            L = sorted([ll for ll in ld if all([ss in ll for ss in ['PoloidalCurvesCoordinates_','_BM','.csv']]) and not any([ss in ll for ss in ['_Poloidal']])])
            NB = len(L)
            for ii in range(0,NB):
                ind1 = L[ii].index('_BM')+1
                ind2 = L[ii].index('.csv')
                name = L[ii][ind1:ind2]
                Poly, addInfo = tfpf.get_PolyFromPolyFileObj(L[ii], SavePathInp=SavePathInp, units=units, comments='#', skiprows=0, shape0=2)
                ss = tfg.Struct(name, Poly, Type='Tor', Ves=Ves, Exp='ITER', shot=shot, SavePath=SavePathObj)
                for dd in addInfo.keys():
                    ss.Id._USRdict[dd] = addInfo[dd]
                LS.append(ss)

        # Plot
        if 'V' in Elt:
            Lax = Ves.plot(Lax=Lax, Proj=Proj, Elt=EltVes)
        for ii in range(0,len(LS)):
            Lax = LS[ii].plot(Lax=Lax, Proj=Proj, Elt=EltStruct)

        return Lax, LS