Skip to content

Commit

Permalink
give up on mpl animate, fix alt az
Browse files Browse the repository at this point in the history
  • Loading branch information
palumbom committed Jan 27, 2025
1 parent 04f144d commit a2c4245
Showing 1 changed file with 66 additions and 70 deletions.
136 changes: 66 additions & 70 deletions scripts/plot_eclipse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,16 @@ using PyCall; animation = pyimport("matplotlib.animation");
using LaTeXStrings

# get python imports
# wcs = pyimport("astropy.wcs")
# SkyCoord = pyimport("astropy.coordinates").SkyCoord
# RegionGeom = pyimport("gammapy.maps").RegionGeom
# CircleSkyRegion = pyimport("regions").CircleSkyRegion
# WCSAxes = pyimport("astropy.visualization.wcsaxes").WCSAxes
# coord = pyimport("astropy.coordinates")
# u = pyimport("astropy.units")
# AltAz = pyimport("astropy.coordinates").AltAz
# EarthLocation = pyimport("astropy.coordinates").EarthLocation
# apTime = pyimport("astropy.time").Time
wcs = pyimport("astropy.wcs")
SkyCoord = pyimport("astropy.coordinates").SkyCoord
RegionGeom = pyimport("gammapy.maps").RegionGeom
CircleSkyRegion = pyimport("regions").CircleSkyRegion
WCSAxes = pyimport("astropy.visualization.wcsaxes").WCSAxes
coord = pyimport("astropy.coordinates")
u = pyimport("astropy.units")
AltAz = pyimport("astropy.coordinates").AltAz
EarthLocation = pyimport("astropy.coordinates").EarthLocation
apTime = pyimport("astropy.time").Time

# get kernels
GRASS.get_kernels()
Expand Down Expand Up @@ -87,13 +87,13 @@ obs_alt = 2.097938

# get time_stamps
# time_stamps = range(utc2et("2023-10-14T14:00:00.0"), utc2et.("2023-10-14T19:00:00.0"), step = 100.0)
time_stamps = ["2023-10-14T15:26:45.500000", "2023-10-14T15:28:07.500000", "2023-10-14T15:29:30.500000", "2023-10-14T15:30:53.500000", "2023-10-14T15:32:15.500000", "2023-10-14T15:33:38.500000", "2023-10-14T15:35:01.500000", "2023-10-14T15:36:23.500000", "2023-10-14T15:37:46.500000", "2023-10-14T15:39:09.500000", "2023-10-14T15:40:31.500000", "2023-10-14T15:41:54.500000", "2023-10-14T15:43:17.500000", "2023-10-14T15:44:39.500000", "2023-10-14T15:46:02.500000", "2023-10-14T15:47:25.500000", "2023-10-14T15:48:47.500000", "2023-10-14T15:50:10.500000", "2023-10-14T15:51:33.500000", "2023-10-14T15:52:56.500000", "2023-10-14T15:54:18.500000", "2023-10-14T15:55:41.500000", "2023-10-14T15:57:04.500000", "2023-10-14T15:58:26.500000", "2023-10-14T15:59:49.500000", "2023-10-14T16:01:12.500000", "2023-10-14T16:02:34.500000", "2023-10-14T16:03:57.500000", "2023-10-14T16:05:20.500000", "2023-10-14T16:06:42.500000", "2023-10-14T16:08:05.500000", "2023-10-14T16:09:28.500000", "2023-10-14T16:10:50.500000", "2023-10-14T16:12:13.500000", "2023-10-14T16:13:36.500000", "2023-10-14T16:14:58.500000", "2023-10-14T16:16:21.500000", "2023-10-14T16:17:44.500000", "2023-10-14T16:19:06.500000", "2023-10-14T16:20:29.500000", "2023-10-14T16:21:52.500000", "2023-10-14T16:23:15.500000", "2023-10-14T16:24:37.500000", "2023-10-14T16:26:00.500000", "2023-10-14T16:27:23.500000", "2023-10-14T16:28:45.500000", "2023-10-14T16:30:08.500000", "2023-10-14T16:31:31.500000", "2023-10-14T16:32:53.500000", "2023-10-14T16:34:16.500000", "2023-10-14T16:35:39.500000", "2023-10-14T16:37:01.500000", "2023-10-14T16:38:24.500000", "2023-10-14T16:39:47.500000", "2023-10-14T16:41:09.500000", "2023-10-14T16:42:32.500000", "2023-10-14T16:43:55.500000", "2023-10-14T16:45:17.500000", "2023-10-14T16:46:40.500000", "2023-10-14T16:48:03.500000", "2023-10-14T16:49:25.500000", "2023-10-14T16:50:48.500000", "2023-10-14T16:52:11.500000", "2023-10-14T16:53:33.500000", "2023-10-14T16:54:56.500000", "2023-10-14T16:56:19.500000", "2023-10-14T16:57:42.500000", "2023-10-14T16:59:04.500000", "2023-10-14T17:00:27.500000", "2023-10-14T17:01:50.500000", "2023-10-14T17:03:12.500000", "2023-10-14T17:04:35.500000", "2023-10-14T17:05:58.500000", "2023-10-14T17:07:20.500000", "2023-10-14T17:08:43.500000", "2023-10-14T17:10:06.500000", "2023-10-14T17:11:28.500000", "2023-10-14T17:12:51.500000", "2023-10-14T17:14:14.500000", "2023-10-14T17:15:36.500000", "2023-10-14T17:16:59.500000", "2023-10-14T17:18:22.500000", "2023-10-14T17:19:44.500000", "2023-10-14T17:21:07.500000", "2023-10-14T17:22:30.500000", "2023-10-14T17:23:52.500000", "2023-10-14T17:25:15.500000", "2023-10-14T17:26:38.500000", "2023-10-14T17:28:01.500000", "2023-10-14T17:29:23.500000", "2023-10-14T17:30:46.500000", "2023-10-14T17:32:09.500000", "2023-10-14T17:33:31.500000", "2023-10-14T17:34:54.500000", "2023-10-14T17:36:17.500000", "2023-10-14T17:37:39.500000", "2023-10-14T17:39:02.500000", "2023-10-14T17:40:25.500000", "2023-10-14T17:41:47.500000", "2023-10-14T17:43:10.500000", "2023-10-14T17:44:33.500000", "2023-10-14T17:45:55.500000", "2023-10-14T17:47:18.500000", "2023-10-14T17:48:41.500000", "2023-10-14T17:50:03.500000", "2023-10-14T17:51:26.500000", "2023-10-14T17:52:49.500000", "2023-10-14T17:54:11.500000", "2023-10-14T17:55:34.500000", "2023-10-14T17:56:57.500000", "2023-10-14T17:58:20.500000", "2023-10-14T17:59:42.500000", "2023-10-14T18:01:05.500000", "2023-10-14T18:02:28.500000", "2023-10-14T18:03:50.500000", "2023-10-14T18:05:13.500000", "2023-10-14T18:06:36.500000", "2023-10-14T18:07:58.500000", "2023-10-14T18:09:21.500000", "2023-10-14T18:10:44.500000", "2023-10-14T18:12:06.500000", "2023-10-14T18:13:29.500000", "2023-10-14T18:14:52.500000", "2023-10-14T18:16:14.500000", "2023-10-14T18:17:37.500000", "2023-10-14T18:19:00.500000", "2023-10-14T18:20:22.500000", "2023-10-14T18:21:45.500000", "2023-10-14T18:23:08.500000", "2023-10-14T18:24:30.500000", "2023-10-14T18:25:53.500000", "2023-10-14T18:27:16.500000", "2023-10-14T18:28:38.500000", "2023-10-14T18:30:01.500000", "2023-10-14T18:31:24.500000", "2023-10-14T18:32:47.500000", "2023-10-14T18:34:09.500000", "2023-10-14T18:35:32.500000", "2023-10-14T18:36:55.500000", "2023-10-14T18:38:17.500000", "2023-10-14T18:39:40.500000", "2023-10-14T18:41:03.500000", "2023-10-14T18:42:25.500000", "2023-10-14T18:43:48.500000", "2023-10-14T18:45:11.500000", "2023-10-14T18:46:33.500000", "2023-10-14T18:47:56.500000", "2023-10-14T18:49:19.500000", "2023-10-14T18:50:41.500000", "2023-10-14T18:52:04.500000", "2023-10-14T18:53:27.500000", "2023-10-14T18:54:49.500000", "2023-10-14T18:56:12.500000", "2023-10-14T18:57:35.500000", "2023-10-14T18:58:57.500000", "2023-10-14T19:00:20.500000", "2023-10-14T19:01:43.500000", "2023-10-14T19:03:06.500000"]
time_stamps = utc2et.(time_stamps)
time_stamps_utc = ["2023-10-14T15:26:45.500000", "2023-10-14T15:28:07.500000", "2023-10-14T15:29:30.500000", "2023-10-14T15:30:53.500000", "2023-10-14T15:32:15.500000", "2023-10-14T15:33:38.500000", "2023-10-14T15:35:01.500000", "2023-10-14T15:36:23.500000", "2023-10-14T15:37:46.500000", "2023-10-14T15:39:09.500000", "2023-10-14T15:40:31.500000", "2023-10-14T15:41:54.500000", "2023-10-14T15:43:17.500000", "2023-10-14T15:44:39.500000", "2023-10-14T15:46:02.500000", "2023-10-14T15:47:25.500000", "2023-10-14T15:48:47.500000", "2023-10-14T15:50:10.500000", "2023-10-14T15:51:33.500000", "2023-10-14T15:52:56.500000", "2023-10-14T15:54:18.500000", "2023-10-14T15:55:41.500000", "2023-10-14T15:57:04.500000", "2023-10-14T15:58:26.500000", "2023-10-14T15:59:49.500000", "2023-10-14T16:01:12.500000", "2023-10-14T16:02:34.500000", "2023-10-14T16:03:57.500000", "2023-10-14T16:05:20.500000", "2023-10-14T16:06:42.500000", "2023-10-14T16:08:05.500000", "2023-10-14T16:09:28.500000", "2023-10-14T16:10:50.500000", "2023-10-14T16:12:13.500000", "2023-10-14T16:13:36.500000", "2023-10-14T16:14:58.500000", "2023-10-14T16:16:21.500000", "2023-10-14T16:17:44.500000", "2023-10-14T16:19:06.500000", "2023-10-14T16:20:29.500000", "2023-10-14T16:21:52.500000", "2023-10-14T16:23:15.500000", "2023-10-14T16:24:37.500000", "2023-10-14T16:26:00.500000", "2023-10-14T16:27:23.500000", "2023-10-14T16:28:45.500000", "2023-10-14T16:30:08.500000", "2023-10-14T16:31:31.500000", "2023-10-14T16:32:53.500000", "2023-10-14T16:34:16.500000", "2023-10-14T16:35:39.500000", "2023-10-14T16:37:01.500000", "2023-10-14T16:38:24.500000", "2023-10-14T16:39:47.500000", "2023-10-14T16:41:09.500000", "2023-10-14T16:42:32.500000", "2023-10-14T16:43:55.500000", "2023-10-14T16:45:17.500000", "2023-10-14T16:46:40.500000", "2023-10-14T16:48:03.500000", "2023-10-14T16:49:25.500000", "2023-10-14T16:50:48.500000", "2023-10-14T16:52:11.500000", "2023-10-14T16:53:33.500000", "2023-10-14T16:54:56.500000", "2023-10-14T16:56:19.500000", "2023-10-14T16:57:42.500000", "2023-10-14T16:59:04.500000", "2023-10-14T17:00:27.500000", "2023-10-14T17:01:50.500000", "2023-10-14T17:03:12.500000", "2023-10-14T17:04:35.500000", "2023-10-14T17:05:58.500000", "2023-10-14T17:07:20.500000", "2023-10-14T17:08:43.500000", "2023-10-14T17:10:06.500000", "2023-10-14T17:11:28.500000", "2023-10-14T17:12:51.500000", "2023-10-14T17:14:14.500000", "2023-10-14T17:15:36.500000", "2023-10-14T17:16:59.500000", "2023-10-14T17:18:22.500000", "2023-10-14T17:19:44.500000", "2023-10-14T17:21:07.500000", "2023-10-14T17:22:30.500000", "2023-10-14T17:23:52.500000", "2023-10-14T17:25:15.500000", "2023-10-14T17:26:38.500000", "2023-10-14T17:28:01.500000", "2023-10-14T17:29:23.500000", "2023-10-14T17:30:46.500000", "2023-10-14T17:32:09.500000", "2023-10-14T17:33:31.500000", "2023-10-14T17:34:54.500000", "2023-10-14T17:36:17.500000", "2023-10-14T17:37:39.500000", "2023-10-14T17:39:02.500000", "2023-10-14T17:40:25.500000", "2023-10-14T17:41:47.500000", "2023-10-14T17:43:10.500000", "2023-10-14T17:44:33.500000", "2023-10-14T17:45:55.500000", "2023-10-14T17:47:18.500000", "2023-10-14T17:48:41.500000", "2023-10-14T17:50:03.500000", "2023-10-14T17:51:26.500000", "2023-10-14T17:52:49.500000", "2023-10-14T17:54:11.500000", "2023-10-14T17:55:34.500000", "2023-10-14T17:56:57.500000", "2023-10-14T17:58:20.500000", "2023-10-14T17:59:42.500000", "2023-10-14T18:01:05.500000", "2023-10-14T18:02:28.500000", "2023-10-14T18:03:50.500000", "2023-10-14T18:05:13.500000", "2023-10-14T18:06:36.500000", "2023-10-14T18:07:58.500000", "2023-10-14T18:09:21.500000", "2023-10-14T18:10:44.500000", "2023-10-14T18:12:06.500000", "2023-10-14T18:13:29.500000", "2023-10-14T18:14:52.500000", "2023-10-14T18:16:14.500000", "2023-10-14T18:17:37.500000", "2023-10-14T18:19:00.500000", "2023-10-14T18:20:22.500000", "2023-10-14T18:21:45.500000", "2023-10-14T18:23:08.500000", "2023-10-14T18:24:30.500000", "2023-10-14T18:25:53.500000", "2023-10-14T18:27:16.500000", "2023-10-14T18:28:38.500000", "2023-10-14T18:30:01.500000", "2023-10-14T18:31:24.500000", "2023-10-14T18:32:47.500000", "2023-10-14T18:34:09.500000", "2023-10-14T18:35:32.500000", "2023-10-14T18:36:55.500000", "2023-10-14T18:38:17.500000", "2023-10-14T18:39:40.500000", "2023-10-14T18:41:03.500000", "2023-10-14T18:42:25.500000", "2023-10-14T18:43:48.500000", "2023-10-14T18:45:11.500000", "2023-10-14T18:46:33.500000", "2023-10-14T18:47:56.500000", "2023-10-14T18:49:19.500000", "2023-10-14T18:50:41.500000", "2023-10-14T18:52:04.500000", "2023-10-14T18:53:27.500000", "2023-10-14T18:54:49.500000", "2023-10-14T18:56:12.500000", "2023-10-14T18:57:35.500000", "2023-10-14T18:58:57.500000", "2023-10-14T19:00:20.500000", "2023-10-14T19:01:43.500000", "2023-10-14T19:03:06.500000"]
time_stamps = utc2et.(time_stamps_utc)

# set up disk params
N = 197
N = 40
Nt = length(time_stamps)
Nsubgrid = 40
Nsubgrid = 8
disk = GRASS.DiskParamsEclipse(N=N, Nt=Nt, Nsubgrid=Nsubgrid)

# stuff for line
Expand All @@ -117,50 +117,14 @@ neid_ext_coeff = extinction_coeff[extinction_coeff[!, "Wavelength"] .== lines[1]
# allocate memory for gpu
gpu_allocs = GRASS.GPUAllocsEclipse(spec, disk, length(spec.lines))

# create a WCS for the projection
# w = wcs.WCS(naxis=2)
# w.wcs.ctype = ["RA---ZEA", "DEC--ZEA"]

# get the earth location
# earth_loc = EarthLocation(lat=obs_lat * u.deg, lon=obs_long * u.deg, height = obs_alt * u.km)

# the_coord = SkyCoord(az[1], alt[1], unit="deg", frame="altaz",)
# wcs = RegionGeom(CircleSkyRegion(center=the_coord, radius=0.5 * u.deg)).wcs

# initialize figure objects outside time loop
fig = plt.figure()
# ax1 = plt.subplot(projection=wcs)#projection=w)
ax1 = plt.subplot()#projection=w)

# make colormap for data
cmap = plt.cm.seismic
# norm = mpl.colors.Normalize(vmin=minimum(dat), vmax=maximum(dat))
norm = mpl.colors.Normalize(vmin=-2400, vmax=2400)
smap = plt.cm.ScalarMappable(cmap=cmap, norm=norm)

# add a colorbar
fig.colorbar(smap, ax=ax1, orientation="vertical", label="Velocity (m/s)")

# set labels
ax1.set_xlabel(L"{\rm Azimuth\ (deg)}", labelpad=10)
ax1.set_ylabel(L"{\rm Altitide\ (deg)}", labelpad=10)

# set limits
# ax1.set_xlim(100.0, 210.0)
# ax1.set_ylim(0.0, 50.0)
# ax1.set_aspect("equal")

# ax1.set_xlim(reverse(ax1.get_xlim())...)
# ax1.set_xlabel(L"{\rm Right\ Ascension}")
# ax1.set_ylabel(L"{\rm Declination}")

# function to loop over time
function sun_at_time(t)
# t = length(time_stamps) - 1
# python is zero-indexed
# t += 1
t = length(time_stamps)
# create a subdir to write to
outdir = joinpath(pwd(), "eclipse_frames")
if !isdir(outdir)
mkdir(outdir)
end

# loop over timestamps
for t in eachindex(time_stamps)
# get the geometry data
GRASS.calc_eclipse_quantities_gpu!(time_stamps[t], obs_long, obs_lat, obs_alt, lines,
LD_type, 1.0, neid_ext_coeff[1], disk, gpu_allocs)
Expand Down Expand Up @@ -200,6 +164,46 @@ function sun_at_time(t)
dat[μs .<= 0.0] .= NaN
dat[isnan.(μs)] .= NaN

# create a WCS for the projection
# w = wcs.WCS(naxis=2)
# w.wcs.ctype = ["RA---ZEA", "DEC--ZEA"]

# get the earth location
# earth_loc = EarthLocation(lat=obs_lat * u.deg, lon=obs_long * u.deg, height = obs_alt * u.km)

the_coord = SkyCoord(az[1], alt[1], unit="deg", frame="icrs")
# the_frame = AltAz(obstime=apTime(time_stamps_utc[1]), location=earth_loc)
the_wcs = RegionGeom(CircleSkyRegion(center=the_coord, radius=0.5 * u.deg)).wcs

# the_wcs = wcs.WCS(naxis=2)
# the_wcs.wcs.ctype = ["RA---TAN", "DEC--TAN"] # Azimuth and Altitude
# the_wcs.wcs.crval = [180, 90] # Reference point
# the_wcs.wcs.cdelt = [-1, 1] # Scaling (degrees/pixel)
# the_wcs.wcs.crpix = [180, 45] # Reference pixel

# set up figure
fig = plt.figure()
ax1 = plt.subplot(projection=the_wcs)

# set unit
# ax1.coords[1].set_format_unit("deg", show_decimal_unit=true)
# ax1.coords[2].set_format_unit("deg", show_decimal_unit=true)
ax1.coords[1].set_major_formatter("d.dd")
ax1.coords[2].set_major_formatter("d.dd")
# ax1.coords[1].set_axislabel("Azimuth (deg)")
# ax1.coords[2].set_axislabel("Altitude (deg)")
ax1.set_xlabel("Azimuth (deg)")
ax1.set_ylabel("Altitude (deg)")

# make colormap for data
cmap = plt.cm.seismic
# norm = mpl.colors.Normalize(vmin=minimum(dat), vmax=maximum(dat))
norm = mpl.colors.Normalize(vmin=-2400, vmax=2400)
smap = plt.cm.ScalarMappable(cmap=cmap, norm=norm)

# add a colorbar
fig.colorbar(smap, ax=ax1, orientation="vertical", label="Velocity (m/s)")

# clear collections if they exist
if t > 1
for artist in ax1.patches
Expand Down Expand Up @@ -239,18 +243,10 @@ function sun_at_time(t)
push!(fills, this_fill)
end
end

# get limits
buff = 0.05
ax1.set_xlim(minimum(az[.!idx]) - buff, maximum(az[.!idx]) + buff)
ax1.set_ylim(minimum(alt[.!idx]) - buff, maximum(alt[.!idx]) + buff)
ax1.set_aspect("equal")#, "datalim")
return nothing
fig.savefig(joinpath(outdir, "eclipse_" * string(t) * ".png"))
plt.close()
end

ani = animation.FuncAnimation(fig, sun_at_time, frames=length(time_stamps)-1, interval=1)
ani.save(filename="eclipse2.gif", writer="pillow", fps=8)
ani.event_source.stop()
plt.close("all")

# plt.show()
### then use gifski on command line to stitch together pngs
### download the cli exe here: https://gif.ski
# gifski -o output.gif eclipse_*.png --fps=8

0 comments on commit a2c4245

Please sign in to comment.