-
Notifications
You must be signed in to change notification settings - Fork 1
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 #12 from ungarj/convert_to_xarray
netcdf s3 support
- Loading branch information
Showing
11 changed files
with
269 additions
and
88 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 |
---|---|---|
@@ -1,4 +1,4 @@ | ||
from mapchete_xarray._xarray import InputTile, METADATA, OutputDataWriter | ||
from mapchete_xarray._xarray import InputTile, METADATA, OutputDataWriter, OutputDataReader | ||
|
||
__all__ = ["InputTile", "METADATA", "OutputDataWriter"] | ||
__all__ = ["InputTile", "METADATA", "OutputDataWriter", "OutputDataReader"] | ||
__version__ = "2021.10.0" |
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
Empty file.
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,46 @@ | ||
import json | ||
import xarray as xr | ||
|
||
|
||
def execute( | ||
mp, | ||
band_names=None, | ||
index_band=None, | ||
index_field="index", | ||
slice_id_field="slice_id", | ||
): | ||
""" | ||
Convert raster input array to xarray with optionally named axes. | ||
""" | ||
coords = {} | ||
attrs = {} | ||
with mp.open("raster") as raster: | ||
if raster.is_empty(): | ||
return "empty" | ||
data = raster.read() | ||
|
||
if "indexes" in mp.input: # pragma: no cover | ||
if index_band is None: | ||
raise ValueError("index_band has to be specified if indexes are provided") | ||
s2_indexes = { | ||
i["properties"][slice_id_field]: i["properties"][index_field] | ||
for i in mp.open("indexes").read() | ||
} | ||
attrs.update(slice_ids=s2_indexes) | ||
|
||
if band_names: | ||
if len(band_names) != data.shape[0]: # pragma: no cover | ||
raise ValueError("band_names has to be the same length than input array") | ||
coords.update(bands=band_names) | ||
|
||
return xr.DataArray( | ||
# nd array | ||
data, | ||
# named dimension indexes | ||
coords=coords, | ||
# named dimensions | ||
dims=("bands", "x", "y"), | ||
# additional attributes | ||
attrs=dict(json=json.dumps(attrs)) | ||
) |
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 |
---|---|---|
@@ -1,6 +1,4 @@ | ||
boto3 | ||
mapchete>=0.28 | ||
mapchete[s3]>=2021.11.0 | ||
netCDF4 | ||
s3fs | ||
xarray | ||
zarr |
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
Oops, something went wrong.