Repository: lightkurve/lightkurve

Issue:
LightCurve.create_transit_mask() : should accept Quantity for period, duration
<!-- Fill in the information below before opening an issue. -->

#### Problem description
<!-- Provide a clear and concise description of the issue. -->

Right now, `period` / `duration` in `LightCurve.create_transit_mask()` does not accept `Quantity` objects. Using `Quantity` objects will lead to an unhelpful `UnitConversionError`

```python
>>> lc.create_transit_mask(transit_time=Time(2340, format="btjd"), period=3 * u.day, duration=4 * u.hr)
UnitConversionError: Can only apply 'add' function to dimensionless quantities when other argument is not a quantity (unless the latter is all zero/infinity/nan)

```

#### Proposal
- `period` / `duration` in `LightCurve.create_transit_mask()` should accept `Quantity`, similar to how other functions, e.g., `fold()`, `bin()`, etc.


#### Environment

-  lightkurve version (e.g. 1.0b6): 2.0.10


Discussion:

Patch:
diff --git a/src/lightkurve/lightcurve.py b/src/lightkurve/lightcurve.py
index 85fb1415..98a48b84 100644
--- a/src/lightkurve/lightcurve.py
+++ b/src/lightkurve/lightcurve.py
@@ -37,6 +37,13 @@ __all__ = ["LightCurve", "KeplerLightCurve", "TessLightCurve", "FoldedLightCurve
 
 log = logging.getLogger(__name__)
 
+def _to_unitless_day(data):
+    if isinstance(data, Quantity):
+        return data.to(u.day).value
+    elif not np.isscalar(data):
+        return np.asarray([_to_unitless_day(item) for item in data]).flatten()
+    else:
+        return data
 
 class QColumn(Column):
     """(Temporary) workaround to provide ``.value`` alias to raw data, so as to match ``Quantity``."""
@@ -2597,9 +2604,9 @@ class LightCurve(QTimeSeries):
 
         Parameters
         ----------
-        period : float, or array-like
+        period : `~astropy.units.Quantity`, float, or array-like
             Period(s) of the transits.
-        duration : float, or array-like
+        duration : `~astropy.units.Quantity`, float, or array-like
             Duration(s) of the transits.
         transit_time : `~astropy.time.Time`, float, or array-like
             Transit midpoint(s) of the transits.
@@ -2623,6 +2630,9 @@ class LightCurve(QTimeSeries):
             >>> lc.create_transit_mask(transit_time=[2., 3.], period=[2., 10.], duration=[0.1, 0.1])
             array([False,  True,  True,  True, False])
         """
+        period = _to_unitless_day(period)
+        duration = _to_unitless_day(duration)
+
         # Ensure all parameters are 1D-arrays
         period = np.atleast_1d(period)
         duration = np.atleast_1d(duration)


Test patch:
diff --git a/tests/test_lightcurve.py b/tests/test_lightcurve.py
index f883a0e6..c001ce5b 100644
--- a/tests/test_lightcurve.py
+++ b/tests/test_lightcurve.py
@@ -1538,6 +1538,22 @@ def test_create_transit_mask():
     # Are all unmasked values in transit?
     assert all(f < 0.9 for f in synthetic_lc[mask].flux.value)
 
+    # #1117: Repeat multi-planet planet mask test,
+    # ensure values specified in Quantity are also accepted.
+    mask = synthetic_lc.create_transit_mask(
+        period=u.Quantity([period, period_2], unit="day"),  # inputs in Quantity
+        # ensure:
+        # 1. implementation does proper conversion
+        # 2. accept a mix of float and Quantity
+        duration=[duration, (duration_2 * u.day).to(u.hr)],
+        transit_time=[transit_time, transit_time_2],
+    )
+
+    # Are all masked values out of transit?
+    assert all(f > 0.9 for f in synthetic_lc[~mask].flux.value)
+    # Are all unmasked values in transit?
+    assert all(f < 0.9 for f in synthetic_lc[mask].flux.value)
+
 
 def test_row_repr():
     """Regression test for #830: ensure the repr works for a single row."""