spedas / pyspedas

Python-based Space Physics Environment Data Analysis Software
https://pyspedas.readthedocs.io/
MIT License
147 stars 58 forks source link

tplot crashes while trying to plot some MAVEN data #765

Closed nickssl closed 5 months ago

nickssl commented 6 months ago

Two different problems, one in specplot.py the other in lineplot.py.

To reproduce the first error:

from pyspedas.maven.spdf import load from pytplot import tplot sta_vars = load(trange=['2020-12-30', '2020-12-31'], instrument='static', datatype='c0-64e2m') print(sta_vars) tplot('bkg')

Traceback (most recent call last): File "", line 1, in File "C:\work\github\PyTplot\pytplot\tplot.py", line 158, in tplot return mpl_tplot(name, var_label=var_label, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\work\github\PyTplot\pytplot\MPLPlotter\tplot.py", line 370, in tplot plot_created = specplot(var_data, var_times, this_axis, yaxis_options, zaxis_options, plot_extras, colorbars, axis_font_size, fig, variable, time_idxs=time_idxs, style=style) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\work\github\PyTplot\pytplot\MPLPlotter\specplot.py", line 103, in specplot spec_options['norm'] = mpl.colors.LogNorm(vmin=np.nanmin(var_data.v), vmax=np.nanmax(var_data.v)) ^^^^^^^^^^ AttributeError: 'variable' object has no attribute 'v'. Did you mean: 'v1'?

nickssl commented 6 months ago

To reproduce the second error:

swe_vars = load(trange=['2014-10-18', '2014-10-19'], instrument='swea') print(swe_vars) tplot('diff_en_fluxes')

Traceback (most recent call last): File "", line 1, in File "C:\work\github\PyTplot\pytplot\tplot.py", line 158, in tplot return mpl_tplot(name, var_label=var_label, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\work\github\PyTplot\pytplot\MPLPlotter\tplot.py", line 375, in tplot plot_created = lineplot(var_data, var_times, this_axis, line_opts, yaxis_options, plot_extras, pseudo_plot_num=pseudo_plot_num, time_idxs=time_idxs, style=style, var_metadata=var_metadata) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\work\github\PyTplot\pytplot\MPLPlotter\lineplot.py", line 184, in lineplot this_line = plotter(var_times, var_data.y[time_idxs] if num_lines == 1 else var_data.y[time_idxs, line], color=color, ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\work\github\envs\pyspedas\Lib\site-packages\matplotlib\axes_axes.py", line 1721, in plot lines = [self._get_lines(self, args, data=data, **kwargs)] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "C:\work\github\envs\pyspedas\Lib\site-packages\matplotlib\axes_base.py", line 303, in call yield from self._plot_args( ^^^^^^^^^^^^^^^^ File "C:\work\github\envs\pyspedas\Lib\site-packages\matplotlib\axes_base.py", line 502, in _plot_args raise ValueError(f"x and y can be no greater than 2D, but have " ValueError: x and y can be no greater than 2D, but have shapes (10800,) and (10800, 16, 64)

jameswilburlewis commented 5 months ago

The first (specplot) issue may have been fixed now, after Jim M's recent pytplot changes. With the latest version of pytplot, I get no errors (but the plot is blank?).

I'm still getting an error for the second case (which is also probably supposed to be a specplot...it's no longer trying to plot it as lines). But it's a different error:

['diff_en_fluxes']
Traceback (most recent call last):
  File "/Users/jwl/PycharmProjects/pyspedas/venv/lib/python3.9/site-packages/IPython/core/interactiveshell.py", line 3550, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)
  File "<ipython-input-3-d9ef76b8f56f>", line 3, in <module>
    tplot('diff_en_fluxes')
  File "/Users/jwl/PycharmProjects/PyTplot/pytplot/tplot.py", line 158, in tplot
    return mpl_tplot(name, var_label=var_label,
  File "/Users/jwl/PycharmProjects/PyTplot/pytplot/MPLPlotter/tplot.py", line 131, in tplot
    temp_dq = pytplot.tplot_utilities.reduce_spec_dataset(name=variable)
  File "/Users/jwl/PycharmProjects/PyTplot/pytplot/tplot_utilities.py", line 718, in reduce_spec_dataset
    coordinate_to_plot = da.attrs['plot_options']['extras']['spec_dim_to_plot']
KeyError: 'spec_dim_to_plot'

I think this is also due to Jim's recent changes. Maybe we need to set this option in cdf_to_tplot? Is there a good default, or can we figure out what it needs to be in cdf_to_tplot?