moon module

A module providing facilities to analyze the moon in an image.

Methods in this module predominantly deal with determining the relationship between the phase of the moon and the apparent size of the moon in an all-sky image. The phase of the moon is provided on a scale from 0.0 (a new moon) to 1.0 (a full moon). Methods are provided to find the position of the moon and sun. The phase of the moon in an eclipse and outside of an eclipse are separated into their own methods. There is also a method provided to plot this data and the model linking the apparent size of the image to the moon phase.

moon.eclipse_phase(d)[source]

Calculate the proportion of the moon that is lit up during an eclipse.

Parameters:d (float) – The distance between the center of Earth”s shadow and the center of the moon in kilometers.
Returns:The phase of the moon, ranging between 0.0 and 1.0, where 0.0 is a new moon and 1.0 is a full moon.
Return type:float
moon.find_moon(img)[source]

Find the (x, y, alt) coordinate of the moon”s center in a given image.

Parameters:img (image.AllSkyImage) – The image.
Returns:
  • x (float) – The x coordinate of the moon”s center.
  • y (float) – The y coordinate of the moon”s center.
  • alt (float) – The altitude angle of the moon”s center.

Notes

The x and y coordinates are corrected for irregularities in the lens using coordinates.galactic_conv.

moon.find_sun(img)[source]

Find the (alt, az) coordinate of the sun”s center in a given image.

Parameters:img (image.AllSkyImage) – The image.
Returns:
  • alt (float) – The altitude coordinate of the sun”s center.
  • az (float) – The azimuth coordinate of the sun”s center.
moon.fit_moon(img, x, y)[source]

Fit a Moffat function to the moon in a given image.

Parameters:
  • img (image.AllSkyImage) – The image.
  • x (float) – The x coordinate of the moon”s center.
  • y (float) – The y coordinate of the moon”s center.
Returns:

The Full Width at Half Maximum of the Moffat function.

Return type:

float

moon.generate_eclipse_data(regen=False)[source]

Generate moon phase data for eclipses.

Parameters:regen (bool, optional) – If True, regen from scratch. Otherwise, load it from a file. Defaults to False.
Returns:
  • truevis (list of lists) – A list containing one or more lists where each list contains values corresponding to an eclipse. Each value is the phase of the moon ranging from 0.0 to 1.0, in an image taken during that night. 0.0 corresponds to a new moon, while 1.0 corresponds to a full moon. The list is ordered in chronological order; that is, the first value within the list is calculated from an image that was taken at the beginning of the eclipse, and the last value is taken from the end of the eclipse. Currently, this is hardcoded such that the first list represents the eclipse on 2018/01/31, and the second list represents the eclipse on 2015/04/04.
  • imvis (list of lists) – A list containing one or more lists where each list contains values corresponding to an eclipse. Each value is the area of the moon, in pixels, in an image taken during that night. The list is ordered in chronological order; that is, the first value within the list is calculated from an image that was taken at the beginning of the eclipse, and the last value is taken from the end of the eclipse. Currently, this is hardcoded such that the first list represents the eclipse on 2018/01/31, and the second list represents the eclipse on 2015/04/04.
moon.generate_plots()[source]

Generate a plot of illuminated fraction versus apparent moon size.

Notes

The eclipse dataset is loaded using generate_eclipse_data and then plotted. The file images.txt contains the illuminated fraction of the moon and the pixel area of the moon in that image. This data is plotted on top of the eclipse data. The illuminated fraction of the moon is found using moon_phase, and the size of the moon in the image is found using moon_size. On top of this data the theoretical moon size model used in moon_circle is plotted. Once all of these are plotted, two versions of the plot are saved, one with a standard y and x axis, and one with a logarithmic y axis.

These plots are saved directly to Images/ under the names “moon-size.png” and “moon-size-log.png.”

moon.moon_circle(frac)[source]

Calculate the estimated pixel radius of the moon based on the fraction of the moon that is illuminated.

Parameters:frac (float) – The proportion of the moon that is illuminated by sunlight.
Returns:The estimated radius of the moon.
Return type:float

Notes

The model used in this method to convert between the fraction of the moon that is illuminated to the estimated pixel area was found by plotting the moon pixel area versus the moon phase and picking representative points to model the relation. The model is designed to always overestimate the size of the moon. The model is defined by interpolating from the following table of representative points:

Moon fraction illuminated Moon area (pixels)
0 650
0.345 4000
0.71 10500
0.88 18000
0.97 30000
1.0 35000
moon.moon_mask(img)[source]

Generate a masking array that covers the moon in a given image.

Parameters:img (image.AllSkyImage) – The image.
Returns:An array where pixels inside the moon are marked with False and those outside the moon are marked with True.
Return type:numpy.ndarray
moon.moon_phase(img)[source]

Calculate the proportion of the moon that is lit up for non-eclipse nights.

Parameters:img (image.AllSkyImage) – The image.
Returns:The phase of the moon, ranging between 0.0 and 1.0, where 0.0 is a new moon and 1.0 is a full moon.
Return type:float
moon.moon_size(img)[source]

Calculate the area of the moon in pixels in a given image.

Parameters:img (image.AllSkyImage) – The image.
Returns:The size of the moon in pixels.
Return type:int

Notes

This method first converts the image to a black and white two-tone image where pixels with greyscale values above or equal to 250 is set to white and everything below is set to black. A binary closing is performed on the image, which smooths over any small black pixel regions within the moon. These black regions are created when the pixels are brighter than the maximum of 255 for white pixels and overflow back to 0. The white regions are labeled and their sizes are found using ndimage.label. Then, the approximate position of the center of the moon is found using find_moon.

If the pixel at the moon”s center is black (due to aforementioned pixel value overflow), the nearest white region along the x axis is found and the size of this region is returned.

If this pixel is white, the size of this white region is returned.