Skip to content

Commit

Permalink
Enable more capability in neighborhood explorer.
Browse files Browse the repository at this point in the history
  • Loading branch information
sampottinger committed Jul 12, 2024
1 parent d04a82d commit 5ad6242
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 51 deletions.
4 changes: 2 additions & 2 deletions paper/paper.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,11 @@ Prior work suggests that historic trends would anticipate continued increases in
Prior work expects that larger insured units will reduce risk [@knight_developing_2010] and we similarly observe that the claims rate decreases as the acrage included in an insured unit grows. However, after attempting multiple insured unit sizes including removal of smaller Optional Units [@zulauf_importance_2023] in post-hoc simulations, a gap persists in claims rates between the counterfactual and expected climate change simulations, suggesting our concerns may remain relevant across different risk units.

## Geographic bias
We find significant results ($p < 0.05 / n$) more common on the eastern side of the study area as shown in Figure @fig:geo.
We find significant results ($p < 0.05 / n$) more common in some areas as shown in Figure @fig:geo.

![Example simulation in our interactive tool’s geographic view. Our projections vary across different geographic areas.](./img/map.png "Example simulation in our interactive tool’s geographic view. Our projections vary across different geographic areas."){ width=85% #fig:geo }

This spatial bias may partially reflect that a number of more western neighborhoods have less land dedicated to maize so simulate with smaller sample sizes and fail to reach significance. In other cases, this geographic effect may also reflect disproportionate stress or other changes relative to historic conditions. In particular, as further explorable in our interactive tools, we note some east / west bias in changes to precipitation, temperature, and VPD / SVP.
This spatial bias may partially reflect that a number of neighborhoods have less land dedicated to maize so simulate with smaller sample sizes and fail to reach significance. In other cases, this geographic effect may also reflect disproportionate stress or other changes relative to historic conditions. In particular, as further explorable in our interactive tools, we note some geographic bias in changes to precipitation, temperature, and VPD / SVP.

## Heat and drought stress
Our model shows depressed yields during combined warmer and drier conditions potentially similar to 2012 which saw poor US maize outcomes [@ers_weather_2013].
Expand Down
30 changes: 14 additions & 16 deletions paper/viz/buttons.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,27 +242,25 @@ def __init__(self, sketch, x, y, initial_config, on_change):
0,
current_y,
'Scenario',
['2030 conditions', '2050 conditions'],
['2030 series', '2050 series'],
self._config.get_scenario(),
lambda x: self._set_config(self._config.get_with_scenario(x))
)

# current_y += self._scenario_buttons.get_height() + 12
#
# self._range_buttons = ToggleButtonSet(
# self._sketch,
# 0,
# current_y,
# 'Range of Risk',
# ['1 year', '3 years'],
# self._config.get_risk_range(),
# lambda x: self._set_config(self._config.get_with_risk_range(x))
# )
#
# current_y += self._range_buttons.get_height() + 30

current_y += self._scenario_buttons.get_height() + 12

self._range_buttons = ToggleButtonSet(
self._sketch,
0,
current_y,
'Range of Risk',
['Sample 1 Year', 'Avg All Years'],
self._config.get_risk_range(),
lambda x: self._set_config(self._config.get_with_risk_range(x))
)

current_y += self._range_buttons.get_height() + 30

self._threshold_buttons = ToggleButtonSet(
self._sketch,
0,
Expand Down Expand Up @@ -356,7 +354,7 @@ def step(self, mouse_x, mouse_y, clicked):
mouse_y = mouse_y - self._y

self._scenario_buttons.step(mouse_x, mouse_y, clicked)
# self._range_buttons.step(mouse_x, mouse_y, clicked)
self._range_buttons.step(mouse_x, mouse_y, clicked)
self._metric_buttons.step(mouse_x, mouse_y, clicked)
self._viz_buttons.step(mouse_x, mouse_y, clicked)
self._threshold_buttons.step(mouse_x, mouse_y, clicked)
Expand Down
4 changes: 2 additions & 2 deletions paper/viz/const.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
YIELD_CHANGE_MAX_VALUE = 0.4
YIELD_CHANGE_INCREMENT = 0.05

RISK_MIN_VALUE = -30
RISK_MAX_VALUE = 60
RISK_MIN_VALUE = -20
RISK_MAX_VALUE = 50
RISK_INCREMENT = 10

STD_MIN_VALUE = -30
Expand Down
21 changes: 7 additions & 14 deletions paper/viz/data_struct.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,23 +54,18 @@ def combine(self, 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
new_p = (self_weighted_p + other_weighted_p) / (self_count + other_count)
new_p = min([self.get_p_value(), other.get_p_value()])

def combine_probs(a, b):
a_not = 1 - a
b_not = 1 - b
not_a_b = a_not * b_not
return 1 - not_a_b
def combine_probs(a, a_count, b, b_count):
return (a * a_count + b * b_count) / (a_count + b_count)

self_control_risk = self.get_control_risk()
other_control_risk = other.get_control_risk()
new_control_risk = combine_probs(self_control_risk, other_control_risk)
new_control_risk = combine_probs(self_control_risk, self_count, other_control_risk, other_count)

self_experimental_risk = self.get_experimental_risk()
other_experimental_risk = other.get_experimental_risk()
new_experimental_risk = combine_probs(self_experimental_risk, other_experimental_risk)
new_experimental_risk = combine_probs(self_experimental_risk, self_count, other_experimental_risk, other_count)

new_count = self_count + other_count

Expand Down Expand Up @@ -152,13 +147,11 @@ def combine(self, 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)
new_p = min([self.get_p_value(), other.get_p_value()])
return YieldComparison(
self.get_prior().combine(other.get_prior()),
self.get_predicted().combine(other.get_predicted()),
weighted_p
new_p
)


Expand Down
6 changes: 4 additions & 2 deletions paper/viz/preprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,13 @@ def get_scenario_year(record):


def make_scatter_values(records, climate_deltas, configuration):
count = len(records)
scenario = configuration.get_scenario()
target_year = int(scenario[:4])
target_loss = '25% loss' if configuration.get_loss() == '75% cov' else '15% loss'
scenario_records = filter(lambda x: scenario.startswith(str(get_scenario_year(x))), records)
loss_records = filter(lambda x: x.get_loss() == target_loss, scenario_records)

if configuration.get_risk_range() == '1 year':
if configuration.get_risk_range() == 'Sample 1 Year':
year_records = filter(lambda x: x.get_year() in [2030, 2050], loss_records)
else:
year_records_nested = toolz.itertoolz.reduceby(
Expand All @@ -124,6 +123,9 @@ def make_scatter_values(records, climate_deltas, configuration):
)
year_records = year_records_nested.values()

year_records = list(year_records)
count = len(year_records)

p_threshold_naive = {
'p < 0.05': 0.05,
'p < 0.10': 0.1
Expand Down
4 changes: 2 additions & 2 deletions paper/viz/render_images.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
python3 hist_viz.py ../outputs/export_hist.csv 2050 75 ../img/hist.png
python3 results_viz_entry.py ../outputs/export_summary.csv 2050 risk map 0.05 Bonferroni significant none jul 75 ../outputs/export_climate.csv ../img/map.png
python3 results_viz_entry.py ../outputs/export_summary.csv 2050 risk scatter 0.05 Bonferroni significant chirps jul 75 ../outputs/export_climate.csv ../img/scatter.png
python3 results_viz_entry.py ../outputs/export_summary.csv 2050 risk map 0.05 Bonferroni all none jul 75 ../outputs/export_climate.csv ../img/map.png
python3 results_viz_entry.py ../outputs/export_summary.csv 2030 risk scatter 0.05 Bonferroni significant chirps jul 75 ../outputs/export_climate.csv ../img/scatter.png
python3 std_hist.py ../outputs/export_combined_tasks.csv ../img/std.png
16 changes: 5 additions & 11 deletions paper/viz/results_viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ def __init__(self, target, loading_id, default_configuration=None, data_loc=None
self._config = default_configuration
else:
self._config = buttons.Configuration(
'2050 conditions',
'1 year',
'2050 series',
'Avg All Years',
'yield',
'scatter',
'p < 0.05',
Expand Down Expand Up @@ -243,16 +243,10 @@ def _draw_annotation(self):
def _get_description(self):
metric = self._config.get_metric()

if self._config.get_risk_range() == '3 years':
if metric == 'yield':
agg_str = 'Averaging across 3 years.'
else:
agg_str = 'Prob of event in any of 3 years.'
if self._config.get_risk_range() == '':
agg_str = 'Averaging across all years.'
else:
if metric == 'yield':
agg_str = 'Single year avg yields.'
else:
agg_str = 'Prob of event in single year.'
agg_str = 'Single year avg yields.'

in_map = self._config.get_visualization() == 'map'
no_var = self._config.get_var() == 'no var'
Expand Down
4 changes: 2 additions & 2 deletions paper/viz/results_viz_entry.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def main():
sys.exit(1)
else:
data_loc = sys.argv[1]
scenario = sys.argv[2] + ' conditions'
scenario = sys.argv[2] + ' series'
metric = sys.argv[3]
visualization = sys.argv[4]
threshold = 'p < ' + sys.argv[5]
Expand All @@ -43,7 +43,7 @@ def main():

default_configuration = buttons.Configuration(
scenario,
'1 year',
'Avg All Years',
metric,
visualization,
threshold,
Expand Down

0 comments on commit 5ad6242

Please sign in to comment.