-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [ENH] Switch to ssh submodules So I don't have to retype my password * [ENH] Add a script to prerender figures * [ENH] Make the dash app load the images This also means the app won't work if the images are not there * Apply suggestions from code review Co-authored-by: Alyssa Dai <[email protected]> * Revert "[ENH] Switch to ssh submodules" This reverts commit bdc1979. * More suggestions from review * Use prerendered figures everywhere Also use NUM_DECIMALS * Update data * Updating data submodule to most recent commit * Regenerate the prerendered figures * Make pre-gen figures executable And run that in WF * Update .github/workflows/update_submodule.yml Co-authored-by: Alyssa Dai <[email protected]> * Add Alyssa's python setup suggestion --------- Co-authored-by: Alyssa Dai <[email protected]>
- Loading branch information
Showing
6 changed files
with
126 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
#!/usr/bin/env python | ||
|
||
import pickle as pkl | ||
import sys | ||
from pathlib import Path | ||
|
||
# Hacky hacky gets the job done for the next import | ||
sys.path.append(str(Path(__file__).parent.parent)) | ||
|
||
from climate_emotions_map.make_stacked_bar_plots import ( # noqa | ||
DATA_DICTIONARIES, | ||
make_stacked_bar, | ||
) | ||
from climate_emotions_map.utility import DEFAULT_QUESTION, NUM_DECIMALS # noqa | ||
|
||
UNIQUE_QUESTIONS = ( | ||
DATA_DICTIONARIES["question_dictionary.tsv"]["question"].unique().tolist() | ||
) | ||
UNIQUE_STATES = ( | ||
DATA_DICTIONARIES["state_abbreviations.tsv"]["state"].unique().tolist() | ||
) | ||
OUTPUT_FILE = Path(__file__).parents[0] / "assets/prerendered_figures.pkl" | ||
|
||
|
||
def make_full_set_of_barplots( | ||
state=None, stratify=None, threshold=None, decimals=NUM_DECIMALS | ||
): | ||
""" | ||
This returns a dictionary for all questions where keys are question IDs | ||
and values are the plotly graph object figure for each question. | ||
""" | ||
return { | ||
question: make_stacked_bar( | ||
question, "all", state, stratify, threshold, decimals | ||
) | ||
for question in UNIQUE_QUESTIONS | ||
} | ||
|
||
|
||
def make_all_figures(): | ||
""" | ||
Iterate through all combinations of questions and states | ||
to create the complete set of figures. | ||
Returns a dictionary keyed on the tuple of (state, stratified, threshold) in that order | ||
""" | ||
figures = {} | ||
# A state of None means we are looking at national level questions | ||
for state in UNIQUE_STATES + [None]: | ||
for stratify in [False, True]: | ||
# For state level figures, we don't stratify by party | ||
if state is not None and stratify: | ||
continue | ||
for threshold in [None, DEFAULT_QUESTION["outcome"]]: | ||
key = (state, stratify, threshold, NUM_DECIMALS) | ||
figures[key] = make_full_set_of_barplots(*key) | ||
return figures | ||
|
||
|
||
if __name__ == "__main__": | ||
figures = make_all_figures() | ||
with OUTPUT_FILE.open("wb") as f: | ||
pkl.dump(figures, f) | ||
|
||
print(f"Done prerendering figures to {OUTPUT_FILE}!") |