0

我想将 HRRR 预测数据加载到 Google Earth Engine 中,所以我想我需要将其转换为 GeoTiff。

例如

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")
4

1 回答 1

0

使用rasteriorioxarray完成此示例:


# 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")
于 2021-09-17T20:04:50.343 回答