forked from lmeru/thule
-
Notifications
You must be signed in to change notification settings - Fork 0
/
box_varianza.py
82 lines (48 loc) · 1.68 KB
/
box_varianza.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python
# coding: utf-8
# #### Box varianza. Funziona solo con satpy dalla 0.41 in poi, quando è stato inserito nel lettore modis L2 il dataset mod05
# In[1]:
from glob import glob
import satpy
import xarray as xr
from pyresample.geometry import AreaDefinition, create_area_def, SwathDefinition
from datetime import datetime
from mast import utils
# In[2]:
scene = glob('/home/bornagain/mounting_point/osvaldo/storage/WORK/DATA/MODIS/MOD05_L2/2020/**/*.hdf',recursive=True)
# In[3]:
len(scene)
# In[5]:
area_id = 'thule'
description = 'Thule ice box'
proj_id = 'thule'
center = (-67.8,76.37)
#center = (-68,76)
radius = (1000,1000)
shape = (19,19)
resolution =1000
proj_dict = {'proj': 'tmerc', 'lat_0': center[1], 'lon_0': center[0] , 'lat_ts':center[1], 'a': 6371228.0, 'units': 'm'}
center = xr.DataArray([center[0], center[1]], attrs={"units": "degrees"})
area_def = AreaDefinition.from_area_of_interest(area_id, proj_dict, shape, center, resolution)
datasets=[]
# In[6]:
def run_cycle(element):
try:
scn = satpy.Scene([element], reader='modis_l2')
scn.load(['water_vapor_infrared'])
local_scn = scn.resample(area_def, nprocs=16, radius_of_influence=10000)
local_scn_xr= local_scn.to_xarray_dataset()
local_scn_xr=local_scn_xr.expand_dims(time=[local_scn_xr.start_time])
datasets.append(local_scn_xr)
except(ValueError):
#print(Exception)
pass
# #### Ciclo sequenziale
# In[7]:
#get_ipython().run_cell_magic('time', '', 'for element in scene:\n run_cycle(element)\n')
# #### Ciclo parallelizzato
%%time
utils.parallel.parallel_CPU(run_cycle,scene)
# In[9]:
print(len(datasets))
# In[ ]: