Replies: 4 comments 7 replies
-
Are you able to open it with
You will need to make sure they are on the same grid with the same projection/resolution.
I would recommend |
Beta Was this translation helpful? Give feedback.
-
You could write the transform with transform = from_gcps(...)
cds.rio.write_transform(transform, inplace=True) EDIT: See #339 |
Beta Was this translation helpful? Give feedback.
-
Hello, I am continuing this discussion as it seems I have a similar need on the same satellite: I want to geocode any netcdf array from Sentinel-3 What I am doing is (ie. on a
>>> # LATITUDE
>>> lat = rioxarray.open_rasterio('netcdf:S3A_OL_1_EFR____20191215T105023_20191215T105323_20191216T153115_0179_052_322_2160_LN1_O_NT_002.SEN3\\geo_coordinates.nc:latitude')
<xarray.DataArray 'latitude' (band: 1, y: 4091, x: 4865)>
array([[[41970420, 41970130, ..., 39543947, 39543248],
[41972986, 41972697, ..., 39546495, 39545797],
...,
[52450015, 52449789, ..., 49880462, 49879650],
[52452576, 52452349, ..., 49882966, 49882154]]])
Coordinates:
* band (band) int32 1
* x (x) float64 0.5 1.5 2.5 3.5 ... 4.862e+03 4.864e+03 4.864e+03
* y (y) float64 0.5 1.5 2.5 3.5 ... 4.088e+03 4.09e+03 4.09e+03
spatial_ref int32 0
Attributes:
long_name: DEM corrected latitude
scale_factor: 1e-06
standard_name: latitude
units: degrees_north
valid_max: 90000000
valid_min: -90000000
_FillValue: -2147483648.0
add_offset: 0.0
>>> # LONGITUDE
>>> lon = rioxarray.open_rasterio('netcdf:S3A_OL_1_EFR____20191215T105023_20191215T105323_20191216T153115_0179_052_322_2160_LN1_O_NT_002.SEN3\\geo_coordinates.nc:longitude')
<xarray.DataArray 'longitude' (band: 1, y: 4091, x: 4865)>
array([[[-17401957, -17398723, ..., -2160966, -2157957],
[-17401548, -17398314, ..., -2159975, -2156965],
...,
[-15779766, -15775813, ..., 2597806, 2601348],
[-15779381, -15775428, ..., 2599187, 2602729]]])
Coordinates:
* band (band) int32 1
* x (x) float64 0.5 1.5 2.5 3.5 ... 4.862e+03 4.864e+03 4.864e+03
* y (y) float64 0.5 1.5 2.5 3.5 ... 4.088e+03 4.09e+03 4.09e+03
spatial_ref int32 0
Attributes:
long_name: DEM corrected longitude
scale_factor: 1e-06
standard_name: longitude
units: degrees_east
valid_max: 180000000
valid_min: -180000000
_FillValue: -2147483648.0
add_offset: 0.0
# Compute the transform
>>> tr = rasterio.transform.from_bounds(
west=np.min(lon.data)*lon.scale_factor,
south=np.min(lat.data) * lat.scale_factor,
east=np.max(lon.data) * lon.scale_factor,
north=np.max(lat.data) * lat.scale_factor,
width=lat.x.size,
height=lat.y.size)
>>> path = r"netcdf:S3A_OL_1_EFR____20191215T105023_20191215T105323_20191216T153115_0179_052_322_2160_LN1_O_NT_002.SEN3\Oa06_radiance.nc:Oa06_radiance"
>>> A = rioxarray.open_rasterio(path)
<xarray.DataArray 'Oa06_radiance' (band: 1, y: 4091, x: 4865)>
[19902715 values with dtype=uint16]
Coordinates:
* band (band) int32 1
* x (x) float64 0.5 1.5 2.5 3.5 ... 4.862e+03 4.864e+03 4.864e+03
* y (y) float64 0.5 1.5 2.5 3.5 ... 4.088e+03 4.09e+03 4.09e+03
spatial_ref int32 0
Attributes:
add_offset: 0.0
ancillary_variables: Oa06_radiance_err
coordinates: time_stamp altitude latitude longitude
long_name: TOA radiance for OLCI acquisition band Oa06
scale_factor: 0.012353800237178802
standard_name: toa_upwelling_spectral_radiance
units: mW.m-2.sr-1.nm-1
valid_max: 65534
valid_min: 0
_FillValue: 65535.0
>>> A.rio.write_crs("EPSG:4326", inplace=True)
<xarray.DataArray 'Oa06_radiance' (band: 1, y: 4091, x: 4865)>
[19902715 values with dtype=uint16]
Coordinates:
* band (band) int32 1
* x (x) float64 0.5 1.5 2.5 3.5 ... 4.862e+03 4.864e+03 4.864e+03
* y (y) float64 0.5 1.5 2.5 3.5 ... 4.088e+03 4.09e+03 4.09e+03
spatial_ref int32 0
Attributes:
add_offset: 0.0
ancillary_variables: Oa06_radiance_err
coordinates: time_stamp altitude latitude longitude
long_name: TOA radiance for OLCI acquisition band Oa06
scale_factor: 0.012353800237178802
standard_name: toa_upwelling_spectral_radiance
units: mW.m-2.sr-1.nm-1
valid_max: 65534
valid_min: 0
_FillValue: 65535.0
>>> A.rio.write_transform(transform=tr, inplace=True)
<xarray.DataArray 'Oa06_radiance' (band: 1, y: 4091, x: 4865)>
[19902715 values with dtype=uint16]
Coordinates:
* band (band) int32 1
* x (x) float64 0.5 1.5 2.5 3.5 ... 4.862e+03 4.864e+03 4.864e+03
* y (y) float64 0.5 1.5 2.5 3.5 ... 4.088e+03 4.09e+03 4.09e+03
spatial_ref int32 0
Attributes:
add_offset: 0.0
ancillary_variables: Oa06_radiance_err
coordinates: time_stamp altitude latitude longitude
long_name: TOA radiance for OLCI acquisition band Oa06
scale_factor: 0.012353800237178802
standard_name: toa_upwelling_spectral_radiance
units: mW.m-2.sr-1.nm-1
valid_max: 65534
valid_min: 0
_FillValue: 65535.0
>>> A.rio.to_raster(r"test_green.tif", recalc_transform=False)
Can you help me on those warnings Context: I am currently trying to remove SNAP from my lib (EOReader).
|
Beta Was this translation helpful? Give feedback.
-
any one tried with OLCI level 2 data? I am tired of searching and how to convert to geotif. Thanks |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
My apologies for the long post, but I have been stuck attempting to convert Sentinel-3 LST netCDF data to geotiffs for a while now as part of my master's thesis, and my supervisors are getting rather impatient.
Firstly, an introduction to the data. It is packaged as follow:

The data is packaged as several .nc files, as well as a xml file containing metadata. The metadata suggests that the data should be in EPSG:4346:
<metadataObject ID="measurementFrameSet" classification="DESCRIPTION" category="DMD"> <metadataWrap mimeType="text/xml" vocabularyName="Sentinel-SAFE" textInfo="Frame Set"> <xmlData> <sentinel-safe:frameSet> <sentinel-safe:footPrint srsName="http://www.opengis.net/def/crs/EPSG/0/4326"> <gml:posList>-29.1992 8.81452 -29.1684 9.00931 -29.0806 9.52497 -28.9909 10.035 -28.896 10.5474 -28.801 11.0545 -28.7054 11.5734 -28.605 12.0778 -28.5082 12.5866 -28.4088 13.0983 -28.2994 13.6035 -28.197 14.1087 -28.0927 14.6147 -27.9761 15.1199 -27.8675 15.6236 -27.7564 16.1214 -27.6423 16.627 -27.525 17.1239 -27.4036 17.6145 -27.2806 18.1169 -27.1611 18.6177 -27.0344 19.1076 -26.9124 19.605 -26.781 20.0911 -26.6548 20.5894 -26.5286 21.0864 -26.3885 21.5669 -26.2565 22.0561 -26.1192 22.5398 -25.9879 23.0344 -25.8475 23.5168 -28.389 24.4405 -30.9637 25.4388 -33.5273 26.5043 -36.0695 27.6424 -36.078 27.6463 -36.2329 27.1108 -36.4066 26.5843 -36.5511 26.0457 -36.7063 25.5069 -36.8573 24.9628 -37.0105 24.4346 -37.1568 23.8819 -37.2966 23.3343 -37.4393 22.7945 -37.5805 22.24 -37.7181 21.6969 -37.8487 21.1329 -37.9835 20.584 -38.1138 20.0259 -38.2315 19.464 -38.3634 18.9072 -38.4821 18.3398 -38.5973 17.7783 -38.7109 17.2074 -38.8288 16.6385 -38.9366 16.0638 -39.0387 15.4947 -39.148 14.9205 -39.2443 14.3444 -39.3456 13.7696 -39.4421 13.1931 -39.5308 12.6058 -39.6274 12.0296 -39.7142 11.4424 -39.7416 11.2224 -39.7345 11.2088 -37.1002 10.5838 -34.4547 9.9742 -31.8069 9.37884 -29.1992 8.81452</gml:posList> </sentinel-safe:footPrint> </sentinel-safe:frameSet> </xmlData> </metadataWrap> </metadataObject>
Now I attempted to load the data into xarray using this:
import rioxarray import xarray from pyproj import CRS root = r'G:\MSc\Code\JupyterLab\temp\S3B_SL_2_LST____20201214T214826_20201214T215126_20201216T025309_0179_046_385_5400_LN2_O_NT_004.SEN3\*.nc' xds = xarray.open_mfdataset(root,combine = 'by_coords', decode_times=False)
This did not work, and output the following error:
ValueError: arguments without labels along dimension 'columns' cannot be aligned because they have different dimension sizes: {130, 1500}
Now I believe the problem with this is that the _in files have a 1200 x 1500 grid, whereas the _tx files have a 500 x 1500 grid. Working around this problem, we can open up only the _in files (or the _tx files, but I am using _in for the example):

If I am correct in interpreting the information, it appears that the netCDF does not have any spatial dimensions defined, despite that I have attempted to set the CRS using
xds.rio.set_crs(4326)
and exporting that to a geotiff usingxds.to_netcdf(r'G:\MSc\TestImage\testout\testout.tiff')
, but that did not work and seemed to only map the row and column values as coordinates. This did not work.Now the Sentinel-3 LST product does have some form of spatial referencing in the data that I assume I can work with - the longitude_in/_tx and latitude_in/_tx bands. These are gridded values containing the geographic longitude/latitude coordinates for every cell in the netCDF. I have used this to extract point values from the netCDF grid in the past and have attempted to solve this problem by turning every cell into a point feature, but this proved far too slow to be of much use.
Anyway, I have a feeling that this information could be used somehow to georeference the netCDFs, either by creating a new set of spatial dimensions, or failing that they should be able to act as GCPs, but I fear that this second option may also be too slow. I have also tried using SNAP, but unfortunately it proved too slow and unstable to work for this problem. Speed is a bit of an issue, as I am aiming to process a year's worth of information over an AOI.
I would greatly appreciate any assistance on this matter, be it some code that can already do this, or even just guidance on what to attempt next. Thanks a lot in advance!
Beta Was this translation helpful? Give feedback.
All reactions