<jupyter_start><jupyter_text>15 - Metop-ABC GOME-2 AAI Level 3 - Exercise >> EXERCISE WORKBOOK   Sentinel-5P TROPOMI - Ultraviolet Aerosol Index (AI) - Level 2 This notebook is an `exercise workbook` which allows you to practise the preparation of Sentinel-5P TROPOMI Aerosol Index Level-2 data to analyse a dust event at the beginning of February 2021.  How it works This exercise workbook consists of two types of exercises:  Coding assignmentsCoding assignments ask you to fill an empty code cell with code.You recognize `coding assignments` as the yellow-coloured boxes.Coding assignment  QuestionsQuestions ask you to reflect on a result and output. `Questions` are provided as green-coloured boxes.Question   Outline:* [1 - Load and browse Sentinel-5P TROPOMI Aerosol Index Level 2 data](load_browse_s5p2)* [2 - Retrieve the variable 'Aerosol index from 354 and 388 nm' as xarray.DataArray](data_retrieve_s5p2)* [3 - Visualize 'Sentinel-5P TROPOMI aerosol index from 388 and 354 nm'](visualize_s5p2)* [4 - Create a geographical subset for Europe](subset_s5p2)   Load required libraries<jupyter_code>%matplotlib inline
import os
import xarray as xr
import numpy as np
import netCDF4 as nc
import pandas as pd

from IPython.display import HTML

import matplotlib.pyplot as plt
import matplotlib.colors
from matplotlib.cm import get_cmap
from matplotlib import animation
import cartopy.crs as ccrs
from cartopy.mpl.gridliner import LONGITUDE_FORMATTER, LATITUDE_FORMATTER
import cartopy.feature as cfeature

from matplotlib.axes import Axes
from cartopy.mpl.geoaxes import GeoAxes
GeoAxes._pcolormesh_patched = Axes.pcolormesh

import warnings
warnings.simplefilter(action = "ignore", category = RuntimeWarning)
warnings.simplefilter(action = "ignore", category = UserWarning)<jupyter_output><empty_output><jupyter_text>Load helper functions<jupyter_code>%run ./functions.ipynb<jupyter_output><empty_output><jupyter_text>Load and browse `Sentinel-5P TROPOMI Aerosol Index Level 2` data A Sentinel-5P TROPOMI Aerosol Index Level 2 file is organised in two groups: `PRODUCT` and `METADATA`. The `PRODUCT` group stores the main data fields of the product, including `latitude`, `longitude` and the variable itself. The `METADATA` group provides additional metadata items.Sentinel-5P TROPOMI variables have the following dimensions:* `scanline`: the number of measurements in the granule / along-track dimension index* `ground_pixel`: the number of spectra in a measurement / across-track dimension index* `time`: time reference for the data* `corner`: pixel corner indexSentinel-5P TROPOMI data is disseminated in `netCDF`. You can load a `netCDF` file with the `open_dataset()` function of the xarray library. In order to load the variable as part of a Sentinel-5P data files, you have to specify the following keyword arguments: - `group='PRODUCT'`: to load the `PRODUCT` groupLet us load a Sentinel-5P TROPOMI data file as `xarray.Dataset` from 06 February 2021:<jupyter_code>file = xr.open_dataset('./eodata/sentinel5p/ai/2021/02/06/S5P_OFFL_L2__AER_AI_20210206T120713_20210206T134843_17197_01_010400_20210208T015719.nc', group='PRODUCT')
file<jupyter_output><empty_output><jupyter_text>Question:   Look at the loaded xarray.Dataset and identify the dimensions. What data variables are available in the data file?   Retrieve the variable `Aerosol index from 354 and 388 nm` as xarray.DataArray As a next step, you want to load one specific data variable from the `xarray.Dataset` above. Coding assignment:Enter below the code which selects the data variable aerosol_index_354_388 from the xarray.Dataset file and call it ai.<jupyter_code># Enter your solution here<jupyter_output><empty_output><jupyter_text>Question:    Can you identify the `long_name` of the selected data variable and do you know where it is stored?  You see that the `xarray.DataArray` has three dimensions, with the dimension time only having one entry. Let us select the single time step, in order to have the two-dimensional data array. Coding assignment:Enter below the code which selects the one time step from the xarray.DataArray `ai` and call it ai_0602<jupyter_code># Enter your solution here<jupyter_output><empty_output><jupyter_text>Additionally, you can save the attributes `units` and `longname`, which you can make use of when visualizing the data. Coding assignment:Enter below the code which selects the following attributes: * `long_name` and * `units`.    Call the variables `longname` and `units` respectively.<jupyter_code># Enter your solution here<jupyter_output><empty_output><jupyter_text>Visualize `Sentinel-5P TROPOMI aerosol index from 388 and 354 nm` The next step is to visualize the dataset. Coding assignment:Make use of the function [visualize_pcolormesh](../functions.ipynbvisualize_pcolormesh) in order to visualize the xarray.DataArray ai_0602.     The following kwargs have to be defined:* `data_array`* `longitude`* `latitude`* `projection`* `color_sale`* `unit`* `longname`* `vmin`,* `vmax`,* `lonmin`, `lonmax`, `latmin`, `latmax`* `set_global`    Note: with `?visualize_pcolormesh` you can open the function's docstring to see what keyword arguments are needed to prepare your plot.<jupyter_code># Enter your solution here<jupyter_output><empty_output><jupyter_text>Create a geographical subset for Europe The map above shows the aerosol index of one footprint along the entire latitude range. Let us create a geographical subset for Europe, in order to better analyse the Saharan dust event over Europe. Coding assignment:Create a geographical subset for Europe. Make use of the function generate_geographical_subset and call the new DataArray ai_0602_subset.The bounding box information can be the following:- **latmin=28.**- **latmax=71.**- **lonmin=-22.**- **lonmax=43**HINT: With `?generate_geographical_subset`, you can see what keyword arguments the function requires.<jupyter_code># Enter your solution here<jupyter_output><empty_output><jupyter_text>Question:How many entries for `scanline` does the DataArray **ai_0602_subset** have compared to the DataArray **ai_0602**?  Let us now visualize the subsetted `xarray.DataArray` over Europe. Coding assignment:Make use of the function [visualize_pcolormesh](../functions.ipynbvisualize_pcolormesh) in order to visualize the subsetted DataArray ai_0602_subset.     Make sure to set the `set_global` kwarg to `False` and specify the latitude and longitude bounding box to the ones specified for Europe.Try also to add the time information as part of the title. Add the string of the datetime information to the `longname` variable: `longname + ' ' + str(ai_0602_subset.time.data)`.<jupyter_code># Enter your solution here<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.07005800981704596, 'fraction_numerical': 0.026030046110367397, 'mean_word_length': 5.889344262295082, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 39, 'https://': 0, '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': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '415414', 'license': 'MIT', 'n_tokens_mistral': 2112, 'n_tokens_neox': 1931, 'n_words': 799, 'path': '90_workshops/202104_egu_short_course/14_Sentinel-5P_TROPOMI_AI_L2_exercise.ipynb', 'repo_name': 'trivedi-c/atm_Practical3', 'size': '6723'}