Generation

testsMon, 17 Jul 2023

import xarray as xr import numpy as np import matplotlib.pyplot as plt import cartopy.crs as ccrs from scipy import stats # Define the path to the data data_dir = "C:/Users/alons/OneDrive/Escritorio/KITMaster/Climatology/" file_name = "2001_2020_modis_monthly_l3_teaching.nc" # Open the dataset ds = xr.open_dataset(data_dir + file_name) # Extract AOD data aod = ds["AOD"] # Calculate the trend using linear regression trend = xr.apply_ufunc(stats.linregress, np.arange(len(aod.time)), aod, input_core_dims=[["time"]], output_core_dims=[[]], vectorize=True, dask="parallelized") # Extract the slope coefficient (trend) aod_trend = trend.slope # Mask non-significant trends (p-value > 0.05) aod_trend_masked = aod_trend.where(trend.pvalue < 0.05) # Create a figure and axes fig, ax = plt.subplots(figsize=(12, 6), subplot_kw={"projection": ccrs.PlateCarree()}) # Plot the significant trends aod_trend_masked.plot(ax=ax, transform=ccrs.PlateCarree(), cmap="RdBu_r", robust=True, cbar_kwargs={"label": "AOD Trend"}) ax.set_title("Global Trend Analysis of Aerosol Optical Depth (AOD)") # Add coastlines ax.coastlines() # Show the plot plt.show()

--- # Exercises ## Excercise 1 ### Read the data Read the data stored in `C:/Users/alons/OneDrive/Escritorio/KITMaster/Climatology/2001_2020_modis_monthly_l3_teaching.nc`:

Questions about programming?Chat with your personal AI assistant