Skip to content
Snippets Groups Projects
Commit 6d2b0861 authored by Nick Bearson's avatar Nick Bearson
Browse files

prevent tile files from having 'units' attributes longer than 26 characters

parent 255fea52
No related branches found
No related tags found
No related merge requests found
...@@ -300,7 +300,7 @@ def get_cspp_gglm_version(): ...@@ -300,7 +300,7 @@ def get_cspp_gglm_version():
return "unknown" return "unknown"
def add_gglm_attrs(netcdf_filename, input_filenames): def add_cspp_attrs(netcdf_filename, input_filenames):
try: try:
nc = Dataset(netcdf_filename, 'a') nc = Dataset(netcdf_filename, 'a')
setattr(nc, 'cspp_geo_gglm_version', get_cspp_gglm_version()) setattr(nc, 'cspp_geo_gglm_version', get_cspp_gglm_version())
...@@ -310,6 +310,17 @@ def add_gglm_attrs(netcdf_filename, input_filenames): ...@@ -310,6 +310,17 @@ def add_gglm_attrs(netcdf_filename, input_filenames):
except: except:
log.error("could not add CSPP Geo GGLM attributes to {}".format(netcdf_filename)) log.error("could not add CSPP Geo GGLM attributes to {}".format(netcdf_filename))
def awipsify_file_attributes(netcdf_filename):
try:
nc = Dataset(netcdf_filename, 'a')
for var in nc.variables:
if hasattr(var, 'units'):
# AWIPS requires the units attribute to be 26 characters or less
setattr(var, 'units', getattr(var, 'units')[0:26])
nc.close()
except:
log.error("could not tweak attributes on tile file {}".format(netcdf_filename))
def alarm_handler(signum, frame): def alarm_handler(signum, frame):
raise OSError("Timeout exceeded!") raise OSError("Timeout exceeded!")
...@@ -352,7 +363,7 @@ if __name__ == '__main__': ...@@ -352,7 +363,7 @@ if __name__ == '__main__':
# we need to add attributes here due to an issue where satpy (or its dependencies) are # we need to add attributes here due to an issue where satpy (or its dependencies) are
# holding the input gridded file open until the process exits # holding the input gridded file open until the process exits
for f in gridded_files: for f in gridded_files:
add_gglm_attrs(f, glm_filenames) add_cspp_attrs(f, glm_filenames)
# (optionally) do tiling # (optionally) do tiling
if args.create_tiles: if args.create_tiles:
...@@ -394,7 +405,8 @@ if __name__ == '__main__': ...@@ -394,7 +405,8 @@ if __name__ == '__main__':
tiled_path = os.path.join(tempdir_path, '{}_GLM-L2-GLM*-M?_G??_T??_*.nc'.format(args.system_environment_prefix_tiles)) tiled_path = os.path.join(tempdir_path, '{}_GLM-L2-GLM*-M?_G??_T??_*.nc'.format(args.system_environment_prefix_tiles))
tiled_files = glob(tiled_path) tiled_files = glob(tiled_path)
for f in tiled_files: for f in tiled_files:
add_gglm_attrs(f, glm_filenames) add_cspp_attrs(f, glm_filenames)
awipsify_file_attributes(f)
shutil.move(f, os.path.join(args.output_dir, os.path.basename(f))) shutil.move(f, os.path.join(args.output_dir, os.path.basename(f)))
for f in gridded_files: for f in gridded_files:
shutil.move(f, os.path.join(args.output_dir, os.path.basename(f))) shutil.move(f, os.path.join(args.output_dir, os.path.basename(f)))
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment