How to make subset of data based on index label range along specified dimension?

Hello! I am working on plotting subsets of my data (humidity variation in different height ranges). 

I hope to obtain data intervals of 0-4 km, 4-8 km and 8-12 km in the height coordinate.

For that purpose, I have used the cube.select function to define my subsets:

"height_range_1 = ct.cube.select(data, height=[0, 4000],vertical='height').height.values"

however, I receive the following error:

Traceback (most recent call last):
File "/opt/cdstoolbox/cdscompute/cdscompute/cdshandlers/services/handler.py", line 49, in handle_request
result = cached(context.method, proc, context, context.args, context.kwargs)
File "/opt/cdstoolbox/cdscompute/cdscompute/caching.py", line 108, in cached
result = proc(context, *context.args, **context.kwargs)
File "/opt/cdstoolbox/cdscompute/cdscompute/services.py", line 118, in __call__
return p(*args, **kwargs)
File "/opt/cdstoolbox/cdscompute/cdscompute/services.py", line 59, in __call__
return self.proc(context, *args, **kwargs)
File "/home/cds/cdsservices/services/python_service.py", line 32, in execute
raise exceptions.InternalError(logging + traceback, '')
cdsclient.exceptions.InternalError: Traceback (most recent call last):
File "/opt/cdstoolbox/jsonrequest/jsonrequest/requests.py", line 71, in jsonrequestcall
resp = coding.encode(req.callable(*req.args, **req.kwargs), register=encoders, **context)
File "/opt/cdstoolbox/cdstools/cdstools/util.py", line 265, in select
selection = _vertical_selection(selection, vertical)
File "/opt/cdstoolbox/cdstools/cdstools/util.py", line 183, in _vertical_selection
raise ValueError("Invalid vertical declaration '%r'." % vertical)
ValueError: Invalid vertical declaration ''height''.


How can I create subsets of data based on selected index labels along a specified dimension?

The rest of my code can be found here: https://sis-dev.climate.copernicus.eu/toolbox-editor/1474/seasonal-variations-of-humidity 

Many thanks

Huayuan

Hi Huayuan,

You were actually very close. You do not need to use the 'vertical' kwarg, The 'vertical' kwarg is only useful if you want to select predefined vertical such as standard pressure levels when you have the 'plevel' dimension for example. The documentation will be updated on that as it is confusing.

Here is a running version of your workflow: https://sis-dev.climate.copernicus.eu/toolbox-editor/112/seasonal-variations-of-humidity

Note that I also removed the '.heigh.values' as the remote objects manipulated in the Toolbox are not exactly like xarrays and you can't extract their values like this. You actually don't need to get the values as you will see in the workflow.

Regards.

Vivien

Thank you for your quick response Vivien!