Changeset 70fee58 in flex_extract.git


Ignore:
Timestamp:
Oct 12, 2018, 1:17:12 PM (5 months ago)
Author:
Anne Philipp <anne.philipp@…>
Branches:
dev
Children:
785b882
Parents:
5827ff6
Message:

some bug corrections, minor code improvements

Location:
source/python
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • source/python/_config.py

    rc5074d2 r70fee58  
    2727
    2828_VERSION_STR = '7.1'
     29
     30QUEUES_LIST = ['ecgate', 'cca']
    2931
    3032# ------------------------------------------------------------------------------
     
    7678PATH_TEST_DIR = os.path.join(PATH_SOURCES, 'pythontest')
    7779PATH_INPUT_DIR = os.path.join(PATH_RUN_DIR, INPUT_DIRNAME_DEFAULT)
    78 if os.getenv('CONTROL') and '/' in os.getenv('CONTROL'):
     80if os.getenv('CONTROL'):# and '/' in os.getenv('CONTROL'):
    7981    # this is only needed if remote version with job script is used!
    8082    # because job is directly submitted from SCRATCH and because the
    8183    # CONTROL file is stored there, the normal path is not valid.
    82     PATH_CONTROLFILES = os.getenv('CONTROL')
     84    PATH_CONTROLFILES = '.'
    8385else:
    8486    PATH_CONTROLFILES = os.path.join(PATH_RUN_DIR, 'control')
  • source/python/classes/ControlFile.py

    r0e576fc r70fee58  
    6060sys.path.append('../')
    6161import _config
    62 from mods.tools import my_error
     62from mods.tools import my_error, silent_remove
    6363
    6464# ------------------------------------------------------------------------------
     
    188188
    189189        try:
    190             with open(os.path.join(_config.PATH_CONTROLFILES,
    191                                    self.controlfile)) as f:
     190            cfile = os.path.join(_config.PATH_CONTROLFILES, self.controlfile)
     191            with open(cfile) as f:
    192192                fdata = f.read().split('\n')
    193193        except IOError:
    194             print('Could not read CONTROL file "' + args.controlfile + '"')
     194            print('Could not read CONTROL file "' + cfile + '"')
    195195            print('Either it does not exist or its syntax is wrong.')
    196196            print('Try "' + sys.argv[0].split('/')[-1] + \
     
    450450                self.mailops = [self.mailops]
    451451
    452         if queue in ['ecgate', 'cca'] and \
     452        if queue in _config.QUEUES_LIST and \
    453453           not self.gateway or not self.destination or \
    454454           not self.ecuid or not self.ecgid:
     
    463463                                    _config.FILE_MARS_REQUESTS)
    464464            if os.path.isfile(marsfile):
    465                 os.remove(marsfile)
     465                silent_remove(marsfile)
    466466
    467467        # check all logical variables for data type
  • source/python/classes/EcFlexpart.py

    raa275fc r70fee58  
    8585                     codes_get_values, codes_set_values, codes_set,
    8686                     codes_write, codes_release, codes_new_from_index,
    87                      codes_index_release)
     87                     codes_index_release, codes_index_get)
    8888
    8989# software specific classes and modules from flex_extract
     
    136136        self.types = dict()
    137137
    138         if c.maxstep > len(c.type):    # Pure forecast mode
     138        # Pure forecast mode
     139        if c.maxstep > len(c.type) and 'AN' not in c.type:
    139140            c.type = [c.type[0]]
    140141            c.step = ['{:0>3}'.format(int(c.step[0]))]
     
    168169                    btlist = [13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 0]
    169170
    170                 if ((ty.upper() == 'AN' and
    171                      int(c.time[i]) % int(c.dtime) ==0) or
    172                     (ty.upper() != 'AN' and
    173                      int(c.step[i]) % int(c.dtime) == 0 and
    174                      int(c.step[i]) % int(c.dtime) == 0) ) and \
     171                if ((ty.upper() == 'AN' and (int(c.time[i]) % int(c.dtime)) == 0) or
     172                    (ty.upper() != 'AN' and (int(c.step[i]) % int(c.dtime)) == 0 and
     173                     (int(c.step[i]) % int(c.dtime) == 0)) ) and \
    175174                    (int(c.time[i]) in btlist or c.maxstep > 24):
    176175
     
    434433            #index_vals.append(grib_index_get(iid, key))
    435434            #print(index_vals[-1])
    436             key_vals = grib_index_get(iid, key)
     435            key_vals = codes_index_get(iid, key)
    437436            print(key_vals)
    438437            # have to sort the steps for disaggregation,
     
    532531                if isinstance(pv, str):
    533532                    continue
    534                 retr_param_dict['type'] = '' + ftype
     533                retr_param_dict['type'] = ftype
    535534                retr_param_dict['time'] = self.types[ftype]['times']
    536535                retr_param_dict['step'] = self.types[ftype]['steps']
     
    538537                retr_param_dict['stream'] = self.stream
    539538                retr_param_dict['target'] = \
    540                     self._mk_targetname(ftype, pk,
     539                    self._mk_targetname(ftype,
     540                                        pk,
    541541                                        retr_param_dict['date'].split('/')[0])
    542542                retr_param_dict['param'] = pv[0]
     
    689689
    690690        loader = TemplateLoader(_config.PATH_TEMPLATES, auto_reload=False)
    691         compile_template = loader.load(_config.TEMPFILE_NAMELIST,
     691        namelist_template = loader.load(_config.TEMPFILE_NAMELIST,
    692692                                       cls=NewTextTemplate)
    693693
     
    701701        maxb = int((area[0] - area[2]) / grid[0]) + 1
    702702
    703         stream = compile_template.generate(
     703        stream = namelist_template.generate(
    704704            maxl = str(maxl),
    705705            maxb = str(maxb),
     
    12161216        print(self.outputfilelist)
    12171217
    1218         if c.format.lower() == 'grib2':
    1219             for ofile in self.outputfilelist:
     1218        for ofile in self.outputfilelist:
     1219            ofile = os.path.join(self.inputdir, ofile)
     1220
     1221            if c.format.lower() == 'grib2':
    12201222                p = subprocess.check_call(['grib_set', '-s', 'edition=2, \
    12211223                                           productDefinitionTemplateNumber=8',
     
    12231225                p = subprocess.check_call(['mv', ofile + '_2', ofile])
    12241226
    1225         if c.ectrans and not c.ecapi:
    1226             for ofile in self.outputfilelist:
     1227            if c.ectrans and not c.ecapi:
    12271228                p = subprocess.check_call(['ectrans', '-overwrite', '-gateway',
    12281229                                           c.gateway, '-remote', c.destination,
    12291230                                           '-source', ofile])
    12301231
    1231         if c.ecstorage and not c.ecapi:
    1232             for ofile in self.outputfilelist:
     1232            if c.ecstorage and not c.ecapi:
    12331233                p = subprocess.check_call(['ecp', '-o', ofile,
    12341234                                           os.path.expandvars(c.ecfsdir)])
    12351235
    1236         if c.outputdir != c.inputdir:
    1237             for ofile in self.outputfilelist:
     1236            if c.outputdir != c.inputdir:
    12381237                p = subprocess.check_call(['mv',
    12391238                                           os.path.join(c.inputdir, ofile),
  • source/python/classes/MarsRetrieval.py

    r0e576fc r70fee58  
    418418        # open a file to store all requests to
    419419        with open(os.path.join(inputdir,
    420                                    _config.FILE_MARS_REQUESTS), 'a') as f:
     420                               _config.FILE_MARS_REQUESTS), 'a') as f:
    421421            f.write(str(request_number) + ', ')
    422422            f.write(', '.join(str(attrs[key])
  • source/python/mods/get_mars_data.py

    r5bad6ec r70fee58  
    5252
    5353# software specific classes and modules from flex_extract
    54 sys.path.append('../')
     54sys.path.append(os.path.dirname(os.path.abspath(
     55    inspect.getfile(inspect.currentframe()))) + '/../')
    5556import _config
    5657from tools import (my_error, normal_exit, get_cmdline_arguments,
  • source/python/mods/prepare_flexpart.py

    rc5074d2 r70fee58  
    5959
    6060# software specific classes and modules from flex_extract
    61 sys.path.append('../')
     61
     62sys.path.append(os.path.dirname(os.path.abspath(
     63    inspect.getfile(inspect.currentframe()))) + '/../')
    6264import _config
    6365from classes.UioFiles import UioFiles
     
    156158
    157159    # get all files with flux data to be deaccumulated
    158     inputfiles = UioFiles(c.inputdir, '*OG_acc_SL*.' + c.ppid + '.*')
     160    inputfiles = UioFiles(c.inputdir, '*OG_acc_SL*.' + str(c.ppid) + '.*')
    159161
    160162    # deaccumulate the flux data
     
    164166
    165167    # get a list of all files from the root inputdir
    166     inputfiles = UioFiles(c.inputdir, '????__??.*' + c.ppid + '.*')
     168    inputfiles = UioFiles(c.inputdir, '????__??.*' + str(c.ppid) + '.*')
    167169
    168170    # produce FLEXPART-ready GRIB files and process them -
Note: See TracChangeset for help on using the changeset viewer.
hosted by ZAMG