Skip to content

Commit

Permalink
add functions related to storm track
Browse files Browse the repository at this point in the history
  • Loading branch information
hydrocoast committed Jun 18, 2020
1 parent a3d1c2b commit a6f32b6
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 52 deletions.
7 changes: 6 additions & 1 deletion src/VisClaw.jl
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ include("replaceunit.jl")
# Load
include("loaddata.jl")
include("loadfgmax.jl")
include("loadtrack.jl")
include("loadtopo.jl")
include("loadfort.jl")
include("loadgauge.jl")
Expand All @@ -55,6 +56,7 @@ include("plotsgaugewaveform.jl")
include("plotsgaugevelocity.jl")
include("plotsgaugelocation.jl")
include("plotsfgmax.jl")
include("plotstrack.jl")

using GMT:GMT
# Setup
Expand All @@ -64,13 +66,15 @@ include("gmttopo.jl")
include("gmtgauge.jl")
include("gmtsurface.jl")
include("gmtstorm.jl")
include("gmttrack.jl")

# General functions
export geodata, surgedata, gaugedata, fgmaxdata
export topodata, dtopodata
export loadfgmax
export loadtopo, loaddeform, loaddtopo
export loadgauge
export loadtrack
export loadsurface, loadcurrent, loadstorm
export rmvalue_coarser!
export axesratio
Expand All @@ -89,6 +93,7 @@ export plotstoporange, plotstoporange!
export plotsgaugelocation, plotsgaugelocation!
export plotsgaugewaveform, plotsgaugewaveform!
export plotsgaugevelocity, plotsgaugevelocity!
export plotstrack, plotstrack!
export plotsgif, plotssavefig

# functions with GMT.jl
Expand All @@ -101,6 +106,6 @@ export gmtgaugewaveform, gmtgaugewaveform!
export gmtgaugevelocity, gmtgaugevelocity!
export gmtgaugelocation, gmtgaugelocation!
export gmttoporange!, gmtcoastline!

export gmttrack, gmttrack!

end
11 changes: 7 additions & 4 deletions src/gmtgauge.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,14 @@ gaugexy2mat(gauges::Vector{VisClaw.Gauge}) = permutedims(hcat(getfield.(gauges,
####################################################
"""
gmtgaugelocation(gauge::VisClaw.Gauge; kwargs...)
gmtgaugelocation!(gauge::VisClaw.Gauge; kwargs...)
gmtgaugelocation(gauges::::Vector{VisClaw.Gauge}; kwargs...)
gmtgaugelocation!(gauges::::Vector{VisClaw.Gauge}; kwargs...)
"""
gmtgaugelocation(gauge::VisClaw.Gauge; kwargs...) = GMT.plot([gauge.loc[1] gauge.loc[2]]; kwargs...)
####################################################
"""
gmtgaugelocation!(gauge::VisClaw.Gauge; kwargs...)
gmtgaugelocation!(gauges::::Vector{VisClaw.Gauge}; kwargs...)
$(@doc gmtgaugelocation)
"""
gmtgaugelocation!(gauge::VisClaw.Gauge; kwargs...) = GMT.plot!([gauge.loc[1] gauge.loc[2]]; kwargs...)
####################################################
Expand All @@ -23,21 +24,23 @@ gmtgaugelocation!(gauges::Vector{VisClaw.Gauge}; kwargs...) = GMT.plot!(gaugexy2
####################################################
"""
gmtgaugewaveform(gauge::VisClaw.Gauge; kwargs...)
gmtgaugewaveform!(gauge::VisClaw.Gauge; kwargs...)
"""
gmtgaugewaveform(gauge::VisClaw.Gauge; kwargs...) = GMT.plot(gauge.time, gauge.eta; kwargs...)
####################################################
"""
gmtgaugewaveform!(gauge::VisClaw.Gauge; kwargs...)
$(@doc gmtgaugewaveform)
"""
gmtgaugewaveform!(gauge::VisClaw.Gauge; kwargs...) = GMT.plot!(gauge.time, gauge.eta; kwargs...)
####################################################
"""
gmtgaugevelocity(gauge::VisClaw.Gauge; kwargs...)
gmtgaugevelocity!(gauge::VisClaw.Gauge; kwargs...)
"""
gmtgaugevelocity(gauge::VisClaw.Gauge; kwargs...) = GMT.plot(gauge.time, sqrt.(gauge.u.^2 + gauge.v.^2); kwargs...)
####################################################
"""
gmtgaugevelocity!(gauge::VisClaw.Gauge; kwargs...)
$(@doc gmtgaugevelocity)
"""
gmtgaugevelocity!(gauge::VisClaw.Gauge; kwargs...) = GMT.plot!(gauge.time, sqrt.(gauge.u.^2 + gauge.v.^2); kwargs...)
####################################################
12 changes: 12 additions & 0 deletions src/gmttrack.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
####################################################
"""
gmttrack(track::VisClaw.Track; kwargs...)
gmttrack!(track::VisClaw.Track; kwargs...)
"""
gmttrack(track::VisClaw.Track; kwargs...) = GMT.plot(track.lon, track.lat; kwargs...)
####################################################
"""
$(@doc gmttrack)
"""
gmttrack!(track::VisClaw.Track; kwargs...) = GMT.plot!(track.lon, track.lat; kwargs...)
####################################################
47 changes: 0 additions & 47 deletions src/loaddata.jl
Original file line number Diff line number Diff line change
Expand Up @@ -144,50 +144,3 @@ function fgmaxdata(outdir::String)
# return
return fg
end
#=
###################################
"""
fgmaxgrids = fgmaxdata("simlation/path/_output"::String)
fgmaxgrids = fgmaxdata("simlation/path/_output/fgmax.data"::String)
Function: fgmax.data reader
"""
function fgmaxdata(outdir::String)
# definition of filename
fname = occursin("fgmax.data", basename(outdir)) ? outdir : joinpath(outdir, "fgmax.data")
# check whether exist
if !isfile(fname); error("File $fname is not found."); end
# read all lines
open(fname,"r") do f
global txt = readlines(f)
end
# parse parameters
num_fgmax_val = parse(Int64, split(txt[occursin.("num_fgmax_val",txt)][1],r"\s+")[1])
num_fgmax_grids = parse(Int64, split(txt[occursin.("num_fgmax_grids",txt)][1],r"\s+")[1])
# preallocate
#fgmax_files = Vector{String}(undef, num_fgmax_grids)
fgmaxgrids = Vector{VisClaw.FGmaxGrid}(undef, num_fgmax_grids)
if num_fgmax_grids==0
println("fgmax grid is not specified")
return num_fgmax_val, num_fgmax_grids, fgmax_files
end
# baseline in fgmax.data
baseline = findfirst(x->occursin("num_fgmax_grids", x), txt)
if baseline === nothing; error("Not found: fgmax_grids"); end
for i = 1:num_fgmax_grids
filename = strip(txt[baseline+2i+1])[2:end-1] # remove quotes \'
fgmaxgrids[i] = VisClaw.FGmaxGrid(i, filename, num_fgmax_val)
end
# return
return fgmaxgrids
end
###################################
=#
20 changes: 20 additions & 0 deletions src/loadtrack.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
###################################
"""
track = loadtrack("simlation/path/_output"::String)
track = loadtrack("simlation/path/_output/fort.track"::String)
Function: fort.track reader
"""
function loadtrack(outdir::String)
## definition of filename
fname = occursin("fort.track", basename(outdir)) ? outdir : joinpath(outdir, "fort.track")
## check
isfile(fname) || error("File $fname is not found.")

## load
datorg = readdlm(fname)
datorg[datorg.>1e30] .= NaN

## return
return VisClaw.Track(datorg[:,1], datorg[:,2], datorg[:,3], datorg[:,4])
end
23 changes: 23 additions & 0 deletions src/plotstrack.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
####################################################
"""
plt = plotstrack(track::VisClaw.Track; kwargs...)
plotstrack!(plt::Plots.Plot, track::VisClaw.Track; kwargs...)
plot a typhoon/hurricane track using Plots
"""
function plotstrack!(plt, track::VisClaw.Track; kwargs...)
# parse keyword args
kwdict = KWARG(kwargs)
label, kwdict = VisClaw.kwarg_default(kwdict, VisClaw.parse_label, "")

# plot
plt = Plots.plot!(plt, track.lon, track.lat; axis_ratio=:equal, label=label, kwdict...)
return plt
end
####################################################
"""
$(@doc plotstrack!)
"""
plotstrack(track::VisClaw.Track; kwargs...) = plotstrack!(Plots.plot(), track; kwargs...)
####################################################
18 changes: 18 additions & 0 deletions src/structclaw.jl
Original file line number Diff line number Diff line change
Expand Up @@ -240,3 +240,21 @@ mutable struct FGmax
new(topo,D,v,M,Mflux,Dmin,tD,tv,tM,tMflux,tDmin,tarrival,:second)
end
########################################


########################################
"""
Struct: track data container
"""
struct Track
timelap :: AbstractVector{Float64}
lon :: AbstractVector{Float64}
lat :: AbstractVector{Float64}
direction :: AbstractVector{Float64}
unittime :: Symbol

# Constructor
VisClaw.Track(lon,lat) = new(emptyF,lon,lat,emptyF,:second)
VisClaw.Track(timelap,lon,lat,direction) = new(timelap,lon,lat,direction,:second)
end
########################################

0 comments on commit a6f32b6

Please sign in to comment.