Changeset 0690a6c in flex_extract.git for Source/Python/Classes/EcFlexpart.py
- Timestamp:
- Aug 13, 2019, 12:35:02 PM (5 years ago)
- Branches:
- master, ctbto, dev
- Children:
- 30f7911
- Parents:
- c77630a (diff), 2d1c338 (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
Source/Python/Classes/EcFlexpart.py
rba99230 rc77630a 1 #!/usr/bin/env python 1 #!/usr/bin/env python3 2 2 # -*- coding: utf-8 -*- 3 3 #******************************************************************************* … … 42 42 # Anne Philipp, Leopold Haimberger 43 43 # 44 # SPDX-License-Identifier: CC-BY-4.0 45 # 44 46 # This work is licensed under the Creative Commons Attribution 4.0 45 47 # International License. To view a copy of this license, visit … … 415 417 # ----------------------------------------------------------------------- 416 418 if wrf: 417 self.params['OG__ML'][0] += '/Z/VO' 418 if '/D' not in self.params['OG__ML'][0]: 419 self.params['OG__ML'][0] += '/D' 420 421 wrf_sfc = ['SP','SKT','SST','CI','STL1','STL2', 'STL3','STL4', 422 'SWVL1','SWVL2','SWVL3','SWVL4'] 423 for par in wrf_sfc: 424 if par not in self.params['OG__SL'][0]: 425 self.params['OG__SL'][0] += '/' + par 419 # @WRF 420 # THIS IS NOT YET CORRECTLY IMPLEMENTED !!! 421 # 422 # UNDER CONSTRUCTION !!! 423 # 424 425 print('WRF VERSION IS UNDER CONSTRUCTION!') # dummy argument 426 427 #self.params['OG__ML'][0] += '/Z/VO' 428 #if '/D' not in self.params['OG__ML'][0]: 429 # self.params['OG__ML'][0] += '/D' 430 431 #wrf_sfc = ['SP','SKT','SST','CI','STL1','STL2', 'STL3','STL4', 432 # 'SWVL1','SWVL2','SWVL3','SWVL4'] 433 #for par in wrf_sfc: 434 # if par not in self.params['OG__SL'][0]: 435 # self.params['OG__SL'][0] += '/' + par 426 436 427 437 return … … 846 856 if area[1] > area[3]: 847 857 area[1] -= 360 848 maxl = round((area[3] - area[1]) / grid[1]) + 1849 maxb = round((area[0] - area[2]) / grid[0]) + 1858 maxl = int(round((area[3] - area[1]) / grid[1])) + 1 859 maxb = int(round((area[0] - area[2]) / grid[0])) + 1 850 860 851 861 stream = namelist_template.generate( … … 1084 1094 1085 1095 print("outputfile = " + fnout) 1086 f_handle = open(fnout, 'w ')1087 h_handle = open(hnout, 'w ')1088 g_handle = open(gnout, 'w ')1096 f_handle = open(fnout, 'wb') 1097 h_handle = open(hnout, 'wb') 1098 g_handle = open(gnout, 'wb') 1089 1099 1090 1100 # read message for message and store relevant data fields, where … … 1392 1402 # write original time step to flux file as usual 1393 1403 fluxfile = GribUtil(os.path.join(c.inputdir, fluxfilename)) 1394 fluxfile.set_keys(tmpfile, filemode='a ', strict=True,1404 fluxfile.set_keys(tmpfile, filemode='ab', strict=True, 1395 1405 wherekeynames=['paramId'], wherekeyvalues=[142], 1396 1406 keynames=['perturbationNumber','date','time','stepRange','values'], … … 1398 1408 date.hour*100, 0, lsp_new_np[inumb,:,it]], 1399 1409 ) 1400 fluxfile.set_keys(tmpfile, filemode='a ', strict=True,1410 fluxfile.set_keys(tmpfile, filemode='ab', strict=True, 1401 1411 wherekeynames=['paramId'], wherekeyvalues=[143], 1402 1412 keynames=['perturbationNumber','date','time','stepRange','values'], … … 1406 1416 1407 1417 # rr for first subgrid point is identified by step = 1 1408 fluxfile.set_keys(tmpfile, filemode='a ', strict=True,1418 fluxfile.set_keys(tmpfile, filemode='ab', strict=True, 1409 1419 wherekeynames=['paramId'], wherekeyvalues=[142], 1410 1420 keynames=['perturbationNumber','date','time','stepRange','values'], … … 1412 1422 date.hour*100, '1', lsp_new_np[inumb,:,it+1]] 1413 1423 ) 1414 fluxfile.set_keys(tmpfile, filemode='a ', strict=True,1424 fluxfile.set_keys(tmpfile, filemode='ab', strict=True, 1415 1425 wherekeynames=['paramId'], wherekeyvalues=[143], 1416 1426 keynames=['perturbationNumber','date','time','stepRange','values'], … … 1420 1430 1421 1431 # rr for second subgrid point is identified by step = 2 1422 fluxfile.set_keys(tmpfile, filemode='a ', strict=True,1432 fluxfile.set_keys(tmpfile, filemode='ab', strict=True, 1423 1433 wherekeynames=['paramId'], wherekeyvalues=[142], 1424 1434 keynames=['perturbationNumber','date','time','stepRange','values'], … … 1426 1436 date.hour*100, '2', lsp_new_np[inumb,:,it+2]] 1427 1437 ) 1428 fluxfile.set_keys(tmpfile, filemode='a ', strict=True,1438 fluxfile.set_keys(tmpfile, filemode='ab', strict=True, 1429 1439 wherekeynames=['paramId'], wherekeyvalues=[143], 1430 1440 keynames=['perturbationNumber','date','time','stepRange','values'], … … 1456 1466 1457 1467 gribfile.copy_dummy_msg(ifile, keynames=['paramId'], 1458 keyvalues=[142], filemode='w ')1468 keyvalues=[142], filemode='wb') 1459 1469 1460 1470 gribfile.copy_dummy_msg(ifile, keynames=['paramId'], 1461 keyvalues=[143], filemode='a ')1471 keyvalues=[143], filemode='ab') 1462 1472 1463 1473 return … … 1502 1512 end_period = end_period + timedelta(hours=int(c.step[-1])) 1503 1513 1504 if c.wrf: 1505 table128 = init128(_config.PATH_GRIBTABLE) 1506 wrfpars = to_param_id('sp/mslp/skt/2t/10u/10v/2d/z/lsm/sst/ci/sd/\ 1507 stl1/stl2/stl3/stl4/swvl1/swvl2/swvl3/swvl4', 1508 table128) 1514 # @WRF 1515 # THIS IS NOT YET CORRECTLY IMPLEMENTED !!! 1516 # 1517 # UNDER CONSTRUCTION !!! 1518 # 1519 #if c.wrf: 1520 # table128 = init128(_config.PATH_GRIBTABLE) 1521 # wrfpars = to_param_id('sp/mslp/skt/2t/10u/10v/2d/z/lsm/sst/ci/sd/\ 1522 # stl1/stl2/stl3/stl4/swvl1/swvl2/swvl3/swvl4', 1523 # table128) 1509 1524 1510 1525 # these numbers are indices for the temporary files "fort.xx" … … 1558 1573 fortfile = os.path.join(c.inputdir, 'fort.' + k) 1559 1574 silent_remove(fortfile) 1560 fdict[k] = open(fortfile, 'w ')1575 fdict[k] = open(fortfile, 'wb') 1561 1576 #============================================================================================ 1562 1577 # create correct timestamp from the three time informations … … 1585 1600 continue 1586 1601 1587 if c.wrf: 1588 if 'olddate' not in locals() or cdate != olddate: 1589 fwrf = open(os.path.join(c.outputdir, 1590 'WRF' + cdate + '.' + ctime + '.000.grb2'), 'w') 1591 olddate = cdate[:] 1602 # @WRF 1603 # THIS IS NOT YET CORRECTLY IMPLEMENTED !!! 1604 # 1605 # UNDER CONSTRUCTION !!! 1606 # 1607 #if c.wrf: 1608 # if 'olddate' not in locals() or cdate != olddate: 1609 # fwrf = open(os.path.join(c.outputdir, 1610 # 'WRF' + cdate + '.' + ctime + '.000.grb2'), 'wb') 1611 # olddate = cdate[:] 1592 1612 #============================================================================================ 1593 1613 # savedfields remembers which fields were already used. … … 1627 1647 codes_write(gid, fdict['22']) 1628 1648 scwc = None 1629 elif c.wrf and paramId in [129, 138, 155] and \ 1630 levtype == 'hybrid': # Z, VO, D 1631 # do not do anything right now 1632 # these are specific parameter for WRF 1633 pass 1649 # @WRF 1650 # THIS IS NOT YET CORRECTLY IMPLEMENTED !!! 1651 # 1652 # UNDER CONSTRUCTION !!! 1653 # 1654 #elif c.wrf and paramId in [129, 138, 155] and \ 1655 # levtype == 'hybrid': # Z, VO, D 1656 # # do not do anything right now 1657 # # these are specific parameter for WRF 1658 # pass 1634 1659 else: 1635 1660 if paramId not in savedfields: … … 1640 1665 else: 1641 1666 print('duplicate ' + str(paramId) + ' not written') 1642 1643 try: 1644 if c.wrf: 1645 # model layer 1646 if levtype == 'hybrid' and \ 1647 paramId in [129, 130, 131, 132, 133, 138, 155]: 1648 codes_write(gid, fwrf) 1649 # sfc layer 1650 elif paramId in wrfpars: 1651 codes_write(gid, fwrf) 1652 except AttributeError: 1653 pass 1667 # @WRF 1668 # THIS IS NOT YET CORRECTLY IMPLEMENTED !!! 1669 # 1670 # UNDER CONSTRUCTION !!! 1671 # 1672 #try: 1673 # if c.wrf: 1674 # # model layer 1675 # if levtype == 'hybrid' and \ 1676 # paramId in [129, 130, 131, 132, 133, 138, 155]: 1677 # codes_write(gid, fwrf) 1678 # # sfc layer 1679 # elif paramId in wrfpars: 1680 # codes_write(gid, fwrf) 1681 #except AttributeError: 1682 # pass 1654 1683 1655 1684 codes_release(gid) … … 1721 1750 'rb'), fout) 1722 1751 # ============================================================================================ 1723 if c.wrf: 1724 fwrf.close() 1752 1753 # @WRF 1754 # THIS IS NOT YET CORRECTLY IMPLEMENTED !!! 1755 # 1756 # UNDER CONSTRUCTION !!! 1757 # 1758 #if c.wrf: 1759 # fwrf.close() 1725 1760 1726 1761 codes_index_release(iid) … … 1756 1791 # get a list of all prepared output files with control forecast (CF) 1757 1792 CF_filelist = UioFiles(path, prefix + '*.N000') 1793 CF_filelist.files = sorted(CF_filelist.files) 1758 1794 1759 1795 for cffile in CF_filelist.files: … … 1769 1805 filename = cffile.split('N000')[0] 1770 1806 for i in range(1, maxnum + 1): 1771 1772 1807 # read an ensemble member 1773 1808 g = open(filename + 'N{:0>3}'.format(i), 'rb')
Note: See TracChangeset
for help on using the changeset viewer.