@@ -23,7 +23,15 @@ def change_time_to_unix_time(time_var):
2323 # ICON uses nonstandard units strings
2424 if units == "ms" :
2525 units = "milliseconds since 1970-01-01 00:00:00"
26- dates = num2date (time_var [:], units = units )
26+ # Check if the long_name attribute has stored the epoch description (POES/METOP):
27+ elif hasattr (time_var , "long_name" ):
28+ if time_var .long_name == "milliseconds since 1970" :
29+ units = "milliseconds since 1970-01-01 00:00:00"
30+
31+ time_data = time_var [:]
32+ if hasattr (time_data ,"data" ):
33+ time_data = time_var [:].data
34+ dates = num2date (time_data , units = units )
2735 unix_times = list ()
2836 for date in dates :
2937 unix_time = calendar .timegm (date .timetuple ()) + date .microsecond / 1e6
@@ -130,17 +138,27 @@ def netcdf_to_tplot(
130138 # If multiple matching keys are found, the one that appears latest in the above list
131139 # will take precedence
132140 var_fill_value = atts_dict [key ]
141+
142+ if hasattr (reg_var [:],"get_fill_value" ):
143+ var_fill_value = reg_var [:].get_fill_value ()
133144
134145 # If var_fill_value is None, or already NaN, there's nothing to do here.
135146 # Integer arrays can't be NaN-filled, so if var_fill_value is any kind of integer, skip those too.
136147 # Some missions have strings defined as fill values. (ICON)
137148 if var_fill_value is not None and not isinstance (var_fill_value , np .integer ) and not isinstance (var_fill_value , str ) and not np .isnan (var_fill_value ):
138149 # We want to force missing values to be nan so that plots don't look strange
139- var_mask = np .ma .masked_where (
140- reg_var == np .float32 (var_fill_value ), reg_var
141- )
142- var_filled = np .ma .filled (var_mask , np .nan )
143- masked_vars [var ] = var_filled
150+ if hasattr (reg_var [:],"data" ):
151+ var_mask = np .ma .masked_where (
152+ reg_var [:].data == np .float32 (var_fill_value ), reg_var [:].data
153+ )
154+ var_filled = np .ma .filled (var_mask , np .nan )
155+ masked_vars [var ] = var_filled
156+ else :
157+ var_mask = np .ma .masked_where (
158+ reg_var == np .float32 (var_fill_value ), reg_var
159+ )
160+ var_filled = np .ma .filled (var_mask , np .nan )
161+ masked_vars [var ] = var_filled
144162 else :
145163 var_filled = reg_var
146164 masked_vars [var ] = var_filled
@@ -168,8 +186,19 @@ def netcdf_to_tplot(
168186 # If this_time does not exist, we can't save this as tplot variable.
169187 continue
170188 elif this_time == var :
171- # If this_time has the same name as the current variable, do not save it.
172- continue
189+ # The time the variable depends on may not have been set.
190+ # Check if time is a variable:
191+ if 'time' in vars_and_atts .keys ():
192+ # If it is, check if the sizes match:
193+ if vfile [var ].size == vfile ['time' ].size :
194+ # If they do, we can infer that the time variable is the one we want here.
195+ this_time = "time"
196+ else :
197+ # If not, it probably depends on something else / nothing.
198+ continue
199+ else :
200+ # If this_time has the same name as the current variable, do not save it.
201+ continue
173202
174203 # Find the time values (as unix times).
175204 if this_time in times_dict :
0 commit comments