<jupyter_start><jupyter_text>Demo: analysing soil moisture data from the Climate Data Store in xcube First, we import some necessary libraries and configure some matplotlib display preferences.<jupyter_code># xcube_cds imports
from xcube_cds.store import CDSDataStore

# xcube imports
import xcube
from xcube.core.maskset import MaskSet
from xcube.core.geom import mask_dataset_by_geometry
from xcube.core.geom import clip_dataset_by_geometry
from xcube.core.dsio import open_cube

# Various utilities
import json
import xarray as xr
import shapely.geometry
import IPython.display
import time
import zarr
import matplotlib as mpl
import matplotlib.pyplot as plt
from mpl_toolkits.axes_grid1 import make_axes_locatable
import pathlib

# Plot settings
%matplotlib inline
plt.rcParams["figure.figsize"] = 16,12<jupyter_output><empty_output><jupyter_text>Create a CDS data store object. The optional `normalize_names` parameter specifies that variable names in returned data cubes will be converted to legal Python identifiers, if required.<jupyter_code>cds_store = CDSDataStore(normalize_names=True)<jupyter_output><empty_output><jupyter_text>From the data store we request monthly averages of global volumetric soil moisture data from January 2015 to January 2016.<jupyter_code>generated_cube = cds_store.open_data(
    'satellite-soil-moisture:volumetric:monthly',
    variable_names=['volumetric_surface_soil_moisture'],
    time_range=['2015-01-01', '2016-01-31']
)
cube = generated_cube<jupyter_output>2021-02-18 16:43:52,854 INFO Welcome to the CDS
2021-02-18 16:43:52,857 INFO Sending request to https://cds.climate.copernicus.eu/api/v2/resources/satellite-soil-moisture
2021-02-18 16:43:53,210 INFO Request is queued
2021-02-18 16:43:54,352 INFO Request is running
2021-02-18 16:44:43,517 INFO Request is completed
2021-02-18 16:44:43,518 INFO Downloading https://download-0009.copernicus-climate.eu/cache-compute-0009/cache/data8/dataset-satellite-soil-moisture-c5957ef6-94e6-4357-8383-acf4010dd43f.tar.gz to /tmp/tmpge7fvswt/tmpeow89jkn/data (18.4M)
2021-02-18 16:44:51,241 INFO Download rate 2.4M/s<jupyter_text>Plot the bounding box on a map to check that the cube covers the expected area.<jupyter_code>bbox = [min(cube.lon), min(cube.lat), max(cube.lon), max(cube.lat)]
IPython.display.GeoJSON(shapely.geometry.box(*bbox).__geo_interface__)<jupyter_output><empty_output><jupyter_text>Plot the differences between successive time points in the dataset. We can see that the times are monotonically increasing (all the difference values are positive), but not equally spaced, since months are not all of the same length. The lowest values correspond to February; the four-year leap year cycle can also be discerned.<jupyter_code>cube.time.diff(dim='time').plot.line(figsize=(20, 4))<jupyter_output><empty_output><jupyter_text>As a quick initial test, we plot a simple plate carrée projection (with longitude and latitude mapped directly to the x and y co-ordinates respectively) for the first time-point available.<jupyter_code>sm_2015_jan = cube.sm.sel(time='2015-01-01 00:00:00', method='nearest')
sm_2015_jan.plot.imshow()<jupyter_output><empty_output><jupyter_text>Now we define a plotting function which restricts the plotted area to Europe.<jupyter_code>def plot_map(data_array, colour_scale=(None, None), cmap=None):
    data_array[100:220, 670:800].plot.imshow(vmin=colour_scale[0], vmax=colour_scale[1], figsize=(14,12), cmap=cmap)

common_scale = (260, 300)<jupyter_output><empty_output><jupyter_text>First we plot the soil moisture for January 2015. We use an inverted version of the matplotlib ‘viridis’ colour map ranging from yellow (least moisture) to dark blue (most moisture).<jupyter_code>plot_map(sm_2015_jan, cmap='viridis_r')<jupyter_output><empty_output><jupyter_text>For comparison, we plot the data for July 2015. Note the overall lower moisture levels (particularly in southern regions) and the improved coverage at higher altitudes and latitudes (probably due to less snow and ice cover).<jupyter_code>sm_2015_jul = cube.sm.sel(time='2015-07-01 00:00:00', method='nearest')
plot_map(sm_2015_jul, cmap='viridis_r')<jupyter_output><empty_output><jupyter_text>By subtracting the January data from the July data, we can see more clearly where the soil moisture decreases the most in the summer.<jupyter_code>plot_map(sm_2015_jan - sm_2015_jul)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.0892573245514422, 'fraction_numerical': 0.06336588689529866, 'mean_word_length': 6.850267379679145, 'pattern_counts': {'":': 0, '<': 40, '<?xml version=': 0, '>': 40, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '375314', 'license': 'MIT', 'n_tokens_mistral': 1672, 'n_tokens_neox': 1448, 'n_words': 408, 'path': 'examples/notebooks/Ex2-CDS-store-soil-moisture.ipynb', 'repo_name': 'dcs4cop/xcube-cds', 'size': '4403'}