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

Bnb/dev #173

Merged
merged 51 commits into from
Nov 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
b15d994
doc string fix
bnb32 Oct 24, 2023
8cec3dc
nc topoextract fix
bnb32 Oct 30, 2023
779f679
ignore case for bc adder/scalar lookup
bnb32 Oct 30, 2023
b746cb7
some tweaks for training with cape - only found in era not wtk so nee…
bnb32 Oct 31, 2023
f406d7b
unused import
bnb32 Oct 31, 2023
765dbd8
exo cache naming issue now that data has temporal dimension
bnb32 Oct 31, 2023
81a0db5
exo caching moved to exo_extract and time independent naming conventi…
bnb32 Nov 1, 2023
fe8546d
modified methods to cache single time step for time independent exo d…
bnb32 Nov 1, 2023
5123490
normalization bug for dual handlers - assumed lr and hr handlers had …
bnb32 Nov 1, 2023
3b80de9
normalization bug for dual handlers - assumed lr and hr handlers had …
bnb32 Nov 1, 2023
dfa7eec
Merge branch 'bnb/dev' of github.com:NREL/sup3r into bnb/dev
bnb32 Nov 1, 2023
8e1b550
some edits to netcdf output for multistep forward-pass pipeline (run …
bnb32 Nov 3, 2023
3a7edb6
bc code doc strings
bnb32 Nov 3, 2023
a33e2d9
bc code doc strings
bnb32 Nov 3, 2023
7d0742b
Merge branch 'bnb/dev' of github.com:NREL/sup3r into bnb/dev
bnb32 Nov 3, 2023
f7e107a
misc logging tweaks
bnb32 Nov 4, 2023
a5b4c3e
nc collector for intermediate write during multi fwp pipeline
bnb32 Nov 5, 2023
3a80ec7
cleaning up args
bnb32 Nov 6, 2023
c6784ff
break at max_log_height
bnb32 Nov 6, 2023
e6586f3
doc string fix
bnb32 Oct 24, 2023
9d6ec49
nc topoextract fix
bnb32 Oct 30, 2023
2b298b4
ignore case for bc adder/scalar lookup
bnb32 Oct 30, 2023
6aa3aa9
some tweaks for training with cape - only found in era not wtk so nee…
bnb32 Oct 31, 2023
6878a93
unused import
bnb32 Oct 31, 2023
874e88e
exo cache naming issue now that data has temporal dimension
bnb32 Oct 31, 2023
26d0163
exo caching moved to exo_extract and time independent naming conventi…
bnb32 Nov 1, 2023
34ca76a
modified methods to cache single time step for time independent exo d…
bnb32 Nov 1, 2023
627e2a0
normalization bug for dual handlers - assumed lr and hr handlers had …
bnb32 Nov 1, 2023
63b9227
normalization bug for dual handlers - assumed lr and hr handlers had …
bnb32 Nov 1, 2023
7b6c5c2
some edits to netcdf output for multistep forward-pass pipeline (run …
bnb32 Nov 3, 2023
d61a792
bc code doc strings
bnb32 Nov 3, 2023
f1a37b5
bc code doc strings
bnb32 Nov 3, 2023
f56a471
misc logging tweaks
bnb32 Nov 4, 2023
d221691
misc logging tweaks
bnb32 Nov 4, 2023
f2c8e68
nc collector for intermediate write during multi fwp pipeline
bnb32 Nov 5, 2023
2dac1bb
cleaning up args
bnb32 Nov 6, 2023
e796c4a
break at max_log_height
bnb32 Nov 6, 2023
d4f6376
collection try except
bnb32 Nov 7, 2023
1e69d2b
Merge branch 'bnb/nc_collector' of github.com:NREL/sup3r into bnb/nc_…
bnb32 Nov 7, 2023
a440787
random strings for tmp names to avoid collisions
bnb32 Nov 7, 2023
101428a
some era downloader clean up.
bnb32 Nov 8, 2023
561b704
Merge branch 'bnb/dev' of github.com:NREL/sup3r into bnb/dev
bnb32 Nov 8, 2023
64f29ca
bc case sensitivity fix
bnb32 Nov 8, 2023
7220099
Merge pull request #175 from NREL/bnb/nc_collector
bnb32 Nov 8, 2023
f874437
pr changes
bnb32 Nov 9, 2023
db62a8f
pr changes
bnb32 Nov 9, 2023
14752ad
Merge branch 'bnb/dev' of github.com:NREL/sup3r into bnb/dev
bnb32 Nov 9, 2023
44e40e8
removed era mean prepper and changed vortex mean prepper output to co…
bnb32 Nov 9, 2023
85aa1dd
removed some bc from means code
bnb32 Nov 9, 2023
0d81d79
allow 2d input to regridder
bnb32 Nov 9, 2023
589d5a1
Merge branch 'bnb/dev' of github.com:NREL/sup3r into bnb/dev
bnb32 Nov 9, 2023
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
66 changes: 59 additions & 7 deletions sup3r/bias/bias_calc.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
"""Utilities to calculate the bias correction factors for biased data that is
going to be fed into the sup3r downscaling models. This is typically used to
bias correct GCM data vs. some historical record like the WTK or NSRDB."""
from abc import abstractmethod
import copy
import json
import logging
import os
from abc import abstractmethod
from concurrent.futures import ProcessPoolExecutor, as_completed
from glob import glob

Expand Down Expand Up @@ -875,12 +875,7 @@ def _run_single(cls,
decimals=decimals)

base_arr = np.full(cls.NT, np.nan, dtype=np.float32)
out = {f'bias_{bias_feature}_mean': base_arr.copy(),
f'bias_{bias_feature}_std': base_arr.copy(),
f'base_{base_dset}_mean': base_arr.copy(),
f'base_{base_dset}_std': base_arr.copy(),
f'{bias_feature}_scalar': base_arr.copy(),
f'{bias_feature}_adder': base_arr.copy()}
out = {}

for month in range(1, 13):
bias_mask = bias_ti.month == month
Expand All @@ -892,11 +887,68 @@ def _run_single(cls,
bias_feature,
base_dset)
for k, v in mout.items():
if k not in out:
out[k] = base_arr.copy()
out[k][month - 1] = v

return out


class MonthlyScalarCorrection(MonthlyLinearCorrection):
"""Calculate linear correction *scalar factors to bias correct data. This
typically used when base data is just monthly means and standard deviations
cannot be computed. This is case for vortex data, for example. Thus, just
scalar factors are computed as mean(base_data) / mean(bias_data). Adder
factors are still written but are exactly zero.

This calculation operates on single bias sites on a montly basis
"""

@staticmethod
def get_linear_correction(bias_data, base_data, bias_feature, base_dset):
"""Get the linear correction factors based on 1D bias and base datasets

Parameters
----------
bias_data : np.ndarray
1D array of biased data observations.
base_data : np.ndarray
1D array of base data observations.
bias_feature : str
This is the biased feature from bias_fps to retrieve. This should
be a single feature name corresponding to base_dset
base_dset : str
A single dataset from the base_fps to retrieve. In the case of wind
components, this can be U_100m or V_100m which will retrieve
windspeed and winddirection and derive the U/V component.

Returns
-------
out : dict
Dictionary of values defining the mean/std of the bias + base
data and the scalar + adder factors to correct the biased data
like: bias_data * scalar + adder
"""

bias_std = np.nanstd(bias_data)
if bias_std == 0:
bias_std = np.nanstd(base_data)

scalar = np.nanmean(base_data) / np.nanmean(bias_data)
adder = np.zeros(scalar.shape)

out = {
f'bias_{bias_feature}_mean': np.nanmean(bias_data),
f'bias_{bias_feature}_std': bias_std,
f'base_{base_dset}_mean': np.nanmean(base_data),
f'base_{base_dset}_std': np.nanstd(base_data),
f'{bias_feature}_scalar': scalar,
f'{bias_feature}_adder': adder,
}

return out


class SkillAssessment(MonthlyLinearCorrection):
"""Calculate historical skill of one dataset compared to another."""

Expand Down
Loading