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

Support for multidimensional coordinates in mk_dataset_xarray.py #245

Open
zequihg50 opened this issue Dec 10, 2024 · 4 comments · Fixed by #246
Open

Support for multidimensional coordinates in mk_dataset_xarray.py #245

zequihg50 opened this issue Dec 10, 2024 · 4 comments · Fixed by #246

Comments

@zequihg50
Copy link

When testing publication of CORDEX data in which variables "lat" and "lon" are 2-dimensional, I encountered that the script mk_dataset_xarray.py produces an error, likely because it assumes that these variables are 1-dimensional.

This could be fixed by changing to something like this here and here:

record["north_degrees"] = lat.values.max()
record["south_degrees"] = lat.values.min()
record["east_degrees"] = lon.values.max()
record["west_degrees"] = lon.values.min()

Although this made the trick for me I'm not sure this solution is general enough.

Additional info:

$  esgpublish --version
esgpublish v5.2.4
@sashakames
Copy link
Contributor

@zequihg50 Thanks for pointing this out, your solution might be more comprehensive than the current use of the 1-D bounds array. Can you submit a PR?

@zequihg50
Copy link
Author

Sure.

@meteorologist15
Copy link

I have also encountered this error. Here is the stacktrace:

Traceback (most recent call last):
  File "/esg/publishing/miniconda3/envs/esgf-pub/lib/python3.8/site-packages/esgcet/generic_netcdf.py", line 75, in mk_dataset
    out_json_data = mkd.get_records(map_json_data, scan_arg, self.json_file, user_project=self.proj_config)
  File "/esg/publishing/miniconda3/envs/esgf-pub/lib/python3.8/site-packages/esgcet/mk_dataset.py", line 414, in get_records
    self.update_metadata(self.dataset, scanobj)
  File "/esg/publishing/miniconda3/envs/esgf-pub/lib/python3.8/site-packages/esgcet/mk_dataset.py", line 374, in update_metadata
    self.handler.set_bounds(record, scanobj)
  File "/esg/publishing/miniconda3/envs/esgf-pub/lib/python3.8/site-packages/esgcet/mk_dataset_xarray.py", line 59, in set_bounds
    record["north_degrees"] = float(lat[-1])
  File "/esg/publishing/miniconda3/envs/esgf-pub/lib/python3.8/site-packages/xarray/core/common.py", line 156, in __float__
    return float(self.values)
TypeError: only size-1 arrays can be converted to Python scalars

I saw this potential solution using the NumPy vectorize function:
https://stackoverflow.com/questions/36680402/typeerror-only-length-1-arrays-can-be-converted-to-python-scalars-while-plot-sh

@sashakames
Copy link
Contributor

A PR was merged to this branch v5.2.5-proj you may install form source and use that

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

Successfully merging a pull request may close this issue.

3 participants