ESMValGroup / ESMValCore

ESMValCore: A community tool for pre-processing data from Earth system models in CMIP and running analysis scripts.
https://www.esmvaltool.org
Apache License 2.0
42 stars 38 forks source link

Error when extracting IPCC AR6 region #1669

Closed rswamina closed 2 years ago

rswamina commented 2 years ago

I am reporting an error I get when I try to extract a specific region using the IPCC AR6 region shapefile. I am copying the recipe used and an excerpt from the error message below. From what I understand the error occurs in file _area.py in the _get_bounds function where it seems like there are more than two coordinates in the geometries extracted through the fiona package. I am not certain how to query the names of the coordinates so could not go further. Can someone help with this?

#recipe_extract_IPCC_AR6_regions.yml

---
documentation:
  description: |
    Extracting IPCC regions
  title: Extract IPCC-AR6 regions

  authors:
    - swaminathan_ranjini

  projects:
    - ukesm 

preprocessors:
  preproc_extract_region_land_annual:
    extract_shape:
      shapefile : IPCC-AR6-shapefiles/IPCC-WGI-reference-regions-v4.shp
      decomposed : False
      method : contains
      crop: True
      ids: 
        - 'Russian-Arctic'
    mask_landsea:
      mask_out : sea
    annual_statistics:
      operator: mean

 datasets:
  - {dataset: UKESM1-0-LL, exp: piControl, start_year: 1960, end_year: 3059, grid: gn, ensemble: r1i1p1f2 }

diagnostics:
  annual_means_tas:
    description: calculate annual means for region
    variables:
      tas:
        preprocessor: preproc_extract_region_land_annual
        project: CMIP6
        mip: Amon
    scripts:  null

Here is a part of the error message :

 File "/apps/jasmin/community/esmvaltool/miniconda3/envs/esmvaltool/lib/python3.10/site-packages/esmvalcore/preprocessor/_area.py", line 635, in extract_shape
    lon_min, lat_min, lon_max, lat_max = _get_bounds(
  File "/apps/jasmin/community/esmvaltool/miniconda3/envs/esmvaltool/lib/python3.10/site-packages/esmvalcore/preprocessor/_area.py", line 513, in _get_bounds
    lon_max, lat_max = all_points.max(axis=0)
ValueError: too many values to unpack (expected 2)
"""

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/apps/jasmin/community/esmvaltool/miniconda3/envs/esmvaltool/lib/python3.10/site-packages/esmvalcore/_main.py", line 499, in run
    fire.Fire(ESMValTool())
  File "/apps/jasmin/community/esmvaltool/miniconda3/envs/esmvaltool/lib/python3.10/site-packages/fire/core.py", line 141, in Fire
    component_trace = _Fire(component, args, parsed_flag_args, context, name)
  File "/apps/jasmin/community/esmvaltool/miniconda3/envs/esmvaltool/lib/python3.10/site-packages/fire/core.py", line 466, in _Fire
    component, remaining_args = _CallAndUpdateTrace(
  File "/apps/jasmin/community/esmvaltool/miniconda3/envs/esmvaltool/lib/python3.10/site-packages/fire/core.py", line 681, in _CallAndUpdateTrace
    component = fn(*varargs, **kwargs)
  File "/apps/jasmin/community/esmvaltool/miniconda3/envs/esmvaltool/lib/python3.10/site-packages/esmvalcore/_main.py", line 443, in run
    process_recipe(recipe_file=recipe, config_user=cfg)
  File "/apps/jasmin/community/esmvaltool/miniconda3/envs/esmvaltool/lib/python3.10/site-packages/esmvalcore/_main.py", line 124, in process_recipe
    recipe.run()
  File "/apps/jasmin/community/esmvaltool/miniconda3/envs/esmvaltool/lib/python3.10/site-packages/esmvalcore/_recipe.py", line 1882, in run
    self.tasks.run(max_parallel_tasks=self._cfg['max_parallel_tasks'])
  File "/apps/jasmin/community/esmvaltool/miniconda3/envs/esmvaltool/lib/python3.10/site-packages/esmvalcore/_task.py", line 725, in run
    self._run_parallel(max_parallel_tasks)
  File "/apps/jasmin/community/esmvaltool/miniconda3/envs/esmvaltool/lib/python3.10/site-packages/esmvalcore/_task.py", line 768, in _run_parallel
    _copy_results(task, running[task])
  File "/apps/jasmin/community/esmvaltool/miniconda3/envs/esmvaltool/lib/python3.10/site-packages/esmvalcore/_task.py", line 791, in _copy_results
    task.output_files, task.products = future.get()
  File "/apps/jasmin/community/esmvaltool/miniconda3/envs/esmvaltool/lib/python3.10/multiprocessing/pool.py", line 771, in get
    raise self._value
  File "/apps/jasmin/community/esmvaltool/miniconda3/envs/esmvaltool/lib/python3.10/multiprocessing/pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
  File "/apps/jasmin/community/esmvaltool/miniconda3/envs/esmvaltool/lib/python3.10/site-packages/esmvalcore/_task.py", line 796, in _run_task
    output_files = task.run()
  File "/apps/jasmin/community/esmvaltool/miniconda3/envs/esmvaltool/lib/python3.10/site-packages/esmvalcore/_task.py", line 263, in run
    self.output_files = self._run(input_files)
  File "/apps/jasmin/community/esmvaltool/miniconda3/envs/esmvaltool/lib/python3.10/site-packages/esmvalcore/preprocessor/__init__.py", line 599, in _run
    product.apply(step, self.debug)
  File "/apps/jasmin/community/esmvaltool/miniconda3/envs/esmvaltool/lib/python3.10/site-packages/esmvalcore/preprocessor/__init__.py", line 410, in apply
    self.cubes = preprocess(self.cubes, step,
  File "/apps/jasmin/community/esmvaltool/miniconda3/envs/esmvaltool/lib/python3.10/site-packages/esmvalcore/preprocessor/__init__.py", line 346, in preprocess
    result.append(_run_preproc_function(function, item, settings,
  File "/apps/jasmin/community/esmvaltool/miniconda3/envs/esmvaltool/lib/python3.10/site-packages/esmvalcore/preprocessor/__init__.py", line 302, in _run_preproc_function
    return function(items, **kwargs)
  File "/apps/jasmin/community/esmvaltool/miniconda3/envs/esmvaltool/lib/python3.10/site-packages/esmvalcore/preprocessor/_area.py", line 635, in extract_shape
    lon_min, lat_min, lon_max, lat_max = _get_bounds(
  File "/apps/jasmin/community/esmvaltool/miniconda3/envs/esmvaltool/lib/python3.10/site-packages/esmvalcore/preprocessor/_area.py", line 513, in _get_bounds
    lon_max, lat_max = all_points.max(axis=0)
ValueError: too many values to unpack (expected 2)
2022-07-15 14:47:54,846 UTC [689] INFO    esmvalcore._main:515 
zklaus commented 2 years ago

Thanks for the report, @rswamina. @stefsmeets, could you have a look? (@bouweandela, I have in the back of my head that @stefsmeets is currently not in a position to work on this. If that is true, could you comment here so that we can find someone to look at it?)

bouweandela commented 2 years ago

Indeed, @stefsmeets is currently working on other projects. I can have a look.

bouweandela commented 2 years ago

Is there any documentation available on this shapefile?

bouweandela commented 2 years ago

It looks like the current code does not support regions that are stored as a MultiPolygon. I'll make a pull request to fix it.

rswamina commented 2 years ago

Is there any documentation available on this shapefile?

@bouweandela , Sorry, I meant to include the link. Here it is IPCC AR6 shape file

bouweandela commented 2 years ago

Thanks, I opened a pull request. Could you try it and see if it fixes the issue?

rswamina commented 2 years ago

@bouweandela , Yes, I can try it out. I am not able to checkout the branch fix-extract-shape-bounds-multipolygon though. I tried

git checkout fix-extract-shape-bounds-multipolygon and I get a message saying

error: pathspec 'fix-extract-shape-bounds-multipolygon' did not match any file(s) known to git

Is this an access issue or am I doing something wrong?

bouweandela commented 2 years ago

Maybe the branch is not available on your computer yet. Could you try downloading the latest changes from GitHub first?

git fetch origin
rswamina commented 2 years ago

I have reviewed and approved the PR.