Changeset 2193808 in flex_extract.git for python/FlexpartTools.py
- Timestamp:
- Dec 18, 2018, 4:00:28 PM (5 years ago)
- Branches:
- master, ctbto, dev
- Children:
- 20577dc
- Parents:
- 6067feb
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
python/FlexpartTools.py
r5862eb9 r2193808 49 49 from gribapi import * 50 50 from GribTools import GribTools 51 from opposite import opposite 51 52 52 53 def interpret_args_and_control(*args,**kwargs): … … 411 412 412 413 return sfeld 414 415 def 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 413 440 414 441 class Control: … … 704 731 del attrs['marsclass'] 705 732 attrs['class'] = mclass 733 734 add_previousday_ifneeded(attrs) 735 706 736 target = attrs.get('target') 707 737 if not int(self.public): … … 769 799 self.types=dict() 770 800 try: 771 if c.maxstep> len(c.type): # Pure forecast mode801 if c.maxstep>24: #len(c.type): # Pure forecast mode 772 802 c.type=[c.type[0]] # AP changed this index from 1 to 0 773 803 c.step=['{:0>3}'.format(int(c.step[0]))] … … 804 834 805 835 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 \ 807 837 (ty.upper() != 'AN' and mod(int(c.step[i]),int(c.dtime))==0 and \ 808 838 mod(int(c.step[i]),int(c.dtime))==0) ) and \ … … 1206 1236 p=subprocess.check_call(['grib_set','-s','edition=2,productDefinitionTemplateNumber=8',ofile,ofile+'_2']) 1207 1237 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)) 1208 1251 1209 1252 if int(c.ectrans)==1 and c.ecapi==False: … … 1276 1319 wrfpars=toparamId('sp/mslp/skt/2t/10u/10v/2d/z/lsm/sst/ci/sd/stl1/stl2/stl3/stl4/swvl1/swvl2/swvl3/swvl4',table128) 1277 1320 # 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 1279 1326 indexfile=c.inputdir+"/date_time_stepRange.idx" 1280 1327 silentremove(indexfile) … … 1333 1380 if timestamp<slimit or timestamp>elimit: 1334 1381 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 1335 1388 1336 1389 … … 1432 1485 else: 1433 1486 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 1434 1493 1435 1494 fnout+=suffix … … 1460 1519 grib_index_release(iid) 1461 1520 1521 return 1522 1462 1523 def deacc_fluxes(self, inputfiles, c): 1463 1524 1464 1525 table128=init128(c.flexextractdir+'/grib_templates/ecmwf_grib1_table_128') 1465 1526 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"] 1467 1531 indexfile=c.inputdir+"/date_time_stepRange.idx" 1468 1532 silentremove(indexfile) … … 1475 1539 for key in index_keys: 1476 1540 key_vals = grib_index_get(iid,key) 1477 1541 print(key_vals) 1478 1542 l=[] 1479 1543 for k in key_vals: … … 1521 1585 1522 1586 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 1523 1595 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 1527 1599 g=open(gnout,'w') 1528 1600 h=open(hnout,'w') 1529 1601 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 1533 1605 g=open(gnout,'w') 1534 1606 h=open(hnout,'w') … … 1556 1628 values=(reshape(values,(nj,ni))).flatten()/fak 1557 1629 vdp.append(values[:]) # save the accumulated values 1558 if c.marsclass.upper() == 'EA'or \1630 if c.marsclass.upper() in ('EA') or \ 1559 1631 step<=int(c.dtime): 1560 1632 svdp.append(values[:]/int(c.dtime))
Note: See TracChangeset
for help on using the changeset viewer.