julia: working animation when out file is video
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
#!/usr/bin/env julia
|
||||
#
|
||||
|
||||
using DataFrames
|
||||
using Dates
|
||||
using CSV
|
||||
@@ -122,7 +122,19 @@ function plot_station_data_to_axis(ax, station_name, station_map, station_x, sta
|
||||
ax.title = "$station_name $obs_time_s"
|
||||
wind_rad = deg2rad(90 - df.WDIR[1])
|
||||
wind_mph = df.WSPD[i]
|
||||
txt = @sprintf "Air: %.1f F, Water: %.1f F, Wind: %.1f mph" df.ATMP[i] df.WTMP[i] wind_mph
|
||||
if ismissing(wind_mph) || ismissing(wind_rad)
|
||||
wind_mph = 0.0
|
||||
wind_rad = 0
|
||||
end
|
||||
atmp = df.ATMP[i]
|
||||
wtmp = df.WTMP[i]
|
||||
if ismissing(atmp)
|
||||
atmp = 0.0
|
||||
end
|
||||
if ismissing(wtmp)
|
||||
wtmp = 0.0
|
||||
end
|
||||
txt = @sprintf "Air: %.1f F, Water: %.1f F, Wind: %.1f mph" atmp wtmp wind_mph
|
||||
wind_vec = 50 * Vec2f(cos(wind_rad), sin(wind_rad)) * wind_mph / 10
|
||||
tooltip!(ax, station_x, station_y, txt; offset=10)
|
||||
arrows!(ax, [Point2f(station_x, station_y)], [wind_vec], fxaa=true,
|
||||
@@ -130,22 +142,27 @@ function plot_station_data_to_axis(ax, station_name, station_map, station_x, sta
|
||||
return ax
|
||||
end
|
||||
|
||||
function save_animation(station_name, out_path, days, real_hour_per_animation_second=1)
|
||||
function save_animation(station_name, out_path, hours, real_hour_per_animation_second)
|
||||
lat, lon = get_station_lat_lon(station_name)
|
||||
station_map, station_x, station_y = get_map(lat, lon, 14)
|
||||
df = get_realtime_dataframe(station_name; timezone=tz"America/New_York")
|
||||
diff_hours = (df.TIME[0] - df.TIME[1]).value / 1000 / 3600
|
||||
fps = real_hour_per_animation_second / diff_hours
|
||||
nframes = fps * days * 24 * 3600
|
||||
diff_hours = (df.TIME[1] - df.TIME[2]).value / 1000 / 3600
|
||||
stride = Int(ceil(real_hour_per_animation_second / diff_hours))
|
||||
println("diff hours ", diff_hours)
|
||||
println("data size ", size(df, 1))
|
||||
println("stride ", stride)
|
||||
end_index = Int(min(stride * hours + 1, size(df, 1)))
|
||||
data_indexes = range(end_index, 1; step=-stride)
|
||||
println("data indexes ", data_indexes)
|
||||
|
||||
fig = Figure(resolution=size(station_map))
|
||||
ax = Axis(fig[1, 1])
|
||||
ax = CairoMakie.Axis(fig[1, 1])
|
||||
hidespines!(ax)
|
||||
hidedecorations!(ax)
|
||||
|
||||
record(fig, out_path, range(1, nframes); framerate=fps) do i
|
||||
record(fig, out_path, data_indexes; framerate=1) do i
|
||||
plot_station_data_to_axis(ax, station_name, station_map,
|
||||
station_x, station_y, df, nframes - i + 1)
|
||||
station_x, station_y, df, end_index - i + 1)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -157,16 +174,20 @@ function main()
|
||||
station_name = ARGS[1]
|
||||
|
||||
out_fname = "$station_name.png"
|
||||
if (length(ARGS) > 1)
|
||||
if length(ARGS) > 1
|
||||
out_fname = ARGS[2]
|
||||
end
|
||||
|
||||
if any(endswith.(out_fname, [".gif", ".webm", ".mp4", ".mkv"]))
|
||||
save_animation(station_name, out_fname, 24, 1)
|
||||
else
|
||||
lat, lon = get_station_lat_lon(station_name)
|
||||
station_map, station_x, station_y = get_map(lat, lon, 14)
|
||||
df = get_realtime_dataframe(station_name; timezone=tz"America/New_York")
|
||||
fig = plot_station_data(station_name, station_map, station_x, station_y,
|
||||
df, 1)
|
||||
save("$station_name.png", fig)
|
||||
save(out_fname, fig)
|
||||
end
|
||||
end
|
||||
|
||||
main()
|
||||
|
||||
Reference in New Issue
Block a user