-
Notifications
You must be signed in to change notification settings - Fork 0
/
validation_osisaf_dmi.py
74 lines (60 loc) · 2.49 KB
/
validation_osisaf_dmi.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
import os
from netCDF4 import Dataset
import numpy as np
from scipy.interpolate import RegularGridInterpolator
from sitacval import read_dmi_ice_chart
from validation_dmi_dmi import Validation_DMI_DMI
class Validation_OSISAF_DMI(Validation_DMI_DMI):
products = ['sic']
map_label_aut = 'DMI-auto'
map_label_man = 'OSI-SAF'
def week_auto_files(self, end_date):
"""
Get the list of automatic files for the week ending at str_date.
Parameters:
-----------
end_date : str
Date of NIC shapefile (end of period)
Returns:
--------
aut_files : list
List of automatic files for the week ending at end_date.
"""
auto_file = f'{self.dir_auto}/{end_date.strftime(self.dir_auto_format)}'
if os.path.exists(auto_file):
return [auto_file]
else:
return []
def get_aut_ice_chart(self, aut_files):
""" Get averaged predicted DMI ice chart from several input netDCF files
on grid of the OSISAF AMSR2 SIC """
y_min, y_max, y_size = -5345000, 5845000, 1120
man_y = np.linspace(y_max, y_min, y_size)
x_min, x_max, x_size = -3845000, 3745000, 760
man_x = np.linspace(x_min, x_max, x_size)
sic_dmi, _, _, lnd_dmi, xc, yc = read_dmi_ice_chart(aut_files[0], self.step)
dmi_arrays_pro = []
for dmi_array in [sic_dmi, lnd_dmi]:
rgi = RegularGridInterpolator((yc, xc), dmi_array, method='nearest', bounds_error=False)
man_y_grd, man_x_grd = np.meshgrid(man_y, man_x, indexing='ij')
dmi_array_pro = rgi((man_y_grd, man_x_grd))
dmi_arrays_pro.append(dmi_array_pro)
return {
'sic': dmi_arrays_pro[0],
'landmask': dmi_arrays_pro[1],
}
def get_man_ice_chart(self, man_file):
""" Get OSISAF SIC """
with Dataset(man_file) as ds:
sic_map = ds['ice_conc'][0, :, :]
return {
'sic': sic_map,
}
def find_manual_file(self, date):
""" Find OSISAF AMSR2 SIC files"""
shapefile = f'{self.dir_man}/ice_conc_nh_polstere-100_amsr2_{date.strftime("%Y%m%d")}1200.nc'
return shapefile
def save_stats(self, date, man_ice_chart, aut_ice_chart, mask):
self.save_sic_stats(date, man_ice_chart, aut_ice_chart, mask)
def make_maps(self, date, man_ice_chart, aut_ice_chart, diff, mask):
self.make_sic_maps(date, man_ice_chart, aut_ice_chart, diff, mask)