Changeset 45b99e6 in flex_extract.git
- Timestamp:
- Feb 15, 2019, 3:48:31 PM (5 years ago)
- Branches:
- master, ctbto, dev
- Children:
- b9f1214
- Parents:
- ae2756e
- Location:
- source/python
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
source/python/classes/EcFlexpart.py
rd4696e0 r45b99e6 67 67 codes_get_values, codes_set_values, codes_set, 68 68 codes_write, codes_release, codes_new_from_index, 69 codes_index_release, codes_index_get) 69 codes_index_release, codes_index_get, codes_get_array, 70 codes_set_array, codes_grib_new_from_file) 70 71 71 72 # software specific classes and modules from flex_extract … … 77 78 execute_subprocess) 78 79 from MarsRetrieval import MarsRetrieval 80 from UioFiles import UioFiles 79 81 import mods.disaggregation as disaggregation 80 82 … … 663 665 664 666 for ftype in self.types: 665 # f kcontains field types such as667 # ftype contains field types such as 666 668 # [AN, FC, PF, CV] 667 # fv contains all of the items of the belonging key668 # [times, steps]669 669 for pk, pv in self.params.iteritems(): 670 670 # pk contains one of these keys of params … … 707 707 retr_param_dict['area'] = "" 708 708 retr_param_dict['gaussian'] = 'reduced' 709 if ftype.upper() == 'FC' and \ 710 'acc' not in retr_param_dict['target']: 711 if (int(retr_param_dict['time'][0]) + 712 int(retr_param_dict['step'][0])) > 23: 713 dates = retr_param_dict['date'].split('/') 714 sdate = datetime.strptime(dates[0], '%Y%m%d%H') 715 sdate = sdate - timedelta(days=1) 716 retr_param_dict['date'] = '/'.join( 717 [sdate.strftime("%Y%m%d")] + 718 retr_param_dict['date'][1:]) 719 720 print('CHANGED FC start date to ' + 721 sdate.strftime("%Y%m%d") + 722 ' to accomodate TIME=' + 723 retr_param_dict['time'][0] + 724 ', STEP=' + 725 retr_param_dict['time'][0]) 709 726 710 727 # ------ on demand path -------------------------------------------------- … … 760 777 times = retr_param_dict['time'].split('/') 761 778 steps = retr_param_dict['step'].split('/') 762 print 'times', times, int(times[0]), times[1:] 763 print 'steps', steps, int(steps[0]) 779 764 780 while int(times[0]) + int(steps[0]) <= 12: 765 print 'HELLO'766 781 times = times[1:] 767 print 'in while 1 ', times768 769 782 if len(times) > 1: 770 783 retr_param_dict['time'] = '/'.join(times) 771 784 else: 772 785 retr_param_dict['time'] = times[0] 773 774 print 'in while 2 ', times775 print retr_param_dict['time']776 786 777 787 if (pk != 'OG_OROLSM__SL' and … … 916 926 # get the values of the keys which are used for distinct access 917 927 # of grib messages via product 918 index_keys = ["date", "time", "step"] 928 if '/' in self.number: 929 # more than one ensemble member is selected 930 index_keys = ["number", "date", "time", "step"] 931 else: 932 index_keys = ["date", "time", "step"] 919 933 iid, index_vals = self._mk_index_values(c.inputdir, 920 934 inputfiles, … … 991 1005 t_enddate = t_date + timedelta(2*int(c.dtime)) 992 1006 1007 # if necessary, add ensemble member number to filename suffix 1008 # otherwise, add empty string 1009 if 'number' in index_keys: 1010 index_number = index_keys.index('number') 1011 if len(index_vals[index_number]) > 1: 1012 numbersuffix = '.N{:0>3}'.format(int(prod[index_number])) 1013 else: 1014 numbersuffix = '' 1015 993 1016 if c.purefc: 994 1017 fnout = os.path.join(c.inputdir, 'flux' + 995 1018 t_date.strftime('%Y%m%d.%H') + 996 '.{:0>3}'.format(step-2*int(c.dtime))) 1019 '.{:0>3}'.format(step-2*int(c.dtime)) + 1020 numbersuffix) 997 1021 gnout = os.path.join(c.inputdir, 'flux' + 998 1022 t_date.strftime('%Y%m%d.%H') + 999 '.{:0>3}'.format(step-int(c.dtime))) 1023 '.{:0>3}'.format(step-int(c.dtime)) + 1024 numbersuffix) 1000 1025 hnout = os.path.join(c.inputdir, 'flux' + 1001 1026 t_date.strftime('%Y%m%d.%H') + 1002 '.{:0>3}'.format(step)) 1027 '.{:0>3}'.format(step) + 1028 numbersuffix) 1003 1029 else: 1004 1030 fnout = os.path.join(c.inputdir, 'flux' + 1005 t_m2dt.strftime('%Y%m%d%H') )1031 t_m2dt.strftime('%Y%m%d%H') + numbersuffix) 1006 1032 gnout = os.path.join(c.inputdir, 'flux' + 1007 t_m1dt.strftime('%Y%m%d%H') )1033 t_m1dt.strftime('%Y%m%d%H') + numbersuffix) 1008 1034 hnout = os.path.join(c.inputdir, 'flux' + 1009 t_dt.strftime('%Y%m%d%H') )1035 t_dt.strftime('%Y%m%d%H') + numbersuffix) 1010 1036 1011 1037 print("outputfile = " + fnout) … … 1370 1396 # get the values of the keys which are used for distinct access 1371 1397 # of grib messages via product 1372 index_keys = ["date", "time", "step"] 1398 if '/' in self.number: 1399 # more than one ensemble member is selected 1400 index_keys = ["number", "date", "time", "step"] 1401 else: 1402 index_keys = ["date", "time", "step"] 1373 1403 iid, index_vals = self._mk_index_values(c.inputdir, 1374 1404 inputfiles, … … 1524 1554 else: 1525 1555 suffix = cdate_hour[2:10] 1556 1557 # if necessary, add ensemble member number to filename suffix 1558 if 'number' in index_keys: 1559 index_number = index_keys.index('number') 1560 if len(index_vals[index_number]) > 1: 1561 suffix = suffix + '.N{:0>3}'.format(int(prod[index_number])) 1562 1526 1563 fnout = os.path.join(c.inputdir, c.prefix + suffix) 1527 1564 print("outputfile = " + fnout) … … 1553 1590 1554 1591 codes_index_release(iid) 1592 1593 return 1594 1595 1596 def calc_extra_elda(self, path, prefix): 1597 ''' Calculates extra ensemble members for ELDA - Stream. 1598 1599 Parameters 1600 ---------- 1601 path : str 1602 Path to the output files. 1603 1604 prefix : str 1605 The prefix of the output filenames as defined in Control file. 1606 1607 Return 1608 ------ 1609 1610 ''' 1611 # max number 1612 maxnum = int(self.number.split('/')[-1]) 1613 1614 # get a list of all prepared output files with control forecast (CF) 1615 CF_filelist = UioFiles(path, prefix + '*.N000') 1616 1617 for cffile in CF_filelist.files: 1618 with open(cffile, 'rb') as f: 1619 cfvalues=[] 1620 while True: 1621 fid = codes_grib_new_from_file(f) 1622 if fid is None: 1623 break 1624 cfvalues.append(codes_get_array(fid, 'values')) 1625 codes_release(fid) 1626 1627 filename = cffile.split('N000')[0] 1628 for i in range(1, maxnum+1): # max number nehmen 1629 1630 # read an ensemble member 1631 g = open(filename + 'N{:0>3}'.format(i), 'rb') 1632 # create file for newly calculated ensemble member 1633 h = open(filename + 'N{:0>3}'.format(i+maxnum), 'wb') 1634 # number of message in grib file 1635 j = 0 1636 while True: 1637 gid = codes_grib_new_from_file(g) 1638 if gid is None: 1639 break 1640 values = codes_get_array(gid, 'values') 1641 codes_set_array(gid, 'values', 1642 values-2*(values-cfvalues[j])) 1643 codes_set(gid, 'number', i+maxnum) 1644 codes_write(gid, h) 1645 codes_release(gid) 1646 j += 1 1647 1648 g.close() 1649 h.close() 1650 print('wrote ' + filename + 'N{:0>3}'.format(i+maxnum)) 1651 self.outputfilelist.append( 1652 os.path.basename(filename + 'N{:0>3}'.format(i+maxnum))) 1555 1653 1556 1654 return -
source/python/mods/get_mars_data.py
rd4696e0 r45b99e6 209 209 210 210 211 def check_dates_for_nonflux_fc_times(types, times): 212 ''' 213 ''' 214 for ty, ti in zip(types,times): 215 if ty.upper() == 'FC' and int(ti) == 18: 216 return True 217 return False 218 219 211 220 def mk_dates(c, fluxes): 212 221 '''Prepares start and end date depending on flux or non flux data. … … 258 267 start = start - timedelta(days=1) 259 268 end = end + timedelta(days=1) 269 270 # if we have non-flux forecast data starting at 18 UTC 271 # we need to start retrieving data one day in advance 272 if not fluxes and check_dates_for_nonflux_fc_times(c.type, c.time): 273 start = start - timedelta(days=1) 260 274 261 275 return start, end, chunk -
source/python/mods/prepare_flexpart.py
rd4696e0 r45b99e6 177 177 flexpart = EcFlexpart(c, fluxes=False) 178 178 flexpart.create(inputfiles, c) 179 if c.stream.lower() == 'elda': 180 flexpart.calc_extra_elda(os.path.join(c.inputdir, c.prefix)) 179 181 flexpart.process_output(c) 180 182
Note: See TracChangeset
for help on using the changeset viewer.