alan-turing-institute / clim-recal

Open repository of methods for recalibrating & bias correcting UKCP18 climate projections data
https://alan-turing-institute.github.io/clim-recal/
MIT License
10 stars 0 forks source link

Fix coordinate projections #151

Open griff-rees opened 3 months ago

griff-rees commented 3 months ago

Potential solutions

Separately (but related)

griff-rees commented 3 months ago

@stuartlynn thanks for suggesting following your process_data.py example. I think there's an inherent issue with the way the dimensions are intertwined in the raw UKCP2.2km files that makes this a bit tricky, and the files you're working from have solved that problem (via sticking with the 360 day calendar).

Here's what I've tried to so far:

>>> from xarray.core.dataset import Dataset

>>> lat_lon: Dataset = expanded_calendar.rio.set_spatial_dims("grid_longitude", "grid_latitude", True)
>>> lat_lon_projected: Dataset = lat_lon.rio.reproject("EPSG:27700")
*** rioxarray.exceptions.TooManyDimensions: Only 2D and 3D data arrays supported. Data variable: tasmin

This matches a question I asked on the rioxarray repo some time ago.

Continuing with your suggestion:

>>> without_attrs: DataArray = DataArray(
...    data=expanded_calendar.tasmin.to_numpy(), 
...    coords={'time': expanded_calendar.tasmin.time, 
...            "latitude": expanded_calendar.tasmin.latitude, 
...            "longitude": expanded_calendar.tasmin.longitude}, 
...    name="tasmin")
*** ValueError: coordinate time has dimensions ('time',), but these are not a subset of the DataArray
dimensions ('dim_0', 'dim_1', 'dim_2', 'dim_3')

I'm thinking if I can get the raw coordinate values via your .to_numpy() method that might help. I'll keep trying.