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

Fix xarray-compatible Zarr generation for DegreeDays indicators #145

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

j08lue
Copy link
Contributor

@j08lue j08lue commented Feb 26, 2025

What this PR accomplishes

How to test it

Run the following command:

CEDA_USERNAME=<username> CEDA_PASSWORD=<password> os_climate_hazard degree_days_indicator --store ./uk_60km_dd_28 --source_dataset UKCP18 --source_dataset_kwargs "{'resolution':'60km','domain':'uk'}" --gcm_list "[ukcp18]" --scenario_list "[rcp85]" --threshold_list "[]" --threshold_temperature 28 --central_year_list "[2030,2040,2050,2060,2070,2080,2090]" --central_year_historical 2005 --window_years 20 --write_xarray_compatible_zarr true --dask_cluster_kwargs "{'n_workers': 1, 'threads_per_worker': 1}"

and verify that the output folder structure in uk_60km_dd_28 is

/chronic_heat/osc/v2/
├── longitude
│   └── 0.0.0.0
├── latitude
│   └── 0.0.0.0
├── mean_degree_days_v2_above_28c_ukcp18_rcp85_2030
│   └── 0.0.0.0
├── mean_degree_days_v2_above_28c_ukcp18_rcp85_2040
│   └── 0.0.0.0
...
├── mean_degree_days_v2_above_28c_ukcp18_rcp85_2090
│   └── 0.0.0.0
└── spatial_ref

@j08lue
Copy link
Contributor Author

j08lue commented Feb 26, 2025

NB: Regarding the overall goal to produce data cube and xarray friendly Zarr output,

this solution falls short.

You cannot open individual arrays - this fails:

xr.open_dataset("uk_60km_dd_28/chronic_heat/osc/v2/mean_degree_days_v2_above_28c_ukcp18_rcp85_2030", engine="zarr", consolidated=False)

but you can open the group with

xr.open_dataset("uk_60km_dd_28/chronic_heat/osc/v2", engine="zarr", consolidated=False)

and get a Dataset where all the arrays are variables.

<xarray.Dataset>
Dimensions:                                          (latitude: 18,
                                                      longitude: 26, index: 1)
Coordinates:
  * latitude                                         (latitude) float64 60.86...
  * longitude                                        (longitude) float64 -13....
    spatial_ref                                      int64 ...
Dimensions without coordinates: index
Data variables:
    mean_degree_days_v2_above_28c_ukcp18_rcp85_2030  (index, latitude, longitude) float32 ...
    mean_degree_days_v2_above_28c_ukcp18_rcp85_2040  (index, latitude, longitude) float32 ...
    mean_degree_days_v2_above_28c_ukcp18_rcp85_2050  (index, latitude, longitude) float32 ...
    mean_degree_days_v2_above_28c_ukcp18_rcp85_2060  (index, latitude, longitude) float32 ...
    mean_degree_days_v2_above_28c_ukcp18_rcp85_2070  (index, latitude, longitude) float32 ...
    mean_degree_days_v2_above_28c_ukcp18_rcp85_2080  (index, latitude, longitude) float32 ...
    mean_degree_days_v2_above_28c_ukcp18_rcp85_2090  (index, latitude, longitude) float32 ...

Cool enough (although data cube would be nicer), but how would we describe this in STAC?

Variables with these long parameter chains as names seem to be the wrong way to describe the dimensionality of this dataset.

However, since the maintainers' intention is to maintain backwards compatibility of the Zarr output, this may be the only way.

@j08lue j08lue marked this pull request as ready for review February 26, 2025 12:25
@j08lue
Copy link
Contributor Author

j08lue commented Feb 26, 2025

This notebook shows that the output produced with this branch here can be read with both OscZarr and Xarray: https://gist.github.com/j08lue/ff9634d1221dd00f0707064710ce90f5

@j08lue j08lue force-pushed the fix/explicit-zarr branch 2 times, most recently from 7551f01 to 56c826a Compare February 26, 2025 20:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant