Changeset 2238 in lmdz_wrf for trunk/tools/read_grib.py
- Timestamp:
- Nov 17, 2018, 2:56:47 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/tools/read_grib.py
r2232 r2238 1 1 # FROM: https://pypi.org/project/pupygrib/ 2 from optparse import OptionParser 2 3 import numpy as np 3 4 import pupygrib … … 8 9 9 10 errormsg = 'ERROR -- error -- ERROR -- error' 10 11 ifile = 'ERAI_pl200503_130.grib'12 13 ofile = 'ERAI_pl_130.nc'14 11 15 12 def grib128_ncname(varid): … … 53 50 return [varn,Lvarn,units,cfvalues[0], cfvalues[1], cfvalues[4].replace('|', ' ')] 54 51 55 timeu = 'minutes since 1949-12-01 00:00:00' 52 parser = OptionParser() 53 parser.add_option("-g", "--grib_file", dest="gribfile", help="GRIB file to use", 54 metavar="FILE") 55 parser.add_option("-o", "--output_file", dest="ncfile", help="name of NC file to generate", 56 metavar="FILE") 57 parser.add_option("-t", "--timeunits", dest="timeunits", 58 help="CF reference of time values [Tunits] since [DateRef] ('!', for spaces minutes!since!1949-12-01!00:00:00 as default)", 59 metavar="STRING") 60 61 (opts, args) = parser.parse_args() 56 62 57 63 ####### ####### 58 64 ## MAIN 59 65 ####### 66 67 if opts.gribfile is None: 68 print errormsg 69 print " no grib input file name provided !!" 70 print " you should provide one file name as -g [FileName]" 71 quit(-1) 72 73 if not os.path.isfile(opts.gribfile): 74 print errormsg 75 print " no grib file '" + opts.gribfile + "' found !!" 76 quit(-1) 77 else: 78 ifile = opts.gribfile 79 80 if opts.ncfile is None: 81 print errormsg 82 print " no netcdf output file name provided !!" 83 print " you should provide one file name as -o [FileName]" 84 quit(-1) 85 else: 86 ofile = opts.ncfile 87 88 if opts.timeunits is None: 89 print errormsg 90 print " no time units provided !!" 91 print " using the default ones as 'minutes since 1949-12-01 00:00:00'" 92 quit(-1) 93 else: 94 timeu = opts.timeunits.replace('!', ' ') 60 95 61 96 with open(ifile, 'rb') as stream:
Note: See TracChangeset
for help on using the changeset viewer.