Skip to content
Merged
Changes from all commits
Commits
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
34 changes: 21 additions & 13 deletions routes/arctic_hydrology.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,10 @@ def package_stats_data(stream_id, ds):
if not np.isnan(v)
}

# Move the historical model above the rest.
historical_data = stats_dict["data"].pop("historical")
stats_dict["data"] = {"historical": historical_data, **stats_dict["data"]}

return stats_dict


Expand Down Expand Up @@ -467,6 +471,10 @@ def package_hydrograph_data(stream_id, datasets):

model_dict[era] = rows

# Move the historical model above the rest.
historical_data = hydrograph_dict["data"].pop("historical")
hydrograph_dict["data"] = {"historical": historical_data, **hydrograph_dict["data"]}

return hydrograph_dict


Expand Down Expand Up @@ -823,6 +831,14 @@ def run_get_arctic_hydrology_modeled_climatology(stream_id):
data_dict = populate_feature_attributes(data_dict, gdf)
data_dict = prune_nulls_with_max_intensity(data_dict)

# apply GCM-projected changes to Blaskey climatology if source is "gcm_diff_applied_to_blaskey"
# PGW models without a 1990-2021 historical era are silently absent from this source;
# they are only available via source=original_gcm.
if source == "gcm_diff_applied_to_blaskey":
data_dict["data"] = calculate_and_apply_gcm_diffs_to_blaskey_climatology(
data_dict["data"]
)

if request.args.get("format") == "csv":
try:
return create_csv(
Expand All @@ -837,14 +853,6 @@ def run_get_arctic_hydrology_modeled_climatology(stream_id):
except Exception:
return render_template("500/server_error.html"), 500

# apply GCM-projected changes to Blaskey climatology if source is "gcm_diff_applied_to_blaskey"
# PGW models without a 1990-2021 historical era are silently absent from this source;
# they are only available via source=original_gcm.
if source == "gcm_diff_applied_to_blaskey":
data_dict["data"] = calculate_and_apply_gcm_diffs_to_blaskey_climatology(
data_dict["data"]
)

return jsonify(data_dict)

except Exception as exc:
Expand Down Expand Up @@ -966,6 +974,11 @@ def run_get_arctic_hydrology_wt_modeled_climatology(stream_id):
data_dict = populate_feature_attributes(data_dict, gdf)
data_dict = prune_nulls_with_max_intensity(data_dict)

if source == "gcm_diff_applied_to_blaskey":
data_dict["data"] = calculate_and_apply_gcm_diffs_to_blaskey_wt_climatology(
data_dict["data"]
)

if request.args.get("format") == "csv":
try:
return create_csv(
Expand All @@ -980,11 +993,6 @@ def run_get_arctic_hydrology_wt_modeled_climatology(stream_id):
except Exception:
return render_template("500/server_error.html"), 500

if source == "gcm_diff_applied_to_blaskey":
data_dict["data"] = calculate_and_apply_gcm_diffs_to_blaskey_wt_climatology(
data_dict["data"]
)

return jsonify(data_dict)

except Exception as exc:
Expand Down
Loading