From e6c501cde828f2e244e1a8584e3085043a67091e Mon Sep 17 00:00:00 2001 From: Riley Hales Date: Thu, 26 May 2022 12:40:31 -0600 Subject: [PATCH] rename saber --- README.md | 143 +++++++++--------- .../colombia-magdalena/magdalena_example.py | 46 +++--- examples/example_inputs.py | 4 +- examples/example_script.py | 58 ++++--- hbc/__init__.py | 19 --- saber/__init__.py | 19 +++ {hbc => saber}/_calibrate.py | 0 {hbc => saber}/_propagation.py | 0 {hbc => saber}/_vocab.py | 4 +- {hbc => saber}/_workflow.py | 0 {hbc => saber}/analysis.py | 0 {hbc => saber}/assign.py | 0 {hbc => saber}/cluster.py | 2 +- {hbc => saber}/gis.py | 3 +- {hbc => saber}/prep.py | 0 {hbc => saber}/table.py | 0 {hbc => saber}/tests/calibrate.py | 0 {hbc => saber}/utils.py | 0 {hbc => saber}/validate.py | 6 +- setup.py | 9 +- 20 files changed, 159 insertions(+), 154 deletions(-) delete mode 100644 hbc/__init__.py create mode 100644 saber/__init__.py rename {hbc => saber}/_calibrate.py (100%) rename {hbc => saber}/_propagation.py (100%) rename {hbc => saber}/_vocab.py (79%) rename {hbc => saber}/_workflow.py (100%) rename {hbc => saber}/analysis.py (100%) rename {hbc => saber}/assign.py (100%) rename {hbc => saber}/cluster.py (99%) rename {hbc => saber}/gis.py (99%) rename {hbc => saber}/prep.py (100%) rename {hbc => saber}/table.py (100%) rename {hbc => saber}/tests/calibrate.py (100%) rename {hbc => saber}/utils.py (100%) rename {hbc => saber}/validate.py (96%) diff --git a/README.md b/README.md index 0009d30..42d10cc 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,4 @@ -# Hydrological Bias Correction on Large Mode -This repository contains Python code which can be used to calibrate biased, non-gridded hydrologic models. Most of the -code in this repository will work on any model's results. The data preprocessing and automated calibration functions -are programmed to expect data following the GEOGloWS ECMWF Streamflow Service's structure and format. +# Stream Analysis for Bias Estimation and Reduction ## Theory Basins and streams will be used interchangeably to refer to the specific stream subunit. @@ -45,16 +42,16 @@ file formats are acceptable 5. Historical simulated discharge for each stream segment and for as long (temporally) as is available. 6. Observed discharge data for as many stream reaches as possible within the target region. 7. The units of the simulation and observation data must be in the same units. -8. A working directory folder on the computer where the scripts are going to be run. +8. A working directory on the computer where the scripts are going to be run. ## Process ### 1 Create a Working Directory ```python -import hbc +import saber as saber path_to_working_directory = '/my/file/path' -hbc.prep.scaffold_workdir(path_to_working_directory) +saber.prep.scaffold_workdir(path_to_working_directory) ``` Your working directory should exactly like this. @@ -112,12 +109,12 @@ gdf.to_file('/file/path/to/save', driver='GeoJSON') Your table should look like this: -downstream_model_id | model_id | drainage_area_mod | stream_order | x | y | -------------------- | ----------------- | ----------------- | ------------- | --- | --- | -unique_stream_# | unique_stream_# | area in km^2 | stream_order | ## | ## | -unique_stream_# | unique_stream_# | area in km^2 | stream_order | ## | ## | -unique_stream_# | unique_stream_# | area in km^2 | stream_order | ## | ## | -... | ... | ... | ... | ... | ... | +| downstream_model_id | model_id | drainage_area_mod | stream_order | x | y | +|---------------------|-----------------|-------------------|--------------|-----|-----| +| unique_stream_# | unique_stream_# | area in km^2 | stream_order | ## | ## | +| unique_stream_# | unique_stream_# | area in km^2 | stream_order | ## | ## | +| unique_stream_# | unique_stream_# | area in km^2 | stream_order | ## | ## | +| ... | ... | ... | ... | ... | ... | 2. Prepare a csv of the attribute table of the gauge locations shapefile. - You need the columns: @@ -127,12 +124,12 @@ unique_stream_# | unique_stream_# | area in km^2 | stream_order | ## Your table should look like this (column order is irrelevant): -model_id | drainage_area_obs | gauge_id ------------------ | ----------------- | ------------ -unique_stream_num | area in km^2 | unique_gauge_num -unique_stream_num | area in km^2 | unique_gauge_num -unique_stream_num | area in km^2 | unique_gauge_num -... | ... | ... +| model_id | drainage_area_obs | gauge_id | +|-------------------|-------------------|------------------| +| unique_stream_num | area in km^2 | unique_gauge_num | +| unique_stream_num | area in km^2 | unique_gauge_num | +| unique_stream_num | area in km^2 | unique_gauge_num | +| ... | ... | ... | Your project's working directory now looks like ``` @@ -162,17 +159,17 @@ The Assignments Table is the core of the regional bias correction method it is a stream segment in the model and several columns of other information which are filled in during the RBC algorithm. It looks like this: -downstream_model_id | model_id | drainage_area | stream_order | gauge_id -------------------- | ----------------- | ------------- | ------------ | ---------------- -unique_stream_num | unique_stream_num | area in km^2 | stream_order | unique_gauge_num -unique_stream_num | unique_stream_num | area in km^2 | stream_order | unique_gauge_num -unique_stream_num | unique_stream_num | area in km^2 | stream_order | unique_gauge_num -... | ... | ... | ... | ... +| downstream_model_id | model_id | drainage_area | stream_order | gauge_id | +|---------------------|-------------------|---------------|--------------|------------------| +| unique_stream_num | unique_stream_num | area in km^2 | stream_order | unique_gauge_num | +| unique_stream_num | unique_stream_num | area in km^2 | stream_order | unique_gauge_num | +| unique_stream_num | unique_stream_num | area in km^2 | stream_order | unique_gauge_num | +| ... | ... | ... | ... | ... | ```python -import hbc +import saber as saber workdir = '/path/to/project/directory/' -hbc.prep.gen_assignments_table(workdir) +saber.prep.gen_assignments_table(workdir) ``` Your project's working directory now looks like @@ -211,45 +208,45 @@ Use the dat 1. Create a single large csv of the historical simulation data with a datetime column and 1 column per stream segment labeled by the stream's ID number. -datetime | model_id_1 | model_id_2 | model_id_3 ------------ | ----------- | ----------- | ----------- -1979-01-01 | 50 | 50 | 50 -1979-01-02 | 60 | 60 | 60 -1979-01-03 | 70 | 70 | 70 -... | ... | ... | ... - +| datetime | model_id_1 | model_id_2 | model_id_3 | +|------------|------------|------------|------------| +| 1979-01-01 | 50 | 50 | 50 | +| 1979-01-02 | 60 | 60 | 60 | +| 1979-01-03 | 70 | 70 | 70 | +| ... | ... | ... | ... | + 2. Process the large simulated discharge csv to create a 2nd csv with the flow duration curve on each segment (script provided). -p_exceed | model_id_1 | model_id_2 | model_id_3 ------------ | ----------- | ----------- | ----------- -100 | 0 | 0 | 0 -99 | 10 | 10 | 10 -98 | 20 | 20 | 20 -... | ... | ... | ... +| p_exceed | model_id_1 | model_id_2 | model_id_3 | +|----------|------------|------------|------------| +| 100 | 0 | 0 | 0 | +| 99 | 10 | 10 | 10 | +| 98 | 20 | 20 | 20 | +| ... | ... | ... | ... | 3. Process the large historical discharge csv to create a 3rd csv with the monthly averages on each segment (script provided). -month | model_id_1 | model_id_2 | model_id_3 ------------ | ----------- | ----------- | ----------- -1 | 60 | 60 | 60 -2 | 30 | 30 | 30 -3 | 70 | 70 | 70 -... | ... | ... | ... +| month | model_id_1 | model_id_2 | model_id_3 | +|-------|------------|------------|------------| +| 1 | 60 | 60 | 60 | +| 2 | 30 | 30 | 30 | +| 3 | 70 | 70 | 70 | +| ... | ... | ... | ... | ```python -import hbc +import saber as saber workdir = '/path/to/working/directory' -hbc.prep.historical_simulation( +saber.prep.historical_simulation( workdir, '/path/to/historical/simulation/netcdf.nc' # optional - if nc not stored in data_inputs folder ) -hbc.prep.hist_sim_table( +saber.prep.hist_sim_table( workdir, '/path/to/historical/simulation/netcdf.nc' # optional - if nc not stored in data_inputs folder ) -hbc.prep.observed_data( +saber.prep.observed_data( workdir, '/path/to/obs/csv/directory' # optional - if csvs not stored in workdir/data_inputs/obs_csvs ) @@ -296,10 +293,10 @@ For each of the following, generate and store clusters for many group sizes- bet Use this code: ```python -import hbc +import saber as saber workdir = '/path/to/project/directory/' -hbc.cluster.generate(workdir) +saber.cluster.generate(workdir) ``` This function creates trained kmeans models saved as pickle files, plots (from matplotlib) of what each of the clusters @@ -354,12 +351,12 @@ The justification for this is obvious. The observations are the actual streamflo - The reason listed for this assignment is "gauged" ```python -import hbc +import saber as saber -# assign_table = pandas DataFrame (see hbc.table module) +# assign_table = pandas DataFrame (see saber.table module) workdir = '/path/to/project/directory/' -assign_table = hbc.table.read(workdir) -hbc.assign.gauged(assign_table) +assign_table = saber.table.read(workdir) +saber.assign.gauged(assign_table) ``` ### 7 Assign basins by Propagation (hydraulically connected to a gauge) @@ -375,12 +372,12 @@ be less sensitive to changes in flows up stream, may connect basins with differe i is the number of stream segments up/down from the gauge the river is. ```python -import hbc +import saber as saber -# assign_table = pandas DataFrame (see hbc.table module) +# assign_table = pandas DataFrame (see saber.table module) workdir = '/path/to/project/directory/' -assign_table = hbc.table.read(workdir) -hbc.assign.propagation(assign_table) +assign_table = saber.table.read(workdir) +saber.assign.propagation(assign_table) ``` ### 8 Assign basins by Clusters (hydrologically similar basins) @@ -391,12 +388,12 @@ Using the results of the optimal clusters - Review assignments spatially. Run tests and view improvements. Adjust clusters and reassign as necessary. ```python -import hbc +import saber as saber -# assign_table = pandas DataFrame (see hbc.table module) +# assign_table = pandas DataFrame (see saber.table module) workdir = '/path/to/project/directory/' -assign_table = hbc.table.read(workdir) -hbc.assign.clusters_by_dist(assign_table) +assign_table = saber.table.read(workdir) +saber.assign.clusters_by_dist(assign_table) ``` ### 9 Generate GIS files of the assignments @@ -405,18 +402,18 @@ use to visualize the results of this process. These GIS files help you investiga used at each step. Use this to monitor the results. ```python -import hbc +import saber as saber workdir = '/path/to/project/directory/' -assign_table = hbc.table.read(workdir) +assign_table = saber.table.read(workdir) drain_shape = '/my/file/path/' -hbc.gis.clip_by_assignment(workdir, assign_table, drain_shape) -hbc.gis.clip_by_cluster(workdir, assign_table, drain_shape) -hbc.gis.clip_by_unassigned(workdir, assign_table, drain_shape) +saber.gis.clip_by_assignment(workdir, assign_table, drain_shape) +saber.gis.clip_by_cluster(workdir, assign_table, drain_shape) +saber.gis.clip_by_unassigned(workdir, assign_table, drain_shape) # or if you have a specific set of ID's to check on list_of_model_ids = [123, 456, 789] -hbc.gis.clip_by_ids(workdir, list_of_model_ids, drain_shape) +saber.gis.clip_by_ids(workdir, list_of_model_ids, drain_shape) ``` After this step, your project directory should look like this: @@ -509,13 +506,13 @@ excluded each time. The code provided will help you partition your gauge table i against the observed data which was withheld from the bias correction process. ```python -import hbc +import saber as saber workdir = '/path/to/project/directory' drain_shape = '/path/to/drainageline/gis/file.shp' obs_data_dir = '/path/to/obs/data/directory' # optional - if data not in workdir/data_inputs/obs_csvs -hbc.validate.sample_gauges(workdir) -hbc.validate.run_series(workdir, drain_shape, obs_data_dir) +saber.validate.sample_gauges(workdir) +saber.validate.run_series(workdir, drain_shape, obs_data_dir) ``` After this step your working directory should look like this: diff --git a/examples/colombia-magdalena/magdalena_example.py b/examples/colombia-magdalena/magdalena_example.py index 24dd797..2b0bf39 100644 --- a/examples/colombia-magdalena/magdalena_example.py +++ b/examples/colombia-magdalena/magdalena_example.py @@ -2,7 +2,7 @@ import numpy as np -import hbc +import saber np.seterr(all="ignore") @@ -13,47 +13,47 @@ obs_data_dir = os.path.join(workdir, 'data_inputs', 'obs_csvs') # Only need to do this step 1x ever -# hbc.prep.scaffold_working_directory(workdir) +# saber.prep.scaffold_working_directory(workdir) # Create the gauge_table and drain_table.csv # Scripts not provided, check readme for instructions # Generate the assignments table -# assign_table = hbc.table.gen(workdir) -# hbc.table.cache(workdir, assign_table) +# assign_table = saber.table.gen(workdir) +# saber.table.cache(workdir, assign_table) # Or read the existing table -# assign_table = hbc.table.read(workdir) +# assign_table = saber.table.read(workdir) # Prepare the observation and simulation data # Only need to do this step 1x ever -# hbc.prep.historical_simulation(os.path.join(workdir, 'data_simulated', 'south_america_era5_qout.nc'), workdir) -# hbc.prep.observation_data(workdir) +# saber.prep.historical_simulation(os.path.join(workdir, 'data_simulated', 'south_america_era5_qout.nc'), workdir) +# saber.prep.observation_data(workdir) # Generate the clusters using the historical simulation data -# hbc.cluster.generate(workdir) -# assign_table = hbc.cluster.summarize(workdir, assign_table) -# hbc.table.cache(workdir, assign_table) +# saber.cluster.generate(workdir) +# assign_table = saber.cluster.summarize(workdir, assign_table) +# saber.table.cache(workdir, assign_table) # Assign basins which are gauged and propagate those gauges -# assign_table = hbc.assign.gauged(assign_table) -# assign_table = hbc.assign.propagation(assign_table) -# assign_table = hbc.assign.clusters_by_dist(assign_table) -# todo assign_table = hbc.assign.clusters_by_monavg(assign_table) +# assign_table = saber.assign.gauged(assign_table) +# assign_table = saber.assign.propagation(assign_table) +# assign_table = saber.assign.clusters_by_dist(assign_table) +# todo assign_table = saber.assign.clusters_by_monavg(assign_table) # Cache the assignments table with the updates -# hbc.table.cache(workdir, assign_table) +# saber.table.cache(workdir, assign_table) # Generate GIS files so you can go explore your progress graphically -# hbc.gis.clip_by_assignment(workdir, assign_table, drain_shape) -# hbc.gis.clip_by_cluster(workdir, assign_table, drain_shape) -# hbc.gis.clip_by_unassigned(workdir, assign_table, drain_shape) +# saber.gis.clip_by_assignment(workdir, assign_table, drain_shape) +# saber.gis.clip_by_cluster(workdir, assign_table, drain_shape) +# saber.gis.clip_by_unassigned(workdir, assign_table, drain_shape) # Compute the corrected simulation data -# assign_table = hbc.table.read(workdir) -# hbc.calibrate_region(workdir, assign_table) -# vtab = hbc.validate.gen_val_table(workdir) -hbc.gis.validation_maps(workdir, gauge_shape) -hbc.analysis.plot(workdir, obs_data_dir, 9007721) +# assign_table = saber.table.read(workdir) +# saber.calibrate_region(workdir, assign_table) +# vtab = saber.validate.gen_val_table(workdir) +saber.gis.validation_maps(workdir, gauge_shape) +saber.analysis.plot(workdir, obs_data_dir, 9007721) # import pandas as pd diff --git a/examples/example_inputs.py b/examples/example_inputs.py index 5e8f7dd..4163d24 100644 --- a/examples/example_inputs.py +++ b/examples/example_inputs.py @@ -2,14 +2,14 @@ # COLOMBIA -workdir = '/Users/rchales/data/regional-bias-correction/colombia-magdalena' +workdir = '/Users/rchales/data/saber/colombia-magdalena' drain_shape = os.path.join(workdir, 'gis_inputs', 'magdalena_dl_attrname_xy.json') gauge_shape = os.path.join(workdir, 'gis_inputs', 'ideam_stations.json') obs_data_dir = os.path.join(workdir, 'data_inputs', 'obs_csvs') hist_sim_nc = os.path.join(workdir, 'data_inputs', 'south_america_era5_qout.nc') # TEXAS -workdir = '/Users/rchales/data/regional-bias-correction/texas' +workdir = '/Users/rchales/data/saber/texas' drain_shape = os.path.join(workdir, 'shapefiles', 'texas-dl.json') gauge_shape = os.path.join(workdir, 'shapefiles', 'texas-gauges.shp') obs_data_dir = os.path.join(workdir, 'data_inputs', 'obs_csvs') diff --git a/examples/example_script.py b/examples/example_script.py index b970af1..bedb6a4 100644 --- a/examples/example_script.py +++ b/examples/example_script.py @@ -2,19 +2,27 @@ import numpy as np -import hbc +import saber np.seterr(all="ignore") -workdir = '' -drain_shape = os.path.join(workdir, 'gis_inputs', '') -gauge_shape = '' -obs_data_dir = '' -hist_sim_nc = '' +# workdir = '' +# drain_shape = os.path.join(workdir, 'gis_inputs', '') +# gauge_shape = '' +# obs_data_dir = '' +# hist_sim_nc = '' + +# COLOMBIA +# workdir = '/Users/rchales/data/saber/colombia-magdalena' +# drain_shape = os.path.join(workdir, 'gis_inputs', 'magdalena_dl_attrname_xy.json') +# gauge_shape = os.path.join(workdir, 'gis_inputs', 'ideam_stations.json') +# obs_data_dir = os.path.join(workdir, 'data_inputs', 'obs_csvs') +# hist_sim_nc = os.path.join(workdir, 'data_inputs', 'south_america_era5_qout.nc') + # Prepare the working directory - only need to do this step 1x ever -# hbc.prep.scaffold_working_directory(workdir) +# saber.prep.scaffold_working_directory(workdir) # Scripts not provided. Consult README.md for instructions # Create the gauge_table.csv and drain_table.csv # Put the historical simulation netCDF in the right folder @@ -22,41 +30,41 @@ # Prepare the observation and simulation data - Only need to do this step 1x ever print('Preparing data') -hbc.prep.historical_simulation(workdir) +saber.prep.historical_simulation(workdir) # Generate the assignments table print('Generate Assignment Table') -assign_table = hbc.table.gen(workdir) -hbc.table.cache(workdir, assign_table) +assign_table = saber.table.gen(workdir) +saber.table.cache(workdir, assign_table) # Generate the clusters using the historical simulation data print('Generate Clusters') -hbc.cluster.generate(workdir) -assign_table = hbc.cluster.summarize(workdir, assign_table) -hbc.table.cache(workdir, assign_table) +saber.cluster.generate(workdir) +assign_table = saber.cluster.summarize(workdir, assign_table) +saber.table.cache(workdir, assign_table) # Assign basins which are gauged and propagate those gauges print('Making Assignments') -assign_table = hbc.assign.gauged(assign_table) -assign_table = hbc.assign.propagation(assign_table) -assign_table = hbc.assign.clusters_by_dist(assign_table) +assign_table = saber.assign.gauged(assign_table) +assign_table = saber.assign.propagation(assign_table) +assign_table = saber.assign.clusters_by_dist(assign_table) # Cache the assignments table with the updates -hbc.table.cache(workdir, assign_table) +saber.table.cache(workdir, assign_table) # Generate GIS files so you can go explore your progress graphically print('Generate GIS files') -hbc.gis.clip_by_assignment(workdir, assign_table, drain_shape) -hbc.gis.clip_by_cluster(workdir, assign_table, drain_shape) -hbc.gis.clip_by_unassigned(workdir, assign_table, drain_shape) +saber.gis.clip_by_assignment(workdir, assign_table, drain_shape) +saber.gis.clip_by_cluster(workdir, assign_table, drain_shape) +saber.gis.clip_by_unassigned(workdir, assign_table, drain_shape) # Compute the corrected simulation data print('Starting Calibration') -hbc.calibrate_region(workdir, assign_table) +saber.calibrate_region(workdir, assign_table) # run the validation study print('Performing Validation') -hbc.validate.sample_gauges(workdir, overwrite=True) -hbc.validate.run_series(workdir, drain_shape, obs_data_dir) -vtab = hbc.validate.gen_val_table(workdir) -hbc.gis.validation_maps(workdir, gauge_shape, vtab) +saber.validate.sample_gauges(workdir, overwrite=True) +saber.validate.run_series(workdir, drain_shape, obs_data_dir) +vtab = saber.validate.gen_val_table(workdir) +saber.gis.validation_maps(workdir, gauge_shape, vtab) diff --git a/hbc/__init__.py b/hbc/__init__.py deleted file mode 100644 index dc91d4e..0000000 --- a/hbc/__init__.py +++ /dev/null @@ -1,19 +0,0 @@ -from hbc._workflow import prep_region, analyze_region -from hbc._calibrate import calibrate_stream, calibrate_region - -import hbc.table -import hbc.prep -import hbc.cluster -import hbc.assign -import hbc.gis -import hbc.utils -import hbc.validate -import hbc.analysis - - -__all__ = ['prep_region', 'analyze_region', - 'calibrate_stream', 'calibrate_region', - 'table', 'prep', 'assign', 'gis', 'cluster', 'utils', 'validate', 'analysis'] -__author__ = 'Riley Hales' -__version__ = '0.2.0' -__license__ = 'BSD 3 Clause Clear' diff --git a/saber/__init__.py b/saber/__init__.py new file mode 100644 index 0000000..6b24826 --- /dev/null +++ b/saber/__init__.py @@ -0,0 +1,19 @@ +from saber._workflow import prep_region, analyze_region +from saber._calibrate import calibrate_stream, calibrate_region + +import saber.table +import saber.prep +import saber.cluster +import saber.assign +import saber.gis +import saber.utils +import saber.validate +import saber.analysis + + +__all__ = ['prep_region', 'analyze_region', + 'calibrate_stream', 'calibrate_region', + 'table', 'prep', 'assign', 'gis', 'cluster', 'utils', 'validate', 'analysis'] +__author__ = 'Riley Hales' +__version__ = '0.3.0' +__license__ = 'BSD 3 Clause Clear' diff --git a/hbc/_calibrate.py b/saber/_calibrate.py similarity index 100% rename from hbc/_calibrate.py rename to saber/_calibrate.py diff --git a/hbc/_propagation.py b/saber/_propagation.py similarity index 100% rename from hbc/_propagation.py rename to saber/_propagation.py diff --git a/hbc/_vocab.py b/saber/_vocab.py similarity index 79% rename from hbc/_vocab.py rename to saber/_vocab.py index 9586a09..29a077d 100644 --- a/hbc/_vocab.py +++ b/saber/_vocab.py @@ -8,11 +8,11 @@ area_col = 'drain_area' order_col = 'stream_order' -# name of some of the files produced by the algorithm +# name of some files produced by the algorithm cluster_count_file = 'best-fit-cluster-count.json' cal_nc_name = 'calibrated_simulated_flow.nc' sim_ts_pickle = 'sim_time_series.pickle' # metrics computed on validation sets -metric_list = ["ME", 'MAE', "RMSE", "NRMSE (Mean)", "MAPE", "NSE", "KGE (2012)"] +metric_list = ['ME', 'MAE', 'RMSE', 'NRMSE (Mean)', 'MAPE', 'NSE', 'KGE (2012)'] metric_nc_name_list = ['ME', 'MAE', 'RMSE', 'NRMSE', 'MAPE', 'NSE', 'KGE2012'] diff --git a/hbc/_workflow.py b/saber/_workflow.py similarity index 100% rename from hbc/_workflow.py rename to saber/_workflow.py diff --git a/hbc/analysis.py b/saber/analysis.py similarity index 100% rename from hbc/analysis.py rename to saber/analysis.py diff --git a/hbc/assign.py b/saber/assign.py similarity index 100% rename from hbc/assign.py rename to saber/assign.py diff --git a/hbc/cluster.py b/saber/cluster.py similarity index 99% rename from hbc/cluster.py rename to saber/cluster.py index f6dac31..122e78b 100755 --- a/hbc/cluster.py +++ b/saber/cluster.py @@ -57,7 +57,7 @@ def generate(workdir: str) -> None: plt.plot(j.ravel(), "k-", alpha=.2) plt.plot(km.cluster_centers_[i].ravel(), "r-") plt.xlim(0, size) - plt.ylim(-5, 5) + plt.ylim(-3.5, 3.5) plt.text(0.55, 0.85, f'Cluster {i}', transform=plt.gca().transAxes) if i == math.floor(num_cluster / 4): plt.title("Euclidean $k$-means") diff --git a/hbc/gis.py b/saber/gis.py similarity index 99% rename from hbc/gis.py rename to saber/gis.py index f4f833d..5c494e8 100644 --- a/hbc/gis.py +++ b/saber/gis.py @@ -156,7 +156,7 @@ def validation_maps(workdir: str, gauge_shape: str, val_table: pd.DataFrame = No Args: workdir: path to the project directory - val_table: the validation table produced by hbc.validate + val_table: the validation table produced by saber.validate gauge_shape: path to the gauge locations shapefile prefix: optional, a prefix to prepend to each created file's name @@ -235,6 +235,5 @@ def histomaps(gdf: gpd.GeoDataFrame, metric: str, prct: str, workdir: str) -> No metric, ax=axm, cmap=cmap, norm=norm, legend=True, markersize=10) cx.add_basemap(ax=axm, zoom=9, source=cx.providers.Esri.WorldTopoMap, attribution='') - fig.show() fig.savefig(os.path.join(workdir, 'gis_outputs', f'{metric}_{prct}.png')) return diff --git a/hbc/prep.py b/saber/prep.py similarity index 100% rename from hbc/prep.py rename to saber/prep.py diff --git a/hbc/table.py b/saber/table.py similarity index 100% rename from hbc/table.py rename to saber/table.py diff --git a/hbc/tests/calibrate.py b/saber/tests/calibrate.py similarity index 100% rename from hbc/tests/calibrate.py rename to saber/tests/calibrate.py diff --git a/hbc/utils.py b/saber/utils.py similarity index 100% rename from hbc/utils.py rename to saber/utils.py diff --git a/hbc/validate.py b/saber/validate.py similarity index 96% rename from hbc/validate.py rename to saber/validate.py index 6db10c8..f4969a2 100644 --- a/hbc/validate.py +++ b/saber/validate.py @@ -34,12 +34,12 @@ def sample_gauges(workdir: str, overwrite: bool = False) -> None: os.mkdir(vr_path) gt = pd.read_csv(os.path.join(workdir, 'gis_inputs', 'gauge_table.csv')) - start_row_count = gt.shape[0] + initial_row_count = gt.shape[0] rows_to_drop = round(gt.shape[0] / 10) for i in range(5): # some math related to which iteration of filtering we're on - n = start_row_count - rows_to_drop * (i + 1) + n = initial_row_count - rows_to_drop * (i + 1) pct_remain = 100 - 10 * (i + 1) subpath = os.path.join(vr_path, f'{pct_remain}') @@ -72,7 +72,7 @@ def sample_gauges(workdir: str, overwrite: bool = False) -> None: def run_series(workdir: str, drain_shape: str, obs_data_dir: str = None) -> None: """ - Runs hbc.analyze_region on each project in the validation_runs directory + Runs saber.analyze_region on each project in the validation_runs directory Args: workdir: the project working directory diff --git a/setup.py b/setup.py index ac602c4..4949ea8 100644 --- a/setup.py +++ b/setup.py @@ -6,12 +6,13 @@ with open('requirements.txt', 'r') as req: install_requires = req.read().splitlines() -description = 'tools for hydrological bias correction on large scale models' +description = 'tools for hydrological bias correction on large models' +version = '0.3.0' setup( - name='hbc', - packages=['hbc'], - version='0.2.0', + name='saber', + packages=['saber'], + version=version, description=description, long_description=long_description, long_description_content_type="text/markdown",