Skip to content

Commit

Permalink
Fix positional selection (#118)
Browse files Browse the repository at this point in the history
* BUGFIX: when there was no cluster within 1 arcsec we selected ALL noise datapoints instead of the ones within 1 arcsec

* bump version

* Because of the positional selection we have to deal with empty lightcurves

* plot binned lightcurve only when it is not empty
  • Loading branch information
JannisNe authored Aug 31, 2023
1 parent 7b31af7 commit 37a1d23
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 19 deletions.
2 changes: 1 addition & 1 deletion docs/source/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
author = 'Jannis Necker'

# The full version, including alpha/beta/rc tags
release = 'v0.4.2.post1'
release = 'v0.4.3'


# -- General configuration ---------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "timewise"
version = "0.4.2.post1"
version = "0.4.3"
description = "A small package to download infrared data from the WISE satellite"
authors = ["Jannis Necker <[email protected]>"]
license = "MIT"
Expand Down
2 changes: 1 addition & 1 deletion timewise/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
from timewise.wise_bigdata_desy_cluster import WISEDataDESYCluster
from timewise.parent_sample_base import ParentSampleBase

__version__ = "0.4.2.post1"
__version__ = "0.4.3"
14 changes: 5 additions & 9 deletions timewise/wise_data_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1626,18 +1626,14 @@ def calculate_position_mask(lightcurve, ra, dec, whitelist_region, return_all=Fa
logger.debug(f"Found {len(cluster_separations)} clusters")

# if there is no cluster or no cluster within 1 arcsec,
# we select all noise datapoints within 1 arcsec if there are any
if (
len(cluster_separations) == 0
or min(cluster_separations) > np.radians(whitelist_region / 3600)
):
# only the datapoints within 1 arcsec are selected as we did above
if len(cluster_separations) == 0:
logger.debug("No cluster found. Selecting all noise datapoints within 1 arcsec.")
if len(cluster_separations) > 0:
logger.debug(f"Closest cluster is at {cluster_separations} arcsec")
noise_mask = cluster_res.labels_ == -1
selected_indices |= set(lightcurve.index[data_mask][noise_mask])
elif min(cluster_separations) > np.radians(whitelist_region / 3600):
logger.debug(f"Closest cluster is at {cluster_separations} arcsec")

# if there is a cluster within 1 arcsec, we select all datapoints belonging to that cluster
# in addition to the datapoints within 1 arcsec
else:
closest_label = cluster_separations.argmin()
selected_cluster_mask = cluster_res.labels_ == closest_label
Expand Down
19 changes: 12 additions & 7 deletions timewise/wise_data_by_visit.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ def calculate_epochs(self, f, e, visit_mask, counts, remove_outliers, outlier_ma
:return: the epoch
:rtype: float
"""

if len(f) == 0:
return [], [], [], [], [], []

u_lims = pd.isna(e)
nan_mask = pd.isna(f)

Expand Down Expand Up @@ -516,13 +520,14 @@ def plot_diagnostic_binning(
self.parent_sample.plot_cutout(ind=ind, ax=axs[0], which=which, arcsec=arcsec, **kwargs)

# plot the lightcurve
self._plot_lc(
lightcurve=binned_lightcurve,
unbinned_lc=lightcurve[position_mask],
lum_key=lum_key,
ax=axs[-1],
save=False
)
if len(binned_lightcurve) > 0:
self._plot_lc(
lightcurve=binned_lightcurve,
unbinned_lc=lightcurve[position_mask],
lum_key=lum_key,
ax=axs[-1],
save=False
)
self._plot_lc(
unbinned_lc=lightcurve[~position_mask],
lum_key=lum_key,
Expand Down

0 comments on commit 37a1d23

Please sign in to comment.