Open jameswilburlewis opened 4 months ago
For the Cluster pressure tensor variables and similar situations, we might be able to get away with adding the extra dimension by checking whether the variable has too many DEPEND_N attributes for its actual number of dimensions. Normally the pressure tensor would have dimensions of time x 3 x 3, with DEPEND_0, DEPEND_1, and DEPEND_2. If we lose the time dimension, we 3x3 instead of 1x3x3, so DEPEND_2 is dangling. If we see that DEPEND_0 has a single timestamp, and if there's an extra DEPEND_N, it might be safe to add the extra dimension back.
Some MMS support variables (e.g. FEEPS energy upper/lower/centoid arrays)have a DEPEND_0 but don't actually have a time dimension. Those FEEPS variables are 1-D, I think, and they are marked non-record-variant despite having a DEPEND_0 attribute. Usually there's more than one timestamp, but it's possible this case might collide with the Cluster case, with opposite actions required for each.
For the time being, I've added code to cdf_to_tplot to restore the probably-missing time dimension for the case when there is only a single timestamp.
While troubleshooting a crash loading Cluster data, I discovered a problem with the CDFs themselves: if the CDF contains only a single sample for an array-valued variable, it can lose its leading [time] dimension and is marked as "non-record-variant".
In this example:
we load moments data for all four probes. C1 has multiple samples falling into the selected time range, but C3 only has a single timestamp. C4 seems to have nothing available. Here are some log messages from loading the C3 data, with multiple errors:
The scalar-valued variables seem to have degenerated from 1-element arrays, as they should be, to bare scalars. The array-valued variables (velocity and pressure_tensor) have also lost their leading dimension. Using the cdfeditor command-line utility directly on the CDFs returned by the CSA query (so, bypassing any possible issues PySPEDAS, PyTplot, or cdflib) shows that the C3 variables are marked non-record-variant, which is incorrect.
The same variables for the C1 CDF, with multiple samples, load correctly and are correctly marked as record-variant.
Other than adding some defensive programming to cdf_to_tplot to avoid outright crashes, there's not going to be a clean way to handle this. We can't just add the time dimension back, because that would break applications that rely on correctly marked NRV variables having the expected number of dimensions.