Skip to content
Snippets Groups Projects
Commit 1cb56523 authored by Julian Stürmer's avatar Julian Stürmer
Browse files

Add functions for visualizing hurricane impacts

parent 669f4623
No related branches found
No related tags found
No related merge requests found
#* Functions for plotting hurricane impacts modelled in Impact.jl
#*------------------------------------------------------------------------------
function plothist_tl_failures(
γ_values::Array{Float64,1},
N_runs::Int64,
rstep = 20; # number of realizations that were saved together
datapath="", # path to folder containing different γ scans
plotpath="" # where to save the plot
)
N_γ = length(γ_values) # number of given γ values
mean_Nf_arr = zeros(N_γ) # array for mean number of line failures
σ_arr = zeros(N_γ) # array for standard deviations
### Go through γ values and plot the respective histogram
for i in 1:N_γ
mean_Nf, σ = plothist_tl_failures(
γ_values[i], N_runs, rstep, datapath=datapath, plotpath=plotpath
)
mean_Nf_arr[i] = mean_Nf # save mean number of failures
σ_arr[i] = σ # save standard deviation
end
return mean_Nf_arr, σ_arr
end
function plothist_tl_failures(
γ::Float64,
N_runs::Int64,
rstep = 20; # number of realizations that were saved together
datapath::String, # path to folder containing data files
plotpath::String # where to save the plot
)
Nf = zeros(Int64, N_runs) # array for number of failures
### Read data and save the number of failures that occured in each run
for i in rstep:rstep:N_runs
res = load(datapath * "gamma$γ/" * "results_$γ" * "_$i.jld2", "result")
for j in 1:rstep
Nf[i-rstep+j] = length(res[j])
end
end
### Plot a historgram of the number of failures
N_bins = maximum(Nf) - minimum(Nf) # number of bins
n, bins, patches = plt[:hist](Nf, bins=N_bins, edgecolor="k")
### Calculate mean number of failures and standard deviation
mean_Nf = round(mean!([1.], Nf)[1], digits=1)
σ = round(std(Nf, mean=mean_Nf), digits=1)
### Legend with γ, mean number of failures and standard deviation
mlines = pyimport("matplotlib.lines")
no_marker = mlines.Line2D([], [], ls="None")
plt.legend(
[no_marker for i in 1:4],
[L"γ = " * "$γ",
L"N_r = " * "$N_runs",
L"\bar{N}_\mathrm{f} \approx" * "$mean_Nf",
L"\sigma_\mathrm{f} \approx" * "$σ"],
handletextpad = 0, handlelength = 0
)
### Axes labels
plt.xlabel("Number of line failures " * L"N_\mathrm{f}")
plt.ylabel("Frequency")
### Save and close figure
figpath = plotpath * "Texas_hist_tl_failures_gamma$γ.png"
plt.savefig(figpath, bbox_inches="tight")
plt.clf()
return mean_Nf, σ
end
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment