0

I want to load the HRRR forecast data into Google Earth Engine, so I think I need to convert it to GeoTiff.

e.g.

import xarray as xr
import s3fs
fs = s3fs.S3FileSystem(anon=True)

urls = ["s3://hrrrzarr/sfc/20210915/20210915_12z_fcst.zarr/surface/APCP_acc_fcst",
        "s3://hrrrzarr/sfc/20210915/20210915_12z_fcst.zarr/surface/APCP_acc_fcst/surface"]
ds = xr.open_mfdataset([s3fs.S3Map(url, s3=fs) for url in urls], engine="zarr")

# Now convert to geotiff, e.g. ds.to_geotiff().save("example.tif")

1 Answer 1

0

Use rasterio and rioxarray to finish this example:


# Open zarr data in xarray
import xarray as xr
import s3fs
fs = s3fs.S3FileSystem(anon=True)

urls = ["s3://hrrrzarr/sfc/20210915/20210915_12z_fcst.zarr/surface/APCP_acc_fcst",
        "s3://hrrrzarr/sfc/20210915/20210915_12z_fcst.zarr/surface/APCP_acc_fcst/surface"]
ds = xr.open_mfdataset([s3fs.S3Map(url, s3=fs) for url in urls], engine="zarr")

# Assign CRS projection using rioxarray
import rioxarray
from pyproj import CRS

ds = ds.rename(projection_x_coordinate="x", projection_y_coordinate="y")
crs = CRS.from_cf({"grid_mapping_name":"lambert_conformal_conic", "longitude_of_central_meridian":-97.5,
                             "latitude_of_projection_origin": 38.5,
                             "standard_parallel":38.5})
ds = ds.rio.write_crs(crs, inplace=True)
ds["APCP_acc_fcst"] = ds["APCP_acc_fcst"].astype("float64") # Original data uses short floats which cause an error
ds = ds.rio.reproject("EPSG:4326") # Arbitrarily picked a projection since GEE seems to want projections w/ official codes

# Save as GeoTiff
ds["APCP_acc_fcst"].rio.to_raster("example.tif")
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.