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

Gb/bc #96

Merged
merged 29 commits into from
Oct 4, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
efcf50e
added bias module with a place for bias transformation functions and …
grantbuster Sep 20, 2022
115e9c2
feature specific bias correction
grantbuster Sep 20, 2022
c184917
removed warnings about excessive padding - not a bad thing
grantbuster Sep 20, 2022
1d823e3
added a site-by-site linear bias correction calculation method
grantbuster Sep 21, 2022
8b7f25b
bug fix and logging
grantbuster Sep 21, 2022
56148db
bias calc mods and new functions
grantbuster Sep 22, 2022
50c3692
added bias calc cli
grantbuster Sep 22, 2022
2f7d4f7
added bias calc to main cli
grantbuster Sep 22, 2022
c132b81
make bias out dir
grantbuster Sep 22, 2022
915edd5
bug fixes and minor refactor to run on eagle
grantbuster Sep 22, 2022
7b28943
added local linear bias correct to forward pass bc options
grantbuster Sep 22, 2022
0cee671
added option to smooth spatial bias correction factors outside of the…
grantbuster Sep 23, 2022
aa0a040
better enumerated progress logging for fwp
grantbuster Sep 23, 2022
240a0d6
added bias correction option to QA
grantbuster Sep 23, 2022
9ac0905
minor refactor to bias correct u and v instead of windspeed and direc…
grantbuster Sep 23, 2022
d2fb1e2
fixed up the u/v QA with bias correction
grantbuster Sep 27, 2022
01fbeda
added meta data to bc h5 output attrs
grantbuster Sep 27, 2022
b370b9f
more bc convenience functions
grantbuster Sep 28, 2022
24c40b6
added monthly bias correction
grantbuster Sep 28, 2022
0deab95
added montly bias correction data transformation method and integrate…
grantbuster Sep 29, 2022
1f28ccc
fixed collection logic for undefined mask meta variable when file is …
grantbuster Oct 2, 2022
5d93283
added bias correction calc tests
grantbuster Oct 3, 2022
0638d7b
added bias transform calcs
grantbuster Oct 3, 2022
6cc6ced
added fwp+bc integration test
grantbuster Oct 3, 2022
ca24793
added qa+bc integration test
grantbuster Oct 3, 2022
b75b3fc
added version record to bias calc output files and incremented versio…
grantbuster Oct 4, 2022
b0a2c49
simplify qa test and pylint issue
grantbuster Oct 4, 2022
7b9c88f
fixed test on h5 meta attrs dtype and docstrings
grantbuster Oct 4, 2022
2ea15e3
serial data handling for QA+BC bug
grantbuster Oct 4, 2022
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
Prev Previous commit
Next Next commit
added bias calc to main cli
  • Loading branch information
grantbuster committed Oct 4, 2022
commit 2f7d4f76d5b770cdcb09480c9a389a2f704202fa
1 change: 1 addition & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ def run(self):
"sup3r-batch=sup3r.batch.batch_cli:main",
"sup3r-qa=sup3r.qa.qa_cli:main",
"sup3r-windstats=sup3r.qa.windstats_cli:main",
"sup3r-bias-calc=sup3r.bias.bias_calc_cli:main",
"sup3r-solar=sup3r.solar.solar_cli:main",
("sup3r-forward-pass=sup3r.pipeline."
"forward_pass_cli:main"),
Expand Down
5 changes: 4 additions & 1 deletion sup3r/bias/bias_calc.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ def __init__(self, base_fps, bias_fps, base_dset, bias_features,
logger.error(msg)
raise RuntimeError(msg)

elif 'windspeed' not in self.base_dset and len(self.bias_features) != 1:
elif ('windspeed' not in self.base_dset
and len(self.bias_features) != 1):
msg = ('If base dataset is not windspeed, cannot handle more than '
'one feature from the bias data, but received: {}'
.format(self.bias_features))
Expand Down Expand Up @@ -158,6 +159,7 @@ def get_node_cmd(cls, config):
logger.error(msg)
raise NotImplementedError(msg)

# pylint: disable=E1101
init_str = get_fun_call_str(cls, config)
fun_str = get_fun_call_str(cls.run, config)

Expand Down Expand Up @@ -366,6 +368,7 @@ def write_outputs(self, fp_out):
"""
if fp_out is not None:
with h5py.File(fp_out, 'a') as f:
# pylint: disable=E1136
lat = self.bias_dh.lat_lon[..., 0]
lon = self.bias_dh.lat_lon[..., 1]
f.create_dataset('latitude', data=lat)
Expand Down
67 changes: 66 additions & 1 deletion sup3r/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from sup3r.pipeline.pipeline_cli import from_config as pipe_cli
from sup3r.pipeline.pipeline_cli import valid_config_keys as pipeline_keys
from sup3r.batch.batch_cli import from_config as batch_cli
from sup3r.bias.bias_calc_cli import from_config as bias_calc_cli


logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -143,7 +144,7 @@ def solar(ctx, verbose):
:meth:`sup3r.solar.solar.Solar.run_temporal_chunk` method. You do not need
to include the ``i_t_chunk`` input, this is added by the CLI. The config
also has several optional arguments: ``log_pattern``, ``log_level``, and
``execution_control``. Here's a small example forward pass config::
``execution_control``. Here's a small example solar config::

{
"fp_pattern": "./chunks/sup3r*.h5",
Expand All @@ -167,6 +168,70 @@ def solar(ctx, verbose):
ctx.invoke(solar_cli, config_file=config_file, verbose=verbose)


@main.command()
@click.option('-v', '--verbose', is_flag=True,
help='Flag to turn on debug logging.')
@click.pass_context
def bias_calc(ctx, verbose):
"""Sup3r bias correction calculation module to create bias correction
factors for low res input data.

This is typically used to understand and correct the biases in global
climate model (GCM) data from CMIP. Bias correcting GCM data is a very
common process when dealing with climate data and this helps automate that
process prior to passing GCM data through sup3r generative models. This is
typically the first step in a GCM downscaling pipeline.

You can call the bias calc module via the sup3r-pipeline CLI, or call it
directly with either of these equivelant commands::

$ sup3r -c config_bias.json bias-calc

$ sup3r-bias-calc from-config -c config_bias.json

A sup3r bias calc config.json file can contain any arguments or keyword
arguments required to call the

The config has high level ``bias_calc_class`` and ``jobs`` keys. The
``bias_calc_class`` is a class name from the :mod:`sup3r.bias.bias_calc`
module, and the ``jobs`` argument is a list of kwargs required to
initialize the ``bias_calc_class`` and run the ``bias_calc_class.run()``
method (for example, see
:meth:`sup3r.bias.bias_calc.LinearCorrection.run`). There are also has
several optional arguments: ``log_pattern``, ``log_level``, and
``execution_control``. Here's a small example bias calc config::

{
"bias_calc_class": "LinearCorrection",
"jobs": [
{
"base_fps" : ["/datasets/WIND/HRRR/HRRR_2015.h5"],
"bias_fps": ["./ta_day_EC-Earth3-Veg_ssp585.nc"],
"base_dset": "windspeed_100m",
"bias_features": ["U_100m", "V_100m"],
"target": [20, -130],
"shape": [48, 95]
}
],
"execution_control": {
"option": "local"
},
"execution_control_eagle": {
"option": "eagle",
"walltime": 4,
"alloc": "sup3r"
}
}

Note that the ``execution_control`` block will run the job locally, while
the ``execution_control_eagle`` block are kwargs that would be required to
distribute the job on multiple nodes on the NREL HPC.
"""
config_file = ctx.obj['CONFIG_FILE']
verbose = any([verbose, ctx.obj['VERBOSE']])
ctx.invoke(bias_calc_cli, config_file=config_file, verbose=verbose)


@main.command()
@click.option('-v', '--verbose', is_flag=True,
help='Flag to turn on debug logging.')
Expand Down