Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
15 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 1 addition & 5 deletions src/natcap/invest/carbon/reporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,10 +208,6 @@ def report(file_registry: dict, args_dict: dict, model_spec: ModelSpec,

agg_results_table = _generate_agg_results_table(args_dict, file_registry)

lulc_pre_caption = gettext(
'Values in the legend are listed in order of frequency (most common '
'first).')

with open(target_html_filepath, 'w', encoding='utf-8') as target_file:
target_file.write(TEMPLATE.render(
report_script=model_spec.reporter,
Expand All @@ -226,7 +222,7 @@ def report(file_registry: dict, args_dict: dict, model_spec: ModelSpec,
agg_results_table=agg_results_table,
inputs_img_src=inputs_img_src,
inputs_caption=input_raster_caption,
lulc_pre_caption=lulc_pre_caption,
lulc_pre_caption=report_constants.LULC_PRE_CAPTION,
outputs_img_src=outputs_img_src,
outputs_caption=output_raster_caption,
intermediate_raster_sections=intermediate_raster_sections,
Expand Down
9 changes: 7 additions & 2 deletions src/natcap/invest/reports/raster_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,10 @@ def __post_init__(self):
self.colormap = plt.get_cmap(self.colormap if self.colormap
else COLORMAPS[self.datatype])

def plot_on_axis(self, fig, ax, arr, cmap, imshow_kwargs, colorbar_kwargs):
mappable = ax.imshow(arr, cmap=cmap, **imshow_kwargs)
fig.colorbar(mappable, ax=ax, **colorbar_kwargs)


def build_raster_plot_configs(id_lookup_table, raster_plot_tuples):
"""Build RasterPlotConfigs for use in plotting input or output rasters.
Expand Down Expand Up @@ -462,8 +466,9 @@ def plot_raster_list(raster_list: list[RasterPlotConfig]):
len(patches), n_plots, xy_ratio))
leg.set_in_layout(True)
else:
mappable = ax.imshow(arr, cmap=cmap, **imshow_kwargs)
fig.colorbar(mappable, ax=ax, **colorbar_kwargs)
config.plot_on_axis(
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wanted an extension hook without changing plot_raster_list or duplicating too much code, but curious what you think of this. It also doesn't touch the nominal plots, so maybe there is a better design here? Curious what you think.

fig, ax, arr, cmap, imshow_kwargs, colorbar_kwargs)

[ax.set_axis_off() for ax in axs.flatten()]
return fig

Expand Down
5 changes: 5 additions & 0 deletions src/natcap/invest/reports/report_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@
'in GIS to assess its accuracy.'
)

LULC_PRE_CAPTION = gettext(
'LULC values in the legend are listed in order of frequency (most common '
'first).'
)

TABLE_PAGINATION_THRESHOLD = 10
149 changes: 149 additions & 0 deletions src/natcap/invest/reports/templates/models/urban_mental_health.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
{% extends 'base.html' %}

{% block styles %}
{{ super() }}
{% include 'datatable-styles.html' %}
{% endblock styles %}

{% block content %}

{{ super() }}

{% from 'args-table.html' import args_table %}
{% from 'caption.html' import caption %}
{% from 'content-grid.html' import content_grid %}
{% from 'metadata.html' import list_metadata %}
{% from 'raster-plot-img.html' import raster_plot_img %}
{% from 'wide-table.html' import wide_table %}



<h2 class="section-header">Results</h2>

{{ accordion_section(
'Aggregate Results',
agg_results_table | safe
)}}

{{ accordion_section(
'Primary Outputs',
content_grid([
(caption(raster_group_caption, pre_caption=True), 100),
(raster_plot_img(outputs_img_src, 'Primary Outputs'), 100),
(caption(outputs_caption, definition_list=True), 100)
])
)}}

{{ accordion_section(
'Preventable Cases by AOI Vector',
content_grid(
[
(content_grid([
('<div style="display:flex; justify-content:center;"><div id="cases_map"></div></div>', 100),
(caption(cases_map_caption, aggregate_map_source_list), 100)
]), 50),

(content_grid([
('<div style="display:flex; justify-content:center;"><div id="cost_map"></div></div>', 100),
(caption(cost_map_caption, aggregate_map_source_list), 100)
]), 50)
] if cost_map_json else [
(content_grid([
('<div style="display:flex; justify-content:center;"><div id="cases_map"></div></div>', 100),
(caption(cases_map_caption, aggregate_map_source_list), 100)
]), 100)
]
)
) }}

{% for section in intermediate_raster_sections %}
{{ accordion_section(
section['heading'],
content_grid([
(caption(raster_group_caption, pre_caption=True), 100),
(raster_plot_img(section['img_src'], section['heading']), 100),
(caption(section['caption'], definition_list=True), 100)
])
)}}
{% endfor %}

{{ accordion_section(
'Output Raster Stats',
content_grid([
(stats_table_note, 100),
(wide_table(
output_raster_stats_table | safe,
font_size_px=16
), 100)
])
)}}

<h2 class="section-header">Inputs</h2>

{% if args_dict != None %}
{{ accordion_section(
'Arguments',
args_table(args_dict)
)}}
{% endif %}

{% set input_items = [
(caption(raster_group_caption, pre_caption=True), 100)
] %}

{% if args_dict['lulc_base'] %}
{% set input_items = input_items + [
(caption(lulc_pre_caption, pre_caption=True), 100)
] %}
{% endif %}

{% set input_items = input_items + [
(raster_plot_img(inputs_img_src, 'Raster Inputs'), 100),
(caption(inputs_caption, definition_list=True), 100)
] %}

{{ accordion_section(
'Input Maps',
content_grid(input_items)
)}}

{{ accordion_section(
'Input Raster Stats',
content_grid([
(stats_table_note, 100),
(wide_table(
input_raster_stats_table | safe,
font_size_px=16
), 100)
])
)}}

<h2 class="section-header">Metadata</h2>

{{
accordion_section(
'Output Filenames and Descriptions',
list_metadata(model_spec_outputs),
expanded=False
)
}}

{% endblock content %}



{% from 'vegalite-plot.html' import embed_vega %}

{% block scripts %}
{{ super() }}
<script src="https://cdn.jsdelivr.net/npm/vega@5"></script>
<script src="https://cdn.jsdelivr.net/npm/vega-lite@5.20.1"></script>
<script src="https://cdn.jsdelivr.net/npm/vega-embed@6"></script>
{% include 'vega-embed-js.html' %}

{% set chart_spec_id_list = [(cases_map_json, 'cases_map')] %}
{% if cost_map_json %}
{% set chart_spec_id_list = chart_spec_id_list + [(cost_map_json, 'cost_map')] %}
{% endif %}
{{ embed_vega(chart_spec_id_list) }}
{% endblock scripts %}
Loading
Loading