-
Notifications
You must be signed in to change notification settings - Fork 0
/
depositions.py
61 lines (48 loc) · 2.29 KB
/
depositions.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from netCDF4 import Dataset, num2date # pip install netCDF4
new_rasters = {
'DDEP_N': ['DDEP_RDN_m2Grid', 'DDEP_OXN_m2Grid'],
'WDEP_N': ['WDEP_OXN', 'WDEP_RDN'],
'TDEP_N': ['WDEP_N', 'DDEP_N'],
'TDEP_RDN': ['WDEP_RDN', 'DDEP_RDN_m2Grid'],
'TDEP_OXN': ['DDEP_OXN_m2Grid', 'WDEP_OXN'],
'TDEP_SOX': ['DDEP_SOX_m2Grid', 'WDEP_SOX'],
'TDEP_N_critical_load': [],
}
def add_pollutants():
"""
Return a list of new names for pollutants
"""
return list(new_rasters.keys())
def create_new_depositions_rasters(src_netcdf, dict_EMEP, resolution):
"""
Create new rasters for the depositions: \n
- DDEP_RDN_m2Grid + DDEP_OXN_m2Grid = DDEP_N
- WDEP_OXN + WDEP_RDN = WDEP_N
- WDEP_N + DDEP_N = TDEP_N
- WDEP_RDN + DDEP_RDN_m2Grid = TDEP_RDN
- DDEP_OXN_m2Grid + WDEP_OXN = TDEP_OXN
- DDEP_SOX_m2Grid + WDEP_SOX = TDEP_SOX
"""
for new_raster in new_rasters:
item_pollutant = None
if new_raster == 'TDEP_N_critical_load':
continue
for item in src_netcdf.variables.items():
if item[0] == new_rasters[new_raster][0]:
item_pollutant = item
break
x = src_netcdf.createVariable(new_raster, item_pollutant[1].datatype, item_pollutant[1].dimensions)
src_netcdf[new_raster].setncatts(src_netcdf[item_pollutant[0]].__dict__)
src_netcdf[new_raster].setncattr('long_name', new_raster)
src_netcdf[new_raster][:] = src_netcdf[new_rasters[new_raster][0]][:] + src_netcdf[new_rasters[new_raster][1]][:]
_max = float(src_netcdf[new_raster][:].max())
_min = float(src_netcdf[new_raster][:].min())
if dict_EMEP['max_min'][resolution][new_raster] == None:
dict_EMEP['max_min'][resolution][new_raster] = {}
dict_EMEP['max_min'][resolution][new_raster]['max'] = _max
dict_EMEP['max_min'][resolution][new_raster]['min'] = _min
else:
if _max > dict_EMEP['max_min'][resolution][new_raster]['max']:
dict_EMEP['max_min'][resolution][new_raster]['max'] = _max
if _min < dict_EMEP['max_min'][resolution][new_raster]['min']:
dict_EMEP['max_min'][resolution][new_raster]['min'] = _min