I'm trying to clip this .nc file using either gdal_translate
or gdalwarp
. However I don't think I'm getting the correct output. I'm able to clip the file in Python using either of the following methods
dataset = xarray.open_dataset("OR_ABI-L2-RRQPEF-M6_G16_s20241220000203_e20241220009511_c20241220009593.nc")
satellite_height = dataset.goes_imager_projection.attrs["perspective_point_height"]
x_values = dataset.x.values
y_values = dataset.y.values
x_values *= satellite_height
y_values *= satellite_height
coord_ref_sys = CRS.from_cf(dataset.goes_imager_projection.attrs)
dataset.rio.write_crs(coord_ref_sys.to_string(), inplace=True)
#METHOD 1
#from shapely import box
bbox = box(-124.725839, 24.498131, -66.949895, 49.384358)
feature_proj = rasterio.warp.transform_geom(
CRS.from_epsg(4326),
coord_ref_sys,
bbox
)
ds = dataset.rio.clip([feature_proj])
numpy_array = ds[["RRQPE"]].to_array().to_numpy()[0]
print(numpy_array.shape) #(1030, 2444)
#METHOD 2
ds = dataset.rio.clip_box(
minx=-124.725839,
miny=24.498131,
maxx=-66.949895,
maxy=49.384358
)
numpy_array = ds[["RRQPE"]].to_array().to_numpy()[0]
print(numpy_array.shape) #(1033, 2445)
However when I run
gdal_translate -projwin -124.725839 49.384358 -66.949895 24.498131 -projwin_srs EPSG:4326 -of GTiff NETCDF:"OR_ABI-L2-RRQPEF-M6_G16_s20241220000203_e20241220009511_c20241220009593.nc":RRQPE clip.tif
then gdalinfo clip.tif
tells me Size is 1820, 882
. If I run
gdalwarp -t_srs EPSG:4326 -te -124.725839 24.498131 -66.949895 49.384358 NETCDF:"OR_ABI-L2-RRQPEF-M6_G16_s20241220000203_e20241220009511_c20241220009593.nc":RRQPE clip.tif
then gdalinfo clip.tif
tells me Size is 2808, 1210
. I assume that there are flaws in my understanding of -projwin
and -te
that are preventing me from getting results that are similar to the Python methods.
"PROJ CRS string: +proj=geos +lon_0=-75 +h=35786023 +x_0=0 +y_0=0 +ellps=GRS80 +units=m +no_defs +sweep=x"
into EPSG:4326. At least it tries but shows an errorERROR 1: Unhandled X/Y axis unit rad. SRS will ignore axis unit and be likely wrong.
. Gdal_translate tries to projects the EPSG:4326 bbox into the native CRS and then selects the pixels within the BBOX withour re-projecting data. Adding--debug on
to the gdal_translate command may give more information about why the units confuse GDAL.GDAL 3.7.1, released 2023/07/06
.