Repository: lightkurve/lightkurve

Issue:
Change default column for QLP light curves


#### Problem description
When LightKurve reads light curves from the QLP HLSP, it pulls from a post-processed column (called KSP_FLUX) that is already high-pass-filtered. This makes it impossible to recover the original light curve and see features like stellar variability, etc. Here's a comparison of the same star from three different pipelines: 

![hlspcomparison](https://user-images.githubusercontent.com/32683658/120834889-3d6fcc00-c529-11eb-9d9d-078b466bc6bb.png)

You can see that the large modulation has been removed from QLP that is present in the other two light curves. 

As far as I can tell, there is no way to change this behavior when calling search_lightcurve. 

#### Example

search_result = lk.search_lightcurve('TIC 277554109', author='qlp')
lc = search_result.download()
lc.plot()
search_result2 = lk.search_lightcurve('TIC 277554109', author='pathos')
lc2 = search_result2.download()
lc2.plot()
search_result3 = lk.search_lightcurve('TIC 277554109', author='cdips')
lc3 = search_result3.download()
lc3.plot()

I think this can be fixed by swapping out "kspsap_flux" for "sap_flux" in this line: 
https://github.com/lightkurve/lightkurve/blob/f452a4e4752d9b277025a2ec711ec06b88230d97/src/lightkurve/io/qlp.py#L12

Alternatively, it might be useful to allow the user to specify the flux column when downloading light curves in this way. But I would argue that by default, the QLP light curves should return the sap_flux column to match the behavior of other HLSPs. 

#### Expected behavior
I would expect QLP to return the SAP_FLUX column rather than the KSPSAP_FLUX column

#### Environment

-  platform:  OSX
-  lightkurve version: 2.0.9
-  installation method: pip


Comments:

Patch:
diff --git a/CHANGES.rst b/CHANGES.rst
index 878fac64..0f889711 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -28,6 +28,9 @@
 - Added the ``LightCurve.select_flux()`` method to make it easier to use a different
   column to populate the ``flux`` and ``flux_err`` columns. [#1076]
 
+- Modified the MIT Quicklook Pipeline (QLP) light curve file reader to use the "SAP_FLUX"
+  column as the default flux column. [#1083]
+
 
 2.0.9 (2021-03-31)
 ==================
diff --git a/src/lightkurve/io/qlp.py b/src/lightkurve/io/qlp.py
index bca45640..eb752052 100644
--- a/src/lightkurve/io/qlp.py
+++ b/src/lightkurve/io/qlp.py
@@ -9,15 +9,22 @@ from ..utils import TessQualityFlags
 from .generic import read_generic_lightcurve
 
 
-def read_qlp_lightcurve(filename, flux_column="kspsap_flux", quality_bitmask="default"):
-    """Returns a `TessLightCurve`.
+def read_qlp_lightcurve(filename, flux_column="sap_flux", flux_err_column="kspsap_flux_err", quality_bitmask="default"):
+    """Returns a `TessLightCurve` object given a light curve file from the MIT Quicklook Pipeline (QLP).
+
+    By default, QLP's `sap_flux` column is used to populate the `flux` values,
+    and 'kspsap_flux_err' is used to populate `flux_err`. For a discussion
+    related to this choice, see https://github.com/lightkurve/lightkurve/issues/1083
 
     Parameters
     ----------
     filename : str
         Local path or remote url of a QLP light curve FITS file.
-    flux_column : 'pdcsap_flux' or 'sap_flux'
+    flux_column : 'sap_flux', 'kspsap_flux', 'kspsap_flux_sml', 'kspsap_flux_lag', or 'sap_bkg'
         Which column in the FITS file contains the preferred flux data?
+        By default the "Simple Aperture Photometry" flux (sap_flux) is used.
+    flux_err_column: 'kspsap_flux_err', or 'sap_bkg_err'
+      Which column in the FITS file contains the preferred flux_err data?
     quality_bitmask : str or int
         Bitmask (integer) which identifies the quality flag bitmask that should
         be used to mask out bad cadences. If a string is passed, it has the
@@ -33,7 +40,7 @@ def read_qlp_lightcurve(filename, flux_column="kspsap_flux", quality_bitmask="de
 
         See the :class:`TessQualityFlags` class for details on the bitmasks.
     """
-    lc = read_generic_lightcurve(filename, flux_column=flux_column, time_format="btjd")
+    lc = read_generic_lightcurve(filename, flux_column=flux_column, flux_err_column=flux_err_column, time_format="btjd")
 
     # Filter out poor-quality data
     # NOTE: Unfortunately Astropy Table masking does not yet work for columns


Test patch:
diff --git a/tests/io/test_qlp.py b/tests/io/test_qlp.py
new file mode 100644
index 00000000..99420432
--- /dev/null
+++ b/tests/io/test_qlp.py
@@ -0,0 +1,34 @@
+import pytest
+
+from astropy.io import fits
+import numpy as np
+from numpy.testing import assert_array_equal
+
+from lightkurve import search_lightcurve
+from lightkurve.io.qlp import read_qlp_lightcurve
+from lightkurve.io.detect import detect_filetype
+
+
+@pytest.mark.remote_data
+def test_qlp():
+    """Can we read in QLP light curves?"""
+    url = "https://mast.stsci.edu/api/v0.1/Download/file?uri=mast:HLSP/qlp/s0011/0000/0002/7755/4109/hlsp_qlp_tess_ffi_s0011-0000000277554109_tess_v01_llc.fits"    
+    with fits.open(url, mode="readonly") as hdulist:
+        # Can we auto-detect a QLP file?
+        assert detect_filetype(hdulist) == "QLP"
+        # Are the correct fluxes read in?
+        lc = read_qlp_lightcurve(url, quality_bitmask=0)
+        assert lc.meta["FLUX_ORIGIN"] == "sap_flux"
+        assert_array_equal(lc.flux.value, hdulist[1].data["SAP_FLUX"])
+
+
+@pytest.mark.remote_data
+def test_search_qlp():
+    """Can we search and download QLP light curves from MAST?"""
+    search = search_lightcurve("TIC 277554109", author="QLP", sector=11)
+    assert len(search) == 1
+    assert search.table["author"][0] == "QLP"
+    lc = search.download()
+    assert type(lc).__name__ == "TessLightCurve"
+    assert lc.sector == 11
+    assert lc.author == "QLP"