import xarray as xr
from xcube.core.gridmapping import GridMapping
from xcube.core.resampling import resample_in_space
Xcube with H5NetCDF
def configure_fs_auth():
import earthaccess
import s3fs
= earthaccess.login()
auth = auth.get_s3_credentials("PODAAC")
s3_credentials = s3fs.S3FileSystem(
fs =False,
anon=s3_credentials["accessKeyId"],
key=s3_credentials["secretAccessKey"],
secret=s3_credentials["sessionToken"],
token
)return fs
def warp_resample():
= "podaac-ops-cumulus-protected"
bucket = "MUR-JPL-L4-GLOB-v4.1/20020601090000-JPL-L4_GHRSST-SSTfnd-MUR-GLOB-v02.0-fv04.1.nc"
input_uri = "analysed_sst"
variable = f"s3://{bucket}/{input_uri}"
src = "EPSG:3857"
dstSRS = "EPSG:4326"
srcSRS = height = 256
width = [
te -20037508.342789244,
-20037508.342789244,
20037508.342789244,
20037508.342789244,
]= (te[2] - te[0]) / width
xres = (te[3] - te[1]) / width
yres = configure_fs_auth()
fs = {
fsspec_caching "cache_type": "none",
}with fs.open(src, **fsspec_caching) as f:
= xr.open_dataset(f, engine="h5netcdf")[[variable]]
ds = GridMapping.from_coords(
source_gm =ds.lat, y_coords=ds.lon, crs=srcSRS
x_coords
)= GridMapping.regular(
target_gm =[height, width], xy_min=[te[0], te[1]], xy_res=[xres, yres], crs=dstSRS
size
)return resample_in_space(ds, source_gm=source_gm, target_gm=target_gm)
if __name__ == "__main__":
= warp_resample() da
/opt/conda/lib/python3.11/site-packages/dask/core.py:133: RuntimeWarning: invalid value encountered in subtract
return func(*(_execute_task(a, cache) for a in args))
/opt/conda/lib/python3.11/site-packages/dask/core.py:133: RuntimeWarning: invalid value encountered in subtract
return func(*(_execute_task(a, cache) for a in args))
The Kernel crashed while executing code in the current cell or a previous cell. Please review the code in the cell(s) to identify a possible cause of the failure. Click <a href='https://aka.ms/vscodeJupyterKernelCrash'>here</a> for more info. View Jupyter <a href='command:jupyter.viewOutput'>log</a> for further details.