I'm using the python API to GDAL to try to do a simple geographic warp of a netCDF4 satellite file to a small sub region. My python program fails to produce any output but does not throw any exceptions or errors. Any ideas?
The command line operation of gdalwarp works fine and produces meaningful netCDF output (for a single band or variable). But the python version does not. THe output 'ds' is "None' and no netCDF output file is created. Here is a snapshot:
from osgeo import gdal, gdalconst
kwargs = {'format': 'netCDF', 'copyMetadata': True,
'outputBounds': '[-29 -2 -25 2]',
'dstSRS':'+proj=longlat +datum=WGS84 +no_defs'
}
src_filename = './subset_20180729030000-JPL-L2P_GHRSST-SSTskin-MODIS_A-N-v02.0-fv01.0.nc'
nc_file = 'NETCDF:' + src_filename
src = gdal.Open(nc_file, gdalconst.GA_ReadOnly)
subDatasets = src.GetSubDatasets()
#print('subsdatatsets', subDatasets)
ds = gdal.Warp('./output_lonlat.nc', src, **kwargs)
print("ds is ", ds)
del ds
Here is the command line operation that does work:
% gdalwarp -t_srs "+proj=longlat +datum=WGS84 +no_defs" -te -29 -2 -25 2 NETCDF:"./subset_20180729030000-JPL-L2P_GHRSST-SSTskin-MODIS_A-N-v02.0-fv01.0.nc":sea_surface_temperature -overwrite -of netCDF out_lonlat.nc
NETCDF:"./subset_20180729030000-JPL-L2P_GHRSST-SSTskin-MODIS_A-N-v02.0-fv01.0.nc":sea_surface_temperature
. Thesrc
that you use in the code is different. – user30184 Nov 13 '20 at 8:01-sds
optionCopy all subdatasets of this file to individual output files
. It should not be too difficult to do the same with Python: read the list of subdatasets and convert them one by one. – user30184 Nov 13 '20 at 17:51