julia: refactor script for animations
This commit is contained in:
@@ -103,13 +103,23 @@ function get_realtime_dataframe(station_name; timezone=tz"America/New_York")
|
||||
return df
|
||||
end
|
||||
|
||||
function plot_station_data(station_name, station_map, station_x, station_y, df, i)
|
||||
function plot_station_data(station_name, station_map, station_x, station_y,
|
||||
df, i)
|
||||
fig = Figure(resolution=size(station_map))
|
||||
ax = CairoMakie.Axis(fig[1, 1])
|
||||
hidespines!(ax)
|
||||
hidedecorations!(ax)
|
||||
plot_station_data_to_axis(ax, station_name, station_map,
|
||||
station_x, station_y, df, i)
|
||||
return fig
|
||||
end
|
||||
|
||||
function plot_station_data_to_axis(ax, station_name, station_map, station_x, station_y,
|
||||
df, i)
|
||||
obs_time = df.TIME[i]
|
||||
fig, ax, p = image(rotr90(station_map),
|
||||
axis=(aspect=DataAspect(),
|
||||
title="$station_name $obs_time"))
|
||||
hidespines!(ax)
|
||||
hidedecorations!(ax)
|
||||
obs_time_s = Dates.format(obs_time, "e, u d H:MM")
|
||||
image!(ax, rotr90(station_map))
|
||||
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
|
||||
@@ -117,7 +127,26 @@ function plot_station_data(station_name, station_map, station_x, station_y, df,
|
||||
tooltip!(ax, station_x, station_y, txt; offset=10)
|
||||
arrows!(ax, [Point2f(station_x, station_y)], [wind_vec], fxaa=true,
|
||||
linewidth=2, align=:center, arrowhead='⟰')
|
||||
return fig
|
||||
return ax
|
||||
end
|
||||
|
||||
function save_animation(station_name, out_path, days, real_hour_per_animation_second=1)
|
||||
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
|
||||
|
||||
fig = Figure(resolution=size(station_map))
|
||||
ax = Axis(fig[1, 1])
|
||||
hidespines!(ax)
|
||||
hidedecorations!(ax)
|
||||
|
||||
record(fig, out_path, range(1, nframes); framerate=fps) do i
|
||||
plot_station_data_to_axis(ax, station_name, station_map,
|
||||
station_x, station_y, df, nframes - i + 1)
|
||||
end
|
||||
end
|
||||
|
||||
function main()
|
||||
@@ -133,7 +162,7 @@ function main()
|
||||
end
|
||||
|
||||
lat, lon = get_station_lat_lon(station_name)
|
||||
station_map, station_x, station_y = get_map(lat, lon, 14)
|
||||
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)
|
||||
|
||||
Reference in New Issue
Block a user