Skip to content

Commit 15c1de0

Browse files
replaced shapefile_year to shapefile_tag
1 parent 3bcb1da commit 15c1de0

File tree

5 files changed

+22
-21
lines changed

5 files changed

+22
-21
lines changed

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,4 +20,4 @@ RUN python utils/create_dir_paths.py datapaths=datapaths.yaml
2020

2121
# snakemake --configfile conf/config.yaml --cores 4 -C shapefile_polygon_name=zcta
2222
ENTRYPOINT ["snakemake"]
23-
CMD ["--cores", "1", "-C", "shapefile_year=2015", "shapefile_polygon_name=county"]
23+
CMD ["--cores", "1", "-C", "shapefile_tag=2015", "shapefile_polygon_name=county"]

Snakefile

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,33 @@ import yaml
33
conda: "requirements.yaml"
44
configfile: "conf/config.yaml"
55

6-
year=config["shapefile_year"]
6+
tag=config["shapefile_tag"]
77
polygon_name=config["shapefile_polygon_name"]
88

99
rule all:
1010
input:
11-
f"data/output/climate_types_raster2polygon/climate_types_{polygon_name}_{year}.parquet"
11+
f"data/output/climate_types_raster2polygon/climate_types_{polygon_name}_{tag}.parquet"
1212

1313
rule download_climate_types:
1414
output:
1515
f"data/input/climate_types/{config['climate_types_file']}"
1616
shell:
1717
"python src/download_climate_types.py"
1818

19-
rule download_shapefiles:
20-
output:
21-
f"data/input/shapefiles/shapefile_{polygon_name}_{year}/shapefile.shp" #ext = ["shp", "shx", "dbf", "prj", "cpg", "xml"]
22-
shell:
23-
f"python src/download_shapefile.py shapefile_year={year} shapefile_polygon_name={polygon_name}"
19+
# temporarily removing download step in snakemake
20+
# rule download_shapefiles:
21+
# output:
22+
# f"data/input/shapefiles/shapefile_{polygon_name}_{tag}/shapefile.shp" #ext = ["shp", "shx", "dbf", "prj", "cpg", "xml"]
23+
# shell:
24+
# f"python src/download_shapefile.py shapefile_tag={tag} shapefile_polygon_name={polygon_name}"
2425

2526
rule aggregate_climate_types:
2627
input:
2728
f"data/input/climate_types/{config['climate_types_file']}",
28-
f"data/input/shapefiles/shapefile_{polygon_name}_{year}/shapefile.shp"
29+
f"data/input/shapefiles/shapefile_{polygon_name}_{tag}/shapefile.shp"
2930
output:
30-
f"data/output/climate_types_raster2polygon/climate_types_{polygon_name}_{year}.parquet",
31-
f"data/intermediate/climate_pcts/climate_pcts_{polygon_name}_{year}.json",
32-
f"data/intermediate/climate_pcts/climate_types_{polygon_name}_{year}.csv"
31+
f"data/output/climate_types_raster2polygon/climate_types_{polygon_name}_{tag}.parquet",
32+
f"data/intermediate/climate_pcts/climate_pcts_{polygon_name}_{tag}.json",
33+
f"data/intermediate/climate_pcts/climate_types_{polygon_name}_{tag}.csv"
3334
shell:
34-
f"python src/aggregate_climate_types.py shapefile_year={year} shapefile_polygon_name={polygon_name}"
35+
f"python src/aggregate_climate_types.py shapefile_tag={tag} shapefile_polygon_name={polygon_name}"

conf/config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
defaults:
22
- _self_
33
- datapaths: datapaths
4-
- shapefiles: shapefiles
4+
- shapefiles: us_shapefiles
55
- climate_keys: climate_keys
66

77
# Climate types raw raster information
@@ -14,8 +14,8 @@ climate_types_file: Beck_KG_V1_present_0p0083.tif # it's the one at highest res
1414
# - Beck_KG_V1_present_conf_0p5.tif
1515

1616
# Shapefiles information
17-
shapefile_year: 2015 #to be matched with cfg.shapefiles
18-
shapefile_polygon_name: county #to be matched with cfg.shapefiles, column name of id in output file
17+
shapefile_tag: 2015 #to be matched with cfg.shapefiles
18+
shapefile_polygon_name: zcta #to be matched with cfg.shapefiles, column name of id in output file
1919

2020
hydra:
2121
run:

conf/shapefiles/us_shapefiles.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Catalog of shapefiles
2-
# cfg.shapefile_year and cfg.shapefile_polygon_name are used to match the shapefile to use
2+
# cfg.shapefile_tag and cfg.shapefile_polygon_name are used to match the shapefile to use
33

44
county: #County shapefiles (cartographic boudaries) https://www.census.gov/programs-surveys/geography/guidance/tiger-data-products-guide.html
55
2015:

src/download_us_shapefile.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66

77
@hydra.main(config_path="../conf", config_name="config", version_base=None)
88
def main(cfg):
9-
url = cfg.shapefiles[cfg.shapefile_polygon_name][cfg.shapefile_year].url
9+
url = cfg.shapefiles[cfg.shapefile_polygon_name][cfg.shapefile_tag].url
1010

11-
tgt = f"data/input/shapefiles/shapefile_{cfg.shapefile_polygon_name}_{cfg.shapefile_year}"
11+
tgt = f"data/input/shapefiles/{cfg.shapefile_polygon_name}_{cfg.shapefile_tag}"
1212

1313
tgtdir = os.path.dirname(tgt)
1414
tgtfile = os.path.basename(tgt)
@@ -27,11 +27,11 @@ def main(cfg):
2727
os.remove(f"{tgt}.zip")
2828
logging.info(f"Removed {tgt}.zip")
2929

30-
logging.info(f"Rename files to shapefile.*")
30+
logging.info(f"Rename files within zip folder ")
3131
files = os.listdir(tgt)
3232
for f in files:
3333
_, ext = os.path.splitext(f)
34-
os.rename(f"{tgt}/{f}", f"{tgt}/shapefile{ext}")
34+
os.rename(f"{tgt}/{f}", f"{tgt}/{cfg.shapefile_polygon_name}_{cfg.shapefile_tag}{ext}")
3535

3636

3737
if __name__ == "__main__":

0 commit comments

Comments
 (0)