-
Notifications
You must be signed in to change notification settings - Fork 14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Construction #119
base: main
Are you sure you want to change the base?
Construction #119
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,7 +19,7 @@ def __init__( | |
sort: bool = True, | ||
min_separation: float = None, | ||
min_area: float = 0, | ||
minor_length: float = 0, | ||
eccentricity_bound: float = 0, | ||
name: str = None, | ||
): | ||
"""Base class for sources detection. | ||
|
@@ -38,8 +38,8 @@ def __init__( | |
minimum separation in pixels from one source to the other. Between two sources, greater ADU is kept, by default None | ||
min_area : float, optional | ||
minimum area in pixels of the sources to detect, by default 0 | ||
minor_length : float, optional | ||
minimum length of semi-major axis of sources to detect, by default 0 | ||
eccentricity_bound : int, optional | ||
maximum eccentricity of sources to detect, by default 1 | ||
name : str, optional | ||
name of the block, by default None | ||
""" | ||
|
@@ -49,7 +49,7 @@ def __init__( | |
self.min_separation = min_separation | ||
self.threshold = threshold | ||
self.min_area = min_area | ||
self.minor_length = minor_length | ||
self.eccentricity_bound = eccentricity_bound | ||
|
||
def clean(self, sources): | ||
peaks = np.array([s.peak for s in sources]) | ||
|
@@ -68,7 +68,7 @@ def clean(self, sources): | |
for i, s in enumerate(final_sources): | ||
if final_sources[i].keep: | ||
distances = np.linalg.norm( | ||
s.coords - final_sources.coords, axis=1 | ||
s.coords - [final_source.coords for final_source in final_sources], axis=1 | ||
) | ||
distances[i] == np.nan | ||
idxs = np.flatnonzero(distances < self.min_separation) | ||
|
@@ -114,7 +114,7 @@ def regions(self, image: Image, threshold=None): | |
regions = [ | ||
r | ||
for r in regions | ||
if r.area >= self.min_area and r.axis_major_length >= self.minor_length | ||
if r.area >= self.min_area and r.eccentricity <= self.eccentricity_bound | ||
] | ||
|
||
return regions | ||
|
@@ -133,7 +133,7 @@ def __init__( | |
min_separation=None, | ||
name=None, | ||
min_area=0, | ||
minor_length=0, | ||
eccentricity_bound=1, | ||
): | ||
"""Detect all sources. | ||
|
||
|
@@ -153,8 +153,8 @@ def __init__( | |
minimum separation in pixels from one source to the other. Between two sources, greater ADU is kept, by default None | ||
min_area : str, optional | ||
minimum area in pixels of the sources to detect, by default 0 | ||
minor_length : str, optional | ||
minimum length of semi-major axis of sources to detect, by default 0 | ||
eccentricity_bound : int, optional | ||
maximum eccentricity of sources to detect, by default 1 | ||
name : str, optional | ||
name of the block, by default None | ||
""" | ||
|
@@ -165,7 +165,7 @@ def __init__( | |
min_separation=min_separation, | ||
name=name, | ||
min_area=min_area, | ||
minor_length=minor_length, | ||
eccentricity_bound=eccentricity_bound, | ||
) | ||
|
||
def run(self, image): | ||
|
@@ -175,7 +175,7 @@ def run(self, image): | |
|
||
|
||
class PointSourceDetection(_SourceDetection): | ||
def __init__(self, unit_euler=False, min_area=3, minor_length=2, **kwargs): | ||
def __init__(self, unit_euler=False, min_area=3, eccentricity_bound=2, **kwargs): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It should be that eccentricity is between 0 and 1, isn't it? This applies to the rest of the changes |
||
"""Detect point sources (as :py:class:`~prose.core.source.PointSource`). | ||
|
||
|read| :code:`Image.data` | ||
|
@@ -188,8 +188,8 @@ def __init__(self, unit_euler=False, min_area=3, minor_length=2, **kwargs): | |
whether to consider sources with euler number == 1, by default False | ||
min_area : str, optional | ||
minimum area in pixels of the sources to detect, by default 0 | ||
minor_length : str, optional | ||
minimum length of semi-major axis of sources to detect, by default 0 | ||
eccentricity_bound : int, optional | ||
maximum eccentricity of sources to detect, by default 1 | ||
threshold : float, optional | ||
detection threshold for sources, by default 4 | ||
n : int, optional | ||
|
@@ -202,10 +202,10 @@ def __init__(self, unit_euler=False, min_area=3, minor_length=2, **kwargs): | |
name of the block, by default None | ||
""" | ||
|
||
super().__init__(min_area=min_area, minor_length=minor_length, **kwargs) | ||
super().__init__(min_area=min_area, eccentricity_bound=eccentricity_bound, **kwargs) | ||
self.unit_euler = unit_euler | ||
self.min_area = min_area | ||
self.minor_length = minor_length | ||
self.eccentricity_bound = eccentricity_bound | ||
|
||
def run(self, image): | ||
regions = self.regions(image) | ||
|
@@ -220,13 +220,13 @@ def run(self, image): | |
|
||
|
||
class TraceDetection(_SourceDetection): | ||
def __init__(self, minor_length=5, **kwargs): | ||
def __init__(self, eccentricity_bound=5, **kwargs): | ||
"""Detect trace sources (as :py:class:`~prose.core.source.TraceSource`) | ||
|
||
Parameters | ||
---------- | ||
minor_length : str, optional | ||
minimum length of semi-major axis of sources to detect, by default 0 | ||
eccentricity_bound : int, optional | ||
maximum eccentricity of sources to detect, by default 1 | ||
min_area : str, optional | ||
minimum area in pixels of the sources to detect, by default 0 | ||
threshold : float, optional | ||
|
@@ -240,7 +240,7 @@ def __init__(self, minor_length=5, **kwargs): | |
name : str, optional | ||
name of the block, by default None | ||
""" | ||
super().__init__(minor_length=minor_length, **kwargs) | ||
super().__init__(eccentricity_bound=eccentricity_bound, **kwargs) | ||
|
||
def run(self, image): | ||
regions = self.regions(image) | ||
|
@@ -251,19 +251,19 @@ def run(self, image): | |
# backward compatibility | ||
class SegmentedPeaks(PointSourceDetection): | ||
def __init__( | ||
self, unit_euler=False, min_area=3, minor_length=2, n_stars=None, **kwargs | ||
self, unit_euler=False, min_area=3, eccentricity_bound=2, n_stars=None, **kwargs | ||
): | ||
"""Detect point sources (backward compatibility) | ||
|
||
Same as :py:class:`~prose.blocks.PointSourceDetection` | ||
""" | ||
|
||
super().__init__( | ||
n=n_stars, min_area=min_area, minor_length=minor_length, **kwargs | ||
n=n_stars, min_area=min_area, eccentricity_bound=eccentricity_bound, **kwargs | ||
) | ||
self.unit_euler = unit_euler | ||
self.min_area = min_area | ||
self.minor_length = minor_length | ||
self.eccentricity_bound = eccentricity_bound | ||
|
||
|
||
# TODO: document | ||
|
@@ -336,7 +336,7 @@ def __init__( | |
def detect(self, image): | ||
_, median, std = sigma_clipped_stats(image.data, sigma=self.sigma_clip) | ||
finder = DAOStarFinder(fwhm=self.fwhm, threshold=self.lower_snr * std) | ||
sources = finder(image.data - median) | ||
sources = finder(image.data - median, mask=image.mask) | ||
|
||
coordinates = np.transpose( | ||
np.array([sources["xcentroid"].data, sources["ycentroid"].data]) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -40,7 +40,7 @@ def run(self, image: Image): | |
|
||
apertures = [image.sources.apertures(r) for r in radii] | ||
aperture_fluxes = np.array( | ||
[aperture_photometry(image.data, a)["aperture_sum"].data for a in apertures] | ||
[aperture_photometry(image.data, a, mask=image.mask)["aperture_sum"].data for a in apertures] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would anticipate that other blocks might modify the mask in different ways , such as 8 bit integers to specify the kind of bad pixel (cosmics, dead ... etc). For this reason it would be good to first cast the mask to a boolean before using it in |
||
).T | ||
|
||
image.aperture = {"fluxes": aperture_fluxes, "radii": radii} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -57,6 +57,9 @@ class Image: | |
|
||
header: Optional[Header] = None | ||
"""FITS header associated with the image (optional)""" | ||
|
||
mask: Optional[np.ndarray] = None | ||
"""Mask (commonly used for bad pixels) that is written in the CleanBadPixels block""" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would omit the reference to block here, this mask will be quite general and changed by many other instances There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, the mask should be initialized to a sensitive default I think |
||
|
||
_wcs = None | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expect a tuple specifying the bounds of the eccentricity here, such that sources are better separated depending on their shape (with a single upper bound only, point sources will also fall into traces). What do you think?