Skip to content

Commit

Permalink
Log exception details when converting to unix times; test for nonstan…
Browse files Browse the repository at this point in the history
…dard attribute names and values used by ICON
  • Loading branch information
jameswilburlewis committed Jun 11, 2024
1 parent 07ce5d2 commit 5843e76
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions pytplot/importers/netcdf_to_tplot.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,16 @@ def change_time_to_unix_time(time_var):
'''
Convert the variable to seconds since epoch.
'''
units = time_var.units
# Capitalization of variable attributes may vary...
if hasattr(time_var, 'units'):
units = time_var.units
elif hasattr(time_var, 'Units'):
units = time_var.Units
elif hasattr(time_var,'UNITS'):
units = time_var.UNITS
# ICON uses nonstandard units strings
if units == 'ms':
units = 'milliseconds since 1970-01-01 00:00:00'
dates = num2date(time_var[:], units=units)
unix_times = list()
for date in dates:
Expand Down Expand Up @@ -147,9 +156,10 @@ def netcdf_to_tplot(filenames, time='', prefix='', suffix='', plot=False, merge=
time_var = vfile[this_time]
unix_times = change_time_to_unix_time(time_var)
times_dict[this_time] = unix_times
except:
except Exception as e:
# In this case, we could not handle the time, print an error
logging.error("Could not process time variable '" + this_time + "' for the netcdf variable: '" + var + "'")
logging.error("Exception details: " + str(e))
continue

if var not in masked_vars:
Expand Down

0 comments on commit 5843e76

Please sign in to comment.