-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproduce_all_indices_v5.py
57 lines (49 loc) · 1.68 KB
/
produce_all_indices_v5.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
import datetime
import time
from distributed import Client
import icclim.main
import xarray as xr
from icclim.models.constants import TAS, SNOW_GROUP, TAS_MAX
from icclim.models.ecad_indices import EcadIndex
def run():
time_start = time.perf_counter()
Client(memory_limit="12GB", timeout=20, n_workers=1, threads_per_worker=10)
bp = [datetime.datetime(1991, 1, 1), datetime.datetime(2000, 12, 31)]
tr = [datetime.datetime(1991, 1, 1), datetime.datetime(2010, 12, 31)]
res = []
ds = xr.open_dataset("netcdf_files/climpact.full.nc")
origin_unit = ds.precip.attrs["units"]
tas = filter(lambda x: TAS in x.variables, EcadIndex)
for ind in tas:
out_unit = None
if ind.name.find("P") != -1:
out_unit = "%"
print(ind)
if ind.group == SNOW_GROUP:
ds.precip.attrs["units"] = "mm"
else:
ds.precip.attrs["units"] = origin_unit
res.append(
(
ind.name,
icclim.main.index(
index_name=ind.name,
in_files=ds,
slice_mode="YS",
base_period_time_range=bp,
time_range=tr,
transfer_limit_Mbytes=256,
out_unit=out_unit,
save_percentile=True,
),
)
)
for r in res:
r[1].to_netcdf(
f"netcdf_files/output/{r[0]}_ANN_icclimv5_climpSampleData_1991_2010.nc",
encoding={"time": {"units": "days since 1850-1-1"}},
)
time_elapsed = time.perf_counter() - time_start
print(time_elapsed, " secs")
if __name__ == "__main__":
run()