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

Colocation after running GriddedData.interpolate() does not work #1361

Closed
thorbjoernl opened this issue Oct 7, 2024 · 1 comment · Fixed by #1365
Closed

Colocation after running GriddedData.interpolate() does not work #1361

thorbjoernl opened this issue Oct 7, 2024 · 1 comment · Fixed by #1365
Assignees
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):
Traceback (most recent call last):
  File "/home/thlun8736/Documents/work/aerotools-scripts/bilinear.py", line 36, in <module>
    colocated_data = pya.colocation.colocation_utils.colocate_gridded_ungridded(
  File "/home/thlun8736/Documents/work/aerotools-scripts/venv/lib/python3.10/site-packages/pyaerocom/colocation/colocation_utils.py", line 818, in colocate_gridded_ungridded
    grid_stat_data = data.to_time_series(longitude=ungridded_lons, latitude=ungridded_lats)
  File "/home/thlun8736/Documents/work/aerotools-scripts/venv/lib/python3.10/site-packages/pyaerocom/griddeddata.py", line 1174, in to_time_series
    result = self._to_time_series_xarray(scheme=scheme, add_meta=add_meta, **coords)
  File "/home/thlun8736/Documents/work/aerotools-scripts/venv/lib/python3.10/site-packages/pyaerocom/griddeddata.py", line 1217, in _to_time_series_xarray
    subset = extract_latlon_dataarray(
  File "/home/thlun8736/Documents/work/aerotools-scripts/venv/lib/python3.10/site-packages/pyaerocom/helpers.py", line 189, in extract_latlon_dataarray
    subset = arr.sel(where, method=method)
  File "/home/thlun8736/Documents/work/aerotools-scripts/venv/lib/python3.10/site-packages/xarray/core/dataarray.py", line 1670, in sel
    ds = self._to_temp_dataset().sel(
  File "/home/thlun8736/Documents/work/aerotools-scripts/venv/lib/python3.10/site-packages/xarray/core/dataset.py", line 3184, in sel
    query_results = map_index_queries(
  File "/home/thlun8736/Documents/work/aerotools-scripts/venv/lib/python3.10/site-packages/xarray/core/indexing.py", line 185, in map_index_queries
    grouped_indexers = group_indexers_by_index(obj, indexers, options)
  File "/home/thlun8736/Documents/work/aerotools-scripts/venv/lib/python3.10/site-packages/xarray/core/indexing.py", line 144, in group_indexers_by_index
    raise KeyError(f"no index found for coordinate {key!r}")
KeyError: "no index found for coordinate 'lat'"

To Reproduce

  • Run the following script with and without the commented line uncommented. It only fails if interpolation has been applied.
import iris.analysis
import iris
import iris.cube
import pyaerocom as pya

if __name__ == "__main__":
    mod_reader = pya.io.mscw_ctm.reader.ReadMscwCtm(
        "EMEP",
        data_dir="/lustre/storeB/project/fou/kl/emep/ModelRuns/2024_REPORTING/TRENDS/2020",
    )

    mod_data: pya.griddeddata.GriddedData = mod_reader.read_var("concnh3", "daily")
    obs_reader = pya.io.ReadUngridded("EBASMC")

    obs_data: pya.ungriddeddata.UngriddedData = obs_reader.read(
        vars_to_retrieve="concnh3"
    )

    coord_pairs = obs_data._get_stat_coords()[1]
    lat, lon = list(zip(*coord_pairs))

    #mod_data = mod_data.interpolate(scheme=iris.analysis.Linear(), latitude=lat, longitude=lon)

    colocated_data = pya.colocation.colocation_utils.colocate_gridded_ungridded(
        mod_data, obs_data
    )

    print(colocated_data)

Expected behavior
Both cases should work without error.

**Screenshots

Pasted image 20241007092439

Pasted image 20241007092619

Pasted image 20241007092714

Additional context
Add any other context about the problem here.

@thorbjoernl thorbjoernl added the bug 🐛 Something isn't working label Oct 7, 2024
@thorbjoernl thorbjoernl self-assigned this Oct 7, 2024
@thorbjoernl
Copy link
Collaborator Author

The issue was on my end. lat and lon passed to sample_coords needs to be a ascending ordered list with duplicates removed. Otherwise interpolation will turn the dimcoords int auxcoords during interpolation (since dimcoords must be monotonic)

I'll make a small PR to clarify this requirement to GriddedData.interpolate()

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