Skip to content

Commit

Permalink
adding notebook for testing
Browse files Browse the repository at this point in the history
  • Loading branch information
pertft committed Oct 1, 2024
1 parent 1d9b13e commit 741feb0
Showing 1 changed file with 108 additions and 0 deletions.
108 changes: 108 additions & 0 deletions demos/testing_normfactor.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "51a73813",
"metadata": {},
"outputs": [],
"source": [
"using Pkg\n",
"using JulES\n",
"using TuLiPa\n",
"using Dates, Statistics"
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "65046806",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"0.06619134772002751"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"TuLiPa.INCLUDEELEMENT[TuLiPa.TypeKey(JulES.ABSTRACT_INFLOW_MODEL, \"TwoStateBucketIfm\")] = JulES.includeTwoStateBucketIfm!\n",
"\n",
"inflowpath = joinpath(dirname(dirname(pwd())), \"input\", \"static_input\") # path to ifm_elements data\n",
"\n",
"ifm_elements = JulES.TuLiPa.getelements(JulES.JSON.parsefile(joinpath(inflowpath, \"ifm_elements.json\")), inflowpath)\n",
"\n",
"TuLiPa.addscenariotimeperiod!(ifm_elements, \"ScenarioTimePeriod\", \n",
" TuLiPa.getisoyearstart(1991), \n",
" TuLiPa.getisoyearstart(2000))\n",
"\n",
"modelobjects = getmodelobjects(ifm_elements)\n",
"ifm_model = modelobjects[TuLiPa.Id(\"AbstractInflowModel\", \"127.13\")]\n",
"\n",
"S0 = 0\n",
"G0 = 0\n",
"itp_Lday = ifm_model.handler.hist_Lday\n",
"itp_P = ifm_model.handler.hist_P\n",
"itp_T = ifm_model.handler.hist_T\n",
"\n",
"start_with_buffer = ifm_model.handler.scen_start - Day(365)\n",
"days = Dates.value( Day(ifm_model.handler.scen_stop - start_with_buffer))\n",
"real_days = Dates.value( Day(ifm_model.handler.scen_stop - ifm_model.handler.scen_start)) \n",
"timepoints_start = days - real_days \n",
"timepoints = collect((1: days))\n",
"\n",
"P = Vector{Float64}([i for i in timepoints])\n",
"T = Vector{Float64}([i for i in timepoints])\n",
"Lday =Vector{Float64}([i for i in timepoints])\n",
"for i in timepoints\n",
" start = ifm_model.handler.scen_start + Day(i - 1)\n",
" P[i] = TuLiPa.getweightedaverage(itp_P, start, JulES.ONEDAY_MS_TIMEDELTA)\n",
" T[i] = TuLiPa.getweightedaverage(itp_T, start, JulES.ONEDAY_MS_TIMEDELTA)\n",
" Lday[i] = TuLiPa.getweightedaverage(itp_Lday, start, JulES.ONEDAY_MS_TIMEDELTA)\n",
"end\n",
"\n",
"itp_method = JulES.SteffenMonotonicInterpolation()\n",
"itp_P = JulES.interpolate(timepoints, P, itp_method)\n",
"itp_T = JulES.interpolate(timepoints, T, itp_method)\n",
"itp_Lday = JulES.interpolate(timepoints, Lday, itp_method)\n",
"\n",
"res = JulES.predict(ifm_model.handler.predictor, S0, G0, itp_Lday, itp_P, itp_T, timepoints);\n",
"\n",
"(Q, _) = res\n",
"Q = Float64.(Q)\n",
"Q = Q[timepoints_start:end]\n",
"Q .= Q .* ifm_model.handler.m3s_per_mm\n",
"\n",
"1 / mean(Q)"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8df5239f",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Julia 1.9.2",
"language": "julia",
"name": "julia-1.9"
},
"language_info": {
"file_extension": ".jl",
"mimetype": "application/julia",
"name": "julia",
"version": "1.9.2"
}
},
"nbformat": 4,
"nbformat_minor": 5
}

0 comments on commit 741feb0

Please sign in to comment.