Skip to content

Commit

Permalink
Update viz.
Browse files Browse the repository at this point in the history
  • Loading branch information
sampottinger committed Jul 11, 2024
1 parent aaeafd6 commit 946e4d6
Show file tree
Hide file tree
Showing 16 changed files with 235 additions and 197 deletions.
3 changes: 2 additions & 1 deletion breakpoint_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,8 @@ def requires(self):
'climate': export_tasks.ClimateExportTask(),
'sweep': export_tasks.SweepExportTask(),
'hist': export_tasks.HistExportTask(),
'summary': export_tasks.SummaryExportTask()
'summary': export_tasks.SummaryExportTask(),
'combined': export_tasks.CombinedTasksRecordTask()
}

def output(self):
Expand Down
6 changes: 5 additions & 1 deletion paper/fill_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ def main():
source_contents = f.read()

loader = jinja2.BaseLoader()
template = jinja2.Environment(loader=loader).from_string(source_contents)
template = jinja2.Environment(
loader=loader,
comment_start_string='{//',
comment_end_string='//}'
).from_string(source_contents)

with open(template_loc) as f:
template_vals = json.load(f)
Expand Down
23 changes: 23 additions & 0 deletions paper/paper.bib
Original file line number Diff line number Diff line change
Expand Up @@ -1484,3 +1484,26 @@ @article{hunt_fossil_2020
langid = {english},
file = {Full Text:/home/sam/Zotero/storage/2T72GJT4/Hunt et al. - 2020 - Fossil Energy Use, Climate Change Impacts, and Air.pdf:application/pdf},
}
@article{knight_developing_2010,
title = {Developing Variable Unit-Structure Premium Rate Differentials in Crop Insurance},
volume = {92},
issn = {00029092, 14678276},
url = {http://www.jstor.org/stable/40647972},
abstract = {Federal crop insurance programs offer producers the option of insuring farm units individually or as an aggregate unit. Existing programs offer a fixed 10\% discount for most growers taking coverage at the aggregate level. This article describes an analysis of risk changes when units are aggregated. The methods described here, which base unit aggregation discounts on observable farm characteristics, are approved for implementation into the Federal Crop Insurance Program.},
pages = {141--151},
number = {1},
journaltitle = {American Journal of Agricultural Economics},
author = {Knight, Thomas O. and Coble, Keith H. and Goodwin, Barry K. and Rejesus, Roderick M. and Seo, Sangtaek},
urldate = {2024-07-11},
date = {2010},
note = {Publisher: [Agricultural \& Applied Economics Association, Oxford University Press]},
}
@misc{zulauf_importance_2023,
title = {The Importance of Insurance Unit in Crop Insurance Policy Debates},
url = {https://farmdocdaily.illinois.edu/2023/06/the-importance-of-insurance-unit-in-crop-insurance-policy-debates.html},
publisher = {University of Illinois},
author = {Zulauf, Carl},
date = {2023-06-12},
}
117 changes: 72 additions & 45 deletions paper/paper.md

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions paper/render.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ cd ..

python3 fill_template.py ./paper.md ./outputs/stats.json ./paper_filled.md

pandoc -o paper_filled.pdf --citeproc --number-sections --template=default.tex paper_filled.md
pandoc -o paper_filled.tex --citeproc --number-sections --template=default.tex paper_filled.md
pandoc -o paper_filled.docx --citeproc --number-sections paper_filled.md
pandoc -o paper_filled.pdf --citeproc --number-sections --filter pandoc-tablenos --filter pandoc-fignos --template=default.tex paper_filled.md
pandoc -o paper_filled.tex --citeproc --number-sections --filter pandoc-tablenos --filter pandoc-fignos --template=default.tex paper_filled.md
pandoc -o paper_filled.docx --citeproc --number-sections --filter pandoc-tablenos --filter pandoc-fignos paper_filled.md

rm -r arxiv
mkdir arxiv
Expand Down
2 changes: 2 additions & 0 deletions paper/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pandoc-fignos==2.4.0
pandoc-tablenos==2.3.0
68 changes: 34 additions & 34 deletions paper/viz/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,13 @@
BUTTON_WIDTH_COMPACT = 78
BUTTON_WIDTH_NARROW = 60

YIELD_MIN_VALUE = 0
YIELD_MAX_VALUE = 3000
YIELD_INCREMENT = 250
YIELD_MIN_VALUE = -0.4
YIELD_MAX_VALUE = 0.4
YIELD_INCREMENT = 0.05

YIELD_CHANGE_MIN_VALUE = -100
YIELD_CHANGE_MAX_VALUE = 100
YIELD_CHANGE_INCREMENT = 10
YIELD_CHANGE_MIN_VALUE = -0.4
YIELD_CHANGE_MAX_VALUE = 0.4
YIELD_CHANGE_INCREMENT = 0.05

RISK_MIN_VALUE = -30
RISK_MAX_VALUE = 60
Expand All @@ -46,52 +46,52 @@
ADAPT_INCREMENT = 10

VAR_MINS = {
'chirps': -2,
'rhn': -4,
'rhx': -4,
'svp': -0.1,
'tmax': -5,
'tmin': -5,
'vpd': -0.1,
'wbgtmax': -5
'chirps': -3,
'rhn': -3,
'rhx': -3,
'svp': -3,
'tmax': -3,
'tmin': -3,
'vpd': -3,
'wbgtmax': -3
}

VAR_MAXS = {
'chirps': 2,
'rhn': 4,
'rhx': 4,
'svp': 0.5,
'tmax': 5,
'tmin': 5,
'vpd': 0.5,
'wbgtmax': 5
'chirps': 3,
'rhn': 3,
'rhx': 3,
'svp': 3,
'tmax': 3,
'tmin': 3,
'vpd': 3,
'wbgtmax': 3
}

VAR_INCREMENTS = {
'chirps': 0.5,
'rhn': 0.5,
'rhx': 0.5,
'svp': 0.1,
'tmax': 1,
'tmin': 1,
'vpd': 0.1,
'wbgtmax': 1
'svp': 0.5,
'tmax': 0.5,
'tmin': 0.5,
'vpd': 0.5,
'wbgtmax': 0.5
}

MAX_COUNT = 0.1

CATEGORY_COLORS = {
'not significant': '#c0c0c0',
'decrease': '#d95f02',
'increase': '#1b9e77',
'decrease': '#a6cee3',
'increase': '#b2df8a',
'increased risk, can adapt': '#1f78b4',
'increased risk, cant adapt': '#a6cee3',
'decreased risk, can adapt': '#33a02c',
'decreased risk, cant adapt': '#b2df8a',
'increase risk, increase variability': '#1f78b4',
'increase risk, decrease variability': '#a6cee3',
'decrease risk, increase variability': '#33a02c',
'decrease risk, decrease variability': '#b2df8a'
'increase risk, increase yield': '#a6cee3',
'increase risk, decrease yield': '#1f78b4',
'decrease risk, increase yield': '#b2df8a',
'decrease risk, decrease yield': '#33a02c'
}

MONTH_NUMS = {
Expand All @@ -113,7 +113,7 @@
MAP_SCALE_POSITIVE = ['#e6f5d0a0', '#b8e186a0', '#7fbc41a0', '#4d9221a0']

SELECTION_INSTRUCTION = ' '.join([
'Click select to find fields (dots below) that would be good for a pilot.',
'Click select to find neighborhoods (dots below) that would be good for a pilot.',
'Toggle yield, risk and adaptation or map vs scatter.',
'Do different views change your answer?'
])
Expand Down
22 changes: 21 additions & 1 deletion paper/viz/data_struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ def combine(self, other):
self_count = self.get_count()
other_count = other.get_count()

if self_count == 0:
return other
elif other_count == 0:
return self

self_weighted_p = self.get_p_value() * self_count
other_weighted_p = other.get_p_value() * other_count
weighted_p = (self_weighted_p + other_weighted_p) / (self_count + other_count)
Expand Down Expand Up @@ -99,6 +104,11 @@ def get_count(self):
def combine(self, other):
self_count = self.get_count()
other_count = other.get_count()

if self_count == 0:
return other
elif other_count == 0:
return self

self_weighted_mean = self.get_mean() * self_count
other_weighted_mean = other.get_mean() * other_count
Expand All @@ -107,7 +117,11 @@ def combine(self, other):
self_var_piece = (self_count - 1) * self.get_std()**2
other_var_piece = (other_count - 1) * other.get_std()**2
pooled_count = self_count + other_count - 2
new_std = math.sqrt((self_var_piece + other_var_piece) / pooled_count)

if pooled_count == 0:
new_std = (self.get_std() + other.get_std()) / 2
else:
new_std = math.sqrt((self_var_piece + other_var_piece) / pooled_count)

new_count = self_count + other_count
return YieldDistribution(new_mean, new_std, new_count)
Expand All @@ -132,6 +146,12 @@ def get_p_value(self):
def combine(self, other):
self_count = self.get_predicted().get_count()
other_count = other.get_predicted().get_count()

if self_count == 0:
return other
elif other_count == 0:
return self

self_weighted_p = self.get_p_value() * self_count
other_weighted_p = other.get_p_value() * other_count
weighted_p = (self_weighted_p + other_weighted_p) / (self_count + other_count)
Expand Down
2 changes: 1 addition & 1 deletion paper/viz/hist_viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ def _draw_title(self):
self._sketch.draw_text(
SUB_CHART_WIDTH / 2 + 40,
30,
'Histogram of Simulated Change in Risk Unit-Level Yields'
'Histogram of Change in Risk Unit-Level Yields Relative to Expected (Avg Yield)'
)

self._sketch.pop_style()
Expand Down
12 changes: 5 additions & 7 deletions paper/viz/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,12 @@ def make_point_risk(record):
risk_change = record.get_predicted_risk().get_risk_change()
risk_p = record.get_predicted_risk().get_p_value()

std_before = record.get_yield_comparison().get_prior().get_std_percent()
std_after = record.get_yield_comparison().get_predicted().get_std_percent()
std_change = std_after - std_before
yield_change = record.get_yield_comparison().get_predicted().get_mean()

if std_change > 0:
var_str = 'increase variability'
if yield_change > 0:
var_str = 'increase yield'
else:
var_str = 'decrease variability'
var_str = 'decrease yield'

if risk_p > p_threshold:
category = 'not significant'
Expand All @@ -199,7 +197,7 @@ def make_point_risk(record):
category = 'decrease risk, ' + var_str

var_x = get_var_x(record)
effective_x = std_change * 100 if var_x is None else var_x
effective_x = yield_change if var_x is None else var_x

return ScatterPoint(
record.get_geohash(),
Expand Down
4 changes: 2 additions & 2 deletions paper/viz/results_viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ def __init__(self, target, loading_id, default_configuration=None, data_loc=None
self._config = default_configuration
else:
self._config = buttons.Configuration(
'2030 conditions',
'2050 conditions',
'1 year',
'yield',
'scatter',
'p < 0.05',
'Bonferroni',
'significant only',
'no var',
'jun',
'jul',
'75% cov'
)

Expand Down
Loading

0 comments on commit 946e4d6

Please sign in to comment.