Skip to content

Commit

Permalink
Add julia_warning() function (see edwardlavender/patter#14)
Browse files Browse the repository at this point in the history
  • Loading branch information
edwardlavender committed Oct 21, 2024
1 parent a4f7739 commit 051b949
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ version = "0.1.0"

[deps]
ArchGDAL = "c9ce4bd3-c3d5-55b8-8973-c0e20141b8c3"
Crayons = "a8cc5b0e-0ffa-5ad4-8c14-923d3ee1735f"
DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0"
DataFramesMeta = "1313f7d8-7da2-5740-9ea0-a2ca25f37964"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
Expand Down
12 changes: 12 additions & 0 deletions src/001-utilities.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,18 @@
using Crayons
using DataFrames
using Dates

# julia_warning()
# * This function returns 'warning' messages in red
# * In Patter.jl, we use julia_warning() rather than @warn because the former also forces display on Windows
function julia_warning(msg::String)
crayon = Crayon(foreground = :red)
display(crayon("Warning: " * msg))
nothing
end

# julia_warning("This is a warning!")

# Check the names of a dataframe included required (req) entries
function check_names(input::DataFrame, req)
# If req is a single string, convert to array
Expand Down
2 changes: 1 addition & 1 deletion src/002-spatial.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function asDataFrame(; x::Rasters.Raster, drop_missing::Bool = true)
if drop_missing
dropmissing!(xyz, :map_value)
if nrow(xyz) == 0
@warn "The map only contains missing values: empty DataFrame returned."
julia_warning("The map only contains missing values: empty DataFrame returned.")
end
end
return xyz
Expand Down
2 changes: 1 addition & 1 deletion src/009-particle-filter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ function particle_filter(
stop = t
pos = sort([start, stop])
pos = pos[1]:pos[2]
@warn "Weights from filter ($start -> $finish) are zero at time $t): returning outputs from $(minimum(pos)):$(maximum(pos)). Note that all (log) weights at $t are -Inf."
julia_warning("Weights from filter ($start -> $finish) are zero at time $t): returning outputs from $(minimum(pos)):$(maximum(pos)). Note that all (log) weights at $t are -Inf.")
return (timesteps = collect(pos),
timestamps = timeline[pos],
state = xout[:, pos],
Expand Down

0 comments on commit 051b949

Please sign in to comment.