generated from openclimatefix/ocf-template
-
-
Notifications
You must be signed in to change notification settings - Fork 4
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
Added icon to nwp providers #72
Open
gabrielelibardi
wants to merge
7
commits into
openclimatefix:main
Choose a base branch
from
gabrielelibardi:added_icon_to_nwp_providers
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
c00fc9c
icon data for the load test
gabrielelibardi 7fddd03
added icon to providers
gabrielelibardi f4828a6
added test_load_icon_eu
gabrielelibardi 0240bda
added path to icon-eu dataset
gabrielelibardi a68183f
got rid of transform_to_channels using to_array instead
gabrielelibardi 3efd9f1
cutting the steps to only include data with hourly granularity
gabrielelibardi dee99fb
adjusted test for icon_eu
gabrielelibardi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
"""DWD ICON Loading""" | ||
|
||
import pandas as pd | ||
import xarray as xr | ||
import fsspec | ||
|
||
from ocf_data_sampler.load.nwp.providers.utils import open_zarr_paths | ||
|
||
def transform_to_channels(nwp : xr.Dataset): | ||
""" | ||
Adds a channel dimension to the NWP data | ||
|
||
Args: | ||
nwp: NWP data without channel dimension | ||
|
||
Returns: | ||
NWP data with channel dimension | ||
""" | ||
|
||
channel_data = [] | ||
channel_names = [] | ||
|
||
for var_name in nwp.data_vars: | ||
data_array = nwp[var_name] | ||
expanded_data = data_array.expand_dims(dim={"channel": [var_name]}) | ||
|
||
channel_data.append(expanded_data) | ||
channel_names.append(var_name) | ||
|
||
nwp_channels = xr.concat(channel_data, dim="channel") | ||
nwp_channels["channel"] = channel_names | ||
|
||
return nwp_channels | ||
|
||
def remove_isobaric_lelvels_from_coords(nwp: xr.Dataset) -> xr.Dataset: | ||
""" | ||
Removes the isobaric levels from the coordinates of the NWP data | ||
|
||
Args: | ||
nwp: NWP data | ||
|
||
Returns: | ||
NWP data without isobaric levels in the coordinates | ||
""" | ||
variables_to_drop = [var for var in nwp.data_vars if 'isobaricInhPa' in nwp[var].dims] | ||
return nwp.drop_vars(["isobaricInhPa"] + variables_to_drop) | ||
|
||
def open_icon_eu(zarr_path) -> xr.Dataset: | ||
""" | ||
Opens the ICON data | ||
|
||
ICON EU Data is on a regular lat/lon grid | ||
It has data on multiple pressure levels, as well as the surface | ||
Each of the variables is its own data variable | ||
|
||
Args: | ||
zarr_path: Path to the zarr to open | ||
|
||
Returns: | ||
Xarray DataArray of the NWP data | ||
""" | ||
# Open the data | ||
nwp = open_zarr_paths(zarr_path, time_dim="time") | ||
nwp = nwp.rename({"time": "init_time_utc"}) | ||
# Sanity checks. | ||
time = pd.DatetimeIndex(nwp.init_time_utc) | ||
assert time.is_unique | ||
assert time.is_monotonic_increasing | ||
nwp = nwp.isel(step=slice(0, 48)) | ||
nwp = remove_isobaric_lelvels_from_coords(nwp) | ||
nwp = transform_to_channels(nwp) | ||
print("loaded icon eu data with shape", nwp.shape) | ||
return nwp.transpose('init_time_utc', 'step', 'channel', 'latitude', 'longitude') | ||
|
||
|
||
def open_icon_global(zarr_path) -> xr.Dataset: | ||
""" | ||
Opens the ICON data | ||
|
||
ICON Global Data is on an isohedral grid, so the points are not regularly spaced | ||
It has data on multiple pressure levels, as well as the surface | ||
Each of the variables is its own data variable | ||
|
||
Args: | ||
zarr_path: Path to the zarr to open | ||
|
||
Returns: | ||
Xarray DataArray of the NWP data | ||
""" | ||
# Open the data | ||
nwp = open_zarr_paths(zarr_path, time_dim="time") | ||
nwp = nwp.rename({"time": "init_time_utc"}) | ||
# ICON Global archive script didn't define the values to be | ||
# associated with lat/lon so fixed here | ||
nwp.coords["latitude"] = (("values",), nwp.latitude.values) | ||
nwp.coords["longitude"] = (("values",), nwp.longitude.values) | ||
# Sanity checks. | ||
time = pd.DatetimeIndex(nwp.init_time_utc) | ||
assert time.is_unique | ||
assert time.is_monotonic_increasing | ||
return nwp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am I right in thinking that the input here is an xarray
Dataset
which has multiple data variables for each NWP variable and we want to go from that to aDataArray
(e.g. one data variable but an extra channel dimension?)I think a simpler approach might be to do something like what is done here https://github.com/openclimatefix/ocf_datapipes/blob/main/ocf_datapipes/load/nwp/providers/gfs.py#L26 where we use
to_array()
on the Dataset to convert it to aDataArray
and then rename thevariable
dimension which is created withto_array()
tochannel
But I may have misunderstood the intention/need for this function
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you are perfectly right, I deleted this and use to_array() instead, thx for pointing it out!