diff --git a/posts/2024/2024-04-03-eclipse.ipynb b/posts/2024/2024-04-03-eclipse.ipynb index 0cad1346..b134d638 100644 --- a/posts/2024/2024-04-03-eclipse.ipynb +++ b/posts/2024/2024-04-03-eclipse.ipynb @@ -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", @@ -47,8 +47,6 @@ "metadata": {}, "outputs": [], "source": [ - "import datetime\n", - "\n", "import numpy as np\n", "import matplotlib.image\n", "import matplotlib.pyplot as plt\n", @@ -56,7 +54,6 @@ "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", @@ -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", @@ -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." ] }, { @@ -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)" ] }, @@ -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)" ] }, { @@ -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." ] }, { @@ -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')" ] }, { @@ -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", @@ -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)" ] }, diff --git a/posts/2024/eclipse_helpers.py b/posts/2024/eclipse_helpers.py index 015af508..df6b78f8 100644 --- a/posts/2024/eclipse_helpers.py +++ b/posts/2024/eclipse_helpers.py @@ -1,7 +1,8 @@ -import datetime - import astropy.units as u +from sunpy.time import parse_time + + SOLAR_ECLIPSE_IMAGE = "total_solar_eclipse2017.jpg" @@ -9,11 +10,11 @@ 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): @@ -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