Skip to content

Commit 97cc571

Browse files
authored
Merge pull request #193 from esowc/branch-alba
Improve functions definition
2 parents 5d260e1 + da09ba5 commit 97cc571

File tree

5 files changed

+64
-67
lines changed

5 files changed

+64
-67
lines changed

functions/functions_cams.ipynb

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"def CAMS_download(dates, start_date, end_date, component, component_nom, lat_min, lat_max, lon_min, lon_max, \n",
5050
" area_name, model_full_name, model_level, CAMS_UID = None, CAMS_key = None):\n",
5151
"\n",
52-
" \"\"\" Query and download the CAMS levels dataset from CDS API\n",
52+
" \"\"\" Query and download the CAMS dataset (ADS)\n",
5353
"\n",
5454
" Args:\n",
5555
" dates (arr): Query dates\n",
@@ -247,7 +247,7 @@
247247
"source": [
248248
"def CAMS_read(CAMS_product_name, component, component_nom, dates):\n",
249249
"\n",
250-
" \"\"\" Read CAMS levels dataset as xarray dataset object\n",
250+
" \"\"\" Read CAMS dataset as xarray dataset object (ADS)\n",
251251
"\n",
252252
" Args:\n",
253253
" CAMS_product_name (str): Product name of CAMS product\n",
@@ -328,7 +328,7 @@
328328
"source": [
329329
"def model_levels(model_ds, CAMS_product_name):\n",
330330
"\n",
331-
" \"\"\" Create table with information about the CAMS model levels\n",
331+
" \"\"\" Create table with definition of CAMS model levels\n",
332332
"\n",
333333
" Args:\n",
334334
" model_ds (xarray): Model dataset in xarray format (CAMS)\n",
@@ -338,7 +338,7 @@
338338
" model_levels_df (dataframe): Table with CAMS levels data\n",
339339
" \"\"\"\n",
340340
" \n",
341-
" # Read CSV table with information about the model levels\n",
341+
" # Read CSV table with definition of CAMS model levels\n",
342342
" if '60_LEVELS' in CAMS_product_name:\n",
343343
" model_levels_df = pd.read_csv(os.path.join('/', '/'.join(\n",
344344
" os.getcwd().split('/')[1:3]), 'adc-toolbox', \n",
@@ -518,7 +518,7 @@
518518
"def CAMS_get_levels_data(model_ds, CAMS_product_name, model_levels_df, column_type, \n",
519519
" lat_min, lat_max, lon_min, lon_max):\n",
520520
" \n",
521-
" \"\"\" Get the tropospheric or column model data, depending on the nature of the sensor data\n",
521+
" \"\"\" Retrieve tropospheric or total column model data, depending on the nature of the sensor data\n",
522522
"\n",
523523
" Args:\n",
524524
" model_ds (xarray): Model dataset in xarray format (CAMS)\n",
@@ -577,8 +577,7 @@
577577
"def CAMS_kg_kg_to_kg_m2(model_ds, model_levels_df, sensor, start_date, end_date, \n",
578578
" component_nom, apply_kernels = False, CAMS_UID = None, CAMS_key = None):\n",
579579
"\n",
580-
" \"\"\" Convert the units of the CAMS partial columns for any component from kg/kg to kg/m2. To do this,\n",
581-
" calculate columns above each CAMS half level assuming it is 0 at the top of the atmosphere\n",
580+
" \"\"\" Convert the units of the CAMS data from kg/kg to kg/m2\n",
582581
"\n",
583582
" Args:\n",
584583
" model_ds (xarray): Model dataset in xarray format (CAMS)\n",
@@ -664,7 +663,7 @@
664663
"source": [
665664
"def CAMS_kg_m2_to_molecules_cm2(model_ds, component_MW):\n",
666665
"\n",
667-
" \"\"\" Convert the units of the CAMS dataset for any component from kg/m2 to molecules/cm2\n",
666+
" \"\"\" Convert the units of the CAMS data from kg/m2 to molecules/cm2\n",
668667
"\n",
669668
" Args:\n",
670669
" model_ds (xarray): Model dataset in xarray format (CAMS)\n",
@@ -689,13 +688,13 @@
689688
"source": [
690689
"def CAMS_molecules_cm2_to_DU(model_ds):\n",
691690
"\n",
692-
" \"\"\" Convert the units of the CAMS dataset for any component from molecules/cm2 to DU for ozone\n",
691+
" \"\"\" Convert the units of the CAMS data from molecules/cm2 to DU\n",
693692
"\n",
694693
" Args:\n",
695-
" model_ds (xarray): CAMS levels dataset in xarray format\n",
694+
" model_ds (xarray): Model dataset in xarray format (CAMS)\n",
696695
"\n",
697696
" Returns:\n",
698-
" model_ds (xarray): CAMS levels dataset in xarray format\n",
697+
" model_ds (xarray): Model dataset in xarray format (CAMS)\n",
699698
" \"\"\"\n",
700699
"\n",
701700
" # Convert units from molecules/cm2 to DU\n",

functions/functions_general.ipynb

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
" - 'cams-global-atmospheric-composition-forecasts' \n",
2626
" - 'cams-global-reanalysis-eac4-monthly'\n",
2727
" sensor_type (str): Sensor type\n",
28+
" apply_kernels (bool): Apply (True) or not (False) the averaging kernels \n",
2829
" \"\"\"\n",
2930
"\n",
3031
" if ((sensor == 'tropomi' and sensor_type == 'L2' and model == 'cams' and model_full_name == 'cams-global-atmospheric-composition-forecasts') or\n",
@@ -90,7 +91,7 @@
9091
"source": [
9192
"def components_table(sensor, component_nom, sensor_type):\n",
9293
"\n",
93-
" \"\"\" Create table with information about the components (molecular weight, full name in different datasets)\n",
94+
" \"\"\" Create table with information about the atmospheric component (molecular weight and metadata in each dataset)\n",
9495
"\n",
9596
" Args:\n",
9697
" sensor (str): Name of the sensor\n",
@@ -275,7 +276,7 @@
275276
"source": [
276277
"def available_period(sensor, sensor_type, dates, component_nom, *args):\n",
277278
"\n",
278-
" \"\"\" Remove dates if the folders where the dataset had to be downloaded are empty (dataset not available)\n",
279+
" \"\"\" Get available period and remove the folders where the dataset was downloaded as an empty file (not available)\n",
279280
" \n",
280281
" Args:\n",
281282
" sensor (str): Name of the sensor\n",
@@ -442,7 +443,7 @@
442443
"source": [
443444
"def sensor_convert_units(sensor_ds, sensor, component_nom):\n",
444445
"\n",
445-
" \"\"\" Convert the units of the sensor dataset for any component from mol/m2 to molecules/cm2\n",
446+
" \"\"\" Convert the units of the sensor dataset for any component from mol/m2 to molecules/cm2 or DU\n",
446447
"\n",
447448
" Args:\n",
448449
" sensor_ds (xarray): Sensor dataset in xarray format (TROPOMI, IASI or GOME-2)\n",
@@ -498,7 +499,7 @@
498499
" start_date, end_date, component_nom, apply_kernels = False, \n",
499500
" CAMS_UID = None, CAMS_key = None):\n",
500501
"\n",
501-
" \"\"\" Convert the units of the model dataset for any component from kg/kg or kg/m2 to molecules/cm2\n",
502+
" \"\"\" Convert the units of the model dataset for any component from kg/kg or kg/m2 to molecules/cm2 or DU\n",
502503
"\n",
503504
" Args:\n",
504505
" model (str): Name of the model\n",
@@ -657,7 +658,7 @@
657658
"source": [
658659
"def subset(ds, bbox, sensor, component_nom, sensor_type, subset_type):\n",
659660
"\n",
660-
" \"\"\" Subset any dataset (with latitude and longitude as coordinates) into desired bounding box.\n",
661+
" \"\"\" Subset any dataset (with latitude and longitude as coordinates) into desired bounding box\n",
661662
"\n",
662663
" Args:\n",
663664
" ds (xarray): Dataset in xarray format\n",
@@ -703,7 +704,7 @@
703704
"source": [
704705
"def prepare_df(match_df_time, sensor, component_nom, time, sensor_type):\n",
705706
"\n",
706-
" \"\"\" Prepare dataframe for match\n",
707+
" \"\"\" Organize dataframe columns for match\n",
707708
"\n",
708709
" Args:\n",
709710
" match_df_time (dataframe): Merge table at specific time \n",
@@ -759,8 +760,8 @@
759760
"source": [
760761
"def generate_match_df(sensor_ds, model_ds, bbox, sensor, component_nom, sensor_type, apply_kernels = False):\n",
761762
"\n",
762-
" \"\"\" Intermediate merge table with total column or partial column from both datasets, \n",
763-
" the averaging kernels are applied if possible\n",
763+
" \"\"\" Intermediate merge table with total column or partial column component data \n",
764+
" from both datasets, the averaging kernels can be applied\n",
764765
"\n",
765766
" Args:\n",
766767
" sensor_ds (xarray): Sensor dataset in xarray format (TROPOMI, IASI or GOME-2)\n",
@@ -1057,7 +1058,7 @@
10571058
"def colorbar_range(range_type, data_array, diff_array, max_all, min_all, max_all_diff, min_all_diff,\n",
10581059
" vmin_manual, vmax_manual, vmin_manual_diff, vmax_manual_diff):\n",
10591060
"\n",
1060-
" \"\"\" Define colorbar range\n",
1061+
" \"\"\" Define colorbar range boundaries (original, equal, manual or centered)\n",
10611062
"\n",
10621063
" Args:\n",
10631064
" range_type (str): Range type for colorbar:\n",
@@ -1535,8 +1536,7 @@
15351536
"source": [
15361537
"def define_absolute_limits(vmin_manual, vmax_manual, model_df, sensor_df, diff_df):\n",
15371538
"\n",
1538-
" \"\"\" Define absolute minimum and maximum within model and sensor datasets.\n",
1539-
" Get manual minimum and maximum or calculate it\n",
1539+
" \"\"\" Define absolute minimum and maximum within model and sensor datasets\n",
15401540
"\n",
15411541
" Args:\n",
15421542
" vmin_manual (float): Input vmin by user\n",
@@ -1595,7 +1595,7 @@
15951595
" bbox_list = None, coords_list = None, regions_names = None):\n",
15961596
"\n",
15971597
" \"\"\" Plot model and sensor datasets in the study area for the selected dates, \n",
1598-
" along with a plot of the differences\n",
1598+
" along with a plot of the differences (aggregated, animated, individual or seasonal)\n",
15991599
"\n",
16001600
" Args:\n",
16011601
" model (str): Name of the model\n",
@@ -1793,8 +1793,8 @@
17931793
" width_lon, height_lat,\n",
17941794
" vmin_manual = None, vmax_manual = None):\n",
17951795
"\n",
1796-
" \"\"\" Plot model total columns from the original dataset and the calculated one \n",
1797-
" in the study area for the selected dates\n",
1796+
" \"\"\" Plot model total columns from the original dataset and model total columns \n",
1797+
" after applying the averaging kernels in the study area for the selected dates\n",
17981798
"\n",
17991799
" Args:\n",
18001800
" model (str): Name of the model\n",
@@ -1921,7 +1921,7 @@
19211921
"metadata": {},
19221922
"outputs": [],
19231923
"source": [
1924-
"def get_google_api():\n",
1924+
"def get_Google_API():\n",
19251925
"\n",
19261926
" \"\"\" Get Google API key for reverse geocoding (get country given the coordinates)\n",
19271927
" \n",
@@ -1953,7 +1953,7 @@
19531953
"source": [
19541954
"def get_season(day):\n",
19551955
"\n",
1956-
" \"\"\" Get season given the day\n",
1956+
" \"\"\" Get season given a date\n",
19571957
"\n",
19581958
" Args:\n",
19591959
" day (datetime): Date\n",
@@ -1985,7 +1985,7 @@
19851985
"source": [
19861986
"def linear_regression(axs, X, Y, component_nom):\n",
19871987
"\n",
1988-
" \"\"\" Fit a linear equation to scatter plot between X and Y and print results\n",
1988+
" \"\"\" Fit a linear equation to scatter plot between X and Y and get R2, RMSE and MSE\n",
19891989
"\n",
19901990
" Args:\n",
19911991
" axs (axes): Plot axes\n",
@@ -2039,7 +2039,7 @@
20392039
"source": [
20402040
"def stats_plots_general_settings(axs, component_nom, units, lim_min, lim_max):\n",
20412041
"\n",
2042-
" \"\"\" Set common settings for scatter plots\n",
2042+
" \"\"\" Set common settings for scatter plot and histograms\n",
20432043
"\n",
20442044
" Args:\n",
20452045
" axs (axes): Plot axes\n",
@@ -2226,7 +2226,7 @@
22262226
" elif extent_definition == 'country':\n",
22272227
"\n",
22282228
" # Read Google API key for reverse geocoding (get country by coordinates)\n",
2229-
" google_api_key = get_google_api()\n",
2229+
" google_api_key = get_Google_API()\n",
22302230
"\n",
22312231
" # Reverse geocoding\n",
22322232
" merge_df['country'] = merge_df.apply(lambda row: geocoder.google([row['latitude'], row['longitude']], \n",
@@ -2440,7 +2440,7 @@
24402440
"def timeseries(merge_df, component_nom, sensor, sensor_type, model, plot_dates, units, \n",
24412441
" ymin, ymax, xticks, regions_names, coords_list):\n",
24422442
"\n",
2443-
" \"\"\" Get component data for the closest coordinates to the list of search coordinates and plot them along time\n",
2443+
" \"\"\" Get component data for the closest coordinates to a list of search coordinates and create a timeseries plot\n",
24442444
"\n",
24452445
" Args:\n",
24462446
" merge_df (dataframe): Merge table with datasets total columns and difference\n",
@@ -2646,7 +2646,7 @@
26462646
"def trends(merge_df, component_nom, sensor, model, units, ymin, ymax, \n",
26472647
" plot_dates, regions_names, bbox_list, sensor_break_date, model_break_date):\n",
26482648
"\n",
2649-
" \"\"\" Get trends by region, defined by coordinates. These trends are generated following linear and sinusoidal models.\n",
2649+
" \"\"\" Get trends (linear + sinusoidal model) by region, defined by coordinates\n",
26502650
"\n",
26512651
" Args:\n",
26522652
" merge_df (dataframe): Merge table with datasets total columns and difference\n",
@@ -3067,9 +3067,8 @@
30673067
" width_lon, height_lat, \n",
30683068
" bbox_list = None, coords_list = None, regions_names = None):\n",
30693069
"\n",
3070-
" \"\"\" Get trends at whole plot bounding box. These trends are generated following a linear model.\n",
3071-
" This function is only available for trends without breaks or with a common break \n",
3072-
" at the same day for both the model and sensor datasets.\n",
3070+
" \"\"\" Plot trends (linear) in the study area for selected dates. This function is only available for trends \n",
3071+
" without breaks or with a common break at the same day for both the model and sensor datasets.\n",
30733072
"\n",
30743073
" Args:\n",
30753074
" merge_df (dataframe): Merge table with datasets total columns and difference\n",

functions/functions_gome.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
"source": [
8383
"def GOME_L3_read_AC_SAF(component_nom, sensor_column, dates, lat_res = 0.25, lon_res = 0.25):\n",
8484
"\n",
85-
" \"\"\" Read L3 GOME-2 datasets as xarray dataset object and assign time (AC SAF)\n",
85+
" \"\"\" Read L3 GOME-2 datasets as xarray dataset object (AC SAF)\n",
8686
"\n",
8787
" Args:\n",
8888
" component_nom (str): Component chemical nomenclature\n",
@@ -151,7 +151,7 @@
151151
"source": [
152152
"def GOME_L3_download_TEMIS(component_nom, date, satellite):\n",
153153
"\n",
154-
" \"\"\" Download L3 GOME-2 datasets (TEMIS platform)\n",
154+
" \"\"\" Download L3 GOME-2 datasets (TEMIS)\n",
155155
"\n",
156156
" Args:\n",
157157
" component_nom (str): Component chemical nomenclature\n",
@@ -199,7 +199,7 @@
199199
"source": [
200200
"def GOME_L3_read_TEMIS(component_nom, dates, lat_res = 0.25, lon_res = 0.25):\n",
201201
"\n",
202-
" \"\"\" Read L3 GOME-2 datasets as xarray dataset object and assign time (TEMIS)\n",
202+
" \"\"\" Read L3 GOME-2 datasets as xarray dataset object (TEMIS)\n",
203203
"\n",
204204
" Args:\n",
205205
" component_nom (str): Component chemical nomenclature\n",
@@ -311,7 +311,7 @@
311311
"source": [
312312
"def GOME_L2_download(component_nom, date, satellite):\n",
313313
"\n",
314-
" \"\"\" Download L2 GOME-2 datasets\n",
314+
" \"\"\" Download L2 GOME-2 datasets (AC SAF)\n",
315315
"\n",
316316
" Args:\n",
317317
" component_nom (str): Component chemical nomenclature\n",
@@ -369,7 +369,7 @@
369369
"source": [
370370
"def GOME_L2_read(component_nom, dates, lat_res = 0.25, lon_res = 0.25):\n",
371371
"\n",
372-
" \"\"\" Read L2 GOME-2 datasets as xarray dataset object and assign time\n",
372+
" \"\"\" Read L2 GOME-2 datasets as xarray dataset object (AC SAF)\n",
373373
"\n",
374374
" Args:\n",
375375
" component_nom (str): Component chemical nomenclature\n",

functions/functions_iasi.ipynb

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
"source": [
1616
"def IASI_L3_version(component_nom, year, month):\n",
1717
"\n",
18-
" \"\"\" Get version of L3 IASI dataset for each component nomenclature\n",
18+
" \"\"\" Get version of L3 IASI dataset for each component nomenclature (AERIS)\n",
1919
"\n",
2020
" Args:\n",
2121
" component_nom (str): Component chemical nomenclature\n",
@@ -61,7 +61,7 @@
6161
"source": [
6262
"def IASI_L3_download(component_nom, date, satellite):\n",
6363
"\n",
64-
" \"\"\" Download L3 IASI dataset with curl\n",
64+
" \"\"\" Download L3 IASI dataset with curl (AERIS)\n",
6565
"\n",
6666
" Args:\n",
6767
" component_nom (str): Component chemical nomenclature\n",
@@ -109,7 +109,7 @@
109109
"source": [
110110
"def IASI_L3_read(component_nom, sensor_column, dates, lat_res = 1, lon_res = 1):\n",
111111
"\n",
112-
" \"\"\" Read L3 IASI dataset as xarray dataset object and assign time\n",
112+
" \"\"\" Read L3 IASI dataset as xarray dataset object (AERIS)\n",
113113
"\n",
114114
" Args:\n",
115115
" component_nom (str): Component chemical nomenclature\n",
@@ -176,7 +176,7 @@
176176
"source": [
177177
"def IASI_L2_version(component_nom, year, month, day, satellite):\n",
178178
"\n",
179-
" \"\"\" Get version of L2 IASI dataset for each component nomenclature\n",
179+
" \"\"\" Get version of L2 IASI dataset for each component nomenclature (AERIS)\n",
180180
"\n",
181181
" Args:\n",
182182
" component_nom (str): Component chemical nomenclature\n",
@@ -236,7 +236,7 @@
236236
"source": [
237237
"def IASI_L2_download(component_nom, date, satellite):\n",
238238
"\n",
239-
" \"\"\" Download L2 IASI dataset with curl\n",
239+
" \"\"\" Download L2 IASI dataset with curl (AERIS)\n",
240240
"\n",
241241
" Args:\n",
242242
" component_nom (str): Component chemical nomenclature\n",
@@ -278,7 +278,7 @@
278278
"source": [
279279
"def IASI_L2_read(component_nom, sensor_column, dates, lat_res = 1, lon_res = 1):\n",
280280
"\n",
281-
" \"\"\" Read the L2 IASI dataset as xarray dataset object and assign time\n",
281+
" \"\"\" Read the L2 IASI dataset as xarray dataset object (AERIS)\n",
282282
"\n",
283283
" Args:\n",
284284
" component_nom (str): Component chemical nomenclature\n",
@@ -342,10 +342,10 @@
342342
"\n",
343343
" sensor_ds_sat = xr.DataArray(\n",
344344
" sensor_ds_sat[sensor_column].data,\n",
345-
" dims=('ground_pixel'),\n",
346-
" coords={\n",
347-
" 'latitude': ('ground_pixel', latitude),\n",
348-
" 'longitude': ('ground_pixel', longitude)\n",
345+
" dims = ('ground_pixel'),\n",
346+
" coords = {\n",
347+
" 'latitude': ('ground_pixel', latitude),\n",
348+
" 'longitude': ('ground_pixel', longitude)\n",
349349
" },\n",
350350
" name = component_nom\n",
351351
" )\n",
@@ -367,8 +367,8 @@
367367
" zi,\n",
368368
" dims = ['latitude', 'longitude'],\n",
369369
" coords = {\n",
370-
" 'latitude': (['latitude'], yi[:-1]),\n",
371-
" 'longitude': (['longitude'], xi[:-1])\n",
370+
" 'latitude': (['latitude'], yi[:-1]),\n",
371+
" 'longitude': (['longitude'], xi[:-1])\n",
372372
" },\n",
373373
" name = 'sensor_column'\n",
374374
" )\n",

0 commit comments

Comments
 (0)