Skip to content

Commit

Permalink
Merge pull request #89 from uwent/improve-map-images
Browse files Browse the repository at this point in the history
Improve map images
  • Loading branch information
bzbradford authored Aug 30, 2023
2 parents 473c2dd + 571a158 commit fc73102
Show file tree
Hide file tree
Showing 12 changed files with 127 additions and 126 deletions.
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ GEM
rspec-mocks (~> 3.12)
rspec-support (~> 3.12)
rspec-support (3.12.1)
rubocop (1.56.1)
rubocop (1.56.2)
base64 (~> 0.1.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
Expand Down Expand Up @@ -356,7 +356,7 @@ GEM
uglifier (4.2.0)
execjs (>= 0.3.0, < 3)
unicode-display_width (2.4.2)
webmock (3.18.1)
webmock (3.19.1)
addressable (>= 2.8.0)
crack (>= 0.3.2)
hashdiff (>= 0.4.0, < 2.0.0)
Expand Down
19 changes: 10 additions & 9 deletions app/assets/stylesheets/style.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -606,27 +606,28 @@ div .success {

.map-container {
margin-bottom: 1em;
padding: 0 20px;
// padding: 0 20px;

@media #{$small-only} {
padding: 0;
}
}

.map-form {
padding: 10px;
padding: 10px 10px 5px 10px;
border: 1px solid $form-border-color;
border-radius: 5px;
background: $map-form-bg-color;
flex: 1 1 auto;
}

.form-row {
margin-bottom: 1em;
margin-bottom: 10px;
}

.form-row:last-child {
margin-bottom: 0;
.map-form-row {
line-height: 20px;
margin-bottom: 5px;
display: flex;
flex-wrap: wrap;
flex-direction: row;
gap: 5px 15px;
}

.grey {
Expand Down
6 changes: 3 additions & 3 deletions app/controllers/subscribers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class SubscribersController < ApplicationController

def index
# only show the index page when logged out
return redirect_to(action: :manage) unless @subscriber.nil?
redirect_to(action: :manage) unless @subscriber.nil?
end

def new
Expand Down Expand Up @@ -151,7 +151,7 @@ def create
# confirm email
def confirm
@subscriber = Subscriber.find(params[:id])
return redirect_to action: :manage if @subscriber.is_confirmed?
redirect_to action: :manage if @subscriber.is_confirmed?
end

# handle link from confirmation email
Expand Down Expand Up @@ -353,7 +353,7 @@ def disable_subscription
private

def require_session
return reject("You must be logged in to perform this action.") if session[:subscriber].nil?
reject("You must be logged in to perform this action.") if session[:subscriber].nil?
end

def fix_email
Expand Down
12 changes: 11 additions & 1 deletion app/controllers/weather_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@ def et
parse_cumulative_params
@units = params[:units].presence || "in"
@unit_opts = ["in", "mm"]
@cum_stat_opts = ["sum", "avg", "min", "max"]
@stat = params[:stat].presence || @cum_stat_opts[0]
@et_methods = ["classic", "adjusted"]
@et_method = params[:et_method].presence || "classic"
@wi_only = params[:wi_only] == "true"
@map_opts = {
date: @date,
start_date: @start_date,
stat: @start_date ? @stat : nil,
units: @units,
extent: @wi_only ? "wi" : nil
}.compact
Expand Down Expand Up @@ -53,10 +56,13 @@ def insol
parse_cumulative_params
@units = params[:units].presence || "MJ"
@unit_opts = ["MJ", "KWh"]
@cum_stat_opts = ["sum", "avg", "min", "max"]
@stat = params[:stat].presence || @cum_stat_opts[0]
@wi_only = params[:wi_only] == "true"
@map_opts = {
date: @date,
start_date: @start_date,
stat: @start_date ? @stat : nil,
units: @units,
extent: @wi_only ? "wi" : nil
}.compact
Expand All @@ -82,7 +88,8 @@ def weather
@unit_opts = ["F", "C"]
@units = params[:units].presence || @unit_opts[0]
@stat_opts = ["avg", "min", "max"]
@stat = params[:stat].presence || @stat_opts[0]
@cum_stat_opts = @stat_opts
@stat = params[:stat].presence || (@start_date ? @cum_stat_opts[0] : @stat_opts[0])
@temp_selector = true
@wi_only = params[:wi_only] == "true"
@map_opts = {
Expand Down Expand Up @@ -113,10 +120,13 @@ def precip
parse_cumulative_params
@units = params[:units].presence || "in"
@unit_opts = ["mm", "in"]
@cum_stat_opts = ["sum", "avg", "max"]
@stat = params[:stat].presence || @cum_stat_opts[0]
@wi_only = params[:wi_only] == "true"
@map_opts = {
date: @date,
start_date: @start_date,
stat: @start_date ? @stat : nil,
units: @units,
extent: @wi_only ? "wi" : nil
}.compact
Expand Down
2 changes: 1 addition & 1 deletion app/models/t403.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class T403 < ApplicationRecord
def self.description
"Pre-2000 Half-Hourly Weather and Soil"
end

def self.attr_human_readables
[
["date", "Date"],
Expand Down
61 changes: 30 additions & 31 deletions app/views/weather/_map_form__browse.html.erb
Original file line number Diff line number Diff line change
@@ -1,50 +1,49 @@
<div class="box">
<b>Browse single-day maps:</b>
<div class="map-form">
<div class="form-row">
<div class="map-form">
<div class="map-form-row">
<div>
<%= form_tag do %>
Change date:
<label><%= submit_tag "Prev: #{@date - 1}", name: :date %></label>&nbsp;
<% if @date < Date.current - 2.days %>
<label><%= submit_tag "Next: #{@date + 1}", name: :date %></label>&nbsp;
<% end %>
<% if @date < Date.yesterday %>
<label><%= submit_tag "Latest: #{Date.yesterday}", name: :date %></label>
<% end %>
Browse daily maps:
<button type=submit name=date value=<%= @date - 1 %>>&lt;== Prev</button>
<button type=submit name=date value=<%= @date + 1 %> <%= @date < Date.yesterday ? "" : "disabled" %>>Next ==&gt;</button>
<button type=submit name=date value=<%= Date.yesterday %>>Latest</button>
<%= hidden_field_tag :units, @units %>
<% end %>
</div>
<div class="form-row">

<div>
<%= form_tag do %>
<%= hidden_field_tag :units, @units %>
Or enter a specific date:
<%= text_field_tag :date %>&nbsp;<%= submit_tag "Go" %>
<% end %>
</div>
</div>

<div class="form-row">
<%= form_tag do %>
<%= hidden_field_tag :date, @date %>
<% if @unit_opts %>
<span style="margin-right: 2em;">
Units:
<% @unit_opts.each do |unit| %>
<label><%= radio_button_tag :units, unit, @units == unit, onchange: "this.form.submit()" %><%= unit %></label>&nbsp;
<% end %>
</span>
<% end %>
<%= form_tag do %>
<div class="map-form-row">
<%= hidden_field_tag :date, @date %>

<div>
<label>Wisconsin only? <%= check_box_tag :wi_only, true, @wi_only, onchange: "this.form.submit()" %></label>
<% if @stat_opts %>
<p>
</div>

<% if @unit_opts %>
<div>
Units:
<% @unit_opts.each do |unit| %>
<label><%= radio_button_tag :units, unit, @units == unit, onchange: "this.form.submit()" %><%= unit %></label>&nbsp;
<% end %>
</div>
<% end %>
<% if @stat_opts %>
<div>
Summary statistic:
<% @stat_opts.each do |stat| %>
<label><%= radio_button_tag :stat, stat, @stat == stat, onchange: "this.form.submit()" %><%= stat %></label>&nbsp;
<% end %>
</p>
<% end %>
</div>
<% end %>
</div>
</div>
<% end %>
</div>
81 changes: 44 additions & 37 deletions app/views/weather/_map_form__cumulative.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,60 @@
<b>Generate cumulative map:</b>
<div class="map-form">
<%= form_tag do %>
<div class="form-row">
<label>
Start:
<%= date_field_tag :start_date,
@start_date || @date - 1.week,
title: "Start date",
id: "map-date-start",
max: Date.today,
min: Date.new(2016, 1, 1),
onfocusout: "validateDates('start', 'map-date')" %>
</label>
<label>
End:
<%= date_field_tag :end_date,
@date,
title: "End date",
id: "map-date-end",
max: Date.today,
min: Date.new(2016, 1, 1),
onfocusout: "validateDates('end', 'map-date')" %>
</label>
</div>
<%= hidden_field_tag :cumulative, true %>

<div class="map-form-row">
<div>
<label>
Start:
<%= date_field_tag :start_date,
@start_date || @date - 1.week,
title: "Start date",
id: "map-date-start",
max: Date.today,
min: Date.new(2016, 1, 1),
onfocusout: "validateDates('start', 'map-date')" %>
</label>
<label>
End:
<%= date_field_tag :end_date,
@date,
title: "End date",
id: "map-date-end",
max: Date.today,
min: Date.new(2016, 1, 1),
onfocusout: "validateDates('end', 'map-date')" %>
</label>
</div>

<div class="form-row">
<% if @unit_opts %>
<span style="margin-right: 2em;">
<div>
Units:
<% @unit_opts.each do |unit| %>
<label><%= radio_button_tag :units, unit, @units == unit %><%= unit %></label>&nbsp;
<% end %>
</span>
</div>
<% end %>

<div>
<label>Wisconsin only? <%= check_box_tag :wi_only, true, @wi_only %></label>
</div>

<% if @cum_stat_opts %>
<div>
Summary statistic:
<% @cum_stat_opts.each do |stat| %>
<label><%= radio_button_tag :stat, stat, @stat == stat %><%= stat %></label>&nbsp;
<% end %>
</div>
<% end %>
<label>Wisconsin only? <%= check_box_tag :wi_only, true, @wi_only %></label>
</div>

<% if @stat_opts %>
<div class="form-row">
Summary statistic:
<% @stat_opts.each do |stat| %>
<label><%= radio_button_tag :stat, stat, @stat == stat %><%= stat %></label>&nbsp;
<% end %>
<div class="map-form-row">
<div style="min-width:200px; max-width: 100%; margin-left:auto; margin-right:auto;">
<%= submit_tag "Get cumulative map", id: "submit", class: "submit" %>
</div>
<% end %>
<%= hidden_field_tag :cumulative, true %>
<%= submit_tag "Get cumulative map", id: "submit", class: "submit" %>
</div>
<% end %>
</div>
</div>
9 changes: 9 additions & 0 deletions app/views/weather/_map_heading.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<% if @start_date %>
<h3 id="map">
Cumulative map for <%= @start_date.strftime("%b %-d, %Y") %> to <%= @date.strftime("%b %-d, %Y") %> (<%= pluralize((@start_date..@date).count, "day") %>)
</h3>
<% else %>
<h3 id="map">
Daily map for <%= @date.strftime("%b %-d, %Y") %> (<%= pluralize((Date.current - @date).to_i, "day") %> ago)
</h3>
<% end %>
18 changes: 5 additions & 13 deletions app/views/weather/et.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,13 @@
<p>For more details on the science behind these products, see Diak et al, "Agricultural Management Decision Aids Driven by Real-Time Satellite Data", <span style="font-style: italic">Bulletin of the American Meteorological Society</span> 79 (1998): 1345-1355. <%= link_to "Link to article", "https://doi.org/10.1175/1520-0477(1998)079%3C1345:AMDADB%3E2.0.CO;2" %>. <%= link_to "Download PDF", "/Diak-et-al-1998.pdf", target: "_blank" %>.</p>
<p>Daily evapotranspiration maps in the default units are already rendered by our server and can be browsed quickly. Changing the units or using the cumulative map tool below will take around 10 seconds to render the image</p>

<% if @start_date %>
<h4 id="map">Cumulative evapotranspiration map for <%= @start_date.strftime("%b %-d") %> to <%= @date.strftime("%b %-d") %> (<%= pluralize((@start_date..@date).count, "day") %>)</h4>
<% else %>
<h4 id="map">Evapotranspiration map for <%= @date.strftime("%b %-d") %> (<%= pluralize((Date.current - @date).to_i, "day") %> ago)</h4>
<% end %>
<%= render partial: "map_heading" %>
<%= render partial: "map_form__browse" %>
<%= render_async url_for(action: :map_image),
method: "POST",
data: {
endpoint: @endpoint,
query: @map_opts,
caption: "Note: Single-day map color scale is based on min/max values for the entire year."
}.to_json do %>
<%= render layout: "partials/loading" do %>
<p style="margin-top: 10px;"><b>Please wait, loading map may take up to 10 seconds...</b></p>
Expand All @@ -41,18 +36,15 @@
<% end %>
<% end %>
<div class="two-box">
<%= render partial: "map_form__browse" %>
<%= render partial: "map_form__cumulative" %>
</div>
<%= render partial: "map_form__cumulative" %>

<h4>Download evapotranspiration data grid for <%= @date.strftime("%b %-d, %Y") %></h4>
<h3>Download evapotranspiration data grid for <%= @date.strftime("%b %-d, %Y") %></h3>
<ul>
<li><%= link_to "Download entire grid (standard calculation method)", action: :et, format: :csv, params: {date: @date} %></li>
<li><%= link_to "Download entire grid (new adjusted calculation method)", action: :et, format: :csv, params: {date: @date, et_method: "adjusted"} %></li>
</ul>

<h4>Get evapotranspiration data for a single location</h4>
<h3>Get evapotranspiration data for a single location</h3>
<div class="note">
Note: You can click on the map to set the latitude and longitude. The 'adjusted' ET calculation method uses new coefficients under investigation by Ankur Desai and Ammara Talib at the UW Atmospheric and Oceanic Sciences department. The adjusted method will result in slightly lower ET values that may reflect real-world conditions in Wisconsin better than the old method.
</div>
Expand Down
Loading

0 comments on commit fc73102

Please sign in to comment.