Changeset 25b14be in flex_extract.git for source/python


Ignore:
Timestamp:
Sep 23, 2018, 11:40:28 AM (6 years ago)
Author:
Anne Philipp <anne.philipp@…>
Branches:
master, ctbto, dev
Children:
4971f63
Parents:
5d42acd
Message:

changed whole tree structure of flex_extract to have better overview

Location:
source/python
Files:
4 added
13 moved

Legend:

Unmodified
Added
Removed
  • source/python/classes/ControlFile.py

    r5d42acd r25b14be  
    143143        self.ecstorage = 0
    144144        self.ectrans = 0
    145         self.inputdir = '../work'
     145        self.inputdir = _config.PATH_INPUT_DIR
    146146        self.outputdir = self.inputdir
    147147        self.ecmwfdatadir = _config.PATH_FLEXEXTRACT_DIR
     
    177177            <nothing>
    178178        '''
    179         from tools import my_error
     179        from mods.tools import my_error
    180180
    181181        # read whole CONTROL file
     
    331331            <nothing>
    332332        '''
    333         from tools import my_error
     333        from mods.tools import my_error
    334334        import numpy as np
    335335
  • source/python/classes/EcFlexpart.py

    r5d42acd r25b14be  
    6161#
    6262# @Class Attributes:
    63 #    - dtime
    64 #    - basetime
    65 #    - server
    66 #    - marsclass
    67 #    - stream
    68 #    - resol
    69 #    - accuracy
    70 #    - number
    71 #    - expver
    72 #    - glevelist
    73 #    - area
    74 #    - grid
    75 #    - level
    76 #    - levelist
    77 #    - types
    78 #    - dates
    79 #    - area
    80 #    - gaussian
    81 #    - params
    82 #    - inputdir
    83 #    - outputfilelist
     63#
     64#  TODO
    8465#
    8566#*******************************************************************************
    8667#pylint: disable=unsupported-assignment-operation
    87 # this is disabled because its an error in pylint for this specific case
     68# this is disabled because for this specific case its an error in pylint
    8869#pylint: disable=consider-using-enumerate
    8970# this is not useful in this case
     
    10485import _config
    10586from GribTools import GribTools
    106 from tools import init128, to_param_id, silent_remove, product, my_error
     87from mods.tools import init128, to_param_id, silent_remove, product, my_error
    10788from MarsRetrieval import MarsRetrieval
    108 import disaggregation
     89import mods.disaggregation
    10990
    11091# ------------------------------------------------------------------------------
     
    471452                        MR.data_retrieve()
    472453                    elif request == 1:
    473                         MR.print_info()
     454                        MR.print_info(self.inputdir)
    474455                    elif request == 2:
    475                         MR.print_info()
     456                        MR.print_info(self.inputdir)
    476457                        MR.display_info()
    477458                        MR.data_retrieve()
  • source/python/classes/MarsRetrieval.py

    r2fb99de r25b14be  
    335335
    336336
    337     def print_info(self):
     337    def print_info(self, inputdir):
    338338        '''
    339339        @Description:
     
    345345                For description see class documentation.
    346346
     347            inputdir: string
     348                The path where all data from the retrievals are stored.
     349
    347350        @Return:
    348351            <nothing>
     
    352355
    353356        # open a file to store all requests to
    354         with open(os.path.join(_config.PATH_RUN_DIR,
     357        with open(os.path.join(inputdir,
    355358                               _config.FILE_MARS_REQUESTS), 'a') as f:
    356359            f.write('mars\n')
  • source/python/classes/UioFiles.py

    r2fb99de r25b14be  
    5252# software specific module from flex_extract
    5353#import profiling
    54 from tools import silent_remove, get_list_as_string
     54from mods.tools import silent_remove, get_list_as_string
    5555
    5656# ------------------------------------------------------------------------------
     
    6060class UioFiles(object):
    6161    '''
    62     Class to manipulate files. At initialisation it has the attribute
    63     pattern which stores a regular expression pattern for the files associated
    64     with the instance of the class.
     62    Class to manipulate files. At initialisation it has the pattern
     63    which stores a regular expression pattern for the files, the path
     64    to the files and the files already.
    6565    '''
    6666    # --------------------------------------------------------------------------
     
    8888        self.path = path
    8989        self.pattern = pattern
    90         self.files = None
     90        self.files = []
    9191
    9292        self.__list_files__(self.path)
     
    9595
    9696    #@profiling.timefn
    97     def __list_files__(self, path, callid=0):
     97    def __list_files__(self, path):
    9898        '''
    9999        @Description:
     
    108108                Path to the files.
    109109
    110             callid: integer
    111                 Id which tells the function if its the first call
    112                 or a recursive call. Default and first call is 0.
    113                 Everything different from 0 is ment to be a recursive case.
    114 
    115110        @Return:
    116111            <nothing>
    117112        '''
    118 
    119         # initialize variable in first function call
    120         if callid == 0:
    121             self.files = []
    122 
    123113        # Get the absolute path
    124114        path = os.path.abspath(path)
    125115
    126         # get the file list of the path if its not a directory and
    127         # if it contains the pattern
    128         self.files.extend([os.path.join(path, k) for k in os.listdir(path)
    129                            if fnmatch.fnmatch(k, self.pattern)])
    130 
    131         # find possible sub-directories in the path
    132         subdirs = [s for s in os.listdir(path)
    133                    if os.path.isdir(os.path.join(path, s))]
    134 
    135         # do recursive calls for sub-direcorties
    136         if subdirs:
    137             for subdir in subdirs:
    138                 self.__list_files__(os.path.join(path, subdir), callid=1)
     116        # get all files in the dir and subdir as absolut path
     117        for root, dirnames, filenames in os.walk(path):
     118            for filename in fnmatch.filter(filenames, self.pattern):
     119                self.files.append(os.path.join(root, filename))
    139120
    140121        return
  • source/python/install.py

    r2fb99de r25b14be  
    5858# software specific classes and modules from flex_extract
    5959import _config
    60 from ControlFile import ControlFile
    61 from UioFiles import UioFiles
    62 from tools import make_dir, put_file_to_ecserver, submit_job_to_ecserver
     60from classes.ControlFile import ControlFile
     61from classes.UioFiles import UioFiles
     62from mods.tools import make_dir, put_file_to_ecserver, submit_job_to_ecserver
    6363
    6464# ------------------------------------------------------------------------------
     
    189189        mk_env_vars(c.ecuid, c.ecgid, c.gateway, c.destination)
    190190
    191         mk_tarball(tar_file)
     191        mk_tarball(tar_file, c.install_target)
    192192
    193193        put_file_to_ecserver(ecd, tarball_name, c.install_target,
     
    195195
    196196        submit_job_to_ecserver(c.install_target,
    197                                os.path.join(_config.PATH_RELATIVE_JOBSCRIPTS,
     197                               os.path.join(_config.PATH_REL_JOBSCRIPTS,
    198198                                            _config.FILE_INSTALL_COMPILEJOB))
    199199
     
    214214                                        c.flexpart_root_scripts))
    215215            if os.path.abspath(ecd) != os.path.abspath(c.flexpart_root_scripts):
    216                 mk_tarball(tar_file)
     216                mk_tarball(tar_file, c.install_target)
    217217                make_dir(os.path.join(c.flexpart_root_scripts,
    218218                                      target_dirname))
     
    222222                os.chdir(os.path.join(c.flexpart_root_scripts,
    223223                                      target_dirname,
    224                                       _config.PATH_RELATIVE_FORTRAN_SRC))
     224                                      _config.PATH_REL_FORTRAN_SRC))
    225225
    226226        # Create Fortran executable - CONVERT2
     
    238238    return
    239239
    240 def mk_tarball(tarball_path):
     240def mk_tarball(tarball_path, target):
    241241    '''
    242242    @Description:
     
    253253            relevant data for flex_extract.
    254254
     255        target: string
     256            The queue where the job is submitted to.
     257
    255258    @Return:
    256259        <nothing>
     
    267270
    268271    # get lists of the files to be added to the tar file
    269     ECMWF_ENV_FILE = [_config.PATH_RELATIVE_ECMWF_ENV]
     272    if target == 'local':
     273        ECMWF_ENV_FILE = []
     274    else:
     275        ECMWF_ENV_FILE = [_config.PATH_REL_ECMWF_ENV]
     276
    270277    pyfiles = [os.path.relpath(x, ecd)
    271                for x in glob(_config.PATH_LOCAL_PYTHON +
    272                              os.path.sep + '*py')]
     278               for x in UioFiles(_config.PATH_LOCAL_PYTHON, '*py').files]
    273279    controlfiles = [os.path.relpath(x, ecd)
    274                     for x in glob(_config.PATH_CONTROLFILES +
    275                                   os.path.sep + 'CONTROL*')]
     280                    for x in UioFiles(_config.PATH_CONTROLFILES,
     281                                      'CONTROL*').files]
    276282    tempfiles = [os.path.relpath(x, ecd)
    277                  for x in glob(_config.PATH_TEMPLATES +
    278                                os.path.sep + '*')]
     283                 for x in UioFiles(_config.PATH_TEMPLATES , '*').files]
    279284    ffiles = [os.path.relpath(x, ecd)
    280               for x in glob(_config.PATH_FORTRAN_SRC +
    281                             os.path.sep + '*.f*')]
     285              for x in UioFiles(_config.PATH_FORTRAN_SRC, '*.f*').files]
    282286    hfiles = [os.path.relpath(x, ecd)
    283               for x in glob(_config.PATH_FORTRAN_SRC +
    284                             os.path.sep + '*.h')]
     287              for x in UioFiles(_config.PATH_FORTRAN_SRC, '*.h').files]
    285288    makefiles = [os.path.relpath(x, ecd)
    286                  for x in glob(_config.PATH_FORTRAN_SRC +
    287                                os.path.sep + 'Makefile*')]
     289                 for x in UioFiles(_config.PATH_FORTRAN_SRC, 'Makefile*').files]
    288290
    289291    # concatenate single lists to one for a better looping
     
    352354    '''
    353355
    354     with open(_config.PATH_RELATIVE_ECMWF_ENV, 'w') as fo:
     356    with open(_config.PATH_REL_ECMWF_ENV, 'w') as fo:
    355357        fo.write('ECUID ' + ecuid + '\n')
    356358        fo.write('ECGID ' + ecgid + '\n')
     
    389391    '''
    390392
    391     template = os.path.join(_config.PATH_RELATIVE_TEMPLATES,
     393    template = os.path.join(_config.PATH_REL_TEMPLATES,
    392394                            _config.TEMPFILE_INSTALL_COMPILEJOB)
    393395    with open(template) as f:
    394396        fdata = f.read().split('\n')
    395397
    396     compilejob = os.path.join(_config.PATH_RELATIVE_JOBSCRIPTS,
     398    compilejob = os.path.join(_config.PATH_REL_JOBSCRIPTS,
    397399                              _config.FILE_INSTALL_COMPILEJOB)
    398400    with open(compilejob, 'w') as fo:
     
    450452    '''
    451453    fp_root_path_to_python = os.path.join(fp_root, _config.FLEXEXTRACT_DIRNAME,
    452                          _config.PATH_RELATIVE_PYTHON)
    453 
    454     template = os.path.join(_config.PATH_RELATIVE_TEMPLATES,
     454                         _config.PATH_REL_PYTHON)
     455
     456    template = os.path.join(_config.PATH_REL_TEMPLATES,
    455457                            _config.TEMPFILE_INSTALL_JOB)
    456458    with open(template) as f:
    457459        fdata = f.read().split('\n')
    458460
    459     jobfile_temp = os.path.join(_config.PATH_RELATIVE_TEMPLATES,
     461    jobfile_temp = os.path.join(_config.PATH_REL_TEMPLATES,
    460462                                _config.TEMPFILE_JOB)
    461463    with open(jobfile_temp, 'w') as fo:
  • source/python/mods/get_mars_data.py

    r2fb99de r25b14be  
    5959import _config
    6060from tools import my_error, normal_exit, get_cmdline_arguments, read_ecenv
    61 from EcFlexpart import EcFlexpart
    62 from UioFiles import UioFiles
     61from classes.EcFlexpart import EcFlexpart
     62from classes.UioFiles import UioFiles
    6363# ------------------------------------------------------------------------------
    6464# FUNCTION
  • source/python/mods/plot_retrieved.py

    r2fb99de r25b14be  
    5353
    5454# software specific classes and modules from flex_extract
    55 from ControlFile import ControlFile
    56 from UioFiles import UioFiles
    57 
    58 # add path to pythonpath so that python finds its buddies
    59 LOCAL_PYTHON_PATH = os.path.dirname(os.path.abspath(
    60     inspect.getfile(inspect.currentframe())))
    61 if LOCAL_PYTHON_PATH not in sys.path:
    62     sys.path.append(LOCAL_PYTHON_PATH)
     55import _config
     56from classes.ControlFile import ControlFile
     57from classes.UioFiles import UioFiles
    6358
    6459font = {'family': 'monospace', 'size': 12}
  • source/python/mods/prepare_flexpart.py

    r2fb99de r25b14be  
    6060# software specific classes and modules from flex_extract
    6161import _config
    62 from UioFiles import UioFiles
     62from classes.UioFiles import UioFiles
    6363from tools import clean_up, get_cmdline_arguments, read_ecenv
    64 from EcFlexpart import EcFlexpart
     64from classes.EcFlexpart import EcFlexpart
    6565
    6666ecapi = 'ecmwf' not in socket.gethostname()
  • source/python/submit.py

    r2fb99de r25b14be  
    5151# software specific classes and modules from flex_extract
    5252import _config
    53 from tools import normal_exit, get_cmdline_arguments, submit_job_to_ecserver, \
    54                   read_ecenv
    55 from get_mars_data import get_mars_data
    56 from prepare_flexpart import prepare_flexpart
    57 from ControlFile import ControlFile
     53from mods.tools import (normal_exit, get_cmdline_arguments,
     54                        submit_job_to_ecserver, read_ecenv)
     55from mods.get_mars_data import get_mars_data
     56from mods.prepare_flexpart import prepare_flexpart
     57from classes.ControlFile import ControlFile
    5858
    5959# ------------------------------------------------------------------------------
Note: See TracChangeset for help on using the changeset viewer.
hosted by ZAMG