Qui troverai l'ultimo passo "dell'avventura" iniziata con questo articolo in cui riporto l'andamento del PM10 nel nord Italia nell'ultimo decennio. Il come ho proceduto all'analisi è riportato in quest'altro articolo.

Lo scopo dell'articolo che stai per leggere è visualizzare su mappa le aree di analisi, cosa che fino ad ora non avevo mostrato.

Tutto l'iter è stato bello lungo ed è per questo che l'ho dovuto suddividere in ben tre differenti articoli.

Prima di iniziare¶

Librerie¶

Come per tutti gli articoli di PyGIS-Blog inizio con l'elenco delle librerie usate. Una menzione speciale è per la funzione xarray.open_mfdataset perchè mi ha consentito di velocizzare tantissimo la lettura di tutti i file .nc grazie al nativo supporto a dask.delayed.

Devo approfondire Dask appena ho tempo e Dask Delayed sembra un buon punto di partenza pratico su cui lavorare per il mio solito training on the job :)

In [1]:
from pathlib import Path
import xarray as xr
import geopandas as gpd
import matplotlib.pyplot as plt
from matplotlib import patheffects

Fonti dati¶

Come giĂ  spiegato nei precedenti articoli di questa involontaria miniserie, i dati usati sono quelli distributi dal Copernicus Atmosphere Monitoring Service. In particolare ho usato dati con una copertura temporale che va dal 2013 a marzo 2024.

In [2]:
nc_data_path = Path("/home/max/Desktop/pianura_padana/processed/netcdf")

nc_files = list(nc_data_path.glob("*.nc"))

nc_files
Out[2]:
[PosixPath('/home/max/Desktop/pianura_padana/processed/netcdf/particulate_matter_10um-2021-forecasts.nc'),
 PosixPath('/home/max/Desktop/pianura_padana/processed/netcdf/particulate_matter_10um-2017-reanalyses.nc'),
 PosixPath('/home/max/Desktop/pianura_padana/processed/netcdf/particulate_matter_10um-2020-reanalyses.nc'),
 PosixPath('/home/max/Desktop/pianura_padana/processed/netcdf/particulate_matter_10um-2014-reanalyses.nc'),
 PosixPath('/home/max/Desktop/pianura_padana/processed/netcdf/particulate_matter_10um-2013-reanalyses.nc'),
 PosixPath('/home/max/Desktop/pianura_padana/processed/netcdf/particulate_matter_10um-2016-reanalyses.nc'),
 PosixPath('/home/max/Desktop/pianura_padana/processed/netcdf/particulate_matter_10um-2023-forecasts.nc'),
 PosixPath('/home/max/Desktop/pianura_padana/processed/netcdf/particulate_matter_10um-2019-reanalyses.nc'),
 PosixPath('/home/max/Desktop/pianura_padana/processed/netcdf/particulate_matter_10um-2015-reanalyses.nc'),
 PosixPath('/home/max/Desktop/pianura_padana/processed/netcdf/particulate_matter_10um-2018-reanalyses.nc'),
 PosixPath('/home/max/Desktop/pianura_padana/processed/netcdf/particulate_matter_10um-2022-forecasts.nc'),
 PosixPath('/home/max/Desktop/pianura_padana/processed/netcdf/particulate_matter_10um-2024-forecasts.nc')]
In [3]:
main_city_path = Path.cwd().joinpath('data', 'citta_significative.shp')
main_city = gpd.read_file(main_city_path)

target_zones_boundaries = Path.cwd().parent.parent.parent.parent.joinpath('sample_data').joinpath('ProvCM01012023_g').joinpath('ProvCM01012023_g_WGS84.shp')

target_zones = gpd.read_file(target_zones_boundaries)
target_zones = target_zones[target_zones['COD_REG'].isin(list(range(1, 12)))]
target_zones = target_zones.to_crs(4326).sort_values('DEN_UTS')

figsize_w = 10
figsize_h = figsize_w / 1
plot_dpi = 300

polygon_facecolor = "none"
polygon_edgecolor = "#76CFEF"
polygon_linewidth = 1.0

marker_edgecolor = "black"
marker_facecolor = "red"
marker_type = "*"
marker_s = 250
marker_label_facecolor = "white"
marker_label_alpha = 0.75
marker_font_color = "black"
marker_font_size = 8
marker_x_offset = 0.05
marker_y_offset = -0.05

path_effects_linewidth = 3
path_effects_foreground = "white"

raster_cmap = "autumn"

L'area geografica è sempre quella dei precedenti due articoli, la riporto comunque di seguito per completezza.

In [4]:
fig1, ax1 = plt.subplots(figsize=(figsize_w, figsize_h), dpi=plot_dpi)

target_zones.plot(
    ax=ax1,
    facecolor=polygon_facecolor, 
    edgecolor=polygon_edgecolor,
    linewidth=polygon_linewidth
)
for _index, _row in main_city.iterrows():
    coordinates = _row.geometry.xy
    ax1.scatter(
        *coordinates,
        s=marker_s,
        marker=marker_type,
        facecolor=marker_facecolor,
        edgecolor=marker_edgecolor
    )
    label = plt.text(
        x=coordinates[0][0] + marker_x_offset,
        y=coordinates[1][0] + marker_y_offset,
        s=_row.citta,
        fontdict=dict(color=marker_font_color, size=marker_font_size),
        bbox=dict(facecolor=marker_label_facecolor, alpha=marker_label_alpha),
        path_effects=[patheffects.withStroke(linewidth=path_effects_linewidth, foreground=path_effects_foreground)]
    )
    label.set_path_effects([patheffects.withStroke(linewidth=path_effects_linewidth, foreground=path_effects_foreground)])
plt.show()
No description has been provided for this image

Contenuti¶

  • Analisi sul singolo file
  • Analisi su tutti i file
  • Conclusione

Analisi sul singolo file¶

Lettura del .nc¶

Prima di iterare tutto il processo sull'intero arco temporale ho preferito effettuare delle verifiche su un solo anno, anche per prendere meglio confidenza con i dati.

In [5]:
single_dataset = xr.open_dataset(
    filename_or_obj='/home/max/Desktop/pianura_padana/processed/netcdf/particulate_matter_10um-2013-reanalyses.nc',
    engine="netcdf4",
    decode_coords="all",
)

single_dataset
Out[5]:
<xarray.Dataset> Size: 163MB
Dimensions:                  (time: 8760, lon: 91, lat: 51)
Coordinates:
  * time                     (time) datetime64[ns] 70kB 2013-01-01 ... 2013-1...
  * lon                      (lon) float64 728B 6.0 6.1 6.2 ... 14.8 14.9 15.0
  * lat                      (lat) float64 408B 42.0 42.1 42.2 ... 46.9 47.0
    spatial_ref              int64 8B ...
    level                    int64 8B ...
Data variables:
    particulate_matter_10um  (time, lat, lon) float32 163MB ...
Attributes:
    Conventions:  CF-1.7
    Title:        CAMS European air quality interim reanalysis
    Provider:     COPERNICUS European air quality service
    Production:   COPERNICUS Atmosphere Monitoring Service
    pollutant:    particulate_matter_10um
    sea_level:    0
xarray.Dataset
    • time: 8760
    • lon: 91
    • lat: 51
    • time
      (time)
      datetime64[ns]
      2013-01-01 ... 2013-12-31T23:00:00
      standard_name :
      time
      axis :
      T
      long_name :
      valid time
      array(['2013-01-01T00:00:00.000000000', '2013-01-01T01:00:00.000000000',
             '2013-01-01T02:00:00.000000000', ..., '2013-12-31T21:00:00.000000000',
             '2013-12-31T22:00:00.000000000', '2013-12-31T23:00:00.000000000'],
            dtype='datetime64[ns]')
    • lon
      (lon)
      float64
      6.0 6.1 6.2 6.3 ... 14.8 14.9 15.0
      standard_name :
      longitude
      long_name :
      longitude
      units :
      degrees_east
      axis :
      X
      array([ 6. ,  6.1,  6.2,  6.3,  6.4,  6.5,  6.6,  6.7,  6.8,  6.9,  7. ,  7.1,
              7.2,  7.3,  7.4,  7.5,  7.6,  7.7,  7.8,  7.9,  8. ,  8.1,  8.2,  8.3,
              8.4,  8.5,  8.6,  8.7,  8.8,  8.9,  9. ,  9.1,  9.2,  9.3,  9.4,  9.5,
              9.6,  9.7,  9.8,  9.9, 10. , 10.1, 10.2, 10.3, 10.4, 10.5, 10.6, 10.7,
             10.8, 10.9, 11. , 11.1, 11.2, 11.3, 11.4, 11.5, 11.6, 11.7, 11.8, 11.9,
             12. , 12.1, 12.2, 12.3, 12.4, 12.5, 12.6, 12.7, 12.8, 12.9, 13. , 13.1,
             13.2, 13.3, 13.4, 13.5, 13.6, 13.7, 13.8, 13.9, 14. , 14.1, 14.2, 14.3,
             14.4, 14.5, 14.6, 14.7, 14.8, 14.9, 15. ])
    • lat
      (lat)
      float64
      42.0 42.1 42.2 ... 46.8 46.9 47.0
      standard_name :
      latitude
      long_name :
      latitude
      units :
      degrees_north
      axis :
      Y
      array([42. , 42.1, 42.2, 42.3, 42.4, 42.5, 42.6, 42.7, 42.8, 42.9, 43. , 43.1,
             43.2, 43.3, 43.4, 43.5, 43.6, 43.7, 43.8, 43.9, 44. , 44.1, 44.2, 44.3,
             44.4, 44.5, 44.6, 44.7, 44.8, 44.9, 45. , 45.1, 45.2, 45.3, 45.4, 45.5,
             45.6, 45.7, 45.8, 45.9, 46. , 46.1, 46.2, 46.3, 46.4, 46.5, 46.6, 46.7,
             46.8, 46.9, 47. ])
    • spatial_ref
      ()
      int64
      ...
      crs_wkt :
      GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]
      semi_major_axis :
      6378137.0
      semi_minor_axis :
      6356752.314245179
      inverse_flattening :
      298.257223563
      reference_ellipsoid_name :
      WGS 84
      longitude_of_prime_meridian :
      0.0
      prime_meridian_name :
      Greenwich
      geographic_crs_name :
      WGS 84
      horizontal_datum_name :
      World Geodetic System 1984
      grid_mapping_name :
      latitude_longitude
      spatial_ref :
      GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]
      [1 values with dtype=int64]
    • level
      ()
      int64
      ...
      [1 values with dtype=int64]
    • particulate_matter_10um
      (time, lat, lon)
      float32
      ...
      standard_name :
      mass_concentration_of_pm10_ambient_aerosol_in_air
      long_name :
      mass concentration of particulate matter with d < 10 µm
      units :
      µg/m3
      [40655160 values with dtype=float32]
    • time
      PandasIndex
      PandasIndex(DatetimeIndex(['2013-01-01 00:00:00', '2013-01-01 01:00:00',
                     '2013-01-01 02:00:00', '2013-01-01 03:00:00',
                     '2013-01-01 04:00:00', '2013-01-01 05:00:00',
                     '2013-01-01 06:00:00', '2013-01-01 07:00:00',
                     '2013-01-01 08:00:00', '2013-01-01 09:00:00',
                     ...
                     '2013-12-31 14:00:00', '2013-12-31 15:00:00',
                     '2013-12-31 16:00:00', '2013-12-31 17:00:00',
                     '2013-12-31 18:00:00', '2013-12-31 19:00:00',
                     '2013-12-31 20:00:00', '2013-12-31 21:00:00',
                     '2013-12-31 22:00:00', '2013-12-31 23:00:00'],
                    dtype='datetime64[ns]', name='time', length=8760, freq=None))
    • lon
      PandasIndex
      PandasIndex(Index([               6.0,  6.100000000000001,  6.200000000000003,
              6.300000000000001,  6.400000000000002,                6.5,
              6.600000000000001,  6.700000000000003,  6.800000000000001,
              6.900000000000002,                7.0,  7.100000000000001,
              7.200000000000003,  7.300000000000004,  7.399999999999999,
                            7.5,  7.600000000000001,  7.700000000000003,
              7.800000000000004,  7.899999999999999,                8.0,
              8.100000000000001,  8.200000000000003,  8.300000000000004,
              8.399999999999999,                8.5,  8.600000000000001,
              8.700000000000003,  8.800000000000004,  8.899999999999999,
                            9.0,  9.100000000000001,  9.200000000000003,
              9.300000000000004,  9.399999999999999,                9.5,
              9.600000000000001,  9.700000000000003,  9.800000000000004,
              9.899999999999999,               10.0, 10.100000000000001,
             10.200000000000003, 10.300000000000004, 10.399999999999999,
                           10.5, 10.600000000000001, 10.700000000000003,
             10.800000000000004, 10.899999999999999,               11.0,
             11.100000000000001, 11.200000000000003, 11.300000000000004,
             11.399999999999999,               11.5, 11.600000000000001,
             11.700000000000003, 11.800000000000004, 11.899999999999999,
                           12.0, 12.100000000000001, 12.200000000000003,
             12.300000000000004, 12.399999999999999,               12.5,
             12.600000000000001, 12.700000000000003, 12.800000000000004,
             12.899999999999999,               13.0, 13.100000000000001,
             13.200000000000003, 13.300000000000004, 13.400000000000006,
                           13.5, 13.600000000000001, 13.700000000000003,
             13.800000000000004, 13.900000000000006,               14.0,
             14.100000000000001, 14.200000000000003, 14.300000000000004,
             14.400000000000006,               14.5, 14.600000000000001,
             14.700000000000003, 14.800000000000004, 14.900000000000006,
                           15.0],
            dtype='float64', name='lon'))
    • lat
      PandasIndex
      PandasIndex(Index([              42.0,               42.1,               42.2,
                           42.3,               42.4,               42.5,
                           42.6,               42.7,               42.8,
                           42.9,               43.0,               43.1,
                           43.2,               43.3,               43.4,
                           43.5,               43.6,               43.7,
                           43.8,               43.9,               44.0,
                           44.1,               44.2,               44.3,
                           44.4,               44.5,               44.6,
                           44.7,               44.8,               44.9,
                           45.0,               45.1,               45.2,
                           45.3,               45.4,               45.5,
                           45.6,               45.7,               45.8,
                           45.9,               46.0,               46.1,
                           46.2,               46.3, 46.400000000000006,
                           46.5,               46.6,               46.7,
                           46.8, 46.900000000000006,               47.0],
            dtype='float64', name='lat'))
  • Conventions :
    CF-1.7
    Title :
    CAMS European air quality interim reanalysis
    Provider :
    COPERNICUS European air quality service
    Production :
    COPERNICUS Atmosphere Monitoring Service
    pollutant :
    particulate_matter_10um
    sea_level :
    0

Come si può vedere, il Dataset del 2013 è composto da 8760 ore (24h x 365d) per un peso di ben 163MB. Ricordo che la risoluzione spaziale di questi dati è circa 7.5km x 7.5km.

Analisi sul singolo giorno¶

Di seguito punto all'estrazione e visualizzazione di una singola ora di un singolo giorno.

In [6]:
target_test_time = '2013-07-09T13:00:00'

target_hour_selection = single_dataset.sel(time=target_test_time).to_array().squeeze()

target_hour_selection
Out[6]:
<xarray.DataArray (lat: 51, lon: 91)> Size: 19kB
array([[32.88422  , 32.85841  , 32.44171  , ..., 13.436613 , 14.311139 ,
        15.214118 ],
       [33.01072  , 32.81864  , 32.40152  , ..., 15.240301 , 15.444803 ,
        15.649314 ],
       [33.0541   , 32.07483  , 31.37025  , ..., 15.6916895, 15.567043 ,
        15.631379 ],
       ...,
       [14.526992 , 14.565249 , 14.565497 , ..., 19.279963 , 19.53084  ,
        19.920486 ],
       [14.2113695, 14.210173 , 14.210417 , ..., 19.572437 , 20.62339  ,
        20.301117 ],
       [14.699474 , 14.72564  , 14.72589  , ..., 20.786325 , 21.017164 ,
        20.689896 ]], dtype=float32)
Coordinates:
    time         datetime64[ns] 8B 2013-07-09T13:00:00
  * lon          (lon) float64 728B 6.0 6.1 6.2 6.3 6.4 ... 14.7 14.8 14.9 15.0
  * lat          (lat) float64 408B 42.0 42.1 42.2 42.3 ... 46.7 46.8 46.9 47.0
    spatial_ref  int64 8B ...
    level        int64 8B ...
    variable     <U23 92B 'particulate_matter_10um'
Attributes:
    Conventions:  CF-1.7
    Title:        CAMS European air quality interim reanalysis
    Provider:     COPERNICUS European air quality service
    Production:   COPERNICUS Atmosphere Monitoring Service
    pollutant:    particulate_matter_10um
    sea_level:    0
xarray.DataArray
  • lat: 51
  • lon: 91
  • 32.88 32.86 32.44 31.98 31.43 30.07 ... 18.36 20.0 20.79 21.02 20.69
    array([[32.88422  , 32.85841  , 32.44171  , ..., 13.436613 , 14.311139 ,
            15.214118 ],
           [33.01072  , 32.81864  , 32.40152  , ..., 15.240301 , 15.444803 ,
            15.649314 ],
           [33.0541   , 32.07483  , 31.37025  , ..., 15.6916895, 15.567043 ,
            15.631379 ],
           ...,
           [14.526992 , 14.565249 , 14.565497 , ..., 19.279963 , 19.53084  ,
            19.920486 ],
           [14.2113695, 14.210173 , 14.210417 , ..., 19.572437 , 20.62339  ,
            20.301117 ],
           [14.699474 , 14.72564  , 14.72589  , ..., 20.786325 , 21.017164 ,
            20.689896 ]], dtype=float32)
    • time
      ()
      datetime64[ns]
      2013-07-09T13:00:00
      standard_name :
      time
      axis :
      T
      long_name :
      valid time
      array('2013-07-09T13:00:00.000000000', dtype='datetime64[ns]')
    • lon
      (lon)
      float64
      6.0 6.1 6.2 6.3 ... 14.8 14.9 15.0
      standard_name :
      longitude
      long_name :
      longitude
      units :
      degrees_east
      axis :
      X
      array([ 6. ,  6.1,  6.2,  6.3,  6.4,  6.5,  6.6,  6.7,  6.8,  6.9,  7. ,  7.1,
              7.2,  7.3,  7.4,  7.5,  7.6,  7.7,  7.8,  7.9,  8. ,  8.1,  8.2,  8.3,
              8.4,  8.5,  8.6,  8.7,  8.8,  8.9,  9. ,  9.1,  9.2,  9.3,  9.4,  9.5,
              9.6,  9.7,  9.8,  9.9, 10. , 10.1, 10.2, 10.3, 10.4, 10.5, 10.6, 10.7,
             10.8, 10.9, 11. , 11.1, 11.2, 11.3, 11.4, 11.5, 11.6, 11.7, 11.8, 11.9,
             12. , 12.1, 12.2, 12.3, 12.4, 12.5, 12.6, 12.7, 12.8, 12.9, 13. , 13.1,
             13.2, 13.3, 13.4, 13.5, 13.6, 13.7, 13.8, 13.9, 14. , 14.1, 14.2, 14.3,
             14.4, 14.5, 14.6, 14.7, 14.8, 14.9, 15. ])
    • lat
      (lat)
      float64
      42.0 42.1 42.2 ... 46.8 46.9 47.0
      standard_name :
      latitude
      long_name :
      latitude
      units :
      degrees_north
      axis :
      Y
      array([42. , 42.1, 42.2, 42.3, 42.4, 42.5, 42.6, 42.7, 42.8, 42.9, 43. , 43.1,
             43.2, 43.3, 43.4, 43.5, 43.6, 43.7, 43.8, 43.9, 44. , 44.1, 44.2, 44.3,
             44.4, 44.5, 44.6, 44.7, 44.8, 44.9, 45. , 45.1, 45.2, 45.3, 45.4, 45.5,
             45.6, 45.7, 45.8, 45.9, 46. , 46.1, 46.2, 46.3, 46.4, 46.5, 46.6, 46.7,
             46.8, 46.9, 47. ])
    • spatial_ref
      ()
      int64
      ...
      crs_wkt :
      GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]
      semi_major_axis :
      6378137.0
      semi_minor_axis :
      6356752.314245179
      inverse_flattening :
      298.257223563
      reference_ellipsoid_name :
      WGS 84
      longitude_of_prime_meridian :
      0.0
      prime_meridian_name :
      Greenwich
      geographic_crs_name :
      WGS 84
      horizontal_datum_name :
      World Geodetic System 1984
      grid_mapping_name :
      latitude_longitude
      spatial_ref :
      GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]
      [1 values with dtype=int64]
    • level
      ()
      int64
      ...
      [1 values with dtype=int64]
    • variable
      ()
      <U23
      'particulate_matter_10um'
      array('particulate_matter_10um', dtype='<U23')
    • lon
      PandasIndex
      PandasIndex(Index([               6.0,  6.100000000000001,  6.200000000000003,
              6.300000000000001,  6.400000000000002,                6.5,
              6.600000000000001,  6.700000000000003,  6.800000000000001,
              6.900000000000002,                7.0,  7.100000000000001,
              7.200000000000003,  7.300000000000004,  7.399999999999999,
                            7.5,  7.600000000000001,  7.700000000000003,
              7.800000000000004,  7.899999999999999,                8.0,
              8.100000000000001,  8.200000000000003,  8.300000000000004,
              8.399999999999999,                8.5,  8.600000000000001,
              8.700000000000003,  8.800000000000004,  8.899999999999999,
                            9.0,  9.100000000000001,  9.200000000000003,
              9.300000000000004,  9.399999999999999,                9.5,
              9.600000000000001,  9.700000000000003,  9.800000000000004,
              9.899999999999999,               10.0, 10.100000000000001,
             10.200000000000003, 10.300000000000004, 10.399999999999999,
                           10.5, 10.600000000000001, 10.700000000000003,
             10.800000000000004, 10.899999999999999,               11.0,
             11.100000000000001, 11.200000000000003, 11.300000000000004,
             11.399999999999999,               11.5, 11.600000000000001,
             11.700000000000003, 11.800000000000004, 11.899999999999999,
                           12.0, 12.100000000000001, 12.200000000000003,
             12.300000000000004, 12.399999999999999,               12.5,
             12.600000000000001, 12.700000000000003, 12.800000000000004,
             12.899999999999999,               13.0, 13.100000000000001,
             13.200000000000003, 13.300000000000004, 13.400000000000006,
                           13.5, 13.600000000000001, 13.700000000000003,
             13.800000000000004, 13.900000000000006,               14.0,
             14.100000000000001, 14.200000000000003, 14.300000000000004,
             14.400000000000006,               14.5, 14.600000000000001,
             14.700000000000003, 14.800000000000004, 14.900000000000006,
                           15.0],
            dtype='float64', name='lon'))
    • lat
      PandasIndex
      PandasIndex(Index([              42.0,               42.1,               42.2,
                           42.3,               42.4,               42.5,
                           42.6,               42.7,               42.8,
                           42.9,               43.0,               43.1,
                           43.2,               43.3,               43.4,
                           43.5,               43.6,               43.7,
                           43.8,               43.9,               44.0,
                           44.1,               44.2,               44.3,
                           44.4,               44.5,               44.6,
                           44.7,               44.8,               44.9,
                           45.0,               45.1,               45.2,
                           45.3,               45.4,               45.5,
                           45.6,               45.7,               45.8,
                           45.9,               46.0,               46.1,
                           46.2,               46.3, 46.400000000000006,
                           46.5,               46.6,               46.7,
                           46.8, 46.900000000000006,               47.0],
            dtype='float64', name='lat'))
  • Conventions :
    CF-1.7
    Title :
    CAMS European air quality interim reanalysis
    Provider :
    COPERNICUS European air quality service
    Production :
    COPERNICUS Atmosphere Monitoring Service
    pollutant :
    particulate_matter_10um
    sea_level :
    0
In [7]:
s_min = target_hour_selection.min().values.round(2)
s_max = target_hour_selection.max().values.round(2)

print(f"Nell'ora presa in considerazione si nota che\n il PM10 minimo era pari a {s_min} µg/m3\n ed il massimo era {s_max} µg/m3")
Nell'ora presa in considerazione si nota che
 il PM10 minimo era pari a 2.180000066757202 µg/m3
 ed il massimo era 37.630001068115234 µg/m3
In [8]:
fig2, ax2 = plt.subplots(figsize=(figsize_w, figsize_h), dpi=plot_dpi)

target_zones.plot(
    ax=ax2,
    facecolor=polygon_facecolor, 
    edgecolor=polygon_edgecolor,
    linewidth=polygon_linewidth
)
target_hour_selection.plot.imshow(
    ax=ax2,
    cmap=raster_cmap,
)
for _index, _row in main_city.iterrows():
    coordinates = _row.geometry.xy
    ax2.scatter(
        *coordinates,
        s=marker_s,
        marker=marker_type,
        facecolor=marker_facecolor,
        edgecolor=marker_edgecolor
    )
    label = plt.text(
        x=coordinates[0][0] + marker_x_offset,
        y=coordinates[1][0] + marker_y_offset,
        s=_row.citta,
        fontdict=dict(color=marker_font_color, size=marker_font_size),
        bbox=dict(facecolor=marker_label_facecolor, alpha=marker_label_alpha),
        path_effects=[patheffects.withStroke(linewidth=path_effects_linewidth, foreground=path_effects_foreground)]
    )
    label.set_path_effects([patheffects.withStroke(linewidth=path_effects_linewidth, foreground=path_effects_foreground)])
plt.title(f"Distribuzione del PM10 per il {target_test_time}")
plt.show()
No description has been provided for this image

Conteggio degli sforamenti in un anno¶

Di seguito calcolo la media giornaliera per tutto l'anno in esame.

In [9]:
daily_data = single_dataset.resample(time='D').mean('time')  

daily_data
Out[9]:
<xarray.Dataset> Size: 7MB
Dimensions:                  (lon: 91, lat: 51, time: 365)
Coordinates:
  * lon                      (lon) float64 728B 6.0 6.1 6.2 ... 14.8 14.9 15.0
  * lat                      (lat) float64 408B 42.0 42.1 42.2 ... 46.9 47.0
    spatial_ref              int64 8B 0
    level                    int64 8B 0
  * time                     (time) datetime64[ns] 3kB 2013-01-01 ... 2013-12-31
Data variables:
    particulate_matter_10um  (time, lat, lon) float32 7MB 14.59 14.76 ... 15.35
Attributes:
    Conventions:  CF-1.7
    Title:        CAMS European air quality interim reanalysis
    Provider:     COPERNICUS European air quality service
    Production:   COPERNICUS Atmosphere Monitoring Service
    pollutant:    particulate_matter_10um
    sea_level:    0
xarray.Dataset
    • lon: 91
    • lat: 51
    • time: 365
    • lon
      (lon)
      float64
      6.0 6.1 6.2 6.3 ... 14.8 14.9 15.0
      standard_name :
      longitude
      long_name :
      longitude
      units :
      degrees_east
      axis :
      X
      array([ 6. ,  6.1,  6.2,  6.3,  6.4,  6.5,  6.6,  6.7,  6.8,  6.9,  7. ,  7.1,
              7.2,  7.3,  7.4,  7.5,  7.6,  7.7,  7.8,  7.9,  8. ,  8.1,  8.2,  8.3,
              8.4,  8.5,  8.6,  8.7,  8.8,  8.9,  9. ,  9.1,  9.2,  9.3,  9.4,  9.5,
              9.6,  9.7,  9.8,  9.9, 10. , 10.1, 10.2, 10.3, 10.4, 10.5, 10.6, 10.7,
             10.8, 10.9, 11. , 11.1, 11.2, 11.3, 11.4, 11.5, 11.6, 11.7, 11.8, 11.9,
             12. , 12.1, 12.2, 12.3, 12.4, 12.5, 12.6, 12.7, 12.8, 12.9, 13. , 13.1,
             13.2, 13.3, 13.4, 13.5, 13.6, 13.7, 13.8, 13.9, 14. , 14.1, 14.2, 14.3,
             14.4, 14.5, 14.6, 14.7, 14.8, 14.9, 15. ])
    • lat
      (lat)
      float64
      42.0 42.1 42.2 ... 46.8 46.9 47.0
      standard_name :
      latitude
      long_name :
      latitude
      units :
      degrees_north
      axis :
      Y
      array([42. , 42.1, 42.2, 42.3, 42.4, 42.5, 42.6, 42.7, 42.8, 42.9, 43. , 43.1,
             43.2, 43.3, 43.4, 43.5, 43.6, 43.7, 43.8, 43.9, 44. , 44.1, 44.2, 44.3,
             44.4, 44.5, 44.6, 44.7, 44.8, 44.9, 45. , 45.1, 45.2, 45.3, 45.4, 45.5,
             45.6, 45.7, 45.8, 45.9, 46. , 46.1, 46.2, 46.3, 46.4, 46.5, 46.6, 46.7,
             46.8, 46.9, 47. ])
    • spatial_ref
      ()
      int64
      0
      crs_wkt :
      GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]
      semi_major_axis :
      6378137.0
      semi_minor_axis :
      6356752.314245179
      inverse_flattening :
      298.257223563
      reference_ellipsoid_name :
      WGS 84
      longitude_of_prime_meridian :
      0.0
      prime_meridian_name :
      Greenwich
      geographic_crs_name :
      WGS 84
      horizontal_datum_name :
      World Geodetic System 1984
      grid_mapping_name :
      latitude_longitude
      spatial_ref :
      GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]
      array(0)
    • level
      ()
      int64
      0
      array(0)
    • time
      (time)
      datetime64[ns]
      2013-01-01 ... 2013-12-31
      standard_name :
      time
      axis :
      T
      long_name :
      valid time
      array(['2013-01-01T00:00:00.000000000', '2013-01-02T00:00:00.000000000',
             '2013-01-03T00:00:00.000000000', ..., '2013-12-29T00:00:00.000000000',
             '2013-12-30T00:00:00.000000000', '2013-12-31T00:00:00.000000000'],
            dtype='datetime64[ns]')
    • particulate_matter_10um
      (time, lat, lon)
      float32
      14.59 14.76 14.92 ... 14.46 15.35
      standard_name :
      mass_concentration_of_pm10_ambient_aerosol_in_air
      long_name :
      mass concentration of particulate matter with d < 10 µm
      units :
      µg/m3
      array([[[14.592389 , 14.759457 , 14.917909 , ..., 14.891944 ,
               15.582585 , 15.655021 ],
              [14.596129 , 14.755959 , 14.862533 , ..., 16.38024  ,
               17.361605 , 16.727972 ],
              [14.518109 , 14.655281 , 14.849431 , ..., 18.80936  ,
               20.070242 , 19.64971  ],
              ...,
              [ 7.4413733,  7.1963983,  6.795315 , ..., 26.047684 ,
               25.667284 , 23.330217 ],
              [ 7.71304  ,  7.229029 ,  6.944201 , ..., 22.538801 ,
               22.392464 , 21.6281   ],
              [ 7.8016715,  7.4701333,  7.0764604, ..., 21.022505 ,
               20.789503 , 20.647959 ]],
      
             [[14.877109 , 14.632808 , 14.616009 , ..., 16.446352 ,
               16.62877  , 16.954191 ],
              [14.566825 , 14.241462 , 14.111385 , ..., 17.39913  ,
               17.016415 , 16.470217 ],
              [14.175804 , 13.910232 , 13.980977 , ..., 17.266829 ,
               17.02157  , 16.339254 ],
      ...
              [ 7.5833764,  6.5890756,  6.379118 , ...,  9.714561 ,
                9.675725 ,  9.1065445],
              [ 7.569799 ,  7.0618615,  6.794848 , ...,  8.49215  ,
                8.513318 ,  8.81111  ],
              [ 8.45769  ,  7.95235  ,  7.6479497, ...,  7.9181004,
                8.306134 ,  9.493762 ]],
      
             [[10.792905 , 11.4779215, 11.46659  , ..., 13.953046 ,
               14.311807 , 13.548112 ],
              [10.89552  , 11.240757 , 11.225829 , ..., 14.242565 ,
               14.58522  , 13.864326 ],
              [10.970646 , 10.831932 , 10.819848 , ..., 14.637753 ,
               14.84509  , 13.512073 ],
              ...,
              [ 8.019948 ,  8.126159 ,  8.146888 , ..., 16.892054 ,
               15.909488 , 15.434224 ],
              [ 7.992478 ,  8.140747 ,  8.386679 , ..., 14.820127 ,
               15.036208 , 14.927485 ],
              [ 7.9174848,  8.14418  ,  8.4052105, ..., 13.332234 ,
               14.463368 , 15.345876 ]]], dtype=float32)
    • lon
      PandasIndex
      PandasIndex(Index([               6.0,  6.100000000000001,  6.200000000000003,
              6.300000000000001,  6.400000000000002,                6.5,
              6.600000000000001,  6.700000000000003,  6.800000000000001,
              6.900000000000002,                7.0,  7.100000000000001,
              7.200000000000003,  7.300000000000004,  7.399999999999999,
                            7.5,  7.600000000000001,  7.700000000000003,
              7.800000000000004,  7.899999999999999,                8.0,
              8.100000000000001,  8.200000000000003,  8.300000000000004,
              8.399999999999999,                8.5,  8.600000000000001,
              8.700000000000003,  8.800000000000004,  8.899999999999999,
                            9.0,  9.100000000000001,  9.200000000000003,
              9.300000000000004,  9.399999999999999,                9.5,
              9.600000000000001,  9.700000000000003,  9.800000000000004,
              9.899999999999999,               10.0, 10.100000000000001,
             10.200000000000003, 10.300000000000004, 10.399999999999999,
                           10.5, 10.600000000000001, 10.700000000000003,
             10.800000000000004, 10.899999999999999,               11.0,
             11.100000000000001, 11.200000000000003, 11.300000000000004,
             11.399999999999999,               11.5, 11.600000000000001,
             11.700000000000003, 11.800000000000004, 11.899999999999999,
                           12.0, 12.100000000000001, 12.200000000000003,
             12.300000000000004, 12.399999999999999,               12.5,
             12.600000000000001, 12.700000000000003, 12.800000000000004,
             12.899999999999999,               13.0, 13.100000000000001,
             13.200000000000003, 13.300000000000004, 13.400000000000006,
                           13.5, 13.600000000000001, 13.700000000000003,
             13.800000000000004, 13.900000000000006,               14.0,
             14.100000000000001, 14.200000000000003, 14.300000000000004,
             14.400000000000006,               14.5, 14.600000000000001,
             14.700000000000003, 14.800000000000004, 14.900000000000006,
                           15.0],
            dtype='float64', name='lon'))
    • lat
      PandasIndex
      PandasIndex(Index([              42.0,               42.1,               42.2,
                           42.3,               42.4,               42.5,
                           42.6,               42.7,               42.8,
                           42.9,               43.0,               43.1,
                           43.2,               43.3,               43.4,
                           43.5,               43.6,               43.7,
                           43.8,               43.9,               44.0,
                           44.1,               44.2,               44.3,
                           44.4,               44.5,               44.6,
                           44.7,               44.8,               44.9,
                           45.0,               45.1,               45.2,
                           45.3,               45.4,               45.5,
                           45.6,               45.7,               45.8,
                           45.9,               46.0,               46.1,
                           46.2,               46.3, 46.400000000000006,
                           46.5,               46.6,               46.7,
                           46.8, 46.900000000000006,               47.0],
            dtype='float64', name='lat'))
    • time
      PandasIndex
      PandasIndex(DatetimeIndex(['2013-01-01', '2013-01-02', '2013-01-03', '2013-01-04',
                     '2013-01-05', '2013-01-06', '2013-01-07', '2013-01-08',
                     '2013-01-09', '2013-01-10',
                     ...
                     '2013-12-22', '2013-12-23', '2013-12-24', '2013-12-25',
                     '2013-12-26', '2013-12-27', '2013-12-28', '2013-12-29',
                     '2013-12-30', '2013-12-31'],
                    dtype='datetime64[ns]', name='time', length=365, freq='D'))
  • Conventions :
    CF-1.7
    Title :
    CAMS European air quality interim reanalysis
    Provider :
    COPERNICUS European air quality service
    Production :
    COPERNICUS Atmosphere Monitoring Service
    pollutant :
    particulate_matter_10um
    sea_level :
    0

Quindi seleziono le sole celle che sforano il limite di 50 µg/m3 previsti dalla normativa.

In [10]:
daily_data_target = daily_data.copy()
daily_data_target['particulate_matter_10um'] = xr.where(daily_data['particulate_matter_10um'] >= 50, 1, 0)

daily_data_target
Out[10]:
<xarray.Dataset> Size: 14MB
Dimensions:                  (lon: 91, lat: 51, time: 365)
Coordinates:
  * lon                      (lon) float64 728B 6.0 6.1 6.2 ... 14.8 14.9 15.0
  * lat                      (lat) float64 408B 42.0 42.1 42.2 ... 46.9 47.0
    spatial_ref              int64 8B 0
    level                    int64 8B 0
  * time                     (time) datetime64[ns] 3kB 2013-01-01 ... 2013-12-31
Data variables:
    particulate_matter_10um  (time, lat, lon) int64 14MB 0 0 0 0 0 ... 0 0 0 0 0
Attributes:
    Conventions:  CF-1.7
    Title:        CAMS European air quality interim reanalysis
    Provider:     COPERNICUS European air quality service
    Production:   COPERNICUS Atmosphere Monitoring Service
    pollutant:    particulate_matter_10um
    sea_level:    0
xarray.Dataset
    • lon: 91
    • lat: 51
    • time: 365
    • lon
      (lon)
      float64
      6.0 6.1 6.2 6.3 ... 14.8 14.9 15.0
      standard_name :
      longitude
      long_name :
      longitude
      units :
      degrees_east
      axis :
      X
      array([ 6. ,  6.1,  6.2,  6.3,  6.4,  6.5,  6.6,  6.7,  6.8,  6.9,  7. ,  7.1,
              7.2,  7.3,  7.4,  7.5,  7.6,  7.7,  7.8,  7.9,  8. ,  8.1,  8.2,  8.3,
              8.4,  8.5,  8.6,  8.7,  8.8,  8.9,  9. ,  9.1,  9.2,  9.3,  9.4,  9.5,
              9.6,  9.7,  9.8,  9.9, 10. , 10.1, 10.2, 10.3, 10.4, 10.5, 10.6, 10.7,
             10.8, 10.9, 11. , 11.1, 11.2, 11.3, 11.4, 11.5, 11.6, 11.7, 11.8, 11.9,
             12. , 12.1, 12.2, 12.3, 12.4, 12.5, 12.6, 12.7, 12.8, 12.9, 13. , 13.1,
             13.2, 13.3, 13.4, 13.5, 13.6, 13.7, 13.8, 13.9, 14. , 14.1, 14.2, 14.3,
             14.4, 14.5, 14.6, 14.7, 14.8, 14.9, 15. ])
    • lat
      (lat)
      float64
      42.0 42.1 42.2 ... 46.8 46.9 47.0
      standard_name :
      latitude
      long_name :
      latitude
      units :
      degrees_north
      axis :
      Y
      array([42. , 42.1, 42.2, 42.3, 42.4, 42.5, 42.6, 42.7, 42.8, 42.9, 43. , 43.1,
             43.2, 43.3, 43.4, 43.5, 43.6, 43.7, 43.8, 43.9, 44. , 44.1, 44.2, 44.3,
             44.4, 44.5, 44.6, 44.7, 44.8, 44.9, 45. , 45.1, 45.2, 45.3, 45.4, 45.5,
             45.6, 45.7, 45.8, 45.9, 46. , 46.1, 46.2, 46.3, 46.4, 46.5, 46.6, 46.7,
             46.8, 46.9, 47. ])
    • spatial_ref
      ()
      int64
      0
      crs_wkt :
      GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]
      semi_major_axis :
      6378137.0
      semi_minor_axis :
      6356752.314245179
      inverse_flattening :
      298.257223563
      reference_ellipsoid_name :
      WGS 84
      longitude_of_prime_meridian :
      0.0
      prime_meridian_name :
      Greenwich
      geographic_crs_name :
      WGS 84
      horizontal_datum_name :
      World Geodetic System 1984
      grid_mapping_name :
      latitude_longitude
      spatial_ref :
      GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]
      array(0)
    • level
      ()
      int64
      0
      array(0)
    • time
      (time)
      datetime64[ns]
      2013-01-01 ... 2013-12-31
      standard_name :
      time
      axis :
      T
      long_name :
      valid time
      array(['2013-01-01T00:00:00.000000000', '2013-01-02T00:00:00.000000000',
             '2013-01-03T00:00:00.000000000', ..., '2013-12-29T00:00:00.000000000',
             '2013-12-30T00:00:00.000000000', '2013-12-31T00:00:00.000000000'],
            dtype='datetime64[ns]')
    • particulate_matter_10um
      (time, lat, lon)
      int64
      0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0
      array([[[0, 0, 0, ..., 0, 0, 0],
              [0, 0, 0, ..., 0, 0, 0],
              [0, 0, 0, ..., 0, 0, 0],
              ...,
              [0, 0, 0, ..., 0, 0, 0],
              [0, 0, 0, ..., 0, 0, 0],
              [0, 0, 0, ..., 0, 0, 0]],
      
             [[0, 0, 0, ..., 0, 0, 0],
              [0, 0, 0, ..., 0, 0, 0],
              [0, 0, 0, ..., 0, 0, 0],
              ...,
              [0, 0, 0, ..., 0, 0, 0],
              [0, 0, 0, ..., 0, 0, 0],
              [0, 0, 0, ..., 0, 0, 0]],
      
             [[0, 0, 0, ..., 0, 0, 0],
              [0, 0, 0, ..., 0, 0, 0],
              [0, 0, 0, ..., 0, 0, 0],
              ...,
      ...
              ...,
              [0, 0, 0, ..., 0, 0, 0],
              [0, 0, 0, ..., 0, 0, 0],
              [0, 0, 0, ..., 0, 0, 0]],
      
             [[0, 0, 0, ..., 0, 0, 0],
              [0, 0, 0, ..., 0, 0, 0],
              [0, 0, 0, ..., 0, 0, 0],
              ...,
              [0, 0, 0, ..., 0, 0, 0],
              [0, 0, 0, ..., 0, 0, 0],
              [0, 0, 0, ..., 0, 0, 0]],
      
             [[0, 0, 0, ..., 0, 0, 0],
              [0, 0, 0, ..., 0, 0, 0],
              [0, 0, 0, ..., 0, 0, 0],
              ...,
              [0, 0, 0, ..., 0, 0, 0],
              [0, 0, 0, ..., 0, 0, 0],
              [0, 0, 0, ..., 0, 0, 0]]])
    • lon
      PandasIndex
      PandasIndex(Index([               6.0,  6.100000000000001,  6.200000000000003,
              6.300000000000001,  6.400000000000002,                6.5,
              6.600000000000001,  6.700000000000003,  6.800000000000001,
              6.900000000000002,                7.0,  7.100000000000001,
              7.200000000000003,  7.300000000000004,  7.399999999999999,
                            7.5,  7.600000000000001,  7.700000000000003,
              7.800000000000004,  7.899999999999999,                8.0,
              8.100000000000001,  8.200000000000003,  8.300000000000004,
              8.399999999999999,                8.5,  8.600000000000001,
              8.700000000000003,  8.800000000000004,  8.899999999999999,
                            9.0,  9.100000000000001,  9.200000000000003,
              9.300000000000004,  9.399999999999999,                9.5,
              9.600000000000001,  9.700000000000003,  9.800000000000004,
              9.899999999999999,               10.0, 10.100000000000001,
             10.200000000000003, 10.300000000000004, 10.399999999999999,
                           10.5, 10.600000000000001, 10.700000000000003,
             10.800000000000004, 10.899999999999999,               11.0,
             11.100000000000001, 11.200000000000003, 11.300000000000004,
             11.399999999999999,               11.5, 11.600000000000001,
             11.700000000000003, 11.800000000000004, 11.899999999999999,
                           12.0, 12.100000000000001, 12.200000000000003,
             12.300000000000004, 12.399999999999999,               12.5,
             12.600000000000001, 12.700000000000003, 12.800000000000004,
             12.899999999999999,               13.0, 13.100000000000001,
             13.200000000000003, 13.300000000000004, 13.400000000000006,
                           13.5, 13.600000000000001, 13.700000000000003,
             13.800000000000004, 13.900000000000006,               14.0,
             14.100000000000001, 14.200000000000003, 14.300000000000004,
             14.400000000000006,               14.5, 14.600000000000001,
             14.700000000000003, 14.800000000000004, 14.900000000000006,
                           15.0],
            dtype='float64', name='lon'))
    • lat
      PandasIndex
      PandasIndex(Index([              42.0,               42.1,               42.2,
                           42.3,               42.4,               42.5,
                           42.6,               42.7,               42.8,
                           42.9,               43.0,               43.1,
                           43.2,               43.3,               43.4,
                           43.5,               43.6,               43.7,
                           43.8,               43.9,               44.0,
                           44.1,               44.2,               44.3,
                           44.4,               44.5,               44.6,
                           44.7,               44.8,               44.9,
                           45.0,               45.1,               45.2,
                           45.3,               45.4,               45.5,
                           45.6,               45.7,               45.8,
                           45.9,               46.0,               46.1,
                           46.2,               46.3, 46.400000000000006,
                           46.5,               46.6,               46.7,
                           46.8, 46.900000000000006,               47.0],
            dtype='float64', name='lat'))
    • time
      PandasIndex
      PandasIndex(DatetimeIndex(['2013-01-01', '2013-01-02', '2013-01-03', '2013-01-04',
                     '2013-01-05', '2013-01-06', '2013-01-07', '2013-01-08',
                     '2013-01-09', '2013-01-10',
                     ...
                     '2013-12-22', '2013-12-23', '2013-12-24', '2013-12-25',
                     '2013-12-26', '2013-12-27', '2013-12-28', '2013-12-29',
                     '2013-12-30', '2013-12-31'],
                    dtype='datetime64[ns]', name='time', length=365, freq='D'))
  • Conventions :
    CF-1.7
    Title :
    CAMS European air quality interim reanalysis
    Provider :
    COPERNICUS European air quality service
    Production :
    COPERNICUS Atmosphere Monitoring Service
    pollutant :
    particulate_matter_10um
    sea_level :
    0

I pixel che sforano il limite li ho sostituiti con il valore 1 e gli altri con 0, in questo modo con il passaggio successivo ho potuto calcolare quante volte viene sforato il limite.

In [11]:
year_data = daily_data_target.resample(time='YE').sum('time')  

year_data
Out[11]:
<xarray.Dataset> Size: 38kB
Dimensions:                  (lon: 91, lat: 51, time: 1)
Coordinates:
  * lon                      (lon) float64 728B 6.0 6.1 6.2 ... 14.8 14.9 15.0
  * lat                      (lat) float64 408B 42.0 42.1 42.2 ... 46.9 47.0
    spatial_ref              int64 8B 0
    level                    int64 8B 0
  * time                     (time) datetime64[ns] 8B 2013-12-31
Data variables:
    particulate_matter_10um  (time, lat, lon) int64 37kB 0 0 0 0 0 ... 0 0 0 0 0
Attributes:
    Conventions:  CF-1.7
    Title:        CAMS European air quality interim reanalysis
    Provider:     COPERNICUS European air quality service
    Production:   COPERNICUS Atmosphere Monitoring Service
    pollutant:    particulate_matter_10um
    sea_level:    0
xarray.Dataset
    • lon: 91
    • lat: 51
    • time: 1
    • lon
      (lon)
      float64
      6.0 6.1 6.2 6.3 ... 14.8 14.9 15.0
      standard_name :
      longitude
      long_name :
      longitude
      units :
      degrees_east
      axis :
      X
      array([ 6. ,  6.1,  6.2,  6.3,  6.4,  6.5,  6.6,  6.7,  6.8,  6.9,  7. ,  7.1,
              7.2,  7.3,  7.4,  7.5,  7.6,  7.7,  7.8,  7.9,  8. ,  8.1,  8.2,  8.3,
              8.4,  8.5,  8.6,  8.7,  8.8,  8.9,  9. ,  9.1,  9.2,  9.3,  9.4,  9.5,
              9.6,  9.7,  9.8,  9.9, 10. , 10.1, 10.2, 10.3, 10.4, 10.5, 10.6, 10.7,
             10.8, 10.9, 11. , 11.1, 11.2, 11.3, 11.4, 11.5, 11.6, 11.7, 11.8, 11.9,
             12. , 12.1, 12.2, 12.3, 12.4, 12.5, 12.6, 12.7, 12.8, 12.9, 13. , 13.1,
             13.2, 13.3, 13.4, 13.5, 13.6, 13.7, 13.8, 13.9, 14. , 14.1, 14.2, 14.3,
             14.4, 14.5, 14.6, 14.7, 14.8, 14.9, 15. ])
    • lat
      (lat)
      float64
      42.0 42.1 42.2 ... 46.8 46.9 47.0
      standard_name :
      latitude
      long_name :
      latitude
      units :
      degrees_north
      axis :
      Y
      array([42. , 42.1, 42.2, 42.3, 42.4, 42.5, 42.6, 42.7, 42.8, 42.9, 43. , 43.1,
             43.2, 43.3, 43.4, 43.5, 43.6, 43.7, 43.8, 43.9, 44. , 44.1, 44.2, 44.3,
             44.4, 44.5, 44.6, 44.7, 44.8, 44.9, 45. , 45.1, 45.2, 45.3, 45.4, 45.5,
             45.6, 45.7, 45.8, 45.9, 46. , 46.1, 46.2, 46.3, 46.4, 46.5, 46.6, 46.7,
             46.8, 46.9, 47. ])
    • spatial_ref
      ()
      int64
      0
      crs_wkt :
      GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]
      semi_major_axis :
      6378137.0
      semi_minor_axis :
      6356752.314245179
      inverse_flattening :
      298.257223563
      reference_ellipsoid_name :
      WGS 84
      longitude_of_prime_meridian :
      0.0
      prime_meridian_name :
      Greenwich
      geographic_crs_name :
      WGS 84
      horizontal_datum_name :
      World Geodetic System 1984
      grid_mapping_name :
      latitude_longitude
      spatial_ref :
      GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]
      array(0)
    • level
      ()
      int64
      0
      array(0)
    • time
      (time)
      datetime64[ns]
      2013-12-31
      standard_name :
      time
      axis :
      T
      long_name :
      valid time
      array(['2013-12-31T00:00:00.000000000'], dtype='datetime64[ns]')
    • particulate_matter_10um
      (time, lat, lon)
      int64
      0 0 0 0 0 0 0 0 ... 0 0 0 0 0 0 0 0
      array([[[0, 0, 0, ..., 0, 0, 0],
              [0, 0, 0, ..., 0, 0, 0],
              [0, 0, 0, ..., 0, 0, 0],
              ...,
              [0, 0, 0, ..., 0, 0, 0],
              [0, 0, 0, ..., 0, 0, 0],
              [0, 0, 0, ..., 0, 0, 0]]])
    • lon
      PandasIndex
      PandasIndex(Index([               6.0,  6.100000000000001,  6.200000000000003,
              6.300000000000001,  6.400000000000002,                6.5,
              6.600000000000001,  6.700000000000003,  6.800000000000001,
              6.900000000000002,                7.0,  7.100000000000001,
              7.200000000000003,  7.300000000000004,  7.399999999999999,
                            7.5,  7.600000000000001,  7.700000000000003,
              7.800000000000004,  7.899999999999999,                8.0,
              8.100000000000001,  8.200000000000003,  8.300000000000004,
              8.399999999999999,                8.5,  8.600000000000001,
              8.700000000000003,  8.800000000000004,  8.899999999999999,
                            9.0,  9.100000000000001,  9.200000000000003,
              9.300000000000004,  9.399999999999999,                9.5,
              9.600000000000001,  9.700000000000003,  9.800000000000004,
              9.899999999999999,               10.0, 10.100000000000001,
             10.200000000000003, 10.300000000000004, 10.399999999999999,
                           10.5, 10.600000000000001, 10.700000000000003,
             10.800000000000004, 10.899999999999999,               11.0,
             11.100000000000001, 11.200000000000003, 11.300000000000004,
             11.399999999999999,               11.5, 11.600000000000001,
             11.700000000000003, 11.800000000000004, 11.899999999999999,
                           12.0, 12.100000000000001, 12.200000000000003,
             12.300000000000004, 12.399999999999999,               12.5,
             12.600000000000001, 12.700000000000003, 12.800000000000004,
             12.899999999999999,               13.0, 13.100000000000001,
             13.200000000000003, 13.300000000000004, 13.400000000000006,
                           13.5, 13.600000000000001, 13.700000000000003,
             13.800000000000004, 13.900000000000006,               14.0,
             14.100000000000001, 14.200000000000003, 14.300000000000004,
             14.400000000000006,               14.5, 14.600000000000001,
             14.700000000000003, 14.800000000000004, 14.900000000000006,
                           15.0],
            dtype='float64', name='lon'))
    • lat
      PandasIndex
      PandasIndex(Index([              42.0,               42.1,               42.2,
                           42.3,               42.4,               42.5,
                           42.6,               42.7,               42.8,
                           42.9,               43.0,               43.1,
                           43.2,               43.3,               43.4,
                           43.5,               43.6,               43.7,
                           43.8,               43.9,               44.0,
                           44.1,               44.2,               44.3,
                           44.4,               44.5,               44.6,
                           44.7,               44.8,               44.9,
                           45.0,               45.1,               45.2,
                           45.3,               45.4,               45.5,
                           45.6,               45.7,               45.8,
                           45.9,               46.0,               46.1,
                           46.2,               46.3, 46.400000000000006,
                           46.5,               46.6,               46.7,
                           46.8, 46.900000000000006,               47.0],
            dtype='float64', name='lat'))
    • time
      PandasIndex
      PandasIndex(DatetimeIndex(['2013-12-31'], dtype='datetime64[ns]', name='time', freq='YE-DEC'))
  • Conventions :
    CF-1.7
    Title :
    CAMS European air quality interim reanalysis
    Provider :
    COPERNICUS European air quality service
    Production :
    COPERNICUS Atmosphere Monitoring Service
    pollutant :
    particulate_matter_10um
    sea_level :
    0
In [12]:
y_min = year_data.min().to_array().values[0]
y_max = year_data.max().to_array().values[0]
law_limit = 35

print(f"Nell'anno preso in considerazione i valori di PM10\n limite previsti dalla normativa sono stati sforati\n per un massimo di {y_max} volte. Il limite normativo è {law_limit}.")
Nell'anno preso in considerazione i valori di PM10
 limite previsti dalla normativa sono stati sforati
 per un massimo di 58 volte. Il limite normativo è 35.
In [13]:
fig3, ax3 = plt.subplots(figsize=(figsize_w, figsize_h), dpi=plot_dpi)

add_colorbar = False
colorbar_orientation = "horizontal"
colorbar_fraction = 0.046
colorbar_pad = 0.07

target_zones.plot(
    ax=ax3,
    facecolor=polygon_facecolor, 
    edgecolor=polygon_edgecolor,
    linewidth=polygon_linewidth
)
year_data_img = year_data.to_array().squeeze().plot.imshow(
    ax=ax3,
    cmap=raster_cmap,
    vmin=y_min,
    vmax=y_max,
    add_colorbar=add_colorbar,
)
cbar_ax3 = plt.colorbar(
    year_data_img, 
    ax=ax3,
    orientation=colorbar_orientation,
    fraction=colorbar_fraction, 
    pad=colorbar_pad,
)
cbar_ax3.set_label('Conteggio sforamenti')
cbar_ax3.set_ticks([y_min, law_limit, y_max])
cbar_ax3.set_ticklabels([str(y_min), str(law_limit), str(y_max)])
for _index, _row in main_city.iterrows():
    coordinates = _row.geometry.xy
    ax3.scatter(
        *coordinates,
        s=marker_s,
        marker=marker_type,
        facecolor=marker_facecolor,
        edgecolor=marker_edgecolor
    )
    label = plt.text(
        x=coordinates[0][0] + marker_x_offset,
        y=coordinates[1][0] + marker_y_offset,
        s=_row.citta,
        fontdict=dict(color=marker_font_color, size=marker_font_size),
        bbox=dict(facecolor=marker_label_facecolor, alpha=marker_label_alpha),
        path_effects=[patheffects.withStroke(linewidth=path_effects_linewidth, foreground=path_effects_foreground)]
    )
    label.set_path_effects([patheffects.withStroke(linewidth=path_effects_linewidth, foreground=path_effects_foreground)])
plt.title("Mappatura degli sforamenti del limite normativo di PM10 per l'anno preso in considerazione.")
plt.show()
No description has been provided for this image

Ora voglio visualizzare solo le aree che hanno effettivamente sforato il limite normativo di 35 sforamenti annui.

In [14]:
year_data_limit = year_data.where(year_data >= 35)

fig4, ax4 = plt.subplots(figsize=(figsize_w, figsize_h), dpi=plot_dpi)
target_zones.plot(
    ax=ax4,
    facecolor=polygon_facecolor, 
    edgecolor=polygon_edgecolor,
    linewidth=polygon_linewidth
)
year_data_img_limit = year_data_limit.to_array().squeeze().plot.imshow(
    ax=ax4,
    cmap=raster_cmap,
    vmin=law_limit,
    vmax=y_max,
    add_colorbar=add_colorbar,
)
cbar_ax4 = plt.colorbar(
    year_data_img_limit, 
    ax=ax4,
    orientation=colorbar_orientation,
    fraction=colorbar_fraction, 
    pad=colorbar_pad,
)
cbar_ax4.set_label('Conteggio sforamenti')
cbar_ax4.set_ticks([law_limit, y_max])
cbar_ax4.set_ticklabels([str(law_limit), str(y_max)])
for _index, _row in main_city.iterrows():
    coordinates = _row.geometry.xy
    ax4.scatter(
        *coordinates,
        s=marker_s,
        marker=marker_type,
        facecolor=marker_facecolor,
        edgecolor=marker_edgecolor
    )
    label = plt.text(
        x=coordinates[0][0] + marker_x_offset,
        y=coordinates[1][0] + marker_y_offset,
        s=_row.citta,
        fontdict=dict(color=marker_font_color, size=marker_font_size),
        bbox=dict(facecolor=marker_label_facecolor, alpha=marker_label_alpha),
        path_effects=[patheffects.withStroke(linewidth=path_effects_linewidth, foreground=path_effects_foreground)]
    )
    label.set_path_effects([patheffects.withStroke(linewidth=path_effects_linewidth, foreground=path_effects_foreground)])
plt.title("Mappatura degli sforamenti del limite normativo di PM10 per l'anno preso in considerazione.")
plt.show()
No description has been provided for this image

Analisi su tutti i file¶

Ora che ho familiarizzato con il dato del singolo anno procedo ad analizzare tutto in una unica volta.

In [15]:
%%time

complete_dataset = []

for nc_file in nc_files:
    dataset = xr.open_mfdataset(
        paths=nc_file,
        engine="netcdf4",
        decode_coords="all",
        parallel=True,
        chunks={'time': 24},
    )
    complete_dataset.append(dataset)

full_dataset = xr.concat(complete_dataset, dim="time")
full_dataset = full_dataset.sortby('time')

full_dataset
CPU times: user 212 ms, sys: 16.3 ms, total: 229 ms
Wall time: 227 ms
Out[15]:
<xarray.Dataset> Size: 20GB
Dimensions:                  (lon: 331, lat: 151, time: 98136)
Coordinates:
  * lon                      (lon) float64 3kB 6.0 6.0 6.05 ... 14.95 14.95 15.0
  * lat                      (lat) float64 1kB 42.0 42.05 42.05 ... 46.95 47.0
  * time                     (time) datetime64[ns] 785kB 2013-01-01 ... 2024-...
    level                    float32 4B 0.0
    spatial_ref              int64 8B 0
Data variables:
    particulate_matter_10um  (time, lat, lon) float32 20GB dask.array<chunksize=(24, 151, 331), meta=np.ndarray>
Attributes:
    title:        PM10 Air Pollutant ANALYSIS at the Surface
    institution:  Data produced by Meteo France
    source:       Data from ENSEMBLE model
    history:      Model ENSEMBLE ANALYSIS
    ANALYSIS:     Europe, 20210101-20210131+[0H_23H]
    summary:      ENSEMBLE model hourly ANALYSIS of PM10 concentration at the...
    project:      MACC-RAQ (http://macc-raq.gmes-atmosphere.eu)
    pollutant:    particulate_matter_10um
    sea_level:    0
xarray.Dataset
    • lon: 331
    • lat: 151
    • time: 98136
    • lon
      (lon)
      float64
      6.0 6.0 6.05 ... 14.95 14.95 15.0
      long_name :
      longitude
      units :
      degrees_east
      array([ 6.  ,  6.  ,  6.05, ..., 14.95, 14.95, 15.  ])
    • lat
      (lat)
      float64
      42.0 42.05 42.05 ... 46.95 47.0
      long_name :
      latitude
      units :
      degrees_north
      array([42.      , 42.049999, 42.05    , 42.1     , 42.15    , 42.150002,
             42.2     , 42.25    , 42.3     , 42.349998, 42.35    , 42.4     ,
             42.45    , 42.450001, 42.5     , 42.549999, 42.55    , 42.6     ,
             42.65    , 42.650002, 42.7     , 42.75    , 42.8     , 42.849998,
             42.85    , 42.9     , 42.95    , 42.950001, 43.      , 43.049999,
             43.05    , 43.1     , 43.15    , 43.150002, 43.2     , 43.25    ,
             43.3     , 43.3     , 43.349998, 43.35    , 43.4     , 43.45    ,
             43.450001, 43.5     , 43.549999, 43.55    , 43.6     , 43.65    ,
             43.650002, 43.7     , 43.75    , 43.8     , 43.8     , 43.849998,
             43.85    , 43.9     , 43.95    , 43.950001, 44.      , 44.049999,
             44.05    , 44.1     , 44.15    , 44.150002, 44.2     , 44.25    ,
             44.3     , 44.3     , 44.349998, 44.35    , 44.4     , 44.45    ,
             44.450001, 44.5     , 44.549999, 44.55    , 44.6     , 44.65    ,
             44.650002, 44.7     , 44.75    , 44.8     , 44.8     , 44.849998,
             44.85    , 44.9     , 44.95    , 44.950001, 45.      , 45.049999,
             45.05    , 45.1     , 45.15    , 45.150002, 45.2     , 45.25    ,
             45.3     , 45.3     , 45.349998, 45.35    , 45.4     , 45.45    ,
             45.450001, 45.5     , 45.549999, 45.55    , 45.6     , 45.65    ,
             45.650002, 45.7     , 45.75    , 45.8     , 45.8     , 45.849998,
             45.85    , 45.9     , 45.95    , 45.950001, 46.      , 46.049999,
             46.05    , 46.1     , 46.15    , 46.150002, 46.2     , 46.25    ,
             46.3     , 46.3     , 46.349998, 46.35    , 46.4     , 46.4     ,
             46.45    , 46.450001, 46.5     , 46.549999, 46.55    , 46.6     ,
             46.65    , 46.650002, 46.7     , 46.75    , 46.8     , 46.8     ,
             46.849998, 46.85    , 46.9     , 46.9     , 46.95    , 46.950001,
             47.      ])
    • time
      (time)
      datetime64[ns]
      2013-01-01 ... 2024-03-12T23:00:00
      array(['2013-01-01T00:00:00.000000000', '2013-01-01T01:00:00.000000000',
             '2013-01-01T02:00:00.000000000', ..., '2024-03-12T21:00:00.000000000',
             '2024-03-12T22:00:00.000000000', '2024-03-12T23:00:00.000000000'],
            dtype='datetime64[ns]')
    • level
      ()
      float32
      0.0
      long_name :
      level
      units :
      m
      array(0., dtype=float32)
    • spatial_ref
      ()
      int64
      0
      crs_wkt :
      GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]
      semi_major_axis :
      6378137.0
      semi_minor_axis :
      6356752.314245179
      inverse_flattening :
      298.257223563
      reference_ellipsoid_name :
      WGS 84
      longitude_of_prime_meridian :
      0.0
      prime_meridian_name :
      Greenwich
      geographic_crs_name :
      WGS 84
      horizontal_datum_name :
      World Geodetic System 1984
      grid_mapping_name :
      latitude_longitude
      spatial_ref :
      GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]
      array(0)
    • particulate_matter_10um
      (time, lat, lon)
      float32
      dask.array<chunksize=(24, 151, 331), meta=np.ndarray>
      species :
      PM10 Aerosol
      units :
      µg/m3
      value :
      hourly values
      standard_name :
      mass_concentration_of_pm10_ambient_aerosol_in_air
      Array Chunk
      Bytes 18.27 GiB 4.58 MiB
      Shape (98136, 151, 331) (24, 151, 331)
      Dask graph 4089 chunks in 102 graph layers
      Data type float32 numpy.ndarray
      331 151 98136
    • lon
      PandasIndex
      PandasIndex(Index([               6.0,  6.000000000000002,  6.050000000000001,
              6.050000190734863,  6.100000000000001,  6.150000000000002,
              6.150000095367432,  6.200000000000002,  6.200000000000003,
                           6.25,
             ...
             14.750000000000004, 14.800000000000002, 14.800000000000004,
             14.850000000000005, 14.850000381469727, 14.900000000000002,
             14.900000000000006, 14.949999809265137, 14.950000000000006,
                           15.0],
            dtype='float64', name='lon', length=331))
    • lat
      PandasIndex
      PandasIndex(Index([              42.0,  42.04999923706055,              42.05,
                           42.1, 42.150000000000006, 42.150001525878906,
                           42.2,              42.25,               42.3,
             42.349998474121094,
             ...
                          46.75,               46.8, 46.800000000000004,
             46.849998474121094,              46.85,               46.9,
             46.900000000000006,              46.95,  46.95000076293945,
                           47.0],
            dtype='float64', name='lat', length=151))
    • time
      PandasIndex
      PandasIndex(DatetimeIndex(['2013-01-01 00:00:00', '2013-01-01 01:00:00',
                     '2013-01-01 02:00:00', '2013-01-01 03:00:00',
                     '2013-01-01 04:00:00', '2013-01-01 05:00:00',
                     '2013-01-01 06:00:00', '2013-01-01 07:00:00',
                     '2013-01-01 08:00:00', '2013-01-01 09:00:00',
                     ...
                     '2024-03-12 14:00:00', '2024-03-12 15:00:00',
                     '2024-03-12 16:00:00', '2024-03-12 17:00:00',
                     '2024-03-12 18:00:00', '2024-03-12 19:00:00',
                     '2024-03-12 20:00:00', '2024-03-12 21:00:00',
                     '2024-03-12 22:00:00', '2024-03-12 23:00:00'],
                    dtype='datetime64[ns]', name='time', length=98136, freq=None))
  • title :
    PM10 Air Pollutant ANALYSIS at the Surface
    institution :
    Data produced by Meteo France
    source :
    Data from ENSEMBLE model
    history :
    Model ENSEMBLE ANALYSIS
    ANALYSIS :
    Europe, 20210101-20210131+[0H_23H]
    summary :
    ENSEMBLE model hourly ANALYSIS of PM10 concentration at the Surface from 20210101-20210131+[0H_23H] on Europe
    project :
    MACC-RAQ (http://macc-raq.gmes-atmosphere.eu)
    pollutant :
    particulate_matter_10um
    sea_level :
    0

Da notare che l'intero dataset pesa 20GB!

Procedo con il calcolo della media giornaliera e la sostituzione dei valori di sforamento con 1.

In [16]:
%%time

full_dataset_daily_data = full_dataset.resample(time='D').mean('time')  

full_dataset_daily_data
CPU times: user 8.64 s, sys: 97.9 ms, total: 8.74 s
Wall time: 8.67 s
Out[16]:
<xarray.Dataset> Size: 818MB
Dimensions:                  (lon: 331, lat: 151, time: 4089)
Coordinates:
  * lon                      (lon) float64 3kB 6.0 6.0 6.05 ... 14.95 14.95 15.0
  * lat                      (lat) float64 1kB 42.0 42.05 42.05 ... 46.95 47.0
    level                    float32 4B 0.0
    spatial_ref              int64 8B 0
  * time                     (time) datetime64[ns] 33kB 2013-01-01 ... 2024-0...
Data variables:
    particulate_matter_10um  (time, lat, lon) float32 817MB dask.array<chunksize=(1, 151, 331), meta=np.ndarray>
Attributes:
    title:        PM10 Air Pollutant ANALYSIS at the Surface
    institution:  Data produced by Meteo France
    source:       Data from ENSEMBLE model
    history:      Model ENSEMBLE ANALYSIS
    ANALYSIS:     Europe, 20210101-20210131+[0H_23H]
    summary:      ENSEMBLE model hourly ANALYSIS of PM10 concentration at the...
    project:      MACC-RAQ (http://macc-raq.gmes-atmosphere.eu)
    pollutant:    particulate_matter_10um
    sea_level:    0
xarray.Dataset
    • lon: 331
    • lat: 151
    • time: 4089
    • lon
      (lon)
      float64
      6.0 6.0 6.05 ... 14.95 14.95 15.0
      long_name :
      longitude
      units :
      degrees_east
      array([ 6.  ,  6.  ,  6.05, ..., 14.95, 14.95, 15.  ])
    • lat
      (lat)
      float64
      42.0 42.05 42.05 ... 46.95 47.0
      long_name :
      latitude
      units :
      degrees_north
      array([42.      , 42.049999, 42.05    , 42.1     , 42.15    , 42.150002,
             42.2     , 42.25    , 42.3     , 42.349998, 42.35    , 42.4     ,
             42.45    , 42.450001, 42.5     , 42.549999, 42.55    , 42.6     ,
             42.65    , 42.650002, 42.7     , 42.75    , 42.8     , 42.849998,
             42.85    , 42.9     , 42.95    , 42.950001, 43.      , 43.049999,
             43.05    , 43.1     , 43.15    , 43.150002, 43.2     , 43.25    ,
             43.3     , 43.3     , 43.349998, 43.35    , 43.4     , 43.45    ,
             43.450001, 43.5     , 43.549999, 43.55    , 43.6     , 43.65    ,
             43.650002, 43.7     , 43.75    , 43.8     , 43.8     , 43.849998,
             43.85    , 43.9     , 43.95    , 43.950001, 44.      , 44.049999,
             44.05    , 44.1     , 44.15    , 44.150002, 44.2     , 44.25    ,
             44.3     , 44.3     , 44.349998, 44.35    , 44.4     , 44.45    ,
             44.450001, 44.5     , 44.549999, 44.55    , 44.6     , 44.65    ,
             44.650002, 44.7     , 44.75    , 44.8     , 44.8     , 44.849998,
             44.85    , 44.9     , 44.95    , 44.950001, 45.      , 45.049999,
             45.05    , 45.1     , 45.15    , 45.150002, 45.2     , 45.25    ,
             45.3     , 45.3     , 45.349998, 45.35    , 45.4     , 45.45    ,
             45.450001, 45.5     , 45.549999, 45.55    , 45.6     , 45.65    ,
             45.650002, 45.7     , 45.75    , 45.8     , 45.8     , 45.849998,
             45.85    , 45.9     , 45.95    , 45.950001, 46.      , 46.049999,
             46.05    , 46.1     , 46.15    , 46.150002, 46.2     , 46.25    ,
             46.3     , 46.3     , 46.349998, 46.35    , 46.4     , 46.4     ,
             46.45    , 46.450001, 46.5     , 46.549999, 46.55    , 46.6     ,
             46.65    , 46.650002, 46.7     , 46.75    , 46.8     , 46.8     ,
             46.849998, 46.85    , 46.9     , 46.9     , 46.95    , 46.950001,
             47.      ])
    • level
      ()
      float32
      0.0
      long_name :
      level
      units :
      m
      array(0., dtype=float32)
    • spatial_ref
      ()
      int64
      0
      crs_wkt :
      GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]
      semi_major_axis :
      6378137.0
      semi_minor_axis :
      6356752.314245179
      inverse_flattening :
      298.257223563
      reference_ellipsoid_name :
      WGS 84
      longitude_of_prime_meridian :
      0.0
      prime_meridian_name :
      Greenwich
      geographic_crs_name :
      WGS 84
      horizontal_datum_name :
      World Geodetic System 1984
      grid_mapping_name :
      latitude_longitude
      spatial_ref :
      GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]
      array(0)
    • time
      (time)
      datetime64[ns]
      2013-01-01 ... 2024-03-12
      array(['2013-01-01T00:00:00.000000000', '2013-01-02T00:00:00.000000000',
             '2013-01-03T00:00:00.000000000', ..., '2024-03-10T00:00:00.000000000',
             '2024-03-11T00:00:00.000000000', '2024-03-12T00:00:00.000000000'],
            dtype='datetime64[ns]')
    • particulate_matter_10um
      (time, lat, lon)
      float32
      dask.array<chunksize=(1, 151, 331), meta=np.ndarray>
      species :
      PM10 Aerosol
      units :
      µg/m3
      value :
      hourly values
      standard_name :
      mass_concentration_of_pm10_ambient_aerosol_in_air
      Array Chunk
      Bytes 779.62 MiB 195.24 kiB
      Shape (4089, 151, 331) (1, 151, 331)
      Dask graph 4089 chunks in 16459 graph layers
      Data type float32 numpy.ndarray
      331 151 4089
    • lon
      PandasIndex
      PandasIndex(Index([               6.0,  6.000000000000002,  6.050000000000001,
              6.050000190734863,  6.100000000000001,  6.150000000000002,
              6.150000095367432,  6.200000000000002,  6.200000000000003,
                           6.25,
             ...
             14.750000000000004, 14.800000000000002, 14.800000000000004,
             14.850000000000005, 14.850000381469727, 14.900000000000002,
             14.900000000000006, 14.949999809265137, 14.950000000000006,
                           15.0],
            dtype='float64', name='lon', length=331))
    • lat
      PandasIndex
      PandasIndex(Index([              42.0,  42.04999923706055,              42.05,
                           42.1, 42.150000000000006, 42.150001525878906,
                           42.2,              42.25,               42.3,
             42.349998474121094,
             ...
                          46.75,               46.8, 46.800000000000004,
             46.849998474121094,              46.85,               46.9,
             46.900000000000006,              46.95,  46.95000076293945,
                           47.0],
            dtype='float64', name='lat', length=151))
    • time
      PandasIndex
      PandasIndex(DatetimeIndex(['2013-01-01', '2013-01-02', '2013-01-03', '2013-01-04',
                     '2013-01-05', '2013-01-06', '2013-01-07', '2013-01-08',
                     '2013-01-09', '2013-01-10',
                     ...
                     '2024-03-03', '2024-03-04', '2024-03-05', '2024-03-06',
                     '2024-03-07', '2024-03-08', '2024-03-09', '2024-03-10',
                     '2024-03-11', '2024-03-12'],
                    dtype='datetime64[ns]', name='time', length=4089, freq='D'))
  • title :
    PM10 Air Pollutant ANALYSIS at the Surface
    institution :
    Data produced by Meteo France
    source :
    Data from ENSEMBLE model
    history :
    Model ENSEMBLE ANALYSIS
    ANALYSIS :
    Europe, 20210101-20210131+[0H_23H]
    summary :
    ENSEMBLE model hourly ANALYSIS of PM10 concentration at the Surface from 20210101-20210131+[0H_23H] on Europe
    project :
    MACC-RAQ (http://macc-raq.gmes-atmosphere.eu)
    pollutant :
    particulate_matter_10um
    sea_level :
    0
In [17]:
%%time

full_dataset_daily_data_target = full_dataset_daily_data.copy()
full_dataset_daily_data_target['particulate_matter_10um'] = xr.where(full_dataset_daily_data_target['particulate_matter_10um'] > 50, 1, 0)

full_dataset_daily_data_target
CPU times: user 10.5 ms, sys: 0 ns, total: 10.5 ms
Wall time: 10.6 ms
Out[17]:
<xarray.Dataset> Size: 2GB
Dimensions:                  (lon: 331, lat: 151, time: 4089)
Coordinates:
  * lon                      (lon) float64 3kB 6.0 6.0 6.05 ... 14.95 14.95 15.0
  * lat                      (lat) float64 1kB 42.0 42.05 42.05 ... 46.95 47.0
    level                    float32 4B 0.0
    spatial_ref              int64 8B 0
  * time                     (time) datetime64[ns] 33kB 2013-01-01 ... 2024-0...
Data variables:
    particulate_matter_10um  (time, lat, lon) int64 2GB dask.array<chunksize=(1, 151, 331), meta=np.ndarray>
Attributes:
    title:        PM10 Air Pollutant ANALYSIS at the Surface
    institution:  Data produced by Meteo France
    source:       Data from ENSEMBLE model
    history:      Model ENSEMBLE ANALYSIS
    ANALYSIS:     Europe, 20210101-20210131+[0H_23H]
    summary:      ENSEMBLE model hourly ANALYSIS of PM10 concentration at the...
    project:      MACC-RAQ (http://macc-raq.gmes-atmosphere.eu)
    pollutant:    particulate_matter_10um
    sea_level:    0
xarray.Dataset
    • lon: 331
    • lat: 151
    • time: 4089
    • lon
      (lon)
      float64
      6.0 6.0 6.05 ... 14.95 14.95 15.0
      long_name :
      longitude
      units :
      degrees_east
      array([ 6.  ,  6.  ,  6.05, ..., 14.95, 14.95, 15.  ])
    • lat
      (lat)
      float64
      42.0 42.05 42.05 ... 46.95 47.0
      long_name :
      latitude
      units :
      degrees_north
      array([42.      , 42.049999, 42.05    , 42.1     , 42.15    , 42.150002,
             42.2     , 42.25    , 42.3     , 42.349998, 42.35    , 42.4     ,
             42.45    , 42.450001, 42.5     , 42.549999, 42.55    , 42.6     ,
             42.65    , 42.650002, 42.7     , 42.75    , 42.8     , 42.849998,
             42.85    , 42.9     , 42.95    , 42.950001, 43.      , 43.049999,
             43.05    , 43.1     , 43.15    , 43.150002, 43.2     , 43.25    ,
             43.3     , 43.3     , 43.349998, 43.35    , 43.4     , 43.45    ,
             43.450001, 43.5     , 43.549999, 43.55    , 43.6     , 43.65    ,
             43.650002, 43.7     , 43.75    , 43.8     , 43.8     , 43.849998,
             43.85    , 43.9     , 43.95    , 43.950001, 44.      , 44.049999,
             44.05    , 44.1     , 44.15    , 44.150002, 44.2     , 44.25    ,
             44.3     , 44.3     , 44.349998, 44.35    , 44.4     , 44.45    ,
             44.450001, 44.5     , 44.549999, 44.55    , 44.6     , 44.65    ,
             44.650002, 44.7     , 44.75    , 44.8     , 44.8     , 44.849998,
             44.85    , 44.9     , 44.95    , 44.950001, 45.      , 45.049999,
             45.05    , 45.1     , 45.15    , 45.150002, 45.2     , 45.25    ,
             45.3     , 45.3     , 45.349998, 45.35    , 45.4     , 45.45    ,
             45.450001, 45.5     , 45.549999, 45.55    , 45.6     , 45.65    ,
             45.650002, 45.7     , 45.75    , 45.8     , 45.8     , 45.849998,
             45.85    , 45.9     , 45.95    , 45.950001, 46.      , 46.049999,
             46.05    , 46.1     , 46.15    , 46.150002, 46.2     , 46.25    ,
             46.3     , 46.3     , 46.349998, 46.35    , 46.4     , 46.4     ,
             46.45    , 46.450001, 46.5     , 46.549999, 46.55    , 46.6     ,
             46.65    , 46.650002, 46.7     , 46.75    , 46.8     , 46.8     ,
             46.849998, 46.85    , 46.9     , 46.9     , 46.95    , 46.950001,
             47.      ])
    • level
      ()
      float32
      0.0
      long_name :
      level
      units :
      m
      array(0., dtype=float32)
    • spatial_ref
      ()
      int64
      0
      crs_wkt :
      GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]
      semi_major_axis :
      6378137.0
      semi_minor_axis :
      6356752.314245179
      inverse_flattening :
      298.257223563
      reference_ellipsoid_name :
      WGS 84
      longitude_of_prime_meridian :
      0.0
      prime_meridian_name :
      Greenwich
      geographic_crs_name :
      WGS 84
      horizontal_datum_name :
      World Geodetic System 1984
      grid_mapping_name :
      latitude_longitude
      spatial_ref :
      GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]
      array(0)
    • time
      (time)
      datetime64[ns]
      2013-01-01 ... 2024-03-12
      array(['2013-01-01T00:00:00.000000000', '2013-01-02T00:00:00.000000000',
             '2013-01-03T00:00:00.000000000', ..., '2024-03-10T00:00:00.000000000',
             '2024-03-11T00:00:00.000000000', '2024-03-12T00:00:00.000000000'],
            dtype='datetime64[ns]')
    • particulate_matter_10um
      (time, lat, lon)
      int64
      dask.array<chunksize=(1, 151, 331), meta=np.ndarray>
      Array Chunk
      Bytes 1.52 GiB 390.48 kiB
      Shape (4089, 151, 331) (1, 151, 331)
      Dask graph 4089 chunks in 16461 graph layers
      Data type int64 numpy.ndarray
      331 151 4089
    • lon
      PandasIndex
      PandasIndex(Index([               6.0,  6.000000000000002,  6.050000000000001,
              6.050000190734863,  6.100000000000001,  6.150000000000002,
              6.150000095367432,  6.200000000000002,  6.200000000000003,
                           6.25,
             ...
             14.750000000000004, 14.800000000000002, 14.800000000000004,
             14.850000000000005, 14.850000381469727, 14.900000000000002,
             14.900000000000006, 14.949999809265137, 14.950000000000006,
                           15.0],
            dtype='float64', name='lon', length=331))
    • lat
      PandasIndex
      PandasIndex(Index([              42.0,  42.04999923706055,              42.05,
                           42.1, 42.150000000000006, 42.150001525878906,
                           42.2,              42.25,               42.3,
             42.349998474121094,
             ...
                          46.75,               46.8, 46.800000000000004,
             46.849998474121094,              46.85,               46.9,
             46.900000000000006,              46.95,  46.95000076293945,
                           47.0],
            dtype='float64', name='lat', length=151))
    • time
      PandasIndex
      PandasIndex(DatetimeIndex(['2013-01-01', '2013-01-02', '2013-01-03', '2013-01-04',
                     '2013-01-05', '2013-01-06', '2013-01-07', '2013-01-08',
                     '2013-01-09', '2013-01-10',
                     ...
                     '2024-03-03', '2024-03-04', '2024-03-05', '2024-03-06',
                     '2024-03-07', '2024-03-08', '2024-03-09', '2024-03-10',
                     '2024-03-11', '2024-03-12'],
                    dtype='datetime64[ns]', name='time', length=4089, freq='D'))
  • title :
    PM10 Air Pollutant ANALYSIS at the Surface
    institution :
    Data produced by Meteo France
    source :
    Data from ENSEMBLE model
    history :
    Model ENSEMBLE ANALYSIS
    ANALYSIS :
    Europe, 20210101-20210131+[0H_23H]
    summary :
    ENSEMBLE model hourly ANALYSIS of PM10 concentration at the Surface from 20210101-20210131+[0H_23H] on Europe
    project :
    MACC-RAQ (http://macc-raq.gmes-atmosphere.eu)
    pollutant :
    particulate_matter_10um
    sea_level :
    0

A questo punto posso conteggiare gli sforamenti per tutto il dataset

In [18]:
full_dataset_year_data = full_dataset_daily_data_target.resample(time='YE').sum('time')  
full_dataset_year_data = full_dataset_year_data.where(full_dataset_year_data >= 35)
full_dataset_year_data
Out[18]:
<xarray.Dataset> Size: 5MB
Dimensions:                  (time: 12, lat: 151, lon: 331)
Coordinates:
  * lon                      (lon) float64 3kB 6.0 6.0 6.05 ... 14.95 14.95 15.0
  * lat                      (lat) float64 1kB 42.0 42.05 42.05 ... 46.95 47.0
    level                    float32 4B 0.0
    spatial_ref              int64 8B 0
  * time                     (time) datetime64[ns] 96B 2013-12-31 ... 2024-12-31
Data variables:
    particulate_matter_10um  (time, lat, lon) float64 5MB dask.array<chunksize=(1, 151, 331), meta=np.ndarray>
Attributes:
    title:        PM10 Air Pollutant ANALYSIS at the Surface
    institution:  Data produced by Meteo France
    source:       Data from ENSEMBLE model
    history:      Model ENSEMBLE ANALYSIS
    ANALYSIS:     Europe, 20210101-20210131+[0H_23H]
    summary:      ENSEMBLE model hourly ANALYSIS of PM10 concentration at the...
    project:      MACC-RAQ (http://macc-raq.gmes-atmosphere.eu)
    pollutant:    particulate_matter_10um
    sea_level:    0
xarray.Dataset
    • time: 12
    • lat: 151
    • lon: 331
    • lon
      (lon)
      float64
      6.0 6.0 6.05 ... 14.95 14.95 15.0
      long_name :
      longitude
      units :
      degrees_east
      array([ 6.  ,  6.  ,  6.05, ..., 14.95, 14.95, 15.  ])
    • lat
      (lat)
      float64
      42.0 42.05 42.05 ... 46.95 47.0
      long_name :
      latitude
      units :
      degrees_north
      array([42.      , 42.049999, 42.05    , 42.1     , 42.15    , 42.150002,
             42.2     , 42.25    , 42.3     , 42.349998, 42.35    , 42.4     ,
             42.45    , 42.450001, 42.5     , 42.549999, 42.55    , 42.6     ,
             42.65    , 42.650002, 42.7     , 42.75    , 42.8     , 42.849998,
             42.85    , 42.9     , 42.95    , 42.950001, 43.      , 43.049999,
             43.05    , 43.1     , 43.15    , 43.150002, 43.2     , 43.25    ,
             43.3     , 43.3     , 43.349998, 43.35    , 43.4     , 43.45    ,
             43.450001, 43.5     , 43.549999, 43.55    , 43.6     , 43.65    ,
             43.650002, 43.7     , 43.75    , 43.8     , 43.8     , 43.849998,
             43.85    , 43.9     , 43.95    , 43.950001, 44.      , 44.049999,
             44.05    , 44.1     , 44.15    , 44.150002, 44.2     , 44.25    ,
             44.3     , 44.3     , 44.349998, 44.35    , 44.4     , 44.45    ,
             44.450001, 44.5     , 44.549999, 44.55    , 44.6     , 44.65    ,
             44.650002, 44.7     , 44.75    , 44.8     , 44.8     , 44.849998,
             44.85    , 44.9     , 44.95    , 44.950001, 45.      , 45.049999,
             45.05    , 45.1     , 45.15    , 45.150002, 45.2     , 45.25    ,
             45.3     , 45.3     , 45.349998, 45.35    , 45.4     , 45.45    ,
             45.450001, 45.5     , 45.549999, 45.55    , 45.6     , 45.65    ,
             45.650002, 45.7     , 45.75    , 45.8     , 45.8     , 45.849998,
             45.85    , 45.9     , 45.95    , 45.950001, 46.      , 46.049999,
             46.05    , 46.1     , 46.15    , 46.150002, 46.2     , 46.25    ,
             46.3     , 46.3     , 46.349998, 46.35    , 46.4     , 46.4     ,
             46.45    , 46.450001, 46.5     , 46.549999, 46.55    , 46.6     ,
             46.65    , 46.650002, 46.7     , 46.75    , 46.8     , 46.8     ,
             46.849998, 46.85    , 46.9     , 46.9     , 46.95    , 46.950001,
             47.      ])
    • level
      ()
      float32
      0.0
      long_name :
      level
      units :
      m
      array(0., dtype=float32)
    • spatial_ref
      ()
      int64
      0
      crs_wkt :
      GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]
      semi_major_axis :
      6378137.0
      semi_minor_axis :
      6356752.314245179
      inverse_flattening :
      298.257223563
      reference_ellipsoid_name :
      WGS 84
      longitude_of_prime_meridian :
      0.0
      prime_meridian_name :
      Greenwich
      geographic_crs_name :
      WGS 84
      horizontal_datum_name :
      World Geodetic System 1984
      grid_mapping_name :
      latitude_longitude
      spatial_ref :
      GEOGCS["WGS 84",DATUM["WGS_1984",SPHEROID["WGS 84",6378137,298.257223563,AUTHORITY["EPSG","7030"]],AUTHORITY["EPSG","6326"]],PRIMEM["Greenwich",0,AUTHORITY["EPSG","8901"]],UNIT["degree",0.0174532925199433,AUTHORITY["EPSG","9122"]],AXIS["Latitude",NORTH],AXIS["Longitude",EAST],AUTHORITY["EPSG","4326"]]
      array(0)
    • time
      (time)
      datetime64[ns]
      2013-12-31 ... 2024-12-31
      array(['2013-12-31T00:00:00.000000000', '2014-12-31T00:00:00.000000000',
             '2015-12-31T00:00:00.000000000', '2016-12-31T00:00:00.000000000',
             '2017-12-31T00:00:00.000000000', '2018-12-31T00:00:00.000000000',
             '2019-12-31T00:00:00.000000000', '2020-12-31T00:00:00.000000000',
             '2021-12-31T00:00:00.000000000', '2022-12-31T00:00:00.000000000',
             '2023-12-31T00:00:00.000000000', '2024-12-31T00:00:00.000000000'],
            dtype='datetime64[ns]')
    • particulate_matter_10um
      (time, lat, lon)
      float64
      dask.array<chunksize=(1, 151, 331), meta=np.ndarray>
      Array Chunk
      Bytes 4.58 MiB 390.48 kiB
      Shape (12, 151, 331) (1, 151, 331)
      Dask graph 12 chunks in 16560 graph layers
      Data type float64 numpy.ndarray
      331 151 12
    • lon
      PandasIndex
      PandasIndex(Index([               6.0,  6.000000000000002,  6.050000000000001,
              6.050000190734863,  6.100000000000001,  6.150000000000002,
              6.150000095367432,  6.200000000000002,  6.200000000000003,
                           6.25,
             ...
             14.750000000000004, 14.800000000000002, 14.800000000000004,
             14.850000000000005, 14.850000381469727, 14.900000000000002,
             14.900000000000006, 14.949999809265137, 14.950000000000006,
                           15.0],
            dtype='float64', name='lon', length=331))
    • lat
      PandasIndex
      PandasIndex(Index([              42.0,  42.04999923706055,              42.05,
                           42.1, 42.150000000000006, 42.150001525878906,
                           42.2,              42.25,               42.3,
             42.349998474121094,
             ...
                          46.75,               46.8, 46.800000000000004,
             46.849998474121094,              46.85,               46.9,
             46.900000000000006,              46.95,  46.95000076293945,
                           47.0],
            dtype='float64', name='lat', length=151))
    • time
      PandasIndex
      PandasIndex(DatetimeIndex(['2013-12-31', '2014-12-31', '2015-12-31', '2016-12-31',
                     '2017-12-31', '2018-12-31', '2019-12-31', '2020-12-31',
                     '2021-12-31', '2022-12-31', '2023-12-31', '2024-12-31'],
                    dtype='datetime64[ns]', name='time', freq='YE-DEC'))
  • title :
    PM10 Air Pollutant ANALYSIS at the Surface
    institution :
    Data produced by Meteo France
    source :
    Data from ENSEMBLE model
    history :
    Model ENSEMBLE ANALYSIS
    ANALYSIS :
    Europe, 20210101-20210131+[0H_23H]
    summary :
    ENSEMBLE model hourly ANALYSIS of PM10 concentration at the Surface from 20210101-20210131+[0H_23H] on Europe
    project :
    MACC-RAQ (http://macc-raq.gmes-atmosphere.eu)
    pollutant :
    particulate_matter_10um
    sea_level :
    0

Il dataset a questo punto si è ridotto tantissimo in peso.

In [19]:
full_max = int(full_dataset_year_data.max().to_array().values[0])
full_max
print(f"Nell'anno preso in considerazione i valori di PM10\n limite previsti dalla normativa sono stati sforati per un\n massimo di {full_max} volte")
Nell'anno preso in considerazione i valori di PM10
 limite previsti dalla normativa sono stati sforati per un
 massimo di 74 volte
In [20]:
%%time

dataset_list = []
variable = 'particulate_matter_10um'
target_shape = (50, 90)
img_folder = Path.cwd().joinpath('img')
final_main_city = main_city[~main_city['citta'].isin(['Ginevra', 'Monaco'])]


for nc_file in nc_files:
    dataset = xr.open_mfdataset(
        paths=nc_file,
        engine="netcdf4",
        decode_coords="all",
        parallel=True,
        chunks={'time': 24},
    )
    dataset = dataset.sortby('time')
    
    daily_mean = dataset.resample(time='D').mean('time')  

    anomaly = daily_mean.copy()
    anomaly[variable] = xr.where(daily_mean[variable] >= 50, 1, 0)
    
    out_layer = anomaly.resample(time='YE').sum('time')  
    out_layer = out_layer.where(out_layer >= 35)
    year = str(out_layer['time'].values[0])[:4]

    fig5, ax5 = plt.subplots(figsize=(figsize_w, figsize_h), dpi=plot_dpi)
    target_zones.plot(
        ax=ax5,
        facecolor=polygon_facecolor, 
        edgecolor=polygon_edgecolor,
        linewidth=polygon_linewidth
    )
    year_data_img_limit = out_layer.to_array().squeeze().plot.imshow(
        ax=ax5,
        cmap=raster_cmap,
        vmin=law_limit,
        vmax=full_max,
        add_colorbar=add_colorbar,
    )
    cbar_ax5 = plt.colorbar(
        year_data_img_limit, 
        ax=ax5,
        orientation=colorbar_orientation,
        fraction=colorbar_fraction, 
        pad=colorbar_pad,
    )
    cbar_ax5.set_label('Conteggio sforamenti')
    cbar_ax5.set_ticks([law_limit, 40, 45, 50, 55, 60, 65, 70,  full_max])
    cbar_ax5.set_ticklabels([str(law_limit), str(40), str(45), str(50), str(55), str(60), str(65), str(70), str(full_max)])
    for _index, _row in final_main_city.iterrows():
        coordinates = _row.geometry.xy
        label = plt.text(
            x=coordinates[0][0] + marker_x_offset,
            y=coordinates[1][0] + marker_y_offset,
            s=_row.citta,
            fontdict=dict(color=marker_font_color, size=marker_font_size),
            path_effects=[patheffects.withStroke(linewidth=path_effects_linewidth, foreground=path_effects_foreground)]
        )
        label.set_path_effects([patheffects.withStroke(linewidth=path_effects_linewidth, foreground=path_effects_foreground)])
    plt.title(f"Mappatura degli sforamenti del limite normativo di PM10 per l'anno {year}")
    
    # Save chart
    chart_name = f'anno_{year}.jpg'
    plt.savefig(img_folder.joinpath(chart_name))
    plt.close(fig5) # Avoid to show the figure
CPU times: user 23.9 s, sys: 3.49 s, total: 27.4 s
Wall time: 22.7 s

Inquinamento mappato

Conclusione¶

A parte il poco tempo che ho avuto in questi mesi, l'analisi è stata davvero molto complessa, le difficoltà non sono mancate. Una cosa che non sono riuscito a risolvere è il problema che espongo di seguito e che mi ha costretto ad usare il ciclo for per creare le immagini finali anzichè usare la funzione di selezione temporale che mette e disposizione xarray.

In [21]:
test_year = 2017
test = full_dataset_year_data.sel(time=f"{test_year}-12-31")

fig6, ax6 = plt.subplots(figsize=(figsize_w, figsize_h), dpi=plot_dpi)
target_zones.plot(
    ax=ax6,
    facecolor=polygon_facecolor, 
    edgecolor=polygon_edgecolor,
    linewidth=polygon_linewidth
)
year_data_img_limit = test.to_array().squeeze().plot.imshow(
    ax=ax6,
    cmap=raster_cmap,
    vmin=law_limit,
    vmax=full_max,
    add_colorbar=add_colorbar,
)
cbar_ax6 = plt.colorbar(
    year_data_img_limit, 
    ax=ax6,
    orientation=colorbar_orientation,
    fraction=colorbar_fraction, 
    pad=colorbar_pad,
)
cbar_ax6.set_label('Conteggio sforamenti')
cbar_ax6.set_ticks([law_limit, 40, 45, 50, 55, 60, 65, 70,  full_max])
cbar_ax6.set_ticklabels([str(law_limit), str(40), str(45), str(50), str(55), str(60), str(65), str(70), str(full_max)])
for _index, _row in final_main_city.iterrows():
    coordinates = _row.geometry.xy
    label = plt.text(
        x=coordinates[0][0] + marker_x_offset,
        y=coordinates[1][0] + marker_y_offset,
        s=_row.citta,
        fontdict=dict(color=marker_font_color, size=marker_font_size),
        path_effects=[patheffects.withStroke(linewidth=path_effects_linewidth, foreground=path_effects_foreground)]
    )
    label.set_path_effects([patheffects.withStroke(linewidth=path_effects_linewidth, foreground=path_effects_foreground)])
plt.title(f"Mappatura degli sforamenti del limite normativo di PM10 per l'anno {test_year}")

plt.show()
No description has been provided for this image

Come si può notare, il raster degli sforamenti risulta quadrettato. Se sai darmi una risposta del perchè accade do 100 punti a Grifondoro.

Se vuoi cimentarti con i dati li trovi qui