-
Notifications
You must be signed in to change notification settings - Fork 2
[ENH] Use pregenerate figures #96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
bdc1979
[ENH] Switch to ssh submodules
surchs 2a9c2d3
[ENH] Add a script to prerender figures
surchs abd9d8c
[ENH] Make the dash app load the images
surchs 4ec6353
Merge remote-tracking branch 'origin/main' into pregenerate_figures
surchs bffac74
Apply suggestions from code review
surchs e047ab0
Revert "[ENH] Switch to ssh submodules"
surchs 431a8a4
More suggestions from review
surchs a518cdd
Use prerendered figures everywhere
surchs 82a0c35
Update data
surchs fd57877
Updating data submodule to most recent commit
surchs a9858ff
Regenerate the prerendered figures
surchs ba90d2a
Make pre-gen figures executable
surchs 9843d64
Update .github/workflows/update_submodule.yml
surchs 9ebddd4
Add Alyssa's python setup suggestion
surchs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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}!") |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I just realized that we should also install the Python dependencies to ensure that your nice script doesn't error out during the wf 🤦♀️
can't suggest in this part of the file, but I think
after the checkout step should do the trick!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, good point