Skip to main content

How to use the xcube Viewer?

If you've just installed xcube and are wondering how to use it, this article is for you!

Alexandre avatar
Written by Alexandre
Updated over a week ago

Context


The xcube software package has been developed to generate, manipulate, analyze and publish datacubes from Earth Observation data. Please check you have installed xcube before going further.

You can also access the WEkEO JupyterHub and its Earth Observation Tools server, where xcube is installed. To find out more, go to the See xcube Viewer in action section of this article.

This guide aims to demonstrates how to display the multi-dimensional array datacube with the xcube Viewer in a browser.

You can download here the files needed to follow this article:

πŸ“Œ Note: please extract the files before using them.

Create a configuration file


To add datacubes to the xcube Viewer, they have to be defined in a configuration file. The datacubes are stored locally, that's why we will now create a configuration file for locally stored datacubes. For remotely stored objects (e.g. on a s3 bucket) please refer to the official documentation.

The configuration file is stored with the name config.yml in the same directory as the datacubes. In our case this is the working directory. There are two main parts in the configuration file: Datasets and Styles.

The Datasets description contains:

  • Identifier: unique name for the datacube

  • Title: this is what the cube will be called in the Viewer

  • BoundingBox: spatial extent of the dataset

  • FileSystem: local or remote

  • Path: file name of cube in directory

  • Style: identifier of the style as defined below

  • TimeSeriesDataset: type of time series

The Styles description contains:

  • Identifier: unique name for the style

  • ColorMappings:

    • VariableName: must be identical to the variable name in the cube

      • ColorBar: name of colorbar as in matplotlib

      • ValueRange: range of the dataset

You can copy/paste the content below of the configuration file to the config.yml file in your directory:

See content of config.yml

DatasetChunkCacheSize: 100M

Datasets:
- Identifier: local1
Title: LST Spain Cube
BoundingBox: [-10, 35, 4, 44]
FileSystem: file
Path: dc_lst_spain.zarr
Style: temp
TimeSeriesDataset: local_ts
- Identifier: local2
Title: Air Temp Spain Cube
BoundingBox: [-10, 35, 4, 44]
FileSystem: file
Path: dc_temp_spain.zarr
Style: temp
TimeSeriesDataset: local_ts

Styles:
- Identifier: temp
ColorMappings:
LST:
ColorBar: "inferno"
ValueRange: [250., 330.]
t2m:
ColorBar: "inferno"
ValueRange: [250., 330.]

πŸ“Œ Note: you don't need to do this if you have downloaded the files at the beginning of this article.

Visualize the data in xcube


Now you can:

  1. Open a terminal.

  2. Go to the directory where you stored the datacubes and the configuration file.

  3. Run the command xcube serve -c config.yml --verbose &

The output will look like this:

Loaded service API 'auth'
Loaded service API 'styles'
...
Applying initial configuration...
Starting service...
Service running, listening on 0.0.0.0:8080
Try http://127.0.0.1:8080/openapi.html
Press CTRL+C to stop service

where http://127.0.0.1:8080/ is the server's endpoint in our case.

You can access to the Viewer by copy/pasting http://127.0.0.1:8080/viewer

Open this link in your web browser and the datacubes appear in the xcube Viewer:

See xcube Viewer in action


If you'd like to see the xcube Viewer in action, it is now possible to execute it inside the WEkEO JupyterHub. All necessary packages for the execution of the notebooks are installed in the python3 kernel of the Earth Observation Tools Server.

Here are two notebooks to see xcube Viewer in action:

πŸ’‘WEkEO Pro Tip: you can open the notebooks directly in the WEkEO JupyterHub by clicking on Open via Jupyter.

⚠️ In the second notebook cell, insert your username in this url:

​os.environ["XCUBE_JUPYTER_LAB_URL"] = https://jupyterhub.prod.wekeo2.eu/user/<your username>/

What's next?


Feel free to check these articles that might be of interest for you:

Additional resources can be found in our Help Center. Should you require further assistance or wish to provide feedback, feel free to contact us through a chat session available in the bottom right corner of the page.

Did this answer your question?