Changeset 2193808 in flex_extract.git


Ignore:
Timestamp:
Dec 18, 2018, 4:00:28 PM (5 years ago)
Author:
anphi <anne.philipp@…>
Branches:
master, ctbto, dev
Children:
20577dc
Parents:
6067feb
Message:

added ensemble analysis/forecast retrievement option

Location:
python
Files:
6 added
4 edited

Legend:

Unmodified
Added
Removed
  • python/FlexpartTools.py

    r5862eb9 r2193808  
    4949from gribapi import *
    5050from GribTools import GribTools
     51from opposite import opposite
    5152
    5253def interpret_args_and_control(*args,**kwargs):
     
    411412
    412413    return sfeld
     414
     415def add_previousday_ifneeded(attrs):
     416
     417    if attrs['type']=='FC' and 'acc' not in attrs['target']:
     418        steps=attrs['step'].split('/')
     419        times=attrs['time'].split('/')
     420        addpday=False
     421        #for t in times:
     422            #for s in steps:
     423        if int(times[0])+int(steps[0])>23:
     424            addpday=True
     425        if(addpday):
     426            dates=attrs['date'].split('/')
     427            start_date=dates[0]
     428            syear=int(start_date[:4])
     429            smonth=int(start_date[4:6])
     430            sday=int(start_date[6:])
     431            start = datetime.date( year = syear, month = smonth, day = sday )
     432            startm1=start- datetime.timedelta(days=1)
     433
     434            attrs['date']='/'.join([startm1.strftime("%Y%m%d")]+dates[1:])
     435            print('CHANGED FC start date to '+startm1.strftime("%Y%m%d")+'to accomodate TIME='+times[0]+', STEP='+steps[0])
     436
     437    return
     438
     439
    413440
    414441class Control:
     
    704731        del attrs['marsclass']
    705732        attrs['class'] = mclass
     733
     734        add_previousday_ifneeded(attrs)
     735
    706736        target = attrs.get('target')
    707737        if not int(self.public):
     
    769799        self.types=dict()
    770800        try:
    771             if c.maxstep>len(c.type):    # Pure forecast mode
     801            if c.maxstep>24: #len(c.type):    # Pure forecast mode
    772802                c.type=[c.type[0]] # AP changed this index from 1 to 0
    773803                c.step=['{:0>3}'.format(int(c.step[0]))]
     
    804834
    805835
    806                 if ((ty.upper() == 'AN' and mod(int(c.time[i]),int(c.dtime))==0) or \
     836                if ((ty.upper() == 'AN' and mod(int(c.time[i]),int(c.dtime))==0 and int(c.step[i])==0) or \
    807837                   (ty.upper() != 'AN' and mod(int(c.step[i]),int(c.dtime))==0 and \
    808838                    mod(int(c.step[i]),int(c.dtime))==0) ) and \
     
    12061236                p=subprocess.check_call(['grib_set','-s','edition=2,productDefinitionTemplateNumber=8',ofile,ofile+'_2'])
    12071237                p=subprocess.check_call(['mv',ofile+'_2',ofile])
     1238        if c.debug==0:
     1239            inputfiles=glob.glob('*.grb')
     1240            for grb in inputfiles:
     1241                try:
     1242                    os.remove(grb)
     1243                except:
     1244                    pass
     1245        if c.stream=='ELDA':
     1246            opposite(self.inputdir+'/'+c.prefix)
     1247            for i in range(len(self.outputfilelist)):
     1248                if self.outputfilelist[i][-4:]!='N000' :
     1249                    j=int(self.outputfilelist[i][-3:])
     1250                    self.outputfilelist.append(self.outputfilelist[i][:-3]+'{:0>3}'.format(j+25))
    12081251
    12091252        if int(c.ectrans)==1 and c.ecapi==False:
     
    12761319        wrfpars=toparamId('sp/mslp/skt/2t/10u/10v/2d/z/lsm/sst/ci/sd/stl1/stl2/stl3/stl4/swvl1/swvl2/swvl3/swvl4',table128)
    12771320#        index_keys=["date","time","stepRange"]
    1278         index_keys=["date","time","step"]
     1321        if '/' in c.number:
     1322            index_keys=["number","date","time","step"]
     1323        else:
     1324            index_keys=["date","time","step"]
     1325
    12791326        indexfile=c.inputdir+"/date_time_stepRange.idx"
    12801327        silentremove(indexfile)
     
    13331380                    if timestamp<slimit or timestamp>elimit:
    13341381                        continue
     1382                else:
     1383                    if c.maxstep<24:
     1384                        if cdateH<c.start_date+'00':
     1385                            continue
     1386                        if cdateH>c.end_date+'23':
     1387                            continue
    13351388
    13361389
     
    14321485                else:
    14331486                    suffix=cdateH[2:10]
     1487                try:
     1488                    numberindex=index_keys.index('number')
     1489                    if len(index_vals[numberindex])>1:
     1490                        suffix=suffix+'.N{:0>3}'.format(int(prod[numberindex]))
     1491                except:
     1492                    pass
    14341493
    14351494                fnout+=suffix
     
    14601519        grib_index_release(iid)
    14611520
     1521        return
     1522
    14621523    def deacc_fluxes(self, inputfiles, c):
    14631524
    14641525        table128=init128(c.flexextractdir+'/grib_templates/ecmwf_grib1_table_128')
    14651526        pars=toparamId(self.params['OG_acc_SL'][0],table128)
    1466         index_keys=["date","time","step"]
     1527        if '/' in c.number:
     1528            index_keys=["number","date","time","step"]
     1529        else:
     1530            index_keys=["date","time","step"]
    14671531        indexfile=c.inputdir+"/date_time_stepRange.idx"
    14681532        silentremove(indexfile)
     
    14751539        for key in index_keys:
    14761540            key_vals = grib_index_get(iid,key)
    1477 
     1541            print(key_vals)
    14781542            l=[]
    14791543            for k in key_vals:
     
    15211585
    15221586            fnout=c.inputdir+'/'
     1587            numbersuffix=''
     1588            try:
     1589                numberindex=index_keys.index('number')
     1590                if len(index_vals[numberindex])>1:
     1591                    numbersuffix='.N{:0>3}'.format(int(prod[numberindex]))
     1592            except:
     1593                pass
     1594
    15231595            if c.maxstep>12:
    1524                 fnout+='flux'+sdate.strftime('%Y%m%d')+'.{:0>2}'.format(time/100)+'.{:0>3}'.format(step-2*int(c.dtime))
    1525                 gnout=c.inputdir+'/flux'+sdate.strftime('%Y%m%d')+'.{:0>2}'.format(time/100)+'.{:0>3}'.format(step-int(c.dtime))
    1526                 hnout=c.inputdir+'/flux'+sdate.strftime('%Y%m%d')+'.{:0>2}'.format(time/100)+'.{:0>3}'.format(step)
     1596                fnout+='flux'+sdate.strftime('%Y%m%d')+'.{:0>2}'.format(time/100)+'.{:0>3}'.format(step-2*int(c.dtime))+numbersuffix
     1597                gnout=c.inputdir+'/flux'+sdate.strftime('%Y%m%d')+'.{:0>2}'.format(time/100)+'.{:0>3}'.format(step-int(c.dtime))+numbersuffix
     1598                hnout=c.inputdir+'/flux'+sdate.strftime('%Y%m%d')+'.{:0>2}'.format(time/100)+'.{:0>3}'.format(step)+numbersuffix
    15271599                g=open(gnout,'w')
    15281600                h=open(hnout,'w')
    15291601            else:
    1530                 fnout+='flux'+fdate.strftime('%Y%m%d%H')
    1531                 gnout=c.inputdir+'/flux'+(fdate+datetime.timedelta(hours=int(c.dtime))).strftime('%Y%m%d%H')
    1532                 hnout=c.inputdir+'/flux'+sdates.strftime('%Y%m%d%H')
     1602                fnout+='flux'+fdate.strftime('%Y%m%d%H')+numbersuffix
     1603                gnout=c.inputdir+'/flux'+(fdate+datetime.timedelta(hours=int(c.dtime))).strftime('%Y%m%d%H')+numbersuffix
     1604                hnout=c.inputdir+'/flux'+sdates.strftime('%Y%m%d%H')+numbersuffix
    15331605                g=open(gnout,'w')
    15341606                h=open(hnout,'w')
     
    15561628                    values=(reshape(values,(nj,ni))).flatten()/fak
    15571629                    vdp.append(values[:]) # save the accumulated values
    1558                     if c.marsclass.upper() == 'EA' or \
     1630                    if c.marsclass.upper() in ('EA') or \
    15591631                       step<=int(c.dtime):
    15601632                        svdp.append(values[:]/int(c.dtime))
  • python/job.temp

    r5862eb9 r2193808  
    1111#SBATCH --error=flex_ecmwf.%j.out
    1212#SBATCH --mail-type=FAIL
    13 #SBATCH --time=12:00:00
     13#SBATCH --time=24:00:00
    1414
    1515## CRAY specific batch requests
  • python/job.temp.o

    rfb8810c r2193808  
    1111#SBATCH --error=flex_ecmwf.%j.out
    1212#SBATCH --mail-type=FAIL
    13 #SBATCH --time=12:00:00
     13#SBATCH --time=24:00:00
    1414
    1515## CRAY specific batch requests
  • python/prepareFLEXPART.py

    re18f4b5 r2193808  
    3737from GribTools import GribTools
    3838from FlexpartTools import EIFlexpart, Control,interpret_args_and_control, cleanup
     39from opposite import opposite
    3940
    4041hostname=socket.gethostname()
Note: See TracChangeset for help on using the changeset viewer.
hosted by ZAMG