Skip to content

Commit

Permalink
[USGS-R#13] updates to snakefile
Browse files Browse the repository at this point in the history
  • Loading branch information
jsadler2 committed May 19, 2022
1 parent fa5cb8e commit d2a4daf
Showing 1 changed file with 19 additions and 17 deletions.
36 changes: 19 additions & 17 deletions Snakefile
Original file line number Diff line number Diff line change
@@ -1,47 +1,49 @@
import pickle
import geopandas as gpd
from gridmet_split_script import get_gridmet_datasets, create_weightmap
from gridmet_aggregation_PRMS import ncdf_to_gdf, gridmet_prms_area_avg_agg

run_date = "2022-04-07"
run_date = "2022_04_07"
out_dir = "data/out"
segments_file = "data/GFv1_catchments_edited.gpkg"
data_dir = "data/"
drb_hru_file = "data/GFv1_catchments_edited.gpkg"

rule all:
input:
f"{out_dir}/drb_climate_{run_date}.nc",
f"{out_dir}/drb_segs_climate{run_date}.csv"
f"{out_dir}/drb_climate_{run_date}_segments.csv"


rule fetch_drb_catchments:
output:
"{outdir}/GFv1_catchments_edited.gpkg"
drb_hru_file
shell:
"wget https://github.com/USGS-R/drb-network-prep/blob/940073e8d77c911b6fb9dc4e3657aeab1162a158/2_process/out/GFv1_catchments_edited.gpkg?raw=true -O {output}"


rule make_dataset_dict:
input:
"{outdir}/GFv1_catchments_edited.gpkg"
drb_hru_file,
params:
data_vars = ['tmmx', 'tmmn', 'pr', 'srad', 'vs','rmax','rmin','sph'],
start_date = "1979-01-01-",
end_date = run_date
end_date = run_date.replace("_", "-")
output:
"{outdir}/dataset_dict_{run_date}.pickle"
run:
gdf = gpd.read_file(input[0], layer="GFv1_catchments_edited")
data_dict = get_gridmet_datasets(variable = params.data_vars,
start_date = params.start_date,
end_date = params.end_date
end_date = params.end_date,
polygon_for_bbox = gdf)
with open(output[0], "wb") as f:
pickle.dump(data_dict, f)


rule make_weight_map:
input:
"{outdir}/GFv1_catchments_edited.gpkg",
"{outdir}/dataset_dict_{run_date}.pickle"
drb_hru_file,
f"{{outdir}}/dataset_dict_{run_date}.pickle"
output:
"{outdir}/grd2shp_weights.pickle"
run:
Expand All @@ -56,11 +58,11 @@ rule make_weight_map:

rule aggregate_gridmet_to_polygons:
input:
"{outdir}/GFv1_catchments_edited.gpkg",
drb_hru_file,
"{outdir}/dataset_dict_{run_date}.pickle",
"{outdir}/grd2shp_weights.pickle"
output:
"{output}/drb_climate_{run_date}.nc"
"{outdir}/drb_climate_{run_date}.nc"
run:
gdf = gpd.read_file(input[0], layer="GFv1_catchments_edited")
with open(input[1], "rb") as f:
Expand All @@ -77,10 +79,10 @@ rule aggregate_gridmet_to_polygons:

rule make_nc_gdf:
input:
"{outdir}/GFv1_catchments_edited.gpkg",
"{output}/drb_climate_{run_date}.nc"
drb_hru_file,
"{outdir}/drb_climate_{run_date}.nc"
output:
"{output}/drb_climate_{run_date}_gdf.pickle"
"{outdir}/drb_climate_{run_date}_gdf.pickle"
run:
gdf = gpd.read_file(input[0], layer="GFv1_catchments_edited")
gridmet_drb_gdf = ncdf_to_gdf(ncdf_path=input[1],
Expand All @@ -93,12 +95,12 @@ rule make_nc_gdf:

rule aggregate_gridmet_polygons_to_flowlines:
input:
"{output}/drb_climate_{run_date}_gdf.pickle",
"{output}/drb_climate_{run_date}.nc"
"{outdir}/drb_climate_{run_date}_gdf.pickle",
"{outdir}/drb_climate_{run_date}.nc"
params:
data_vars = ['tmmx', 'tmmn', 'pr', 'srad', 'vs','rmax','rmin','sph'],
output:
"{output}/drb_climate_{run_date}_segments.csv"
"{outdir}/drb_climate_{run_date}_segments.csv"
run:
with open(input[0], "rb") as f:
gridmet_drb_gdf = pickle.load(f)
Expand Down

0 comments on commit d2a4daf

Please sign in to comment.