<jupyter_start><jupyter_text>Load dataLoad all the files as a single dataset using xarray and its dask capabilities. In this way the files are not loaded in-memory but dask/xarray load them **only** when needed. `mask_and_scale` to True replaces array values equal to `_FillValue` with NA and scale values according to the formula `original_values * scale_factor + add_offset`.<jupyter_code>ds = xr.open_mfdataset(path + '/*.nc', mask_and_scale=True)
ds<jupyter_output><empty_output><jupyter_text>Widget The above selection method allows as to build custom interactive dashboards with a simple jupyter widgets through `ipywidget`. This process is very is simple. You just need to encapsulate you query in a function and decorate it with [interact](https://ipywidgets.readthedocs.io/en/stable/examples/Using%20Interact.htmlBasic-interact) by specifying the desired range. Due to xarray and dask's out of core computation, querying and plotting this dataset is almost instant<jupyter_code>@interact(var=list(ds.data_vars), 
          region=ds.coords['region'].values,
          month=(1,12),
          year=(1980,2018))
def plot_region_month(var, region, year, month):
    ds[var].sel(time='{}-{}'.format(year, month), region=region).plot(color='k') # year
@interact(var=list(ds.data_vars), 
          region=ds.coords['region'].values,
          year_range=IntRangeSlider(min=1980,max=2018),
          timestep=ToggleButtons(options=[('week','w'),('month','m'),('year','a')]),
          continuous_update=False,
         )
def plot_region_month(var, region, year_range,timestep='m'):
    (ds[var].sel(region=region,
                 time=slice(str(year_range[0]), str(year_range[1])))
            .resample(time=timestep).mean()
            .plot(color='k')
    )<jupyter_output><empty_output><jupyter_text>Querying works also for a selection of regions<jupyter_code>#Extract unique countries by taking the first two characters of all regions
countries = set(s[0:2] for s in ds.coords['region'].values)

@interact(var=list(ds.data_vars), 
          region=countries,
          month=(1,12),
          year=(1980,2018))
def plot_region_month(var, region, year, month):
    selection = [s for s in ds.coords['region'].values if s[0:2]==region]
    ds[var].sel(time='{}-{}'.format(year, month), region=selection).plot.line(x='time')<jupyter_output><empty_output><jupyter_text>Another example using geopandas. Here we plot the mean of each selected month/year per region<jupyter_code>plot_min=dict(t2m=-10)
plot_max=dict(t2m=35)

@interact(var=list(ds.data_vars), 
          month=(1,12), 
          year=(1980,2018), # Play(value=1,min=1,max=12,step=1,description='Loop months'),
          continuous_update=False,)
def plot_region_month(var, year, month):
    fig, ax = plt.subplots(1, figsize=(14, 10))
    ax.axis('off')
    time_str = '{}-{}'.format(year, month)
    a = ds[var].sel(time=time_str).mean(dim='time').to_series().reset_index()
    annot_str = '{} \nMean Temp:${:.3g}^oC$'.format(time_str,a.mean().values[0])
    ax.text(.7,0.9,annot_str,fontdict={'fontsize':'xx-large'},transform=ax.transAxes)
    
    (map_df.merge(a, left_on='id', right_on='region')
                  .plot(column=var, cmap='coolwarm', vmin=plot_min.get(var,None),vmax=plot_max.get(var,None),
                        linewidth=0.3, edgecolor='0.4',
                        ax=ax,legend=True,)
                    )<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14756488772236803, 'fraction_numerical': 0.0215806357538641, 'mean_word_length': 4.268817204301075, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '458712', 'license': 'MIT', 'n_tokens_mistral': 1189, 'n_tokens_neox': 1126, 'n_words': 238, 'path': 'notebooks/ERA-NUTS-explore-with-widget.ipynb', 'repo_name': 'energy-modelling-toolkit/era-nuts-code', 'size': '3429'}