Skip to content

Commit 2e87bdc

Browse files
authored
Merge pull request #48 from NSAPH-Data-Processing/audiracmichelle/issue47
Audiracmichelle/issue47
2 parents 1f3edf8 + c811698 commit 2e87bdc

17 files changed

+4351
-79
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ mamba activate <env_name>
8282
Run
8383

8484
```bash
85-
python utils/create_dir_paths.py
85+
python src/create_dir_paths.py
8686
```
8787

8888
### Pipeline

Snakefile

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,37 @@
1-
import yaml
1+
import hydra
2+
from omegaconf import OmegaConf
3+
import json
24

35
conda: "requirements.yaml"
4-
configfile: "conf/config.yaml"
56

6-
# == Load configuration ==
7+
# the workflow configuration file is orchestrated by hydra
8+
# read config with hydra
9+
with hydra.initialize(config_path="conf", version_base=None):
10+
cfg = hydra.compose(config_name="config", overrides=[])
11+
#print(OmegaConf.to_yaml(cfg))
712

8-
# dynamic config files
9-
defaults_dict = {key: value for d in config['defaults'] if isinstance(d, dict) for key, value in d.items()}
10-
shapefiles_cfg = yaml.safe_load(open(f"conf/shapefiles/{defaults_dict['shapefiles']}.yaml", 'r'))
11-
# == Define variables ==
12-
shapefile_list = shapefiles_cfg.keys()
13-
print(shapefile_list)
13+
# convert to dict of single shapefile dicts
14+
shapefiles_cfg = OmegaConf.to_container(cfg.shapefiles, resolve=True)
15+
#print(shapefiles_cfg)
16+
shapefiles_cfg_dict = {shapefile["name"]: "[" + json.dumps(shapefile).replace('"', '') + "]" for shapefile in shapefiles_cfg}
17+
#print(shapefiles_cfg_dict)
18+
shapefiles_list = list(shapefiles_cfg_dict.keys())
19+
#print(shapefiles_list)
20+
# print(f"""
21+
# python src/aggregate_climate_types.py "+shapefiles={shapefiles_cfg_dict[shapefiles_list[0]]}"
22+
# """)
23+
24+
#raise ValueError("stop here")
1425

1526
rule all:
1627
input:
1728
expand(f"data/output/climate_types_raster2polygon/climate_types_{{shapefile_name}}.parquet",
18-
shapefile_name=shapefile_list
29+
shapefile_name=shapefiles_list
1930
)
2031

2132
rule download_climate_types:
2233
output:
23-
f"data/input/climate_types/{config['climate_types_file']}"
34+
f"data/input/climate_types/{cfg.climate_types_file}"
2435
shell:
2536
"python src/download_climate_types.py"
2637

@@ -33,11 +44,17 @@ rule download_climate_types:
3344

3445
rule aggregate_climate_types:
3546
input:
36-
f"data/input/climate_types/{config['climate_types_file']}",
47+
f"data/input/climate_types/{cfg.climate_types_file}",
3748
f"data/input/shapefiles/{{shapefile_name}}/{{shapefile_name}}.shp"
3849
output:
3950
f"data/output/climate_types_raster2polygon/climate_types_{{shapefile_name}}.parquet",
4051
f"data/intermediate/climate_pcts/climate_pcts_{{shapefile_name}}.json",
4152
f"data/intermediate/climate_pcts/climate_types_{{shapefile_name}}.csv"
53+
params:
54+
shapefile_name = lambda wildcards: shapefiles_cfg_dict[wildcards.shapefile_name]
4255
shell:
43-
f"python src/aggregate_climate_types.py"
56+
(f"""
57+
echo {{wildcards.shapefile_name}}
58+
python src/aggregate_climate_types.py "+shapefiles={{params.shapefile_name}}"
59+
""")
60+
#python src/aggregate_climate_types.py "+shapefiles=[{name: CAN_ADM2, url: null, idvar: shapeID, output_idvar: id}]"

conf/config.yaml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
defaults:
22
- _self_
3-
- datapaths: datapaths
4-
- shapefiles: county
3+
- datapaths: example
4+
- geoboundaries: example
55
- climate_keys.yaml
66

7+
shapefiles: ${geoboundaries}
8+
79
# Climate types raw raster information
810
climate_types_url: https://figshare.com/ndownloader/files/12407516
911
climate_types_file: Beck_KG_V1_present_0p0083.tif # it's the one at highest resolution

conf/example_config.yaml

Lines changed: 0 additions & 18 deletions
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
#County shapefiles (cartographic boudaries) https://www.census.gov/programs-surveys/geography/guidance/tiger-data-products-guide.html
2-
county_2015:
2+
- name: county_2015
33
url: https://www2.census.gov/geo/tiger/GENZ2015/shp/cb_2015_us_county_20m.zip
44
idvar: GEOID
55
output_idvar: county

conf/geoboundaries/example.yaml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
- name: CAN_ADM2
2+
url: null
3+
idvar: shapeID
4+
output_idvar: id
5+
- name: MEX_ADM2
6+
url: null
7+
idvar: shapeID
8+
output_idvar: id
9+
- name: USA_ADM2
10+
url: null
11+
idvar: shapeID
12+
output_idvar: id

0 commit comments

Comments
 (0)