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

Datasets failing on get_bbox #11

Open
ellesmith88 opened this issue Dec 2, 2021 · 2 comments
Open

Datasets failing on get_bbox #11

ellesmith88 opened this issue Dec 2, 2021 · 2 comments

Comments

@ellesmith88
Copy link
Contributor

Some datasets for c3s-cordex are failing on get_bbox:

def get_bbox(ds):
lat = get_coord_by_type(ds, "latitude", ignore_aux_coords=False)
lon = get_coord_by_type(ds, "longitude", ignore_aux_coords=False)
min_y, max_y = get_coord_info(lat)
min_x, max_x = get_coord_info(lon)
if min_y < -90 or max_y > 90:
raise Exception(
f"Latitude is not within expected bounds. The minimum and maximum are {min_y}, {max_y}"
)
if min_x < -360 or max_x > 360:
raise Exception(
f"Longitude is not within expected bounds. The minimum and maximum are {min_x}, {max_x}"
)
bbox = f"{min_x:.2f}, {min_y:.2f}, {max_x:.2f}, {max_y:.2f}"
return bbox

with the error AttributeError: 'NoneType' object has no attribute 'values'

An example file is /gws/nopw/j04/cp4cds1_vol1/data/c3s-cordex/output/EUR-11/CNRM/CNRM-CERFACS-CNRM-CM5/rcp45/r1i1p1/CNRM-ALADIN63/v2/day/sfcWind/v20190828/sfcWind_EUR-11_CNRM-CERFACS-CNRM-CM5_rcp45_r1i1p1_CNRM-ALADIN63_v2_day_20360101-20401231.nc

Looking into these files I see that lat/lon are data variables rather than coordinates (with, for example, x and y and time only as coordinates), where as previously all datasets have had latitude and longitude as coordinates.

So our function get_coord_by_type (https://github.com/roocs/roocs-utils/blob/152f33650a44fe3466ffbc8dbd99ebb9f8de783e/roocs_utils/xarray_utils/xarray_utils.py#L235-L260) doesn't find them.

I can fix this by using ds.cf['latitude'] and ds.cf['longitude'] - when I use these I can generate the bbox.

However, we use get_coord_by_type in several places, e.g. in clisops, so this would need to be updated throughout, otherwise these datasets would fail elsewhere.

@agstephens So, I can include the datasets in the catalog with their correct bbox and fix the issue in the other packages. Maybe the best way would be to update the get_coord_by_type function to use cf-xarray?

@agstephens
Copy link

Hi @ellesmith88: I think that I am in favour of updating get_coord_by_type to use ds.cf[...] as long as it is doing the right thing. Please can you review how the cf_xarray library is managing to find these coordinates. Please report your findings here and we can decide how to proceed. Thanks

@ellesmith88
Copy link
Contributor Author

  • ds.cf returns
Coordinates:
- CF Axes: * X: ['x']
           * Y: ['y']
           * T: ['time']
             Z: n/a

- CF Coordinates: * time: ['time']
                    longitude, latitude, vertical: n/a

- Cell Measures:   area, volume: n/a

- Standard Names: * projection_x_coordinate: ['x']
                  * projection_y_coordinate: ['y']
                  * time: ['time']

Data Variables:
- Cell Measures:   area, volume: n/a

- Standard Names:   latitude: ['lat']
                    longitude: ['lon']
                    wind_speed: ['sfcWind']

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants