Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Metadata indecies of UngriddedData are offset relative to the metadata dictionary in some cases #1354

Closed
thorbjoernl opened this issue Sep 30, 2024 · 0 comments · Fixed by #1355
Labels
bug 🐛 Something isn't working

Comments

@thorbjoernl
Copy link
Collaborator

Describe the bug
Please provide a clear and concise description of what the bug is.

  • Pyaerocom version: '0.22.0'
  • Computing platform: NA
  • Configuration file (if applicable): NA
  • Error message (if applicable): NA

To Reproduce
The following script reproduces the error:

import pyaerocom as pya
import pandas as pd
import numpy as np

if __name__ == "__main__":
    VAR = "vmro3max"
    obs_reader = pya.io.ReadUngridded("EBASMC")
    data = obs_reader.read(vars_to_retrieve=VAR)
    data = data.filter_by_meta(ts_type = "hourly", station_id = "NO0001R")
    df = pd.DataFrame()  
    df["time"] = data._data[:, data._TIMEINDEX].astype("datetime64[s]")
    print("UNIQUE METADATAINDEXES:")
    print(np.unique(data._data[:, data._METADATAKEYINDEX]))
    print("METADATA KEYS:")
    print(data.metadata.keys())
    df["station_id"] = [data.metadata[x]["station_id"] for x in data._data[:, data._METADATAKEYINDEX]]

Expected behavior
Metadata key lookup should work without error.

Screenshots

UNIQUE METADATAINDEXES:
[4638. 4639. 4640. 4641. 4642. 4643. 4644. 4645. 4646. 4647. 4648. 4649.
 4650. 4651. 4652. 4653. 4654. 4655. 4656. 4657. 4658. 4659. 4660. 4661.
 4662. 4663. 4664.]
METADATA KEYS:
dict_keys([0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0, 10.0, 11.0, 12.0, 13.0, 14.0, 15.0, 16.0, 17.0, 18.0, 19.0, 20.0, 21.0, 22.0, 23.0, 24.0, 25.0, 26.0])
Traceback (most recent call last):
  File "/home/thlun8736/Documents/work/aerotools-scripts/bug.py", line 16, in <module>
    df["station_id"] = [data.metadata[x]["station_id"] for x in data._data[:, data._METADATAKEYINDEX]]
  File "/home/thlun8736/Documents/work/aerotools-scripts/bug.py", line 16, in <listcomp>
    df["station_id"] = [data.metadata[x]["station_id"] for x in data._data[:, data._METADATAKEYINDEX]]
KeyError: 4638.0

Additional context

  • Unique metadata key indexes has the same number of sequential entries as the dictionary, so it seems likely that some erroneous offset is being applied.
  • UngriddedData.merge may be where this issue occurs as it is the only place which seems to apply an offset.
@thorbjoernl thorbjoernl added the bug 🐛 Something isn't working label Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug 🐛 Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant