pydartdiags 0.0.43__py3-none-any.whl → 0.5.1__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.
Potentially problematic release.
This version of pydartdiags might be problematic. Click here for more details.
- pydartdiags/matplots/__init__.py +0 -0
- pydartdiags/matplots/matplots.py +423 -0
- pydartdiags/obs_sequence/composite_types.yaml +35 -0
- pydartdiags/obs_sequence/obs_sequence.py +756 -343
- pydartdiags/plots/plots.py +80 -228
- pydartdiags/stats/__init__.py +0 -0
- pydartdiags/stats/stats.py +432 -0
- {pydartdiags-0.0.43.dist-info → pydartdiags-0.5.1.dist-info}/METADATA +10 -5
- pydartdiags-0.5.1.dist-info/RECORD +15 -0
- {pydartdiags-0.0.43.dist-info → pydartdiags-0.5.1.dist-info}/WHEEL +1 -1
- pydartdiags-0.0.43.dist-info/RECORD +0 -10
- {pydartdiags-0.0.43.dist-info → pydartdiags-0.5.1.dist-info/licenses}/LICENSE +0 -0
- {pydartdiags-0.0.43.dist-info → pydartdiags-0.5.1.dist-info}/top_level.txt +0 -0
|
@@ -0,0 +1,432 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
import pandas as pd
|
|
3
|
+
import numpy as np
|
|
4
|
+
from functools import wraps
|
|
5
|
+
from datetime import datetime, timedelta
|
|
6
|
+
|
|
7
|
+
# from pydartdiags.obs_sequence import obs_sequence as obsq
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def apply_to_phases_in_place(func):
|
|
11
|
+
"""
|
|
12
|
+
Decorator to apply a function to both 'prior' and 'posterior' phases
|
|
13
|
+
and modify the DataFrame in place.
|
|
14
|
+
|
|
15
|
+
The decorated function should accept 'phase' as its first argument.
|
|
16
|
+
"""
|
|
17
|
+
|
|
18
|
+
@wraps(func)
|
|
19
|
+
def wrapper(df, *args, **kwargs):
|
|
20
|
+
for phase in ["prior", "posterior"]:
|
|
21
|
+
if f"{phase}_ensemble_spread" in df.columns:
|
|
22
|
+
func(df, phase, *args, **kwargs)
|
|
23
|
+
return df
|
|
24
|
+
|
|
25
|
+
return wrapper
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def apply_to_phases_by_type_return_df(func):
|
|
29
|
+
"""
|
|
30
|
+
Decorator to apply a function to both 'prior' and 'posterior' phases and return a new DataFrame.
|
|
31
|
+
|
|
32
|
+
The decorated function should accept 'phase' as its first argument and return a DataFrame.
|
|
33
|
+
"""
|
|
34
|
+
|
|
35
|
+
@wraps(func)
|
|
36
|
+
def wrapper(df, *args, **kwargs):
|
|
37
|
+
results = []
|
|
38
|
+
for phase in ["prior", "posterior"]:
|
|
39
|
+
if f"{phase}_ensemble_mean" in df.columns:
|
|
40
|
+
result = func(df, phase, *args, **kwargs)
|
|
41
|
+
results.append(result)
|
|
42
|
+
|
|
43
|
+
if not results:
|
|
44
|
+
return (
|
|
45
|
+
pd.DataFrame()
|
|
46
|
+
) # Return an empty DataFrame if no results are generated
|
|
47
|
+
|
|
48
|
+
# Dynamically determine merge keys based on common columns
|
|
49
|
+
common_columns = set(results[0].columns)
|
|
50
|
+
for result in results[1:]:
|
|
51
|
+
common_columns &= set(result.columns)
|
|
52
|
+
|
|
53
|
+
# Exclude phase-specific columns from the merge keys
|
|
54
|
+
phase_specific_columns = {
|
|
55
|
+
f"{phase}_sq_err",
|
|
56
|
+
f"{phase}_bias",
|
|
57
|
+
f"{phase}_totalvar",
|
|
58
|
+
f"{phase}_rmse",
|
|
59
|
+
f"{phase}_totalspread",
|
|
60
|
+
}
|
|
61
|
+
merge_keys = list(common_columns - phase_specific_columns)
|
|
62
|
+
|
|
63
|
+
if len(results) == 2:
|
|
64
|
+
return pd.merge(results[0], results[1], on=merge_keys)
|
|
65
|
+
else:
|
|
66
|
+
return results[0]
|
|
67
|
+
|
|
68
|
+
return wrapper
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def apply_to_phases_by_obs(func):
|
|
72
|
+
"""
|
|
73
|
+
Decorator to apply a function to both 'prior' and 'posterior' phases and return a new DataFrame.
|
|
74
|
+
|
|
75
|
+
The decorated function should accept 'phase' as its first argument and return a DataFrame.
|
|
76
|
+
"""
|
|
77
|
+
|
|
78
|
+
@wraps(func)
|
|
79
|
+
def wrapper(df, *args, **kwargs):
|
|
80
|
+
|
|
81
|
+
res_df = func(df, "prior", *args, **kwargs)
|
|
82
|
+
if "posterior_ensemble_mean" in df.columns:
|
|
83
|
+
posterior_df = func(df, "posterior", *args, **kwargs)
|
|
84
|
+
res_df["posterior_rank"] = posterior_df["posterior_rank"]
|
|
85
|
+
|
|
86
|
+
return res_df
|
|
87
|
+
|
|
88
|
+
return wrapper
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
@apply_to_phases_by_obs
|
|
92
|
+
def calculate_rank(df, phase):
|
|
93
|
+
"""
|
|
94
|
+
Calculate the rank of observations within an ensemble.
|
|
95
|
+
|
|
96
|
+
This function takes a DataFrame containing ensemble predictions and observed values,
|
|
97
|
+
adds sampling noise to the ensemble predictions, and calculates the rank of the observed
|
|
98
|
+
value within the perturbed ensemble for each observation. The rank indicates the position
|
|
99
|
+
of the observed value within the sorted ensemble values, with 1 being the lowest. If the
|
|
100
|
+
observed value is larger than the largest ensemble member, its rank is set to the ensemble
|
|
101
|
+
size plus one.
|
|
102
|
+
|
|
103
|
+
Parameters:
|
|
104
|
+
df (pd.DataFrame): A DataFrame with columns for rank, and observation type.
|
|
105
|
+
|
|
106
|
+
phase (str): The phase for which to calculate the statistics ('prior' or 'posterior')
|
|
107
|
+
|
|
108
|
+
Returns:
|
|
109
|
+
DataFrame containing columns for 'rank' and observation 'type'.
|
|
110
|
+
"""
|
|
111
|
+
column = f"{phase}_ensemble_member"
|
|
112
|
+
ensemble_values = df.filter(regex=column).to_numpy().copy()
|
|
113
|
+
std_dev = np.sqrt(df["obs_err_var"]).to_numpy()
|
|
114
|
+
obsvalue = df["observation"].to_numpy()
|
|
115
|
+
obstype = df["type"].to_numpy()
|
|
116
|
+
ens_size = ensemble_values.shape[1]
|
|
117
|
+
mean = 0.0 # mean of the sampling noise
|
|
118
|
+
rank = np.zeros(obsvalue.shape[0], dtype=int)
|
|
119
|
+
|
|
120
|
+
for obs in range(ensemble_values.shape[0]):
|
|
121
|
+
sampling_noise = np.random.normal(mean, std_dev[obs], ens_size)
|
|
122
|
+
ensemble_values[obs] += sampling_noise
|
|
123
|
+
ensemble_values[obs].sort()
|
|
124
|
+
for i, ens in enumerate(ensemble_values[obs]):
|
|
125
|
+
if obsvalue[obs] <= ens:
|
|
126
|
+
rank[obs] = i + 1
|
|
127
|
+
break
|
|
128
|
+
|
|
129
|
+
if rank[obs] == 0: # observation is larger than largest ensemble member
|
|
130
|
+
rank[obs] = ens_size + 1
|
|
131
|
+
|
|
132
|
+
result_df = pd.DataFrame({"type": obstype, f"{phase}_rank": rank})
|
|
133
|
+
|
|
134
|
+
return result_df
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
def mean_then_sqrt(x):
|
|
138
|
+
"""
|
|
139
|
+
Calculates the mean of an array-like object and then takes the square root of the result.
|
|
140
|
+
|
|
141
|
+
Parameters:
|
|
142
|
+
arr (array-like): An array-like object (such as a list or a pandas Series).
|
|
143
|
+
The elements should be numeric.
|
|
144
|
+
|
|
145
|
+
Returns:
|
|
146
|
+
float: The square root of the mean of the input array.
|
|
147
|
+
|
|
148
|
+
Raises:
|
|
149
|
+
TypeError: If the input is not an array-like object containing numeric values.
|
|
150
|
+
ValueError: If the input array is empty.
|
|
151
|
+
"""
|
|
152
|
+
|
|
153
|
+
return np.sqrt(np.mean(x))
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
@apply_to_phases_in_place
|
|
157
|
+
def diag_stats(df, phase):
|
|
158
|
+
"""
|
|
159
|
+
Calculate diagnostic statistics for a given phase and add them to the DataFrame.
|
|
160
|
+
|
|
161
|
+
Args:
|
|
162
|
+
df (pandas.DataFrame): The input DataFrame containing observation data and ensemble statistics.
|
|
163
|
+
The DataFrame must include the following columns:
|
|
164
|
+
- 'observation': The actual observation values.
|
|
165
|
+
- 'obs_err_var': The variance of the observation error.
|
|
166
|
+
- 'prior_ensemble_mean' and/or 'posterior_ensemble_mean': The mean of the ensemble.
|
|
167
|
+
- 'prior_ensemble_spread' and/or 'posterior_ensemble_spread': The spread of the ensemble.
|
|
168
|
+
|
|
169
|
+
phase (str): The phase for which to calculate the statistics ('prior' or 'posterior')
|
|
170
|
+
|
|
171
|
+
Returns:
|
|
172
|
+
None: The function modifies the DataFrame in place by adding the following columns:
|
|
173
|
+
- 'prior_sq_err' and/or 'posterior_sq_err': The square error for the 'prior' and 'posterior' phases.
|
|
174
|
+
- 'prior_bias' and/or 'posterior_bias': The bias for the 'prior' and 'posterior' phases.
|
|
175
|
+
- 'prior_totalvar' and/or 'posterior_totalvar': The total variance for the 'prior' and 'posterior' phases.
|
|
176
|
+
|
|
177
|
+
Notes:
|
|
178
|
+
- Spread is the standard deviation of the ensemble.
|
|
179
|
+
- The function modifies the input DataFrame by adding new columns for the calculated statistics.
|
|
180
|
+
"""
|
|
181
|
+
pd.options.mode.copy_on_write = True
|
|
182
|
+
|
|
183
|
+
# input from the observation sequence
|
|
184
|
+
spread_column = f"{phase}_ensemble_spread"
|
|
185
|
+
mean_column = f"{phase}_ensemble_mean"
|
|
186
|
+
|
|
187
|
+
# Calculated from the observation sequence
|
|
188
|
+
sq_err_column = f"{phase}_sq_err"
|
|
189
|
+
bias_column = f"{phase}_bias"
|
|
190
|
+
totalvar_column = f"{phase}_totalvar"
|
|
191
|
+
|
|
192
|
+
df[sq_err_column] = (df[mean_column] - df["observation"]) ** 2
|
|
193
|
+
df[bias_column] = df[mean_column] - df["observation"]
|
|
194
|
+
df[totalvar_column] = df["obs_err_var"] + df[spread_column] ** 2
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def bin_by_layer(df, levels, verticalUnit="pressure (Pa)"):
|
|
198
|
+
"""
|
|
199
|
+
Bin observations by vertical layers and add 'vlevels' and 'midpoint' columns to the DataFrame.
|
|
200
|
+
|
|
201
|
+
This function bins the observations in the DataFrame based on the specified vertical levels and adds two new columns:
|
|
202
|
+
'vlevels', which represents the categorized vertical levels, and 'midpoint', which represents the midpoint of each
|
|
203
|
+
vertical level bin. Only observations (row) with the specified vertical unit are binned.
|
|
204
|
+
|
|
205
|
+
Args:
|
|
206
|
+
df (pandas.DataFrame): The input DataFrame containing observation data. The DataFrame must include the following columns:
|
|
207
|
+
- 'vertical': The vertical coordinate values of the observations.
|
|
208
|
+
- 'vert_unit': The unit of the vertical coordinate values.
|
|
209
|
+
levels (list): A list of bin edges for the vertical levels.
|
|
210
|
+
verticalUnit (str, optional): The unit of the vertical axis (e.g., 'pressure (Pa)'). Default is 'pressure (Pa)'.
|
|
211
|
+
|
|
212
|
+
Returns:
|
|
213
|
+
pandas.DataFrame: The input DataFrame with additional columns for the binned vertical levels and their midpoints:
|
|
214
|
+
- 'vlevels': The categorized vertical levels.
|
|
215
|
+
- 'midpoint': The midpoint of each vertical level bin.
|
|
216
|
+
|
|
217
|
+
Notes:
|
|
218
|
+
- The function modifies the input DataFrame by adding 'vlevels' and 'midpoint' columns.
|
|
219
|
+
- The 'midpoint' values are calculated as half the midpoint of each vertical level bin.
|
|
220
|
+
"""
|
|
221
|
+
pd.options.mode.copy_on_write = True
|
|
222
|
+
df.loc[df["vert_unit"] == verticalUnit, "vlevels"] = pd.cut(
|
|
223
|
+
df.loc[df["vert_unit"] == verticalUnit, "vertical"], levels
|
|
224
|
+
)
|
|
225
|
+
df.loc[:, "midpoint"] = df["vlevels"].apply(lambda x: x.mid)
|
|
226
|
+
|
|
227
|
+
|
|
228
|
+
def bin_by_time(df, time_value):
|
|
229
|
+
"""
|
|
230
|
+
Bin observations by time and add 'time_bin' and 'time_bin_midpoint' columns to the DataFrame.
|
|
231
|
+
The first bin starts 1 second before the minimum time value, so the minimum time is included in the
|
|
232
|
+
first bin. The last bin is inclusive of the maximum time value.
|
|
233
|
+
|
|
234
|
+
Args:
|
|
235
|
+
df (pd.DataFrame): The input DataFrame containing a 'time' column.
|
|
236
|
+
time_value (str): The width of each time bin (e.g., '3600S' for 1 hour).
|
|
237
|
+
|
|
238
|
+
Returns:
|
|
239
|
+
None: The function modifies the DataFrame in place by adding 'time_bin' and 'time_bin_midpoint' columns.
|
|
240
|
+
"""
|
|
241
|
+
# Create time bins
|
|
242
|
+
start = df["time"].min() - timedelta(seconds=1)
|
|
243
|
+
end = df["time"].max()
|
|
244
|
+
# Determine if the end time aligns with the bin boundary
|
|
245
|
+
time_delta = pd.Timedelta(time_value)
|
|
246
|
+
aligned_end = (pd.Timestamp(end) + time_delta).floor(time_value)
|
|
247
|
+
|
|
248
|
+
time_bins = pd.date_range(
|
|
249
|
+
start=start,
|
|
250
|
+
end=aligned_end,
|
|
251
|
+
freq=time_value,
|
|
252
|
+
)
|
|
253
|
+
|
|
254
|
+
df["time_bin"] = pd.cut(df["time"], bins=time_bins)
|
|
255
|
+
|
|
256
|
+
# Calculate the midpoint of each time bin
|
|
257
|
+
df["time_bin_midpoint"] = df["time_bin"].apply(
|
|
258
|
+
lambda x: x.left + (x.right - x.left) / 2 if pd.notnull(x) else None
|
|
259
|
+
)
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
@apply_to_phases_by_type_return_df
|
|
263
|
+
def grand_statistics(df, phase):
|
|
264
|
+
|
|
265
|
+
# assuming diag_stats has been called
|
|
266
|
+
grand = (
|
|
267
|
+
df.groupby(["type"], observed=False)
|
|
268
|
+
.agg(
|
|
269
|
+
{
|
|
270
|
+
f"{phase}_sq_err": mean_then_sqrt,
|
|
271
|
+
f"{phase}_bias": "mean",
|
|
272
|
+
f"{phase}_totalvar": mean_then_sqrt,
|
|
273
|
+
}
|
|
274
|
+
)
|
|
275
|
+
.reset_index()
|
|
276
|
+
)
|
|
277
|
+
|
|
278
|
+
grand.rename(columns={f"{phase}_sq_err": f"{phase}_rmse"}, inplace=True)
|
|
279
|
+
grand.rename(columns={f"{phase}_totalvar": f"{phase}_totalspread"}, inplace=True)
|
|
280
|
+
|
|
281
|
+
return grand
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
@apply_to_phases_by_type_return_df
|
|
285
|
+
def layer_statistics(df, phase):
|
|
286
|
+
|
|
287
|
+
# assuming diag_stats has been called
|
|
288
|
+
layer_stats = (
|
|
289
|
+
df.groupby(["midpoint", "type"], observed=False)
|
|
290
|
+
.agg(
|
|
291
|
+
{
|
|
292
|
+
f"{phase}_sq_err": mean_then_sqrt,
|
|
293
|
+
f"{phase}_bias": "mean",
|
|
294
|
+
f"{phase}_totalvar": mean_then_sqrt,
|
|
295
|
+
"vert_unit": "first",
|
|
296
|
+
"vlevels": "first",
|
|
297
|
+
}
|
|
298
|
+
)
|
|
299
|
+
.reset_index()
|
|
300
|
+
)
|
|
301
|
+
|
|
302
|
+
layer_stats.rename(columns={f"{phase}_sq_err": f"{phase}_rmse"}, inplace=True)
|
|
303
|
+
layer_stats.rename(
|
|
304
|
+
columns={f"{phase}_totalvar": f"{phase}_totalspread"}, inplace=True
|
|
305
|
+
)
|
|
306
|
+
|
|
307
|
+
return layer_stats
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
@apply_to_phases_by_type_return_df
|
|
311
|
+
def time_statistics(df, phase):
|
|
312
|
+
"""
|
|
313
|
+
Calculate time-based statistics for a given phase and return a new DataFrame.
|
|
314
|
+
|
|
315
|
+
Args:
|
|
316
|
+
df (pandas.DataFrame): The input DataFrame containing observation data and ensemble statistics.
|
|
317
|
+
phase (str): The phase for which to calculate the statistics ('prior' or 'posterior').
|
|
318
|
+
|
|
319
|
+
Returns:
|
|
320
|
+
pandas.DataFrame: A DataFrame containing time-based statistics for the specified phase.
|
|
321
|
+
"""
|
|
322
|
+
# Assuming diag_stats has been called
|
|
323
|
+
time_stats = (
|
|
324
|
+
df.groupby(["time_bin_midpoint", "type"], observed=False)
|
|
325
|
+
.agg(
|
|
326
|
+
{
|
|
327
|
+
f"{phase}_sq_err": mean_then_sqrt,
|
|
328
|
+
f"{phase}_bias": "mean",
|
|
329
|
+
f"{phase}_totalvar": mean_then_sqrt,
|
|
330
|
+
"time_bin": "first",
|
|
331
|
+
"time": "first",
|
|
332
|
+
}
|
|
333
|
+
)
|
|
334
|
+
.reset_index()
|
|
335
|
+
)
|
|
336
|
+
|
|
337
|
+
time_stats.rename(columns={f"{phase}_sq_err": f"{phase}_rmse"}, inplace=True)
|
|
338
|
+
time_stats.rename(
|
|
339
|
+
columns={f"{phase}_totalvar": f"{phase}_totalspread"}, inplace=True
|
|
340
|
+
)
|
|
341
|
+
|
|
342
|
+
return time_stats
|
|
343
|
+
|
|
344
|
+
|
|
345
|
+
def possible_vs_used(df):
|
|
346
|
+
"""
|
|
347
|
+
Calculates the count of possible vs. used observations by type.
|
|
348
|
+
|
|
349
|
+
This function takes a DataFrame containing observation data, including a 'type' column for the observation
|
|
350
|
+
type and an 'observation' column. The number of used observations ('used'), is the total number
|
|
351
|
+
of assimilated observations (as determined by the `select_used_qcs` function).
|
|
352
|
+
The result is a DataFrame with each observation type, the count of possible observations, and the count of
|
|
353
|
+
used observations.
|
|
354
|
+
|
|
355
|
+
Returns:
|
|
356
|
+
pd.DataFrame: A DataFrame with three columns: 'type', 'possible', and 'used'. 'type' is the observation type,
|
|
357
|
+
'possible' is the count of all observations of that type, and 'used' is the count of observations of that type
|
|
358
|
+
that passed quality control checks.
|
|
359
|
+
"""
|
|
360
|
+
possible = df.groupby("type")["observation"].count()
|
|
361
|
+
possible.rename("possible", inplace=True)
|
|
362
|
+
|
|
363
|
+
used_qcs = select_used_qcs(df).groupby("type")["observation"].count()
|
|
364
|
+
used = used_qcs.reindex(possible.index, fill_value=0)
|
|
365
|
+
used.rename("used", inplace=True)
|
|
366
|
+
|
|
367
|
+
return pd.concat([possible, used], axis=1).reset_index()
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
def possible_vs_used_by_layer(df):
|
|
371
|
+
"""
|
|
372
|
+
Calculates the count of possible vs. used observations by type and vertical level.
|
|
373
|
+
"""
|
|
374
|
+
possible = df.groupby(["type", "midpoint"], observed=False)["type"].count()
|
|
375
|
+
possible.rename("possible", inplace=True)
|
|
376
|
+
|
|
377
|
+
used_qcs = (
|
|
378
|
+
select_used_qcs(df)
|
|
379
|
+
.groupby(["type", "midpoint"], observed=False)["type"]
|
|
380
|
+
.count()
|
|
381
|
+
)
|
|
382
|
+
|
|
383
|
+
used = used_qcs.reindex(possible.index, fill_value=0)
|
|
384
|
+
used.rename("used", inplace=True)
|
|
385
|
+
|
|
386
|
+
return pd.concat([possible, used], axis=1).reset_index()
|
|
387
|
+
|
|
388
|
+
|
|
389
|
+
def select_used_qcs(df):
|
|
390
|
+
"""
|
|
391
|
+
Select rows from the DataFrame where the observation was used.
|
|
392
|
+
Includes observations for which the posterior forward observation operators failed.
|
|
393
|
+
|
|
394
|
+
Returns:
|
|
395
|
+
pandas.DataFrame: A DataFrame containing only the rows with a DART quality control flag 0 or 2.
|
|
396
|
+
"""
|
|
397
|
+
return df[(df["DART_quality_control"] == 0) | (df["DART_quality_control"] == 2)]
|
|
398
|
+
|
|
399
|
+
|
|
400
|
+
def possible_vs_used_by_time(df):
|
|
401
|
+
"""
|
|
402
|
+
Calculates the count of possible vs. used observations by type and time bin.
|
|
403
|
+
|
|
404
|
+
Args:
|
|
405
|
+
df (pd.DataFrame): The input DataFrame containing observation data. The DataFrame must include:
|
|
406
|
+
- 'type': The observation type.
|
|
407
|
+
- 'time_bin_midpoint': The midpoint of the time bin.
|
|
408
|
+
- 'observation': The observation values.
|
|
409
|
+
- 'DART_quality_control': The quality control flag.
|
|
410
|
+
|
|
411
|
+
Returns:
|
|
412
|
+
pd.DataFrame: A DataFrame with the following columns:
|
|
413
|
+
- 'time_bin_midpoint': The midpoint of the time bin.
|
|
414
|
+
- 'type': The observation type.
|
|
415
|
+
- 'possible': The count of all observations in the time bin.
|
|
416
|
+
- 'used': The count of observations in the time bin that passed quality control checks.
|
|
417
|
+
"""
|
|
418
|
+
# Count all observations (possible) grouped by time_bin_midpoint and type
|
|
419
|
+
possible = df.groupby(["time_bin_midpoint", "type"], observed=False)["type"].count()
|
|
420
|
+
possible.rename("possible", inplace=True)
|
|
421
|
+
|
|
422
|
+
# Count used observations (QC=0 or QC=2) grouped by time_bin_midpoint and type
|
|
423
|
+
used_qcs = (
|
|
424
|
+
select_used_qcs(df)
|
|
425
|
+
.groupby(["time_bin_midpoint", "type"], observed=False)["type"]
|
|
426
|
+
.count()
|
|
427
|
+
)
|
|
428
|
+
used = used_qcs.reindex(possible.index, fill_value=0)
|
|
429
|
+
used.rename("used", inplace=True)
|
|
430
|
+
|
|
431
|
+
# Combine possible and used into a single DataFrame
|
|
432
|
+
return pd.concat([possible, used], axis=1).reset_index()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: pydartdiags
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.5.1
|
|
4
4
|
Summary: Observation Sequence Diagnostics for DART
|
|
5
5
|
Home-page: https://github.com/NCAR/pyDARTdiags.git
|
|
6
6
|
Author: Helen Kershaw
|
|
@@ -18,22 +18,27 @@ Requires-Dist: pandas>=2.2.0
|
|
|
18
18
|
Requires-Dist: numpy>=1.26
|
|
19
19
|
Requires-Dist: plotly>=5.22.0
|
|
20
20
|
Requires-Dist: pyyaml>=6.0.2
|
|
21
|
+
Requires-Dist: matplotlib>=3.9.4
|
|
22
|
+
Dynamic: author
|
|
23
|
+
Dynamic: home-page
|
|
24
|
+
Dynamic: license-file
|
|
25
|
+
Dynamic: requires-python
|
|
21
26
|
|
|
22
27
|
[](https://opensource.org/licenses/Apache-2.0)
|
|
23
28
|
[](https://codecov.io/gh/NCAR/pyDARTdiags)
|
|
24
29
|
[](https://pypi.org/project/pydartdiags/)
|
|
25
|
-
|
|
30
|
+
[](https://github.com/psf/black)
|
|
26
31
|
|
|
27
32
|
# pyDARTdiags
|
|
28
33
|
|
|
29
|
-
pyDARTdiags is a Python library for
|
|
34
|
+
pyDARTdiags is a Python library for observation space diagnostics for the Data Assimilation Research Testbed ([DART](https://github.com/NCAR/DART)).
|
|
30
35
|
|
|
31
36
|
pyDARTdiags is under initial development, so please use caution.
|
|
32
37
|
The MATLAB [observation space diagnostics](https://docs.dart.ucar.edu/en/latest/guide/matlab-observation-space.html) are available through [DART](https://github.com/NCAR/DART).
|
|
33
38
|
|
|
34
39
|
|
|
35
40
|
pyDARTdiags can be installed through pip: https://pypi.org/project/pydartdiags/
|
|
36
|
-
|
|
41
|
+
Documentation : https://ncar.github.io/pyDARTdiags/
|
|
37
42
|
|
|
38
43
|
## Contributing
|
|
39
44
|
Contributions are welcome! If you have a feature request, bug report, or a suggestion, please open an issue on our GitHub repository.
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
pydartdiags/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
+
pydartdiags/matplots/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
+
pydartdiags/matplots/matplots.py,sha256=Bo0TTz1gvsHEvTfTfLfdTi_3hNRN1okmyY5a5yYgtzk,13455
|
|
4
|
+
pydartdiags/obs_sequence/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
pydartdiags/obs_sequence/composite_types.yaml,sha256=PVLMU6x6KcVMCwPB-U65C_e0YQUemfqUhYMpf1DhFOY,917
|
|
6
|
+
pydartdiags/obs_sequence/obs_sequence.py,sha256=8RGUzfWxSlGtPx_uz5lhLJaUaG8ju6qmiIU7da43nwk,48444
|
|
7
|
+
pydartdiags/plots/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
8
|
+
pydartdiags/plots/plots.py,sha256=U7WQjE_qN-5a8-85D-PkkgILSFBzTJQ1mcGBa7l5DHI,6464
|
|
9
|
+
pydartdiags/stats/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
10
|
+
pydartdiags/stats/stats.py,sha256=HbRj3toQRx63mX1a1FXHA5_7yGITz8JKHbhjMoAHChk,16163
|
|
11
|
+
pydartdiags-0.5.1.dist-info/licenses/LICENSE,sha256=ROglds_Eg_ylXp-1MHmEawDqMw_UsCB4r9sk7z9PU9M,11377
|
|
12
|
+
pydartdiags-0.5.1.dist-info/METADATA,sha256=Fn3KsjQZma-696rO-yGpAHrHqV2izTNpVmBnYPx9z6k,2413
|
|
13
|
+
pydartdiags-0.5.1.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
|
|
14
|
+
pydartdiags-0.5.1.dist-info/top_level.txt,sha256=LfMoPLnSd0VhhlWev1eeX9t6AzvyASOloag0LO_ppWg,12
|
|
15
|
+
pydartdiags-0.5.1.dist-info/RECORD,,
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
pydartdiags/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
2
|
-
pydartdiags/obs_sequence/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
3
|
-
pydartdiags/obs_sequence/obs_sequence.py,sha256=2pddiJ6VRFkaDizYq8HvGUpC4rw7TTV14XjmemjqCNg,34187
|
|
4
|
-
pydartdiags/plots/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
-
pydartdiags/plots/plots.py,sha256=UecLgWauO9L_EaGhEVxW3IuKcSU95uRA2mptsxh4-0E,13901
|
|
6
|
-
pydartdiags-0.0.43.dist-info/LICENSE,sha256=ROglds_Eg_ylXp-1MHmEawDqMw_UsCB4r9sk7z9PU9M,11377
|
|
7
|
-
pydartdiags-0.0.43.dist-info/METADATA,sha256=udwmddMTrqFpyj0tjOffWVf2xbTI_3IwQCS4ZVvnnuU,2185
|
|
8
|
-
pydartdiags-0.0.43.dist-info/WHEEL,sha256=A3WOREP4zgxI0fKrHUG8DC8013e3dK3n7a6HDbcEIwE,91
|
|
9
|
-
pydartdiags-0.0.43.dist-info/top_level.txt,sha256=LfMoPLnSd0VhhlWev1eeX9t6AzvyASOloag0LO_ppWg,12
|
|
10
|
-
pydartdiags-0.0.43.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|