Skip to content

Commit

Permalink
clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
wtbarnes committed Apr 5, 2024
1 parent 3ed071f commit ec78531
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 28 deletions.
24 changes: 10 additions & 14 deletions posts/2024/2024-04-03-eclipse.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"id": "ada63743",
"metadata": {},
"source": [
"On April 8th, 2024, [a total solar eclipse will pass over North America](https://science.nasa.gov/eclipses/future-eclipses/eclipse-2024/).\n",
"On April 8th, 2024, [a total solar eclipse will pass over North America](https://science.nasa.gov/eclipses/).\n",
"A total solar eclipse happens when the Moon passes between the Sun and Earth, completely blocking the face of the Sun.\n",
"Only during totality, when the bright disk is completely obscured, is it possible to see the with the naked eye the solar corona, the outermost layer of the Sun's atmosphere.\n",
"The total solar eclipse will give millions across North America the chance to see and photograph the solar corona.\n",
Expand All @@ -47,16 +47,13 @@
"metadata": {},
"outputs": [],
"source": [
"import datetime\n",
"\n",
"import numpy as np\n",
"import matplotlib.image\n",
"import matplotlib.pyplot as plt\n",
"import astropy.units as u\n",
"import scipy.ndimage as ndimage\n",
"\n",
"from astropy.coordinates import EarthLocation, SkyCoord\n",
"from astropy.time import Time\n",
"from matplotlib.patches import Circle\n",
"from photutils.detection import DAOStarFinder\n",
"from skimage.transform import hough_circle, hough_circle_peaks\n",
Expand All @@ -65,6 +62,7 @@
"import sunpy.coordinates\n",
"from sunpy.map.header_helper import make_fitswcs_header\n",
"from sunpy.net import Fido, attrs as a\n",
"from sunpy.time import parse_time\n",
"\n",
"import exifread\n",
"\n",
Expand All @@ -80,7 +78,8 @@
"## Read in Your Eclipse Photo\n",
"\n",
"The first step is to read in our image.\n",
"As mentioned above, we will be using an image taken during the 2017 eclipse taken with a consumer-grade camera."
"As mentioned above, we will be using an image taken during the 2017 eclipse taken with a consumer-grade camera.\n",
"When reading in our image data, we'll invert the y-axis and average over the \"color\" dimension."
]
},
{
Expand All @@ -90,9 +89,7 @@
"metadata": {},
"outputs": [],
"source": [
"# read in the image and flip it so that it's correct\n",
"im_rgb = np.flipud(matplotlib.image.imread(SOLAR_ECLIPSE_IMAGE))\n",
"# remove color info\n",
"im = np.average(im_rgb, axis=2)"
]
},
Expand Down Expand Up @@ -127,7 +124,8 @@
"metadata": {},
"outputs": [],
"source": [
"tags = exifread.process_file(open(SOLAR_ECLIPSE_IMAGE, 'rb'))"
"with open(SOLAR_ECLIPSE_IMAGE, mode='rb') as f:\n",
" tags = exifread.process_file(f)"
]
},
{
Expand All @@ -145,8 +143,7 @@
"id": "42544bdb",
"metadata": {},
"source": [
"As it turns out, the time on our camera we used to take this eclipse photo was wrong, we we manually correct it here.\n",
"Don't forget to convert your time to UTC!"
"As it turns out, the time on our camera we used to take this eclipse photo was wrong, we we manually correct it here."
]
},
{
Expand All @@ -156,7 +153,7 @@
"metadata": {},
"outputs": [],
"source": [
"camera_metadata[\"time\"] = datetime.datetime(2017, 8, 21, 17, 27, 13)"
"camera_metadata[\"time\"] = parse_time('2017-08-21 17:27:13')"
]
},
{
Expand Down Expand Up @@ -419,8 +416,8 @@
"metadata": {},
"outputs": [],
"source": [
"frame = sunpy.coordinates.Helioprojective(observer=loc.get_itrs(Time(camera_metadata[\"time\"])),\n",
" obstime=Time(camera_metadata[\"time\"]))\n",
"frame = sunpy.coordinates.Helioprojective(observer=loc.get_itrs(camera_metadata[\"time\"]),\n",
" obstime=camera_metadata[\"time\"])\n",
"header = make_fitswcs_header(\n",
" im,\n",
" SkyCoord(0, 0, unit=u.arcsec, frame=frame),\n",
Expand Down Expand Up @@ -763,7 +760,6 @@
"fig = plt.figure(figsize=(9,9))\n",
"ax = plt.subplot(projection=eclipse_map)\n",
"eclipse_map.plot(axes=ax)\n",
"eclipse_map.draw_grid(axes=ax)\n",
"aia_map.plot(axes=ax, autoalign=True)"
]
},
Expand Down
22 changes: 8 additions & 14 deletions posts/2024/eclipse_helpers.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import datetime

import astropy.units as u

from sunpy.time import parse_time


SOLAR_ECLIPSE_IMAGE = "total_solar_eclipse2017.jpg"


def _convert_to_degress(value):
"""
Helper function to convert the GPS coordinates stored in the EXIF to degrees in float format
"""
d = float(value.values[0].num) / float(value.values[0].den)
m = float(value.values[1].num) / float(value.values[1].den)
s = float(value.values[2].num) / float(value.values[2].den)
d = float(value.values[0].num) / float(value.values[0].den) * u.degree
m = float(value.values[1].num) / float(value.values[1].den) * u.arcminute
s = float(value.values[2].num) / float(value.values[2].den) * u.arcsec

return d + (m / 60.0) + (s / 3600.0)
return d + m + s


def get_exif_location(exif_data):
Expand Down Expand Up @@ -51,14 +52,7 @@ def get_camera_metadata(tags):
camera_metadata["author"] = tags["Image Artist"].values
if "EXIF DateTimeOriginal" in tags:
datetime_str = tags["EXIF DateTimeOriginal"].values.replace(" ", ":").split(":")
camera_metadata["time"] = datetime.datetime(
int(datetime_str[0]),
int(datetime_str[1]),
int(datetime_str[2]),
int(datetime_str[3]),
int(datetime_str[4]),
int(datetime_str[5]),
)
camera_metadata["time"] = parse_time(f"{'-'.join(datetime_str[:3])} {':'.join(datetime_str[3:])}")
if "Image Model" in tags:
camera_metadata["camera_model"] = tags["Image Model"].values

Expand Down

0 comments on commit ec78531

Please sign in to comment.