Repository: lightkurve/lightkurve

Issue:
lightkurve.LightCurve.create_transit_mask breaks when using astropy units
<!-- Fill in the information below before opening an issue. -->

#### Problem description
<!-- Provide a clear and concise description of the issue. -->
If I send an orbital period, transit time, and transit duration all with astropy units (which seems to be what the function wants), I get an error about subtracting numbers with units from numbers without units.

#### Example
<!-- Provide a link or minimal code snippet that demonstrates the issue. -->
```python
import lightkurve as lk
import astropy.units as u

search_result = lk.search_lightcurve("Kepler-13", mission="Kepler")
lc = search_result[3].download()

transit_mask = lc.create_transit_mask(1.7635869*u.d, (718.82552  + 2458000. - 2454833.)*u.d, 0.1359816*u.d)
```
It's line 2647 in lightcurve.py that produces the error. 

#### Expected behavior
<!-- Describe the behavior you expected and how it differs from the behavior observed in the example. -->

I expected to get a transit mask array.

#### Environment

-  platform (e.g. Linux, OSX, Windows): Mac OS 11.2.3
-  lightkurve version (e.g. 1.0b6): 2.0.10
-  installation method (e.g. pip, conda, source): pip


Discussion:

Patch:
diff --git a/CHANGES.rst b/CHANGES.rst
index 60db57d6..a1a57f10 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -19,7 +19,7 @@
   Dynamical Time (TDB) scale by default. [#1112]
 
 - Modified ``LightCurve.create_transit_mask()`` to accept AstroPy ``Quantity``
-  objects for the ``period`` and ``duration`` parameters. [#1119]
+  objects for ``period``, ``transit_time``, and ``duration``. [#1119, #1141]
 
 - Modified ``CBVCorrector`` to issue a warning message of the CBVs are
   poorly aligned to the input light curve. [#1113]
diff --git a/src/lightkurve/lightcurve.py b/src/lightkurve/lightcurve.py
index 6125c4d0..7b3247f9 100644
--- a/src/lightkurve/lightcurve.py
+++ b/src/lightkurve/lightcurve.py
@@ -2625,9 +2625,14 @@ 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])
         """
+        # Convert Quantity objects to floats in units "day"
         period = _to_unitless_day(period)
         duration = _to_unitless_day(duration)
 
+        # If ``transit_time`` is a ``Quantity```, attempt converting it to a ``Time`` object
+        if isinstance(transit_time, Quantity):
+            transit_time = Time(transit_time, format=self.time.format, scale=self.time.scale)
+
         # 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 022ffe4d..b8764857 100644
--- a/tests/test_lightcurve.py
+++ b/tests/test_lightcurve.py
@@ -1694,3 +1694,11 @@ def test_select_flux():
         lc.select_flux("doesnotexist")
     with pytest.raises(ValueError):
         lc.select_flux("newflux", "doesnotexist")
+
+
+def test_transit_mask_with_quantities():
+    """Regression test for #1141."""
+    lc = LightCurve(time=range(10), flux=range(10))
+    mask_quantity = lc.create_transit_mask(period=2.9*u.day, transit_time=1*u.day, duration=1*u.day)
+    mask_no_quantity = lc.create_transit_mask(period=2.9, transit_time=1, duration=1)
+    assert all(mask_quantity == mask_no_quantity)