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 function to define my subsets:

"height_range_1 =, 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/", line 49, in handle_request
result = cached(context.method, proc, context, context.args, context.kwargs)
File "/opt/cdstoolbox/cdscompute/cdscompute/", line 108, in cached
result = proc(context, *context.args, **context.kwargs)
File "/opt/cdstoolbox/cdscompute/cdscompute/", line 118, in __call__
return p(*args, **kwargs)
File "/opt/cdstoolbox/cdscompute/cdscompute/", line 59, in __call__
return self.proc(context, *args, **kwargs)
File "/home/cds/cdsservices/services/", line 32, in execute
raise exceptions.InternalError(logging + traceback, '')
cdsclient.exceptions.InternalError: Traceback (most recent call last):
File "/opt/cdstoolbox/jsonrequest/jsonrequest/", line 71, in jsonrequestcall
resp = coding.encode(req.callable(*req.args, **req.kwargs), register=encoders, **context)
File "/opt/cdstoolbox/cdstools/cdstools/", line 265, in select
selection = _vertical_selection(selection, vertical)
File "/opt/cdstoolbox/cdstools/cdstools/", 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: 

Many thanks


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:

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.



Thank you for your quick response Vivien!