Spatial resampling of netCDF file in python

792 Views Asked by At

I am working with Sentinel 3 SLSTR data which comes in netCDF file format. The file contains 11 bands: S1-S6 (500 m resolution) and S7-S9 and F1 & F2 (1000 m resolution). S1-S6 contains radiance values and S7-S9 contains brightness temperature values. Right now, I want to resample my S7-S9 band to 500 m resolution to match the resolution of S1-S6 bands.

I am using xarray to read the netCDF files. There is a function xarray.Dataset.resample() but the documentation says that it resample to a new temporal resolution.

I also tried to resample using gdal but couldn't get any result.

import gdal
import xarray as xr
import matplotlib.pyplot as plt

data = xr.open_dataset('S7_BT_in.nc')          # one of the files in 1000 m resolution
geo = xr.open_dataset(path+'geodetic_an.nc')   # file containing the geodetic values


ds = data['S7_BT_in']                # fetching variable I need to work on
lat = geo['latitude_an']             # fetching latitude values
lon = geo['longitude_an']            # fetching longitude values



#assigning latitude and longitude values to the coordinates of ds 
ds = ds.assign_coords(coords = {'Latitude': lat, 'Longitude': lon})    

x = gdal.Open('ds')             # Opening the netCDF file using gdal


# resampling the data to 500 m resolution
xreproj = gdal.Warp('resampled.nc', x, xRes = 500, yRes = 500)

This is the error I am getting:

SystemError: <built-in function wrapper_GDALWarpDestName> returned NULL without setting an error.

I also tried opening the file directly using gdal but still getting the same error.

0

There are 0 best solutions below