cchdo / hydro

The big ol CCHDO netCDF-CF project
https://hydro.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
1 stars 2 forks source link

Error when converting dataset to exchange with CDOM measurements present #35

Closed asdossant closed 4 months ago

asdossant commented 8 months ago

Attempting to convert a dataset to the exchange format using the to_exchange function gives a KeyError when CDOM measurements are included in the dataset. It looks like the issue comes up specifically when handling the CDOM_WAVELENGTHS coordinate.

Issue: Read in file: ds= read_exchange('/Users/andre/Desktop/bottle_notebook_gui/uow_dirs/20240122_49NZ20170208/1.new_files/49NZ20170208_hy1.csv', checks={'flags':False}, precision_source="database")

Attempt to convert this dataset to exchange format using ds.cchdo.to_exchange().

gives this error:

KeyError                                  Traceback (most recent call last)
Untitled-2.ipynb Cell 2 in ()
----> 1 ds.cchdo.to_exchange()

File "/Users/andre/.pyenv/versions/3.10.11/envs/bottle_gui/lib/python3.10/site-packages/cchdo/hydro/accessors.py", line 419, in to_exchange
    whp_params = self._whpname_from_attrs(var.attrs)

File "/Users/andre/.pyenv/versions/3.10.11/envs/bottle_gui/lib/python3.10/site-packages/cchdo/hydro/accessors.py", line 370, in _whpname_from_attrs
    params.append(WHPNames[(param, unit)])

File "/Users/andre/.pyenv/versions/3.10.11/envs/bottle_gui/lib/python3.10/site-packages/cchdo/params/__init__.py", line 87, in __getitem__
    return self.data[key]

KeyError: ('CDOM{CDOM_WAVELENGTHS}', '/METER')

It seems that hydro is creating the CDOM_WAVELENGTHS coordinate to allow for multispectral CDOM data, so the additional coordinate seems to be causing the issue.

screen_shot_2024-02-12_at_1 39 00_pm_720

Here is the file that was giving this issue: 49NZ20170208_hy1.csv

DocOtak commented 4 months ago

Looks like this got fixed somehow, I seem to be having trouble finding the specific commit that fixed this. I tested the attached file and it seemed to work just fine in cchdo.hydro v1.0.2.8

@asdossant can you confirm this is fixed?

asdossant commented 4 months ago

I also tested it with v1.0.2.8 and it loaded/converted without any problems. I also think it's safe to say it's fixed now.