Skip to content

Commit

Permalink
Merge pull request #126 from mwcraig/update-seeing-profile-functions
Browse files Browse the repository at this point in the history
Update seeing profile functions
  • Loading branch information
mwcraig authored Jul 7, 2023
2 parents cc11354 + df5d945 commit e98be0d
Showing 1 changed file with 45 additions and 42 deletions.
87 changes: 45 additions & 42 deletions stellarphot/visualization/seeing_profile_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@
from stellarphot.visualization.fits_opener import FitsOpener

__all__ = ['set_keybindings', 'find_center', 'radial_profile',
'find_hwhm', 'RadialProfile', 'box', 'SeeingProfileWidget']
'RadialProfile', 'box', 'SeeingProfileWidget']

desc_style = {"description_width": "initial"}


# TODO: maybe move this into SeeingProfileWidget unless we anticipate
# other widgets using this.
def set_keybindings(image_widget, scroll_zoom=False):
"""
Set image widget keyboard bindings. The bindings are:
Expand Down Expand Up @@ -84,6 +86,7 @@ def set_keybindings(image_widget, scroll_zoom=False):
bind_map.map_event(None, (), 'kp_down', 'pan_up')


# TODO: Can this be replaced by a properly masked call to centroid_com?
def find_center(image, center_guess, cutout_size=30, max_iters=10):
"""
Find the centroid of a star from an initial guess of its position. Originally
Expand Down Expand Up @@ -157,6 +160,7 @@ def find_center(image, center_guess, cutout_size=30, max_iters=10):
return cen


# TODO: Why eactly is this separate from the class RadialProfile?
def radial_profile(data, center, size=30, return_scaled=True):
"""
Construct a radial profile of a chunk of width ``size`` centered
Expand Down Expand Up @@ -216,47 +220,6 @@ def radial_profile(data, center, size=30, return_scaled=True):
return r_exact, ravg, radialprofile


def find_hwhm(r, intensity):
"""
Estimate the half-width half-max from normalized, angle-averaged intensity profile.
Parameters
----------
r : array
Radius of each pixel from the center of the star.
intensity : array
Normalized intensity at each radius.
Returns
-------
r_half : float
Radius at which the intensity is 50% the maximum
"""

# Make the bold assumption that intensity decreases monotonically
# so that we just need to find the first place where intensity is
# less than 0.5 to estimate the HWHM.
less_than_half = intensity < 0.5
half_index = np.arange(len(less_than_half))[less_than_half][0]
before_half = half_index - 1

# Do linear interpolation to find the radius at which the intensity
# is 0.5.
r_more = r[before_half]
r_less = r[half_index]
I_more = intensity[before_half]
I_less = intensity[half_index]

I_half = 0.5

r_half = r_less - (I_less - I_half) / (I_less - I_more) * (r_less - r_more)

return r_half


class RadialProfile:
"""
Class to hold radial profile information for a star.
Expand Down Expand Up @@ -345,6 +308,13 @@ def cen(self):
"""
return self._cen

@property
def HWHM(self):
"""
Half-width half-max of the radial profile.
"""
return self.find_hwhm()

@property
def FWHM(self):
"""
Expand All @@ -359,6 +329,39 @@ def radius_values(self):
"""
return np.arange(len(self.radialprofile))

def find_hwhm(self):
"""
Estimate the half-width half-max from normalized, angle-averaged intensity profile.
Returns
-------
r_half : float
Radius at which the intensity is 50% the maximum
"""

r = self.ravg
intensity = self.scaled_profile
# Make the bold assumption that intensity decreases monotonically
# so that we just need to find the first place where intensity is
# less than 0.5 to estimate the HWHM.
less_than_half = intensity < 0.5
half_index = np.arange(len(less_than_half))[less_than_half][0]
before_half = half_index - 1

# Do linear interpolation to find the radius at which the intensity
# is 0.5.
r_more = r[before_half]
r_less = r[half_index]
I_more = intensity[before_half]
I_less = intensity[half_index]

I_half = 0.5

r_half = r_less - (I_less - I_half) / (I_less - I_more) * (r_less - r_more)

return r_half


def box(imagewidget):
"""
Expand Down

0 comments on commit e98be0d

Please sign in to comment.