Skip to content
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
53 changes: 20 additions & 33 deletions demo.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
import ee
import pyproj
from gridwxcomp.prep_metadata import prep_metadata, get_subgrid_bounds
from gridwxcomp.prep_metadata import prep_metadata
from gridwxcomp.ee_download import download_grid_data
from gridwxcomp.plot import daily_comparison, monthly_comparison, station_bar_plot
from gridwxcomp.calc_bias_ratios import calc_bias_ratios
from gridwxcomp.spatial import make_grid, interpolate
from gridwxcomp.util import reproject_crs_for_bounds


# initialize earth engine
ee.Initialize()
# name of the dataset comparison is being made with
gridded_dataset_name = 'conus404'
# Path to station metadata file with lat/long coords
station_meta_path = './gridwxcomp/example_data/Station_Data.txt'
# local path for config file
config_path = f'./gridwxcomp/example_data/gridwxcomp_config_{gridded_dataset_name}.ini'
config_path = f'gridwxcomp/example_data/gridwxcomp_config_{gridded_dataset_name}.ini'
# Path to station metadata file with lat/long coords
station_meta_path = 'gridwxcomp/example_data/Station_Data.txt'

# name of bucket data will be exported to once the earth engine calls complete
export_bucket = 'openet'
# path in bucket to export to
export_path = f'bias_correction_gridwxcomp_testing/gridwxcomp_{gridded_dataset_name}/'
# initialize earth engine
ee.Authenticate()
ee.Initialize(opt_url='https://earthengine-highvolume.googleapis.com')

# local path for prep_metadata output
gridwxcomp_input = f'{gridded_dataset_name}_gridwxcomp_metadata.csv'
Expand Down Expand Up @@ -79,33 +75,27 @@
'crs_id': 'ESRI:102004'}
}

# User has option to automatically pull bounds, aee TODO in function over assumptions
# User has option to automatically pull bounds, see TODO in function over assumptions
# projection_dict['wgs84']['bounds'] = get_subgrid_bounds(gridwxcomp_input, config_path, buffer=25)

projection_dict['lcc']['bounds'] = reproject_crs_for_bounds(
projection_dict['wgs84']['bounds'], projection_dict['lcc']['resolution'],
projection_dict['wgs84']['crs_id'], projection_dict['lcc']['crs_id'], 0)


'''
download_grid_data
The purpose of this module is to make calls to the earth engine API to export gridded timeseries at the station
points contained within the station metadata file generated by prep_metadata. Exported data will be saved to
a cloud storage bucket that the user specifies.

The user will need to manually download the data via gsutil before proceeding further. The module amends the
station metadata file to have paths for the gridded dataset as they would exist locally once the user has
downloaded them.
The purpose of this module is to make calls to the earth engine API to
export timeseries for the gridded dataset at the station locations
contained within the station metadata file generated by prep_metadata.

The data is saved locally as it is downloaded, and the metadata file
generated by prep_metadata is amended with paths to the downloaded files.

Example: the example run is with the dataset conus404, the gridded path will be filled in such that if you
download the 'conus404' folder from the bucket to the local directory of trial_runs.py it will work without
further modification.
'''
download_grid_data(
gridwxcomp_input,
config_path,
export_bucket=export_bucket,
export_path=export_path,
local_folder=None,
force_download=False)

'''
Expand Down Expand Up @@ -139,12 +129,9 @@
config_path,
dataset_name=gridded_dataset_name)

for var in [
'tmax',
'tmin',
'eto']: # Iterate over vars in list. Valid entries found in calc_bias_ratios.py VAR_LIST
# path to bias ratios output file
ratio_filepath = f'{output_dir}/{var}_summary_comp_1980_2020.csv'
for var in ['prcp', 'etr', 'eto']: # Iterate over vars in list. Valid entries found in calc_bias_ratios.py VAR_LIST
ratio_filepath = f'{output_dir}/{var}_summary_comp_all_yrs.csv' # path to bias ratios output file

interpolation_out_path = (f'{var}_invdistnn_p{params["power"]}_' # directory for interpolation outputs
f's{params["smoothing"]}_maxpoints{params["max_points"]}_radius{params["radius"]}')

Expand Down Expand Up @@ -173,15 +160,15 @@
comparison_var=var,
grid_id=None,
day_limit=10,
years='1980-2020',
years='all',
comp=True)

'''
station_bar_plot
Generates boxplots of the bias ratios to visualize overall performance.
Requires the outputs of calc_bias_ratios as an input.
'''
station_bar_plot(ratio_filepath, bar_plot_layer='growseason_mean')
station_bar_plot(ratio_filepath, bar_plot_layer='grow_mean')

'''
make grid
Expand Down
2 changes: 1 addition & 1 deletion gridwxcomp/calc_bias_ratios.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from .util import parse_yr_filter, read_config, read_data, convert_units


VAR_LIST = ['tmax', 'tmin', 'tdew', 'rs', 'wind', 'ea', 'rhmax', 'rhmin', 'rhavg', 'eto', 'etr']
VAR_LIST = ['tmax', 'tmin', 'tdew', 'rs', 'wind', 'ea', 'rhmax', 'rhmin', 'rhavg', 'eto', 'etr', 'prcp']
GROW_THRESH = 65
SUM_THRESH = 35
ANN_THRESH = 125
Expand Down
Loading
Loading