bsod2 0.1.3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- bsod2/__init__.py +6 -0
- bsod2/qc.py +292 -0
- bsod2/sonde.py +259 -0
- bsod2-0.1.3.dist-info/METADATA +146 -0
- bsod2-0.1.3.dist-info/RECORD +8 -0
- bsod2-0.1.3.dist-info/WHEEL +5 -0
- bsod2-0.1.3.dist-info/licenses/LICENSE +674 -0
- bsod2-0.1.3.dist-info/top_level.txt +1 -0
bsod2/__init__.py
ADDED
bsod2/qc.py
ADDED
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
#! /usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
from datetime import datetime, timedelta
|
|
4
|
+
import math
|
|
5
|
+
import numpy as np
|
|
6
|
+
import pandas as pd
|
|
7
|
+
import warnings
|
|
8
|
+
|
|
9
|
+
remove_columns = [
|
|
10
|
+
"ST",
|
|
11
|
+
"SondeN",
|
|
12
|
+
"FCnt",
|
|
13
|
+
"AGC",
|
|
14
|
+
"rcvFREQ",
|
|
15
|
+
"GF",
|
|
16
|
+
"FE",
|
|
17
|
+
"V",
|
|
18
|
+
"RE",
|
|
19
|
+
"N1",
|
|
20
|
+
"N2",
|
|
21
|
+
"N3",
|
|
22
|
+
"N4",
|
|
23
|
+
"N5",
|
|
24
|
+
"N6",
|
|
25
|
+
"N7",
|
|
26
|
+
"N8",
|
|
27
|
+
"Press0",
|
|
28
|
+
"Temp0",
|
|
29
|
+
"Humi0",
|
|
30
|
+
]
|
|
31
|
+
cast_fields = [
|
|
32
|
+
"WD",
|
|
33
|
+
"WS",
|
|
34
|
+
"Height",
|
|
35
|
+
"Xdistanc",
|
|
36
|
+
"Ydistanc",
|
|
37
|
+
"GeodetLat",
|
|
38
|
+
"GeodetLon",
|
|
39
|
+
"Prs",
|
|
40
|
+
"Tmp",
|
|
41
|
+
"Hum",
|
|
42
|
+
]
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def numeric_condition_idx(df: pd.DataFrame, field: str, conditons: list):
|
|
46
|
+
"""evaluate AND conditions
|
|
47
|
+
|
|
48
|
+
Parameters
|
|
49
|
+
----------
|
|
50
|
+
df : pd.DataFrame
|
|
51
|
+
|
|
52
|
+
field : str
|
|
53
|
+
target field name
|
|
54
|
+
conditons : list
|
|
55
|
+
numerical condition
|
|
56
|
+
|
|
57
|
+
Returns
|
|
58
|
+
-------
|
|
59
|
+
_type_
|
|
60
|
+
AND conditions
|
|
61
|
+
"""
|
|
62
|
+
|
|
63
|
+
idx_all = False
|
|
64
|
+
for i in range(len(conditons)):
|
|
65
|
+
idx = pd.to_numeric(df[field], errors="coerce") == conditons[i]
|
|
66
|
+
idx_all = idx_all | idx if i != 0 else idx
|
|
67
|
+
|
|
68
|
+
return idx_all
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def get_qc_df(
|
|
72
|
+
raw_df: pd.DataFrame,
|
|
73
|
+
sonde_no: str,
|
|
74
|
+
launch_time: datetime,
|
|
75
|
+
**kwargs,
|
|
76
|
+
) -> pd.DataFrame:
|
|
77
|
+
"""get post QC DataFrame
|
|
78
|
+
|
|
79
|
+
Parameters
|
|
80
|
+
----------
|
|
81
|
+
raw_df : pd.DataFrame
|
|
82
|
+
raw DataFrame
|
|
83
|
+
sonde_no : str
|
|
84
|
+
sonde No.
|
|
85
|
+
launch_time : datetime
|
|
86
|
+
launch time
|
|
87
|
+
|
|
88
|
+
Returns
|
|
89
|
+
-------
|
|
90
|
+
pd.DataFrame
|
|
91
|
+
post QC DataFrame
|
|
92
|
+
"""
|
|
93
|
+
|
|
94
|
+
df = raw_df.copy()
|
|
95
|
+
|
|
96
|
+
# --- rename column name.
|
|
97
|
+
df.columns = [c.replace(" ", "") for c in df.columns]
|
|
98
|
+
|
|
99
|
+
# --- remove error records.
|
|
100
|
+
# observation status(ST)
|
|
101
|
+
st = numeric_condition_idx(df, "ST", [7])
|
|
102
|
+
# reciever error status(RE)
|
|
103
|
+
re = numeric_condition_idx(df, "RE", [0, 4])
|
|
104
|
+
# sonde No.(sondeN)
|
|
105
|
+
sonden = df["SondeN"].astype(str) == sonde_no
|
|
106
|
+
# GPS Flag(GF)
|
|
107
|
+
gf = numeric_condition_idx(df, "GF", [4, 3, 2, 1])
|
|
108
|
+
# number of the GPS satellite(N)
|
|
109
|
+
n = pd.to_numeric(df["N"], errors="coerce") >= 4
|
|
110
|
+
|
|
111
|
+
condition = st & re & sonden & gf & n
|
|
112
|
+
df = df[condition]
|
|
113
|
+
df = df.reset_index(drop=True)
|
|
114
|
+
|
|
115
|
+
# ---- time control
|
|
116
|
+
time_cname = df.columns[0]
|
|
117
|
+
|
|
118
|
+
df = df.rename(columns={time_cname: "Time"})
|
|
119
|
+
|
|
120
|
+
if len(df) > 0:
|
|
121
|
+
|
|
122
|
+
time0 = datetime.strptime(df["Time"].iloc[0], "%H:%M:%S")
|
|
123
|
+
time0 = datetime(
|
|
124
|
+
launch_time.year,
|
|
125
|
+
launch_time.month,
|
|
126
|
+
launch_time.day,
|
|
127
|
+
time0.hour,
|
|
128
|
+
time0.minute,
|
|
129
|
+
time0.second,
|
|
130
|
+
)
|
|
131
|
+
df.loc[0, "Time"] = time0.strftime("%Y-%m-%d %H:%M:%S")
|
|
132
|
+
for i in range(1, len(df)):
|
|
133
|
+
time = datetime.strptime(df["Time"].iloc[i], "%H:%M:%S")
|
|
134
|
+
time = datetime(
|
|
135
|
+
time0.year,
|
|
136
|
+
time0.month,
|
|
137
|
+
time0.day,
|
|
138
|
+
time.hour,
|
|
139
|
+
time.minute,
|
|
140
|
+
time.second,
|
|
141
|
+
)
|
|
142
|
+
time = time + timedelta(days=1) if time < time0 else time
|
|
143
|
+
df.loc[i, "Time"] = time.strftime("%Y-%m-%d %H:%M:%S")
|
|
144
|
+
time0 = time
|
|
145
|
+
|
|
146
|
+
df["Time"] = pd.to_datetime(df["Time"])
|
|
147
|
+
|
|
148
|
+
# --- error control
|
|
149
|
+
prs = pd.to_numeric(df["Press0"], errors="coerce").values.copy()
|
|
150
|
+
tmp = pd.to_numeric(df["Temp0"], errors="coerce").values.copy()
|
|
151
|
+
hum = pd.to_numeric(df["Humi0"], errors="coerce").values.copy()
|
|
152
|
+
|
|
153
|
+
# VE
|
|
154
|
+
ve = pd.to_numeric(df["V"], errors="coerce").values
|
|
155
|
+
for i in range(ve.shape[0]):
|
|
156
|
+
b = format(ve[i], "03b")
|
|
157
|
+
hum[i] = np.nan if b[0] == 1 else hum[i]
|
|
158
|
+
tmp[i] = np.nan if b[1] == 1 else tmp[i]
|
|
159
|
+
prs[i] = np.nan if b[2] == 1 else prs[i]
|
|
160
|
+
|
|
161
|
+
# FE
|
|
162
|
+
fe = pd.to_numeric(df["FE"], errors="coerce").values
|
|
163
|
+
fcnts = pd.to_numeric(df["FCnt"], errors="coerce").values
|
|
164
|
+
for i in range(fe.shape[0]):
|
|
165
|
+
fcnt = fcnts[i]
|
|
166
|
+
if math.isnan(fcnt):
|
|
167
|
+
hum[i] = np.nan
|
|
168
|
+
tmp[i] = np.nan
|
|
169
|
+
prs[i] = np.nan
|
|
170
|
+
continue
|
|
171
|
+
fcnt = int(fcnt)
|
|
172
|
+
hx = fe[i]
|
|
173
|
+
if math.isnan(hx):
|
|
174
|
+
hum[i] = np.nan
|
|
175
|
+
tmp[i] = np.nan
|
|
176
|
+
prs[i] = np.nan
|
|
177
|
+
else:
|
|
178
|
+
hx = f"{int(hx):04d}"
|
|
179
|
+
if int(hx[0]) != 0:
|
|
180
|
+
hum[i] = np.nan
|
|
181
|
+
tmp[i] = np.nan
|
|
182
|
+
prs[i] = np.nan
|
|
183
|
+
continue
|
|
184
|
+
hx1 = format(int(hx[1]), "03b")
|
|
185
|
+
if int(hx1[0]) == 1 and fcnt % 2 == 0:
|
|
186
|
+
tmp[i] = np.nan
|
|
187
|
+
if int(hx1[1]) == 1 and fcnt % 2 == 0:
|
|
188
|
+
hum[i] = np.nan
|
|
189
|
+
if int(hx1[2]) == 1 and fcnt % 2 == 0:
|
|
190
|
+
prs[i] = np.nan
|
|
191
|
+
hx2 = format(int(hx[2]), "03b")
|
|
192
|
+
if int(hx2[0]) == 1 and fcnt % 2 == 1:
|
|
193
|
+
tmp[i] = np.nan
|
|
194
|
+
if int(hx2[1]) == 1 and fcnt % 2 == 1:
|
|
195
|
+
hum[i] = np.nan
|
|
196
|
+
if int(hx2[2]) == 1 and fcnt % 2 == 1:
|
|
197
|
+
prs[i] = np.nan
|
|
198
|
+
|
|
199
|
+
df["Prs"] = prs
|
|
200
|
+
df["Tmp"] = tmp
|
|
201
|
+
df["Hum"] = hum
|
|
202
|
+
|
|
203
|
+
for col in remove_columns:
|
|
204
|
+
del df[col]
|
|
205
|
+
df = df.reset_index(drop=True)
|
|
206
|
+
|
|
207
|
+
# --- cast some fields
|
|
208
|
+
for field in cast_fields:
|
|
209
|
+
df[field] = pd.to_numeric(df[field], errors="coerce")
|
|
210
|
+
|
|
211
|
+
df["Time"] = pd.to_datetime(df["Time"], errors="coerce")
|
|
212
|
+
|
|
213
|
+
return df
|
|
214
|
+
else:
|
|
215
|
+
warnings.warn("No records found in the DataFrame.")
|
|
216
|
+
df["Prs"] = np.nan
|
|
217
|
+
df["Tmp"] = np.nan
|
|
218
|
+
df["Hum"] = np.nan
|
|
219
|
+
for col in remove_columns:
|
|
220
|
+
if col in df.columns:
|
|
221
|
+
del df[col]
|
|
222
|
+
df = df.reset_index(drop=True)
|
|
223
|
+
|
|
224
|
+
return df
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
def interp_df(
|
|
228
|
+
df: pd.DataFrame, field: str, min: float, max: float, step: float, **kwargs
|
|
229
|
+
) -> pd.DataFrame:
|
|
230
|
+
"""interpolate with vertical coordinate(z or p).
|
|
231
|
+
|
|
232
|
+
Parameters
|
|
233
|
+
----------
|
|
234
|
+
df : pd.DataFrame
|
|
235
|
+
target DataFrame
|
|
236
|
+
field : str
|
|
237
|
+
intepolate axis name.(""p" or "z")
|
|
238
|
+
min : float
|
|
239
|
+
minimum value of interpolated axis.
|
|
240
|
+
max : float
|
|
241
|
+
maximum value of interpolated axis.
|
|
242
|
+
step : float
|
|
243
|
+
step value of interpolated axis.
|
|
244
|
+
|
|
245
|
+
Returns
|
|
246
|
+
-------
|
|
247
|
+
pd.DataFrame
|
|
248
|
+
interpolated DataFrame
|
|
249
|
+
|
|
250
|
+
Raises
|
|
251
|
+
------
|
|
252
|
+
ValueError
|
|
253
|
+
raise if field is not "z" or "p"
|
|
254
|
+
"""
|
|
255
|
+
|
|
256
|
+
if field not in ["z", "p"]:
|
|
257
|
+
raise ValueError("field must be either 'z' or 'p'.")
|
|
258
|
+
if len(df) < 3:
|
|
259
|
+
warnings.warn("Not enough records to interpolate.")
|
|
260
|
+
return df
|
|
261
|
+
|
|
262
|
+
col_name = "Height" if field == "z" else "Prs"
|
|
263
|
+
df = df.sort_values(col_name).reset_index(drop=True)
|
|
264
|
+
new_col = np.arange(min, max + step, step)
|
|
265
|
+
df_interp = pd.DataFrame({col_name: new_col})
|
|
266
|
+
for field in ["Time", *cast_fields]:
|
|
267
|
+
|
|
268
|
+
if field == col_name:
|
|
269
|
+
continue
|
|
270
|
+
elif field == "Time":
|
|
271
|
+
df_interp[field] = pd.to_datetime(
|
|
272
|
+
np.interp(
|
|
273
|
+
new_col,
|
|
274
|
+
df[col_name].to_numpy(dtype=float),
|
|
275
|
+
df["Time"].astype(np.int64).to_numpy(dtype=float),
|
|
276
|
+
left=np.nan,
|
|
277
|
+
right=np.nan,
|
|
278
|
+
)
|
|
279
|
+
)
|
|
280
|
+
else:
|
|
281
|
+
x = df[col_name].to_numpy(dtype=float)
|
|
282
|
+
y = df[field].to_numpy(dtype=float)
|
|
283
|
+
mask = ~np.isnan(x) & ~np.isnan(y)
|
|
284
|
+
df_interp[field] = np.interp(
|
|
285
|
+
new_col,
|
|
286
|
+
x[mask],
|
|
287
|
+
y[mask],
|
|
288
|
+
left=np.nan,
|
|
289
|
+
right=np.nan,
|
|
290
|
+
)
|
|
291
|
+
|
|
292
|
+
return df_interp
|
bsod2/sonde.py
ADDED
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
#! /usr/bin/env python3
|
|
2
|
+
|
|
3
|
+
from dataclasses import dataclass, field
|
|
4
|
+
from datetime import datetime
|
|
5
|
+
import io
|
|
6
|
+
from metpy.units import units
|
|
7
|
+
from pathlib import Path
|
|
8
|
+
import pandas as pd
|
|
9
|
+
import pint
|
|
10
|
+
import warnings
|
|
11
|
+
|
|
12
|
+
from .qc import get_qc_df, interp_df
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
@dataclass(frozen=True)
|
|
16
|
+
class Sonde:
|
|
17
|
+
"""
|
|
18
|
+
Sonde Class
|
|
19
|
+
|
|
20
|
+
Parameters
|
|
21
|
+
----------
|
|
22
|
+
fpath : Path
|
|
23
|
+
path of raw file
|
|
24
|
+
rm_descending : bool, optimal
|
|
25
|
+
True to remove descending records, by default False
|
|
26
|
+
interp : str | None, optimal
|
|
27
|
+
name of interpolation axis. if None, interpolation is not performed, by default None
|
|
28
|
+
interp_pmin : float, optimal
|
|
29
|
+
minimum value of interpolated pressure axis, by default 100.0
|
|
30
|
+
interp_pmax : float, optimal
|
|
31
|
+
maximum value of interpolated pressure axis, by default 1100.0
|
|
32
|
+
interp_dp : float, optimal
|
|
33
|
+
step value of interpolated pressure axis, by default 1.0
|
|
34
|
+
interp_zmin : float, optimal
|
|
35
|
+
minimum value of interpolated z axis, by default 0.0
|
|
36
|
+
interp_zmax : float, optimal
|
|
37
|
+
maximum value of interpolated z axis, by default 20000.0
|
|
38
|
+
interp_dz : float, optimal
|
|
39
|
+
step value of interpolated z axis, by default 10.0
|
|
40
|
+
|
|
41
|
+
"""
|
|
42
|
+
|
|
43
|
+
fpath: Path
|
|
44
|
+
rm_descending: bool = False
|
|
45
|
+
interp: str | None = None
|
|
46
|
+
interp_pmin: float = 100.0
|
|
47
|
+
interp_pmax: float = 1100.0
|
|
48
|
+
interp_dp: float = 1.0
|
|
49
|
+
interp_zmin: float = 0.0
|
|
50
|
+
interp_zmax: float = 20000.0
|
|
51
|
+
interp_dz: float = 10.0
|
|
52
|
+
sonde_no: str = field(init=False)
|
|
53
|
+
launch_time: datetime = field(init=False)
|
|
54
|
+
product_name: str = field(init=False)
|
|
55
|
+
df: pd.DataFrame = field(init=False)
|
|
56
|
+
kwargs: dict | None = None
|
|
57
|
+
|
|
58
|
+
def __post_init__(self) -> None:
|
|
59
|
+
|
|
60
|
+
with open(self.fpath, "r") as f:
|
|
61
|
+
raw_data = f.read()
|
|
62
|
+
|
|
63
|
+
# parse the header lines
|
|
64
|
+
head_lines = raw_data.splitlines()[:6]
|
|
65
|
+
line1 = head_lines[0].split(",")
|
|
66
|
+
product_name = line1[0]
|
|
67
|
+
__sonde_no = line1[1]
|
|
68
|
+
__launch_time = datetime.strptime(f"{line1[4]} {line1[5]}", "%Y/%m/%d %H:%M:%S")
|
|
69
|
+
|
|
70
|
+
object.__setattr__(self, "sonde_no", __sonde_no)
|
|
71
|
+
object.__setattr__(self, "launch_time", __launch_time)
|
|
72
|
+
object.__setattr__(self, "product_name", product_name)
|
|
73
|
+
|
|
74
|
+
df = self.__get_df(raw_data)
|
|
75
|
+
|
|
76
|
+
object.__setattr__(self, "df", df)
|
|
77
|
+
|
|
78
|
+
def __get_df(self, raw_data: str | None = None) -> pd.DataFrame:
|
|
79
|
+
|
|
80
|
+
if raw_data is None:
|
|
81
|
+
with open(self.fpath, "r") as f:
|
|
82
|
+
raw_data = f.read()
|
|
83
|
+
|
|
84
|
+
# add column name "V" if it is not included in the raw data.
|
|
85
|
+
if ",V,Press0," not in raw_data:
|
|
86
|
+
raw_data = raw_data.replace(",,,Press0,", ",V,Press0,")
|
|
87
|
+
|
|
88
|
+
# read the raw data into a DataFrame.
|
|
89
|
+
df = pd.read_csv(io.StringIO(raw_data), skiprows=6, low_memory=False)
|
|
90
|
+
|
|
91
|
+
if len(df) == 0:
|
|
92
|
+
warnings.warn(f"No vertical records found in {self.fpath}.")
|
|
93
|
+
return df
|
|
94
|
+
|
|
95
|
+
# conduct QC.
|
|
96
|
+
df = get_qc_df(df, self.sonde_no, self.launch_time)
|
|
97
|
+
|
|
98
|
+
# remove records with descending height.
|
|
99
|
+
if self.rm_descending or (self.interp is not None):
|
|
100
|
+
df = df[df["Height"].cummax() == df["Height"]].reset_index(drop=True)
|
|
101
|
+
|
|
102
|
+
# interpolate the data if specified.
|
|
103
|
+
if self.interp == "p":
|
|
104
|
+
df = interp_df(df, "p", self.interp_pmin, self.interp_pmax, self.interp_dp)
|
|
105
|
+
elif self.interp == "z":
|
|
106
|
+
df = interp_df(df, "z", self.interp_zmin, self.interp_zmax, self.interp_dz)
|
|
107
|
+
|
|
108
|
+
return df
|
|
109
|
+
|
|
110
|
+
@property
|
|
111
|
+
def time(self) -> pd.Series:
|
|
112
|
+
"""time
|
|
113
|
+
|
|
114
|
+
Returns
|
|
115
|
+
-------
|
|
116
|
+
pd.Series
|
|
117
|
+
time series
|
|
118
|
+
"""
|
|
119
|
+
|
|
120
|
+
return self.df["Time"]
|
|
121
|
+
|
|
122
|
+
@property
|
|
123
|
+
def lat(self) -> pint.Quantity:
|
|
124
|
+
"""latitude
|
|
125
|
+
|
|
126
|
+
Returns
|
|
127
|
+
-------
|
|
128
|
+
pint.Quantity
|
|
129
|
+
latitude with units("degrees")
|
|
130
|
+
"""
|
|
131
|
+
|
|
132
|
+
return self.df["GeodetLat"].values * units.degrees
|
|
133
|
+
|
|
134
|
+
@property
|
|
135
|
+
def lon(self) -> pint.Quantity:
|
|
136
|
+
"""longitude
|
|
137
|
+
|
|
138
|
+
Returns
|
|
139
|
+
-------
|
|
140
|
+
pint.Quantity
|
|
141
|
+
longitude with units ("degrees")
|
|
142
|
+
"""
|
|
143
|
+
|
|
144
|
+
return self.df["GeodetLon"].values * units.degrees
|
|
145
|
+
|
|
146
|
+
@property
|
|
147
|
+
def x(self) -> pint.Quantity:
|
|
148
|
+
"""x-displacement from the launch point
|
|
149
|
+
|
|
150
|
+
Returns
|
|
151
|
+
-------
|
|
152
|
+
pint.Quantity
|
|
153
|
+
x-displacement with units("m")
|
|
154
|
+
"""
|
|
155
|
+
|
|
156
|
+
return self.df["Xdistanc"].values * units.meters
|
|
157
|
+
|
|
158
|
+
@property
|
|
159
|
+
def y(self) -> pint.Quantity:
|
|
160
|
+
"""y-displacement from the launch point
|
|
161
|
+
|
|
162
|
+
Returns
|
|
163
|
+
-------
|
|
164
|
+
pint.Quantity
|
|
165
|
+
y-displacement with units("m")
|
|
166
|
+
"""
|
|
167
|
+
|
|
168
|
+
return self.df["Ydistanc"].values * units.meters
|
|
169
|
+
|
|
170
|
+
@property
|
|
171
|
+
def p(self) -> pint.Quantity:
|
|
172
|
+
"""pressure
|
|
173
|
+
|
|
174
|
+
Returns
|
|
175
|
+
-------
|
|
176
|
+
pint.Quantity
|
|
177
|
+
pressure with units("hPa")
|
|
178
|
+
"""
|
|
179
|
+
|
|
180
|
+
return self.df["Prs"].values * units.hPa
|
|
181
|
+
|
|
182
|
+
@property
|
|
183
|
+
def z(self) -> pint.Quantity:
|
|
184
|
+
"""height
|
|
185
|
+
|
|
186
|
+
Returns
|
|
187
|
+
-------
|
|
188
|
+
pint.Quantity
|
|
189
|
+
height with units("m")
|
|
190
|
+
"""
|
|
191
|
+
|
|
192
|
+
return self.df["Height"].values * units.m
|
|
193
|
+
|
|
194
|
+
@property
|
|
195
|
+
def t(self) -> pint.Quantity:
|
|
196
|
+
"""temperature
|
|
197
|
+
|
|
198
|
+
Returns
|
|
199
|
+
-------
|
|
200
|
+
pint.Quantity
|
|
201
|
+
temperature with units("degC")
|
|
202
|
+
"""
|
|
203
|
+
|
|
204
|
+
return self.df["Tmp"].values * units.degC
|
|
205
|
+
|
|
206
|
+
@property
|
|
207
|
+
def rh(self) -> pint.Quantity:
|
|
208
|
+
"""relative humidity
|
|
209
|
+
|
|
210
|
+
Returns
|
|
211
|
+
-------
|
|
212
|
+
pint.Quantity
|
|
213
|
+
relative humidity with units("percent")
|
|
214
|
+
"""
|
|
215
|
+
|
|
216
|
+
return self.df["Hum"].values * units.percent
|
|
217
|
+
|
|
218
|
+
@property
|
|
219
|
+
def wd(self) -> pint.Quantity:
|
|
220
|
+
"""wind direction
|
|
221
|
+
|
|
222
|
+
Returns
|
|
223
|
+
-------
|
|
224
|
+
pint.Quantity
|
|
225
|
+
wind direction with units("degrees")
|
|
226
|
+
"""
|
|
227
|
+
|
|
228
|
+
return self.df["WD"].values * units.degrees
|
|
229
|
+
|
|
230
|
+
@property
|
|
231
|
+
def ws(self) -> pint.Quantity:
|
|
232
|
+
"""wind speed
|
|
233
|
+
|
|
234
|
+
Returns
|
|
235
|
+
-------
|
|
236
|
+
pint.Quantity
|
|
237
|
+
wind speed with units("m/s")
|
|
238
|
+
"""
|
|
239
|
+
|
|
240
|
+
return self.df["WS"].values * units.meter / units.second
|
|
241
|
+
|
|
242
|
+
def __len__(self) -> int:
|
|
243
|
+
|
|
244
|
+
return len(self.df)
|
|
245
|
+
|
|
246
|
+
def save_df(self, fpath: Path) -> None:
|
|
247
|
+
"""save as csv
|
|
248
|
+
|
|
249
|
+
Parameters
|
|
250
|
+
----------
|
|
251
|
+
fpath : Path
|
|
252
|
+
file path the df saved
|
|
253
|
+
"""
|
|
254
|
+
|
|
255
|
+
self.df.to_csv(fpath, index=False)
|
|
256
|
+
|
|
257
|
+
def __str__(self) -> str:
|
|
258
|
+
|
|
259
|
+
return f"Sonde(sonde_no={self.sonde_no}, launch_time={self.launch_time}, product_name={self.product_name}, num_records={len(self.df)})"
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: bsod2
|
|
3
|
+
Version: 0.1.3
|
|
4
|
+
Summary: package for reading radiosonde data
|
|
5
|
+
Author: So Tomita
|
|
6
|
+
License-Expression: GPL-3.0-only
|
|
7
|
+
Requires-Python: >=3.14
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Requires-Dist: numpy==2.4.3
|
|
11
|
+
Requires-Dist: pandas==3.0.2
|
|
12
|
+
Requires-Dist: metpy==1.7.1
|
|
13
|
+
Dynamic: license-file
|
|
14
|
+
|
|
15
|
+
# bsod2
|
|
16
|
+
BSoD2(BalloonScope on Deck 2) is a package in Python for reading and visualizing radiosonde data.
|
|
17
|
+
|
|
18
|
+
## Requirements
|
|
19
|
+
- numpy == 2.4.3
|
|
20
|
+
- pandas == 3.0.2
|
|
21
|
+
- metpy == 1.7.1
|
|
22
|
+
|
|
23
|
+
## Installation
|
|
24
|
+
This package can be installed from [PyPI](https://pypi.org/project/bsod2/).
|
|
25
|
+
```
|
|
26
|
+
pip install bsod2
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Usage
|
|
30
|
+
The only functionality provided by this package is the `bsod2.Sonde` class, which retrieves radiosonde data and performs quality control.
|
|
31
|
+
|
|
32
|
+
### Basic `Sonde` construction and methods
|
|
33
|
+
Initialize the class with the file path to the raw data.
|
|
34
|
+
```
|
|
35
|
+
from pathlib import Path
|
|
36
|
+
from bsod2 import Sonde
|
|
37
|
+
|
|
38
|
+
data = Sonde(Path("Seisuimaru2407/raw_data/F2024061806S1101771.CSV"))
|
|
39
|
+
data
|
|
40
|
+
>>> Sonde(sonde_no=1101771, launch_time=2024-06-18 06:01:42, product_name=iMS-100 , num_records=1101)
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
### Accessors for observed variables
|
|
44
|
+
The following accessors can be used to retrieve meteorological variables.
|
|
45
|
+
Most accessors return values with `metpy.units.units` attached.
|
|
46
|
+
|
|
47
|
+
| Accessor | units | Description | Example |
|
|
48
|
+
|----------|-------------|---------| ---------|
|
|
49
|
+
|`df`|| quality-controlled `pandas.DataFrame`|`sonde.df`|
|
|
50
|
+
|`time`||Time|`sonde.time`|
|
|
51
|
+
|`lat`|`units("deg")`| Latitude|`sonde.lat`|
|
|
52
|
+
|`lon`|`units("deg")`| Longitude|`sonde.lon`|
|
|
53
|
+
|`x`|`units("m")`| X-displacement from the launch point|`sonde.x`|
|
|
54
|
+
|`y`|`units("m")`| Y-displacement from the launch point|`sonde.y`|
|
|
55
|
+
|`z`| ```units("m")``` | Altitude | `sonde.z` |
|
|
56
|
+
|`p`| ```units("hPa")``` | Pressure | `sonde.p` |
|
|
57
|
+
|`t`| ```units("degC")```| Temperature | `sonde.temp` |
|
|
58
|
+
|`rh`|```units("percents")```| Relative humidity | `sonde.rh` |
|
|
59
|
+
|`wd`|```units("deg")```| Wind direction | `sonde.wd` |
|
|
60
|
+
|`ws`| ```units("m/s")```| Wind speed | `sonde.ws` |
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
### Save as CSV
|
|
64
|
+
Save the quality-controlled DataFrame as a CSV file to the specified file path using the save_df method.
|
|
65
|
+
```
|
|
66
|
+
data.save_df(Path("output.csv"))
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
### Altitude or pressure interpolation
|
|
70
|
+
Interpolate linearly onto an evenly spaced grid in pressure or altitude using the `interp` argument.
|
|
71
|
+
```
|
|
72
|
+
data = Sonde(FILE_PATH,interp="p")
|
|
73
|
+
```
|
|
74
|
+
By default, the interpolated pressure axis ranges from 100 to 1100 hPa at 1 hPa intervals, and the height axis ranges from 0 m to 2000 m at 10 m intervals.
|
|
75
|
+
Values outside the original data range are filled with NaN. The range and resolution of the interpolation axes can be specified using the following arguments.
|
|
76
|
+
|
|
77
|
+
| Argument | Description | Default |
|
|
78
|
+
|---------------|-----------------------------------------------------------------------------|---------|
|
|
79
|
+
| `interp` | Name of the interpolation axis. If None, interpolation is not performed. | None |
|
|
80
|
+
| `interp_pmin` | Minimum value of the interpolated pressure axis (hPa) | 100 |
|
|
81
|
+
| `interp_pmax` | Maximum value of the interpolated pressure axis (hPa) | 1100 |
|
|
82
|
+
| `interp_dp` | Step size of the interpolated pressure axis (hPa) | 1 |
|
|
83
|
+
| `interp_zmin` | Minimum value of the interpolated height axis (m) | 0 |
|
|
84
|
+
| `interp_zmax` | Maximum value of the interpolated height axis (m) | 20000 |
|
|
85
|
+
| `interp_dz` | Step size of the interpolated height axis (m) | 10 |
|
|
86
|
+
|
|
87
|
+
## Sample plots
|
|
88
|
+
### data
|
|
89
|
+
Sample data was observed in Seisui-maru 2407 cruise
|
|
90
|
+
(2024年度 三重大学 陸海空・環境科学実習).
|
|
91
|
+
- [raw data](sample/Seisuimaru2407/raw_data/)
|
|
92
|
+
- [field book(pdf)](sample/Seisuimaru2407/2407オペレーター野帳.pdf)
|
|
93
|
+
|
|
94
|
+
### z vs. sonde variables plot
|
|
95
|
+
<p align="center">
|
|
96
|
+
<img src="docs/images/vertical_profile.png" width="600" alt="vertical profile of observed sonde variables">
|
|
97
|
+
</p>
|
|
98
|
+
|
|
99
|
+
#### additional dependencies
|
|
100
|
+
- matplotlib
|
|
101
|
+
|
|
102
|
+
|
|
103
|
+
See [z_vs_var.ipynb](sample/z_vs_var.ipynb) for more details.
|
|
104
|
+
|
|
105
|
+
### time-z cross section plot
|
|
106
|
+
<p align="center">
|
|
107
|
+
<img src="docs/images/vert_csec.png" width="600" alt="time-z cross section of relative humidity">
|
|
108
|
+
</p>
|
|
109
|
+
|
|
110
|
+
#### additional dependencies
|
|
111
|
+
- matplotlib
|
|
112
|
+
- xarray
|
|
113
|
+
|
|
114
|
+
See [vertcal_csec.ipynb](sample/vertical_csec.ipynb) for more details.
|
|
115
|
+
|
|
116
|
+
### 2D/3D trajectories plot
|
|
117
|
+
<p align="center">
|
|
118
|
+
<img src="docs/images/trj2d.png" width="300" alt="2D trajectories">
|
|
119
|
+
<img src="docs/images/trj3d.png" width="300" alt="3D trajectories">
|
|
120
|
+
</p>
|
|
121
|
+
<p align="center">
|
|
122
|
+
<img src="docs/images/trj3d_animation.gif", width="600" alt="animation of 3D trajectories">
|
|
123
|
+
</p>
|
|
124
|
+
|
|
125
|
+
#### additional dependencies
|
|
126
|
+
- matplotlib
|
|
127
|
+
- cartopy
|
|
128
|
+
- pygmt
|
|
129
|
+
- imageio
|
|
130
|
+
- tqdm
|
|
131
|
+
|
|
132
|
+
See [trajectory.ipynb](sample/trajectory.ipynb) for more details.
|
|
133
|
+
|
|
134
|
+
### emagram
|
|
135
|
+
<p align="center">
|
|
136
|
+
<img src="docs/images/emagram.png" width="400" alt="emagram">
|
|
137
|
+
</p>
|
|
138
|
+
|
|
139
|
+
#### additional dependencies
|
|
140
|
+
- matplotlib
|
|
141
|
+
|
|
142
|
+
See [emagram.ipynb](sample/emagram.ipynb) for more details.
|
|
143
|
+
|
|
144
|
+
## License
|
|
145
|
+
This project is distributed under the terms of the GNU General Public License, Version 3 (GPLv3).
|
|
146
|
+
See the [LICENSE](LICENSE) file for details.
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
bsod2/__init__.py,sha256=LVLY0Pyxd4Z83gOH71NL-FuV9tMh55eTqaopjnZ4aQ8,98
|
|
2
|
+
bsod2/qc.py,sha256=L_GEd9pldiv2lvMNeyC111jhcixh4HUr3rUG5SfcM2I,7589
|
|
3
|
+
bsod2/sonde.py,sha256=hSIHkoK2INlDvOfKJd8TYCZdZIJdJyGDXX3Hh71YYOA,6565
|
|
4
|
+
bsod2-0.1.3.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
5
|
+
bsod2-0.1.3.dist-info/METADATA,sha256=OAn6SGILSPnQaZi5FfNyrGE0Hw2TfjmQG2xWOTJ8OxU,5280
|
|
6
|
+
bsod2-0.1.3.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
7
|
+
bsod2-0.1.3.dist-info/top_level.txt,sha256=zoq196_KAVXSbwuuT8SZHFi6M3GQ0SbH0J0AUvaUBHg,6
|
|
8
|
+
bsod2-0.1.3.dist-info/RECORD,,
|