diff --git a/routes/arctic_hydrology.py b/routes/arctic_hydrology.py index ad9bd216..9427c2d2 100644 --- a/routes/arctic_hydrology.py +++ b/routes/arctic_hydrology.py @@ -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 @@ -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 @@ -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( @@ -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: @@ -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( @@ -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: