Skip to content
Snippets Groups Projects
Commit eb8515d8 authored by xo30xoqa's avatar xo30xoqa
Browse files

Minor additions to utils.jl

parent 0366f200
No related branches found
No related tags found
No related merge requests found
......@@ -257,7 +257,7 @@ function visualiseoutput(model::SimulationModel) #XXX remove this? (#81)
CairoMakie.activate!() # make sure we're using Cairo
for o in keys(model.dataoutputs)
output = model.dataoutputs[o]
isnothing(output.plotfunction) && continue
(output.frequency == "never" || isnothing(output.plotfunction)) && continue
figure = output.plotfunction(model)
isnothing(figure) ? continue :
save(joinpath(@param(core.outdir), o*"."*@param(core.figureformat)), figure)
......
......@@ -46,16 +46,19 @@ end
# Allows writing `(August, 2)` instead of `AnnualDate(August, 2)` where an AnnualDate is expected.
AnnualDate(ad::Tuple{Int64,Int64}) = AnnualDate(ad...)
Base.convert(::Type{AnnualDate}, ad::Tuple{Int64,Int64}) = AnnualDate(ad)
Base.convert(::Type{Tuple{Int64,Int64}}, ad::AnnualDate) = (ad.month, ad.day)
# allow creating AnnualDates from a string of the format "8 August"
AnnualDate(ad::String) = AnnualDate(Date(ad, dateformat"d U"))
Base.convert(::Type{AnnualDate}, ad::String) = AnnualDate(ad)
Base.tryparse(::Type{AnnualDate}, ad::String) = AnnualDate(ad)
# Interface with Dates
AnnualDate(date::Date) = AnnualDate(month(date), day(date))
Base.convert(::Type{AnnualDate}, ad::Date) = AnnualDate(ad)
Dates.month(ad::AnnualDate) = ad.month
Dates.day(ad::AnnualDate) = ad.day
Dates.monthday(ad::AnnualDate) = (ad.month, ad.day)
Date(year::Int64, ad::AnnualDate) = Date(year, ad.month, ad.day)
# Comparison between AnnualDates and with Dates
......@@ -167,6 +170,19 @@ function bounds(x::Number; max::Number=Inf, min::Number=0)
x
end
"""
cycle!(vector, n=1)
Move the first element of the vector to the end, repeat n times.
"""
function cycle!(v::AbstractVector, n::Int64=1)
for i in 1:n
push!(v, v[1])
deleteat!(v, 1)
end
v
end
"""
@areaof(npixels)
......
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