-
Notifications
You must be signed in to change notification settings - Fork 54
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #761 from norlandrhagen/read_zarr_ex
Adds open zarr + rechunk example to feedstock
- Loading branch information
Showing
5 changed files
with
57 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# GPCP Rechunk | ||
|
||
|
||
```{literalinclude} ../../../examples/feedstock/gpcp_rechunk.py | ||
``` |
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,40 @@ | ||
# Example recipe to demonstate reading from an existing Zarr store and | ||
# writing a new Zarr store with a differant chunking structure | ||
|
||
|
||
import apache_beam as beam | ||
import zarr | ||
|
||
from pangeo_forge_recipes.patterns import FileType, pattern_from_file_sequence | ||
from pangeo_forge_recipes.transforms import ( | ||
ConsolidateDimensionCoordinates, | ||
ConsolidateMetadata, | ||
OpenWithXarray, | ||
StoreToZarr, | ||
) | ||
|
||
pattern = pattern_from_file_sequence( | ||
["https://ncsa.osn.xsede.org/Pangeo/pangeo-forge/gpcp-feedstock/gpcp.zarr"], | ||
concat_dim="time", | ||
) | ||
|
||
|
||
def test_ds(store: zarr.storage.FSStore) -> zarr.storage.FSStore: | ||
import xarray as xr | ||
|
||
assert xr.open_dataset(store, engine="zarr", chunks={}) | ||
return store | ||
|
||
|
||
recipe = ( | ||
beam.Create(pattern.items()) | ||
| OpenWithXarray(file_type=FileType("zarr"), xarray_open_kwargs={"chunks": {}}) | ||
| StoreToZarr( | ||
store_name="gpcp_rechunked.zarr", | ||
target_chunks={"time": 9226, "latitude": 16, "longitude": 36, "nv": 2}, | ||
combine_dims=pattern.combine_dim_keys, | ||
) | ||
| ConsolidateDimensionCoordinates() | ||
| ConsolidateMetadata() | ||
| "Test dataset" >> beam.Map(test_ds) | ||
) |
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