Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

incorrect coordinate when export ERA5L #171

Open
kongdd opened this issue Sep 3, 2024 · 1 comment
Open

incorrect coordinate when export ERA5L #171

kongdd opened this issue Sep 3, 2024 · 1 comment
Labels
bug Something isn't working P1

Comments

@kongdd
Copy link

kongdd commented Sep 3, 2024

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]])

image

netCDF4 is installed (v1.7.1).

@kongdd
Copy link
Author

kongdd commented Sep 4, 2024

According to the comments of Alexander-Barth, (the developer of NCDatasets.jl). The netcdf that xee exported has the following format errors:

  1. 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 ;
  1. 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 Alexander-Barth/NCDatasets.jl#265

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working P1
Projects
None yet
Development

No branches or pull requests

2 participants