Changeset a676cf7 in flex_extract.git


Ignore:
Timestamp:
Oct 30, 2022, 1:13:24 AM (17 months ago)
Author:
Anne Tipka <anne.tipka@…>
Branches:
dev
Children:
7271b6f
Parents:
ea754d1
Message:

modifications and adjustments to dates and times for correctly retrieving analysis and forecast data in operational mode

Location:
Source/Python
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • Source/Python/Classes/ControlFile.py

    r0540bd0 ra676cf7  
    624624                                                     self.end_date)
    625625
    626         self.basetime = check_basetime(self.basetime)
    627 
    628626        self.levelist, self.level = check_levels(self.levelist, self.level)
    629627
     
    639637        self.type = check_type(self.type, self.step)
    640638
     639        self.purefc = check_purefc(self.type)
     640
     641        self.basetime, self.time = check_basetime(self.basetime, self.time, self.purefc)
     642
    641643        self.time = check_time(self.time)
    642 
    643         self.purefc = check_purefc(self.type)
    644644
    645645        self.type, self.time, self.step = check_len_type_time_step(self.type,
     
    652652
    653653        self.acctime = check_acctime(self.acctime, self.marsclass,
    654                                      self.purefc, self.time)
     654                                     self.purefc, self.time,
     655                                     self.basetime, self.oper)
    655656
    656657        self.accmaxstep = check_accmaxstep(self.accmaxstep, self.marsclass,
  • Source/Python/Classes/EcFlexpart.py

    r365c82a ra676cf7  
    615615
    616616
    617     def retrieve(self, server, dates, public, request, inputdir='.'):
     617    def retrieve(self, server, dates, public, purefc, request, inputdir='.'):
    618618        '''Finalizing the retrieval information by setting final details
    619619        depending on grid type.
     
    634634            "YYYYMMDD/to/YYYYMMDD"
    635635
     636        public : int
     637            Switch to select kind of ECMWF Web API access and the possible data sets.
     638            Public data sets (1) and Member states data sets (0).
     639
     640        purefc : int
     641            Switch to decide whether the job is a pure forecast retrieval or
     642            coupled with analysis data.
     643
    636644        request : int
    637645            Selects the mode of retrieval.
     
    652660        self.public = public
    653661        self.inputdir = inputdir
     662        self.purefc = purefc
    654663        oro = False
    655664
     
    739748                        print('CHANGED FC start date to ' +
    740749                              sdate.strftime("%Y%m%d") +
    741                               ' to accomodate TIME=' +
     750                              ' to accommodate TIME=' +
    742751                              retr_param_dict['time'][0] +
    743752                              ', STEP=' +
     
    753762                    # if yes eliminate those fields since they may not
    754763                    # be accessible with user's credentials
    755 
     764                    dates = retr_param_dict['date'].split('/')
    756765                    enddate = retr_param_dict['date'].split('/')[-1]
    757                     elimit = datetime.strptime(enddate + str(self.basetime),
    758                                                '%Y%m%d%H')
     766                    elimit = datetime.strptime(enddate, '%Y%m%d')
    759767
    760768                    if self.basetime == 12:
    761769                        # --------------  flux data ----------------------------
    762                         if 'acc' in pk:
    763                             startdate = retr_param_dict['date'].split('/')[0]
    764                             enddate = datetime.strftime(elimit - t24h, '%Y%m%d')
    765                             retr_param_dict['date'] = '/'.join([startdate,
    766                                                                 'to',
    767                                                                 enddate])
     770                        if 'acc' in pk and not self.purefc:
     771
     772                            retr_param_dict['date'] = dates[0]
     773                            retr_param_dict['time'] = '12'
     774                            retr_param_dict['target'] = \
     775                                self._mk_targetname(ftype, pk,
     776                                                    retr_param_dict['date'])
    768777
    769778                            # ******* start retrievement
    770779                            self._start_retrievement(request, retr_param_dict)
    771780
    772                             retr_param_dict['date'] = \
    773                                 datetime.strftime(elimit - t12h, '%Y%m%d')
     781                            retr_param_dict['date'] = dates[-1]
     782                            retr_param_dict['time'] = '00/12'
     783                            retr_param_dict['target'] = \
     784                                self._mk_targetname(ftype, pk,
     785                                                    retr_param_dict['date'])
     786
     787                            # ******* start retrievement
     788                            self._start_retrievement(request, retr_param_dict)
     789
     790                        # --------------  non flux data ------------------------
     791                        else:
     792                            # ******* start retrievement
     793                            self._start_retrievement(request, retr_param_dict)
     794
     795                    elif self.basetime == 0:
     796                        # --------------  flux data ----------------------------
     797                        if 'acc' in pk and not self.purefc:
     798
     799                            retr_param_dict['date'] = dates[0]
     800                            retr_param_dict['time'] = '00/12'
     801                            retr_param_dict['target'] = \
     802                                self._mk_targetname(ftype, pk,
     803                                                    retr_param_dict['date'])
     804
     805                            # ******* start retrievement
     806                            self._start_retrievement(request, retr_param_dict)
     807
     808                            retr_param_dict['date'] = dates[-1]
    774809                            retr_param_dict['time'] = '00'
    775810                            retr_param_dict['target'] = \
     
    779814                            # ******* start retrievement
    780815                            self._start_retrievement(request, retr_param_dict)
    781 
    782                         # --------------  non flux data ------------------------
    783                         else:
     816                        elif 'acc' in pk and self.purefc:
    784817                            # ******* start retrievement
    785818                            self._start_retrievement(request, retr_param_dict)
    786 
    787                     elif self.basetime == 0:
    788 
    789                         timesave = ''.join(retr_param_dict['time'])
    790 
    791                         if all(['/' in retr_param_dict['time'],
    792                                 pk != 'OG_OROLSM__SL',
    793                                 'acc' not in pk]):
    794                             times = retr_param_dict['time'].split('/')
    795                             steps = retr_param_dict['step'].split('/')
    796 
    797                             while int(times[0]) + int(steps[0]) <= 12:
    798                                 times = times[1:]
    799                                 if len(times) > 1:
    800                                     retr_param_dict['time'] = '/'.join(times)
    801                                 else:
    802                                     retr_param_dict['time'] = times[0]
    803 
    804                         if all([pk != 'OG_OROLSM__SL',
    805                                 int(retr_param_dict['step'].split('/')[0]) == 0,
    806                                 int(timesave.split('/')[0]) == 0]):
    807 
    808                             retr_param_dict['date'] = \
    809                                 datetime.strftime(elimit, '%Y%m%d')
    810                             retr_param_dict['time'] = '00'
    811                             retr_param_dict['step'] = '000'
    812                             retr_param_dict['target'] = \
    813                                 self._mk_targetname(ftype, pk,
    814                                                     retr_param_dict['date'])
    815 
    816                         if ftype.upper() == 'FC' and \
    817                                 'acc' not in retr_param_dict['target']:
    818 
    819                             retr_param_dict['date'] = \
    820                                 datetime.strftime(elimit - t24h, '%Y%m%d')
    821 
    822                         # ******* start retrievement
    823                         self._start_retrievement(request, retr_param_dict)
     819                        # --------------  non flux data ------------------------
     820                        else: # 'acc' not in pk
     821                            timesave = ''.join(retr_param_dict['time'])
     822
     823                            if all(['/' in retr_param_dict['time'],
     824                                    pk != 'OG_OROLSM__SL']):
     825                                times = retr_param_dict['time'].split('/')
     826                                steps = retr_param_dict['step'].split('/')
     827
     828                                while int(times[0]) + int(steps[0]) <= 12:
     829                                    times = times[1:]
     830                                    if len(times) > 1:
     831                                        retr_param_dict['time'] = '/'.join(times)
     832                                    else:
     833                                        retr_param_dict['time'] = times[0]
     834
     835                            if all([pk != 'OG_OROLSM__SL',
     836                                    int(retr_param_dict['step'].split('/')[0]) == 0,
     837                                    int(timesave.split('/')[0]) == 0]):
     838
     839                                retr_param_dict['date'] = \
     840                                    datetime.strftime(elimit, '%Y%m%d')
     841                                retr_param_dict['time'] = '00'
     842                                retr_param_dict['step'] = '000'
     843                                retr_param_dict['target'] = \
     844                                    self._mk_targetname(ftype, pk,
     845                                                        retr_param_dict['date'])
     846
     847                            if ftype.upper() == 'FC' and not self.purefc:
     848
     849                                retr_param_dict['date'] = \
     850                                    datetime.strftime(elimit - t24h, '%Y%m%d')
     851
     852                            # ******* start retrievement
     853                            self._start_retrievement(request, retr_param_dict)
    824854                    else:
    825855                        raise ValueError('ERROR: Basetime has an invalid value '
  • Source/Python/Mods/checks.py

    r5606fc9 ra676cf7  
    9393        else:
    9494            raise ValueError('GRID parameter contains two '
    95                              'different values: %s' (grid))
     95                             'different values: %s', grid)
    9696    # # determine grid format
    9797    # if float(grid) / 100. >= 0.5:
     
    236236    return levelist, level
    237237
    238 
    239238def check_ppid(c, ppid):
    240239    '''Sets the current PPID.
     
    262261    return
    263262
    264 
    265263def check_purefc(ftype):
    266264    '''Check for a pure forecast mode.
     
    283281
    284282    return 0
    285 
    286283
    287284def check_step(step):
     
    404401        Valid values are hours (HH) from forecast base time.
    405402    '''
    406     if not len(ftype) == len(ftime) == len(steps):
    407         raise ValueError('ERROR: The number of field types, times and steps '
    408                          'are not the same! Please check the settings in the '
    409                          'CONTROL file!')
    410 
    411403    # if pure forecast is selected and only one field type/time is set
    412404    # prepare a complete list of type/time/step combination upto maxstep
    413     if len(ftype) == 1 and purefc:
     405    if len(ftime) == 1 and purefc:
    414406        nftype = []
    415407        nsteps = []
     
    421413        return nftype, nftime, nsteps
    422414
     415    if not len(ftype) == len(ftime) == len(steps):
     416        raise ValueError('ERROR: The number of field types, times and steps '
     417                         'are not the same! Please check the settings in the '
     418                         'CONTROL file!')
    423419    return ftype, ftime, steps
    424420
     
    605601    return maxstep
    606602
    607 def check_basetime(basetime):
     603def check_basetime(basetime, time, purefc):
    608604    '''Check if basetime is set and contains one of the two
    609605    possible values (0, 12).
     
    615611        retrieved.
    616612
     613    time : str
     614        The time in hours of the field.
     615
     616    purefc : int
     617        1 if pure forecasts are to be retrieved. 0 if there are
     618        analysis fields in between.
     619
    617620    Return
    618621    ------
     
    620623        The time for a half day retrieval. The 12 hours upfront are to be
    621624        retrieved.
     625
     626    time : str or list of str
     627        The time in hours of the field.
    622628    '''
    623629    if basetime is not None:
     
    626632            raise ValueError('ERROR: Basetime has an invalid value '
    627633                             '-> {}'.format(str(basetime)))
    628     return basetime
     634        if purefc:
     635            time = str(basetime)
     636    return basetime, time
    629637
    630638def check_request(request, marsfile):
     
    707715    return acctype
    708716
    709 
    710 def check_acctime(acctime, marsclass, purefc, time):
     717def check_acctime(acctime, marsclass, purefc, time, basetime, oper):
    711718    '''Guarantees that the accumulation forecast times were set.
    712719
     
    725732        Switch for definition of pure forecast mode or not.
    726733
     734    basetime : int
     735        The time for a half day retrieval. The 12 hours upfront are to be
     736        retrieved.
     737
     738    oper : int
     739        Switch to prepare the operational job script. Start date, end date and
     740        basetime will be prepared with environment variables.
     741
    727742    Return
    728743    ------
     
    730745        The starting time for the accumulated forecasts.
    731746    '''
     747
     748    if acctime and basetime and oper:
     749        return basetime
    732750
    733751    if not acctime:
     
    817835        if '/' in addpar:
    818836            parlist = addpar.split('/')
    819             parlist = [p for p in parlist if p is not '']
     837            parlist = [p for p in parlist if p != '']
    820838        else:
    821839            parlist = [addpar]
     
    824842
    825843    return addpar
    826 
    827844
    828845def check_job_chunk(job_chunk):
     
    853870
    854871    return job_chunk
    855 
    856872
    857873def check_number(number):
  • Source/Python/Mods/get_mars_data.py

    r365c82a ra676cf7  
    160160    start, end, datechunk = mk_dates(c, fluxes=True)
    161161    do_retrievement(c, server, start, end, datechunk, fluxes=True)
    162 
     162   
    163163    # --------------  non flux data --------------------------------------------
    164164    start, end, datechunk = mk_dates(c, fluxes=False)
     
    293293    chunk = timedelta(days=int(c.date_chunk))
    294294
    295     if c.basetime == 0 and not fluxes:  # non-fluxes
     295    if c.basetime == 0 and not fluxes and not c.purefc:  # non-fluxes
    296296        start = start - timedelta(days=1)
    297297
    298298    if c.purefc and fluxes and c.maxstep < 24:
    299299        start = start - timedelta(days=1)
    300         if not c.oper:
    301             end = end + timedelta(days=1)
     300#        if not c.oper:
     301#            end = end + timedelta(days=1)
    302302
    303303    if not c.purefc and fluxes:
     
    305305        if not c.oper:
    306306            end = end + timedelta(days=1)
    307         elif c.oper and c.basetime == 0:
    308             end = end - timedelta(days=1)
     307#        elif c.oper and c.basetime == 0:
     308#            end = end - timedelta(days=1)
    309309
    310310    # if we have non-flux forecast data starting at 18 UTC
     
    389389
    390390        try:
    391             flexpart.retrieve(server, dates, c.public, c.request, c.inputdir)
     391            flexpart.retrieve(server, dates, c.public, c.purefc, c.request, c.inputdir)
    392392        except IOError:
    393393            my_error('MARS request failed')
Note: See TracChangeset for help on using the changeset viewer.
hosted by ZAMG