Closed rbavery closed 12 months ago
when I use xr.open_dataset(url, engine="rasterio", mask_and_scale=True)
I get the same affine transform so it seems like this might just be a dataset issue where the affine transform is not read properly. I'm still wondering if this is a bug though that when we don't use engine=rasterio, .rio.transform is incorrect? Should anything be returned if the rasterio engine is not used to open the NetCDF?
Interestingly, it seems fine with older versions of rasterio/GDAL/PROJ:
>>> import rioxarray
>>> rds = rioxarray.open_rasterio("ESACCI-LST-L3S-LST-IRCDR_-0.01deg_1MONTHLY_DAY-20201101000000-fv2.00.nc")
>>> rds
<xarray.Dataset>
Dimensions: (time: 1, x: 36000, y: 18000)
Coordinates:
* time (time) object 2020-11-01 00:00:00
* x (x) float64 -180.0 -180.0 -180.0 ... 180.0 180.0 180.0
* y (y) float64 89.99 89.98 89.97 89.96 ... -89.98 -89.99 -90.0
spatial_ref int64 0
Data variables: (12/13)
dtime (time, y, x) float32 ...
lst_unc_loc_sfc (time, y, x) int16 ...
lcc (time, y, x) int16 ...
n (time, y, x) int16 ...
lst_unc_loc_cor (time, y, x) int16 ...
satze (time, y, x) int16 ...
... ...
solze (time, y, x) int16 ...
solaz (time, y, x) int16 ...
lst (time, y, x) int16 ...
lst_uncertainty (time, y, x) int16 ...
lst_unc_ran (time, y, x) int16 ...
lst_unc_loc_atm (time, y, x) int16 ...
Attributes: (12/41)
cdm_data_type: grid
comment: These data were produced as part of the ESA L...
Conventions: CF-1.8
creator_email: djg20@le.ac.uk
creator_name: University of Leicester Surface Temperature G...
creator_url: https://climate.esa.int/en/projects/land-surf...
... ...
summary: This file contains level L3S global land surf...
time_coverage_duration: P1M
time_coverage_end: 20201130T235959
time_coverage_resolution: P1M
time_coverage_start: 20201101T000000
title: ESA LST CCI land surface temperature time ser...
>>> rds.lst.rio.transform()
Affine(0.009999999728725104, 0.0, -179.99999511705187,
0.0, -0.009999999457435136, 89.9999874875217)
>>> rds.rio.transform()
Affine(0.009999999728725104, 0.0, -179.99999511705187,
0.0, -0.009999999457435136, 89.9999874875217)
>>> rioxarray.show_versions()
rioxarray (0.14.0) deps:
rasterio: 1.3.6
xarray: 2023.3.0
GDAL: 3.6.3
GEOS: 3.11.2
PROJ: 9.1.1
PROJ DATA: ~/mambaforge/envs/rio/share/proj
GDAL DATA: ~/mambaforge/envs/rio/share/gdal
Other python deps:
scipy: 1.10.1
pyproj: 3.5.0
System:
python: 3.10.10 | packaged by conda-forge | (main, Mar 24 2023, 20:08:06) [GCC 11.3.0]
executable: ~/mambaforge/envs/rio/bin/python
machine: Linux-5.19.0-46-generic-x86_64-with-glibc2.35
Seems to work with the latest version as well:
>>> import rioxarray
>>> rds = rioxarray.open_rasterio("ESACCI-LST-L3S-LST-IRCDR_-0.01deg_1MONTHLY_DAY-20201101000000-fv2.00.nc")
>>> rds
<xarray.Dataset>
Dimensions: (time: 1, x: 36000, y: 18000)
Coordinates:
* time (time) object 2020-11-01 00:00:00
* x (x) float64 -180.0 -180.0 -180.0 ... 180.0 180.0 180.0
* y (y) float64 89.99 89.98 89.97 89.96 ... -89.98 -89.99 -90.0
spatial_ref int64 0
Data variables: (12/13)
dtime (time, y, x) float32 ...
lst_unc_loc_sfc (time, y, x) int16 ...
lcc (time, y, x) int16 ...
n (time, y, x) int16 ...
lst_unc_loc_cor (time, y, x) int16 ...
satze (time, y, x) int16 ...
... ...
solze (time, y, x) int16 ...
solaz (time, y, x) int16 ...
lst (time, y, x) int16 ...
lst_uncertainty (time, y, x) int16 ...
lst_unc_ran (time, y, x) int16 ...
lst_unc_loc_atm (time, y, x) int16 ...
Attributes: (12/41)
cdm_data_type: grid
comment: These data were produced as part of the ESA L...
Conventions: CF-1.8
creator_email: djg20@le.ac.uk
creator_name: University of Leicester Surface Temperature G...
creator_url: https://climate.esa.int/en/projects/land-surf...
... ...
summary: This file contains level L3S global land surf...
time_coverage_duration: P1M
time_coverage_end: 20201130T235959
time_coverage_resolution: P1M
time_coverage_start: 20201101T000000
title: ESA LST CCI land surface temperature time ser...
>>> rds.lst.rio.transform()
Affine(0.009999999728725104, 0.0, -179.99999511705187,
0.0, -0.009999999457435136, 89.9999874875217)
>>> rds.rio.transform()
Affine(0.009999999728725104, 0.0, -179.99999511705187,
0.0, -0.009999999457435136, 89.9999874875217)
>>> rioxarray.show_versions()
rioxarray (0.14.1) deps:
rasterio: 1.3.8
xarray: 2023.6.0
GDAL: 3.7.0
GEOS: 3.12.0
PROJ: 9.2.1
PROJ DATA: ~/mambaforge/envs/rio/share/proj
GDAL DATA: ~/mambaforge/envs/rio/share/gdal
Other python deps:
scipy: 1.11.1
pyproj: 3.6.0
System:
python: 3.11.4 | packaged by conda-forge | (main, Jun 10 2023, 18:08:17) [GCC 12.2.0]
executable: ~/mambaforge/envs/rio/bin/python
machine: Linux-5.19.0-46-generic-x86_64-with-glibc2.35
I wonder if the OS & architecture has something to do with the issues you are seeing: macOS
& arm64
Side note: These transforms are equivalent with the datasets width & height:
From xarray.open_dataset
Affine(0.009999999728725104, 0.0, -179.99999511705187,
0.0, 0.009999999457435136, -90.00000274631076)
From rioxarray.open_rasterio
:
Affine(0.009999999728725104, 0.0, -179.99999511705187,
0.0, -0.009999999457435136, 89.9999874875217)
If you export them to a raster (.rio.to_raster(...)
) and open them in QGIS, they will cover the same location.
I think this is likely a rasterio/GDAL issue specific to your OS & Architecture. I think you can confirm that by running this:
>>> with rasterio.open('NETCDF:"ESACCI-LST-L3S-LST-IRCDR_-0.01deg_1MONTHLY_DAY-20201101000000-fv2.00.nc":lst') as rds:
... print(repr(rds.transform))
...
Affine(0.009999999728725104, 0.0, -179.99999511705187,
0.0, -0.009999999457435136, 89.9999874875217)
On Ubuntu AMD when opening the URL I get this which is different
In [4]: with rasterio.open('https://dap.ceda.ac.uk/neodc/esacci/land_surface_temperature/data/MULTISENSOR_IRCDR/L3S/0.01/v2.00/mo
...: nthly/2020/11/ESACCI-LST-L3S-LST-IRCDR_-0.01deg_1MONTHLY_DAY-20201101000000-fv2.00.nc#mode=bytes') as rds:
...:
...: print(repr(rds.transform))
...:
/home/rave/mambaforge/lib/python3.10/site-packages/rasterio/__init__.py:304: NotGeoreferencedWarning: Dataset has no geotransform, gcps, or rpcs. The identity matrix will be returned.
dataset = DatasetReader(path, driver=driver, sharing=sharing, **kwargs)
Affine(1.0, 0.0, 0.0,
0.0, 1.0, 0.0)
Yes, I think this is not something solvable by rioxarray. It is something that needs to be handled by rasterio/GDAL.
Got it thanks, I'll move this issue over to rasterio.
Code Sample, a copy-pastable example if possible
Problem description
I'm trying to open an LST dataset in NetCDF that has a WGS84 projection. When I read the dataset with Xarray vs when I read with rioxarray, I get different affine transforms and I'm not sure why.
With the
xr.open_dataset
method, I getthis is not quite correct, signs are flipped for the last two values I think
https://gis.stackexchange.com/questions/414127/valueerror-negative-dimensions-are-not-allowed-when-using-raster-created-from
with rioxarray I get
Expected Output
I'd expect the geotransform to be read correctly and for both methods to return the same geotransform. Maybe this is a dataset limitation, but I would expect the transforms to be the same when accessing the transform with the rio accessor.
Environment Information
Installation method
Conda environment information (if you installed with conda):