Xee
Xee copied to clipboard
incorrect coordinate when export ERA5L
I faced with a strange issue. It seems that lon and lat is confused (lon becomes lat, lat becomes lon).
import ee
import xee
import xarray as xr
import xarray
# ee.Initialize()
ee.Initialize(opt_url='https://earthengine-highvolume.googleapis.com')
def ee_col_download_year(region, col_id='ECMWF/ERA5_LAND/HOURLY',
year=2022, fout="a.nc"):
# fout = prefix + col_id.replace("/", "_") + "_" + str(year) + ".nc"
ic = (ee.ImageCollection(col_id)
.filter(ee.Filter.calendarRange(year, year, 'year'))
.select(['surface_net_solar_radiation'])
.limit(10)
)
print(fout)
print(ic.size().getInfo())
ds = xarray.open_dataset(
ic,
engine='ee',
projection=ic.first().select(0).projection(),
geometry=region
)
ds.to_netcdf(fout)
ds
region = ee.Geometry.Rectangle(108.5, 28.75, 116.25, 33.5)
ee_col_download_year(region, year=2024, fout="test.nc")
Inspect in R:
library(terra)
ra = rast("./test.nc")
plot(ra[[1]])
netCDF4 is installed (v1.7.1).
According to the comments of Alexander-Barth, (the developer of NCDatasets.jl). The netcdf that xee exported has the following format errors:
- coordinate variable must not have the _FillValue or missing_value attributes: https://github.com/cf-convention/cf-conventions/blob/main/conformance.adoc#5-coordinate-systems-and-domain
double lon(lon) ;
lon:_FillValue = NaN ;
double lat(lat) ;
lat:_FillValue = NaN ;
- the bounds attribute is expected to be a string (a containing a variable name with related metadata): https://cfconventions.org/Data/cf-conventions/cf-conventions-1.11/cf-conventions.html#cell-boundaries
netcdf xee-test {
dimensions:
time = 10 ;
lon = 78 ;
lat = 48 ;
variables:
float surface_net_solar_radiation(time, lon, lat) ;
surface_net_solar_radiation:_FillValue = NaNf ;
surface_net_solar_radiation:id = "surface_net_solar_radiation" ;
surface_net_solar_radiation:data_type = "{\'type\': \'PixelType\', \'precision\': \'double\'}" ;
surface_net_solar_radiation:dimensions = 3601LL, 1801LL ;
surface_net_solar_radiation:crs = "EPSG:4326" ;
surface_net_solar_radiation:crs_transform = 0.1, 0., -180.05, 0., -0.1, 90.05 ;
surface_net_solar_radiation:scale_factor = 0.1 ;
surface_net_solar_radiation:bounds = 108.5, 28.75, 116.25, 33.5603826424351 ;
[...]
see details at https://github.com/Alexander-Barth/NCDatasets.jl/issues/265
Xee's .to_netcdf() method currently does not use the dimension ordering that is expected by many Python plotting libraries, and that appears to include the R terra package.
I started a discussion on whether to update the dimension ordering: #196 Please add your thoughts on whether the ordering should be a change (which would likely be a breaking change for some Xee users).