-
Notifications
You must be signed in to change notification settings - Fork 1
/
get_caliop.py
143 lines (115 loc) · 4.99 KB
/
get_caliop.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
""" Module containing function to read CALIPSO data from matchups. """
import numpy as np
from atrain_match.utils.get_flag_info import get_calipso_clouds_of_type_i_feature_classification_flags_one_layer as get_cal_flag
from atrain_match.utils import validate_cph_util as vcu
def get_tropopause_height(ds):
"""Get tropopause height from caliop file"""
tropo_height = np.array(ds['tropopause_height'])[:] # in km over sea level
tropo_height = np.where(tropo_height < 0,np.nan,tropo_height*1000.)
elev = np.array(ds['elevation']) # in m
# compute height above surface
tropo_height_surf = tropo_height - elev
return tropo_height_surf
def get_caliop_cth(ds):
"""Get CALIOP CTH."""
cth = np.array(ds['layer_top_altitude'])[:, 0]
elev = np.array(ds['elevation'])
# set FillValue to NaN, convert to m
cth = np.where(cth == -9999, np.nan, cth * 1000.)
cth = np.where(cth < 0, np.nan, cth)
# compute height above surface
cth_surf = cth - elev
return cth_surf
def get_caliop_ctt(ds):
"""Get CALIOP CTT."""
ctt = np.array(ds['midlayer_temperature'])[:, 0]
ctt = np.where(ctt == -9999, np.nan, ctt + 273.15)
ctt = np.where(ctt < 0, np.nan, ctt)
return ctt
def get_caliop_ctp(ds):
ctp = np.array(ds['layer_top_pressure'])[:, 0]
ctp = np.where(ctp < 0, np.nan, ctp)
return ctp
def get_calipso_clouds_of_type_i(cflag, calipso_cloudtype=0):
"""Get CALIPSO clouds of type i from top layer."""
# bits 10-12, start at 1 counting
return get_cal_flag(cflag, calipso_cloudtype=calipso_cloudtype)
def get_calipso_low_clouds(cfalg):
"""Get CALIPSO low clouds."""
# type 0, 1, 2, 3 are low cloudtypes
calipso_low = np.logical_or(
np.logical_or(
get_calipso_clouds_of_type_i(cfalg, calipso_cloudtype=0),
get_calipso_clouds_of_type_i(cfalg, calipso_cloudtype=1)),
np.logical_or(
get_calipso_clouds_of_type_i(cfalg, calipso_cloudtype=2),
get_calipso_clouds_of_type_i(cfalg, calipso_cloudtype=3)))
return calipso_low
def get_calipso_medium_clouds(cfalg):
"""Get CALIPSO medium clouds."""
# type 4,5 are mid-level cloudtypes (Ac, As)
calipso_high = np.logical_or(
get_calipso_clouds_of_type_i(cfalg, calipso_cloudtype=4),
get_calipso_clouds_of_type_i(cfalg, calipso_cloudtype=5))
return calipso_high
def get_calipso_high_clouds(cfalg):
"""Get CALIPSO high clouds."""
# type 6, 7 are high cloudtypes
calipso_high = np.logical_or(
get_calipso_clouds_of_type_i(cfalg, calipso_cloudtype=6),
get_calipso_clouds_of_type_i(cfalg, calipso_cloudtype=7))
return calipso_high
def get_calipso_op(cfalg):
"""Get CALIPSO opaque clouds."""
# type 1, 2, 5, 7 are opaque cloudtypes
calipso_low = np.logical_or(
np.logical_or(
get_calipso_clouds_of_type_i(cfalg, calipso_cloudtype=1),
get_calipso_clouds_of_type_i(cfalg, calipso_cloudtype=2)),
np.logical_or(
get_calipso_clouds_of_type_i(cfalg, calipso_cloudtype=5),
get_calipso_clouds_of_type_i(cfalg, calipso_cloudtype=7)))
return calipso_low
def get_calipso_tp(cfalg):
"""Get CALIPSO semi-transparent clouds."""
# type 0,3,4,6 transparent/broken
calipso_low = np.logical_or(
np.logical_or(
get_calipso_clouds_of_type_i(cfalg, calipso_cloudtype=0),
get_calipso_clouds_of_type_i(cfalg, calipso_cloudtype=3)),
np.logical_or(
get_calipso_clouds_of_type_i(cfalg, calipso_cloudtype=4),
get_calipso_clouds_of_type_i(cfalg, calipso_cloudtype=6)))
return calipso_low
def get_calipso_low_clouds_op(match_calipso):
"""Get CALIPSO low and opaque clouds."""
calipso_low = np.logical_or(
get_calipso_clouds_of_type_i(match_calipso, calipso_cloudtype=1),
get_calipso_clouds_of_type_i(match_calipso, calipso_cloudtype=2))
return calipso_low
def get_calipso_medium_and_high_clouds_tp(match_calipso):
"""Get CALIPSO medium transparent and high transparent clouds."""
calipso_transp = np.logical_or(
get_calipso_clouds_of_type_i(match_calipso, calipso_cloudtype=4),
get_calipso_clouds_of_type_i(match_calipso, calipso_cloudtype=6))
return calipso_transp
def get_caliop_cph(ds):
"""
CALIPSO_PHASE_VALUES: unknown=0,
ice=1,
water=2,
"""
phase = vcu.get_calipso_phase_inner(ds['feature_classification_flags'],
max_layers=10,
same_phase_in_top_three_lay=True)
mask = phase.mask
phase = np.array(phase)
phase = np.where(phase == 0, np.nan, phase)
phase = np.where(phase == 2, 0, phase)
phase = np.where(np.logical_or(phase == 1, phase == 3), 1, phase)
phase = np.where(mask, np.nan, phase)
return phase
def get_caliop_cma(ds):
cfrac_limit = 0.5
caliop_cma = np.array(ds['cloud_fraction']) > cfrac_limit
return caliop_cma.astype(bool)