NOAA-CSL / MELODIES-MONET

MELODIES MONET - diagnostic tool for evaluating models against a variety of observations including surface, aircraft, and satellite data all within a common framework
https://melodies-monet.readthedocs.io
Apache License 2.0
21 stars 31 forks source link

_wrfchem_mm.py WRF-Chem read issue #149

Closed dwfncar closed 1 year ago

dwfncar commented 1 year ago

With leaving the line 192, “dset = dset.reset_index(["XTIME", "datetime"], drop=True)”, of monetio/models/_wrfchem_mm.py on, it will complain messages below when I read the sample wrf-chem data on Cheyenne.

“Traceback (most recent call last):

  File "/glade/work/swei/Git/mmm/read_fcst.py", line 28, in <module>

    an.open_models()

  File "/glade/work/swei/Git/MELODIES-MONET/melodies_monet/driver.py", line 525, in open_models

    m.open_model_files()

  File "/glade/work/swei/Git/MELODIES-MONET/melodies_monet/driver.py", line 322, in open_model_files

    self.obj = mio.models._wrfchem_mm.open_mfdataset(self.files,**self.mod_kwargs)

  File "/glade/work/swei/Git/monetio/monetio/models/_wrfchem_mm.py", line 192, in open_mfdataset

    dset = dset.reset_index(["XTIME", "datetime"], drop=True)

  File "/glade/work/swei/conda-envs/melodies-monet/lib/python3.9/site-packages/xarray/core/dataset.py", line 4183, in reset_index

    raise ValueError(

ValueError: ('datetime', 'XTIME') are not coordinates with an index”
rschwant commented 1 year ago

It looks like this line of code worked with older versions of xarray and then with more recent updates it stopped working. On xarray's website it says reset_index is legacy code from pandas, so we should probably move away from it.

I think all that has to happen to get this working again with both older and newer versions of xarray is to replace this: dset = dset.reset_index(["XTIME", "datetime"], drop=True)

With this instead: dset = dset.reset_coords(["XTIME", "datetime"], drop=True)

The overall goal was just to remove XTIME and datetime as coordinates and it seems like the second option does this equally well and is the preferred method. I'm at a conference, but @zmoon I may be able to test this more tomorrow or if you agree with this change and just want to update this in MONETIO feel free.

rschwant commented 1 year ago

This is fixed on the develop branch of MONETIO now (https://github.com/noaa-oar-arl/monetio/pull/95). I will close this once this fix is pushed to the stable branch of MONETIO.

rschwant commented 1 year ago

This is updated in the stable branch of MONETIO now.