-
Notifications
You must be signed in to change notification settings - Fork 110
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add observation traversal logic to LocalExperiment
- Loading branch information
Showing
5 changed files
with
146 additions
and
48 deletions.
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,24 @@ | ||
import xarray as xr | ||
|
||
|
||
def ensure_correct_coordinate_order(ds: xr.Dataset) -> xr.Dataset: | ||
""" | ||
Ensures correct coordinate order or response/param dataset. | ||
Slightly less performant than not doing it, but ensure the | ||
correct coordinate order is applied when doing .to_dataframe(). | ||
It is possible to omit using this and instead pass in the correct | ||
dim order when doing .to_dataframe(), which is always the same as | ||
the .dims of the first data var of this dataset. | ||
""" | ||
# Just to make the order right when | ||
# doing .to_dataframe() | ||
# (it seems notoriously hard to tell xarray to just reorder | ||
# the dimensions/coordinate labels) | ||
data_vars = list(ds.data_vars.keys()) | ||
|
||
# We assume only data vars with the same dimensions, | ||
# i.e., (realization, *index) for all of them. | ||
dim_order_of_first_var = ds[data_vars[0]].dims | ||
return ds[[*dim_order_of_first_var, *data_vars]].sortby( | ||
dim_order_of_first_var[0] # "realization" / "realizations" | ||
) |
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
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