Skip to content

Commit

Permalink
Fixed script location.
Browse files Browse the repository at this point in the history
  • Loading branch information
[email protected] authored and [email protected] committed Nov 10, 2020
1 parent 2897cf4 commit 456fee5
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 137 deletions.
33 changes: 24 additions & 9 deletions parallel/scripts/viirsgrib2nc4.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
__license__ = 'GPL'

'''
Simple utility to convert NCEP grib2 aerosol file into a netCDF4 file
Utilizes wgrib2 utility from NWPROD
Adapted utility to convert VIIRS GVF file into a netCDF4 file
Utilizes wgrib2 from input environmental variable path -- P. Campbell
'''

import os
Expand Down Expand Up @@ -47,7 +47,8 @@ def get_exec_path(exec_name, verbose=False):
:param type: str
'''

exec_path_def = '/nwprod2/grib_util.v1.0.0/exec/%s' % exec_name
## exec_path_def = '/nwprod2/grib_util.v1.0.0/exec/%s' % exec_name
exec_path_def = '/gpfs/hps/nco/ops/nwprod/grib_util.v1.0.5/exec/%s' % exec_name

exec_path = find_executable(exec_name)
if exec_path is None:
Expand All @@ -65,13 +66,19 @@ def chdir(fname):
return os.path.basename(fname)


def change_file(finput,verbose=False):
def change_file(finput,foutput=None,execpath=None,verbose=False):
# first change directory and get file name
# fname = chdir(finput)
fname = finput
# this will create 3 files and append to them
wgrib2 = get_exec_path('wgrib2', verbose=verbose)
fout = foutput
xpath = execpath

# this will create 3 files and append to them
if xpath == None:
wgrib2 = get_exec_path('wgrib2', verbose=verbose)
else:
wgrib2 = xpath

# ENTIRE ATMOSPHERE GRIB LAYER
#cmd = '%s %s -match "entire atmosphere:" -nc_nlev 1 -append -set_ext_name 1 -netcdf %s.entire_atm.nc' % (wgrib2, fname, fname)
#execute_subprocess(cmd, verbose=verbose)
Expand All @@ -83,7 +90,10 @@ def change_file(finput,verbose=False):
#execute_subprocess(cmd, verbose=verbose)

# VIIRS SURFACE GREENESS FRACTION
cmd = '%s %s -match "surface:" -nc_nlev 1 -append -set_ext_name 1 -netcdf %s.nc' % (wgrib2, fname, fname)
if fout == None:
cmd = '%s %s -match "surface:" -nc_nlev 1 -append -set_ext_name 1 -netcdf %s.nc' % (wgrib2, fname, fname)
else:
cmd = '%s %s -match "surface:" -nc_nlev 1 -append -set_ext_name 1 -netcdf %s.nc' % (wgrib2, fname, fout)
execute_subprocess(cmd, verbose=verbose)


Expand All @@ -92,22 +102,27 @@ def change_file(finput,verbose=False):
parser = ArgumentParser(description='convert grib2 file to netCDF4 file', formatter_class=ArgumentDefaultsHelpFormatter)
parser.add_argument('-f', '--files', help='input grib2 file name', type=str, required=True)
parser.add_argument('-v', '--verbose', help='print debugging information', action='store_true', required=False)
parser.add_argument('-o', '--outputf', help='output nc4 file name prefix', type=str, required=False)
parser.add_argument('-x', '--execpath', help='executable path definition', type=str, required=False)

args = parser.parse_args()

finput = args.files
verbose = args.verbose
foutput = args.outputf
execpath = args.execpath

files = sorted(glob(finput))
for i,j in enumerate(files):
# files[i] = os.path.realpath(j)
files[i] = j
if len(files) == 1:
finput = files[0]
change_file(finput,verbose=verbose)
change_file(finput,foutput,execpath,verbose=verbose)
else:
for i in files:
finput = i
print('FINPUT -> ',finput)
change_file(finput,verbose=verbose)
change_file(finput,foutput,execpath,verbose=verbose)

sys.exit(0)
128 changes: 0 additions & 128 deletions viirsgrib2nc4.py

This file was deleted.

0 comments on commit 456fee5

Please sign in to comment.