Changeset c49aa73 in flex_extract.git
- Timestamp:
- Jul 29, 2019, 10:18:33 AM (5 years ago)
- Branches:
- master, ctbto, dev
- Children:
- 6431a70
- Parents:
- 4ef5ba9
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
source/python/classes/EcFlexpart.py
rd727af2 rc49aa73 1 #!/usr/bin/env python 31 #!/usr/bin/env python 2 2 # -*- coding: utf-8 -*- 3 3 #******************************************************************************* … … 24 24 # short term forecast data 25 25 # - added conversion into GRIB2 26 # - added conversion into .fp format for faster execution of FLEXPART27 # (see https://www.flexpart.eu/wiki/FpCtbtoWo4FpFormat)28 26 # 29 27 # February 2018 - Anne Philipp (University of Vienna): … … 56 54 # MODULES 57 55 # ------------------------------------------------------------------------------ 56 from __future__ import print_function 57 58 58 import os 59 59 import sys … … 62 62 import subprocess 63 63 from datetime import datetime, timedelta 64 import numpy as np65 66 from eccodes import (codes_index_select, codes_new_from_index, codes_get,67 codes_get_values, codes_set_values, codes_set,68 codes_write, codes_release, codes_new_from_index,69 codes_index_release, codes_index_get, codes_get_array,70 codes_set_array, codes_grib_new_from_file)71 64 72 65 # software specific classes and modules from flex_extract … … 252 245 self._create_params(c.gauss, c.eta, c.omega, c.cwc, c.wrf) 253 246 254 if fluxes and not c.purefc:247 if fluxes:# and not c.purefc: 255 248 self._create_field_types_fluxes() 256 249 else: … … 574 567 index_vals[2]: ('0', '12', '3', '6', '9') ; stepRange 575 568 ''' 569 from eccodes import codes_index_get 570 576 571 iid = None 577 572 index_keys = keys … … 666 661 'param':None} 667 662 668 for ftype in s elf.types:663 for ftype in sorted(self.types): 669 664 # ftype contains field types such as 670 665 # [AN, FC, PF, CV] 671 for pk, pv in s elf.params.items():666 for pk, pv in sorted(self.params.items()): 672 667 # pk contains one of these keys of params 673 668 # [SH__ML, SH__SL, GG__ML, GG__SL, OG__ML, OG__SL, … … 838 833 from genshi.template import TemplateLoader 839 834 from genshi.template.eval import UndefinedError 835 import numpy as np 840 836 841 837 try: … … 850 846 if area[1] > area[3]: 851 847 area[1] -= 360 852 maxl = int((area[3] - area[1]) / grid[1]) + 1853 maxb = int((area[0] - area[2]) / grid[0]) + 1848 maxl = round((area[3] - area[1]) / grid[1]) + 1 849 maxb = round((area[0] - area[2]) / grid[0]) + 1 854 850 855 851 stream = namelist_template.generate( … … 921 917 922 918 ''' 919 import numpy as np 920 from eccodes import (codes_index_select, codes_new_from_index, codes_get, 921 codes_get_values, codes_set_values, codes_set, 922 codes_write, codes_release, codes_new_from_index, 923 codes_index_release) 923 924 924 925 table128 = init128(_config.PATH_GRIBTABLE) … … 1301 1302 1302 1303 ''' 1304 import numpy as np 1305 1303 1306 print('... disaggregation of precipitation with new method.') 1304 1307 … … 1323 1326 else: 1324 1327 for ix in range(ni*nj): 1325 lsp_new_np[ ix,:] = disaggregation.IA3(lsp_np[0,ix,:])[:-1]1326 cp_new_np[ ix,:] = disaggregation.IA3(cp_np[0,ix,:])[:-1]1328 lsp_new_np[0,ix,:] = disaggregation.IA3(lsp_np[ix,:])[:-1] 1329 cp_new_np[0,ix,:] = disaggregation.IA3(cp_np[ix,:])[:-1] 1327 1330 1328 1331 # write to grib files (full/orig times to flux file and inbetween 1329 # times into seperate end files)1332 # times with step 1 and 2, respectively) 1330 1333 print('... write disaggregated precipitation to files.') 1331 1334 … … 1488 1491 1489 1492 ''' 1493 from eccodes import (codes_index_select, codes_new_from_index, codes_get, 1494 codes_get_values, codes_set_values, codes_set, 1495 codes_write, codes_release, codes_new_from_index, 1496 codes_index_release) 1490 1497 1491 1498 # generate start and end timestamp of the retrieval period … … 1505 1512 # for the Fortran program input 1506 1513 # 10: U,V | 11: T | 12: lnsp | 13: D | 16: sfc fields 1507 # 17: Q | 18: Q , gaussian| 19: w| 21: etadot | 22: clwc+ciwc1514 # 17: Q | 18: Q, SL, GG| 19: omega | 21: etadot | 22: clwc+ciwc 1508 1515 fdict = {'10':None, '11':None, '12':None, '13':None, '16':None, 1509 1516 '17':None, '18':None, '19':None, '21':None, '22':None} … … 1740 1747 1741 1748 ''' 1749 from eccodes import (codes_grib_new_from_file, codes_get_array, 1750 codes_set_array, codes_release, codes_set_values, 1751 codes_set, codes_write, codes_release) 1752 1742 1753 # max number 1743 1754 maxnum = int(self.number.split('/')[-1]) … … 1855 1866 return 1856 1867 1857 1858 def prepare_fp_files(self, c):1859 '''Conversion of GRIB files to FLEXPART binary format.1860 1861 Parameters1862 ----------1863 c : ControlFile1864 Contains all the parameters of CONTROL file and1865 command line.1866 1867 Return1868 ------1869 1870 '''1871 # generate AVAILABLE file1872 # Example of AVAILABLE file data:1873 # 20131107 000000 EN13110700 ON DISC1874 clist = []1875 for ofile in self.outputfilelist:1876 fname = ofile.split('/')1877 if '.' in fname[-1]:1878 l = fname[-1].split('.')1879 timestamp = datetime.strptime(l[0][-6:] + l[1],1880 '%y%m%d%H')1881 timestamp += timedelta(hours=int(l[2]))1882 cdate = datetime.strftime(timestamp, '%Y%m%d')1883 chms = datetime.strftime(timestamp, '%H%M%S')1884 else:1885 cdate = '20' + fname[-1][-8:-2]1886 chms = fname[-1][-2:] + '0000'1887 clist.append(cdate + ' ' + chms + ' '*6 +1888 fname[-1] + ' '*14 + 'ON DISC')1889 clist.sort()1890 with open(c.outputdir + '/' + 'AVAILABLE', 'w') as f:1891 f.write('\n'.join(clist) + '\n')1892 1893 # generate pathnames file1894 pwd = os.path.abspath(c.outputdir)1895 with open(pwd + '/pathnames', 'w') as f:1896 f.write(pwd + '/Options/\n')1897 f.write(pwd + '/\n')1898 f.write(pwd + '/\n')1899 f.write(pwd + '/AVAILABLE\n')1900 f.write(' = == = == = == = == = == == = \n')1901 1902 # create Options dir if necessary1903 if not os.path.exists(pwd + '/Options'):1904 make_dir(pwd+'/Options')1905 1906 # read template COMMAND file1907 with open(os.path.expandvars(os.path.expanduser(1908 c.flexpartdir)) + '/../Options/COMMAND', 'r') as f:1909 lflist = f.read().split('\n')1910 1911 # find index of list where to put in the1912 # date and time information1913 # usually after the LDIRECT parameter1914 i = 01915 for l in lflist:1916 if 'LDIRECT' in l.upper():1917 break1918 i += 11919 1920 # insert the date and time information of run start and end1921 # into the list of lines of COMMAND file1922 lflist = lflist[:i+1] + \1923 [clist[0][:16], clist[-1][:16]] + \1924 lflist[i+3:]1925 1926 # write the new COMMAND file1927 with open(pwd + '/Options/COMMAND', 'w') as g:1928 g.write('\n'.join(lflist) + '\n')1929 1930 # change to outputdir and start the grib2flexpart run1931 # afterwards switch back to the working dir1932 os.chdir(c.outputdir)1933 cmd = [os.path.expandvars(os.path.expanduser(c.flexpartdir)) +1934 '/../FLEXPART_PROGRAM/grib2flexpart', 'useAvailable', '.']1935 execute_subprocess(cmd)1936 os.chdir(pwd)1937 1938 return
Note: See TracChangeset
for help on using the changeset viewer.