Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug fixes and notebook updates #340

Merged
merged 3 commits into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
511 changes: 409 additions & 102 deletions docs/source/notebooks/CAMNotebook.ipynb

Large diffs are not rendered by default.

635 changes: 326 additions & 309 deletions docs/source/notebooks/LargeDataGladeNotebook.ipynb

Large diffs are not rendered by default.

220 changes: 125 additions & 95 deletions docs/source/notebooks/MetricsNotebook.ipynb

Large diffs are not rendered by default.

117 changes: 54 additions & 63 deletions docs/source/notebooks/TutorialNotebook.ipynb

Large diffs are not rendered by default.

541 changes: 269 additions & 272 deletions docs/source/notebooks/error_bias.ipynb

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions ldcpy/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
open_datasets,
save_metrics,
subset_data,
combine_datasets,
)

try:
Expand Down
10 changes: 9 additions & 1 deletion ldcpy/calcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -1943,11 +1943,19 @@ def ks_p_value(self):
if not self._is_memoized('_ks_p_value'):
# Apply the KS test across the specified dimensions
# This will create a DataArray of p-values

if self._aggregate_dims is None:
lat_n = self._ds1.cf['latitude'].name
lon_n = self._ds2.cf['longitude'].name
core_d = [[lat_n, lon_n], [lat_n, lon_n]]
else:
core_d = [self._aggregate_dims, self._aggregate_dims]
# print(core_d)
self._ks_p_value = xr.apply_ufunc(
lambda x, y: ss.ks_2samp(x.ravel(), y.ravel())[1],
self._ds1,
self._ds2,
input_core_dims=[self._aggregate_dims, self._aggregate_dims],
input_core_dims=core_d,
dask='parallelized',
dask_gufunc_kwargs={'allow_rechunk': True},
vectorize=True,
Expand Down
32 changes: 21 additions & 11 deletions ldcpy/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,6 @@ def compare_stats(
else:
temp_zeros.append(temp_return)

# Alex is fixing ..
temp_info.append(da_set_calcs[i].get_single_calc('real_information_cutoff'))

if data_type == 'cam-fv':
Expand Down Expand Up @@ -593,7 +592,10 @@ def compare_stats(
for i in range(num - 1):
temp_nrms.append(diff_calcs[i].get_diff_calc('n_rms'))
temp_max_pe.append(diff_calcs[i].get_diff_calc('n_emax'))
temp_pcc.append(diff_calcs[i].get_diff_calc('pearson_correlation_coefficient'))

temptemp = diff_calcs[i].get_diff_calc('pearson_correlation_coefficient')
temp_pcc.append(temptemp)

temp_ks.append(diff_calcs[i].get_diff_calc('ks_p_value'))
diff_calcs[i].spre_tol = rel_errors[0]
temp_sre.append(diff_calcs[i].get_diff_calc('spatial_rel_error'))
Expand All @@ -610,7 +612,6 @@ def compare_stats(
df_dict2['normalized max pointwise error'] = temp_max_pe
df_dict2['pearson correlation coefficient'] = temp_pcc
df_dict2['ks p-value'] = temp_ks

tmp_str = 'spatial relative error(% > ' + str(rel_errors[0]) + ')'
df_dict2[tmp_str] = temp_sre

Expand Down Expand Up @@ -717,28 +718,37 @@ def check_metrics(
num_fail = 0
# Pearson less than pcc_tol means fail
pcc = diff_calcs.get_diff_calc('pearson_correlation_coefficient')
# print(type(pcc))
if pcc < pcc_tol:

print(' *FAILED pearson correlation coefficient test...(pcc = {0:.5f}'.format(pcc), ')')
print(
' *FAILED pearson correlation coefficient test...(pcc = {0:.5f}'.format(pcc.values),
')',
)
num_fail = num_fail + 1
else:
print(' PASSED pearson correlation coefficient test...(pcc = {0: .5f}'.format(pcc), ')')
print(
' PASSED pearson correlation coefficient test...(pcc = {0:.5f}'.format(pcc.values),
')',
)
# K-S p-value less than ks_tol means fail (can reject null hypo)
ks = diff_calcs.get_diff_calc('ks_p_value')
if ks < ks_tol:
print(' *FAILED ks test...(ks p_val = {0:.4f}'.format(ks), ')')
print(' *FAILED ks test...(ks p_val = {0:.5f}'.format(ks.values), ')')
num_fail = num_fail + 1
else:
print(' PASSED ks test...(ks p_val = {0:.4f}'.format(ks), ')')
print(' PASSED ks test...(ks p_val = {0:.5f}'.format(ks.values), ')')
# Spatial rel error fails if more than spre_tol
spre = diff_calcs.get_diff_calc('spatial_rel_error')

if spre > spre_tol:
print(' *FAILED spatial relative error test ... (spre = {0:.2f}'.format(spre), ' %)')
print(
' *FAILED spatial relative error test ... (spre = {0:.2f}'.format(spre.values),
' %)',
)
num_fail = num_fail + 1
else:
print(' PASSED spatial relative error test ...(spre = {0:.2f}'.format(spre), ' %)')
print(
' PASSED spatial relative error test ...(spre = {0:.2f}'.format(spre.values), ' %)'
)
# SSIM less than of ssim_tol is failing
ssim_val = diff_calcs.get_diff_calc('ssim_fp')
if ssim_val < ssim_tol:
Expand Down
Loading