transitfetcher 1.0.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Chatdanai Sawangwong
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,118 @@
1
+ Metadata-Version: 2.1
2
+ Name: transitfetcher
3
+ Version: 1.0.0
4
+ Summary: A Python Package for Retrieving Exoplanet Transit Light Curves
5
+ Author-email: Chatdanai Sawangwong <chatdanai.saw@gmail.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/chatdanai-s/TransitFetcher
8
+ Project-URL: BugTracker, https://github.com/chatdanai-s/TransitFetcher/issues
9
+ Project-URL: Documentation, https://github.com/chatdanai-s/TransitFetcher
10
+ Keywords: astronomy,exoplanets,transit,light-curve,tess,kepler,astrophysics
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Operating System :: OS Independent
13
+ Requires-Python: >=3.9
14
+ Description-Content-Type: text/markdown
15
+ License-File: LICENSE
16
+ Requires-Dist: lightkurve
17
+ Requires-Dist: numpy
18
+ Requires-Dist: pandas
19
+ Requires-Dist: matplotlib
20
+ Requires-Dist: requests
21
+
22
+ # TransitFetcher
23
+ An automated space-based (Kepler/TESS) exoplanet transit retrieval and preprocessing pipeline.
24
+
25
+ Simply provide a host star name (e.g. Kepler-10), then `TransitFetcher` automatically downloads and extracts
26
+ all individual transit light curves (from MAST via `lightkurve`) for known transiting planets in the system!
27
+
28
+ # Installation
29
+ Install the latest stable release from PyPI:
30
+ ```bash
31
+ pip install transitfetcher
32
+ ```
33
+
34
+ # Usage
35
+
36
+ TransitFetcher only has one function: `fetch()`, which retrieves and (optionally) plots various transit light curves. For example,
37
+
38
+ ```python
39
+ from transitfetcher import fetch
40
+
41
+ fetch("Kepler-10")
42
+ ```
43
+
44
+ ## Function Parameters
45
+
46
+ ```python
47
+ fetch(
48
+ target,
49
+ output_root=None,
50
+ includes=["Kepler", "TESS"],
51
+ normalize_flux=False,
52
+ plot_entire_lightcurve=True,
53
+ plot_individual_transits=True,
54
+ plot_folded_transits=True,
55
+ plot_riverplot=True,
56
+ generate_transitfit_csvs=False
57
+ )
58
+ ```
59
+
60
+ | Parameter | Type | Default | Description | Notes |
61
+ |---|---|---|---|---|
62
+ | `target` | `str` | Required | Target name or identifier. | Do not include planet letters (e.g. `"Kepler-10"` NOT `"Kepler-10 b"`). |
63
+ | `output_root` | `str` or `Path` | `None` | Root directory for output files. | `None` defaults to the current working directory. |
64
+ | `includes` | `list[str]` | `["Kepler", "TESS"]` | Missions to include when searching for transit data. | Only accepts `"Kepler"` and/or `"TESS"`. |
65
+ | `normalize_flux` | `bool` | `False` | Prioritize flux-detrended data (by Savitzky-Golay filtering) when processing transits. | |
66
+ | `plot_entire_lightcurve` | `bool` | `True` | Generate unfolded light curve plots by quarter/sector. | |
67
+ | `plot_individual_transits` | `bool` | `True` | Generate plots for individual transit events. | |
68
+ | `plot_folded_transits` | `bool` | `True` | Generate phase-folded transit plots by quarter/sector. | Always uses detrended data |
69
+ | `plot_riverplot` | `bool` | `True` | Generate transit river plots by mission. | Always uses detrended data |
70
+ | `generate_transitfit_csvs` | `bool` | `False` | Generate configuration CSV files for `TransitFit`. | |
71
+
72
+ ## Output
73
+
74
+ For each target, `TransitFetcher` creates a dedicated output directory containing the retrieved light curves, extracted transit events, plots, and other auxiliary files.
75
+ Directories containing planet-specific outputs (`folded_transit_plots`, `individual_transit_csv`, `individual_transit_plot`, and `transitfit_configs`)
76
+ are further organized into sub-directories for each known transiting planet in the system.
77
+
78
+ ```text
79
+ TransitFetcher_<target>/
80
+ ├── folded_transit_plots/ # Phase-folded light curves per planet (always detrended)
81
+ │ ├── <planet_1>/
82
+ │ ├── <planet_2>/
83
+ │ └── ...
84
+ ├── individual_transit_csv/ # Individual transit CSVs (detrended if normalize_flux=True)
85
+ │ ├── <planet_1>/
86
+ │ ├── <planet_2>/
87
+ │ └── ...
88
+ ├── individual_transit_plot/ # Individual transit plots (detrended if normalize_flux=True)
89
+ │ ├── <planet_1>/
90
+ │ ├── <planet_2>/
91
+ │ └── ...
92
+ ├── lightcurve_plots/ # Full mission light curve plots (detrended if normalize_flux=True)
93
+ ├── river_plots/ # River plots for each mission per planet (always detrended)
94
+ ├── transitfit_configs/ # Configuration files for further TransitFit use
95
+ │ ├── <planet_1>/
96
+ │ ├── <planet_2>/
97
+ │ └── ...
98
+ ├── <target>_lc_flattened.csv # Combined detrended light curve
99
+ ├── <target>_lc_unflattened.csv # Combined original light curve
100
+ └── <target>_transit_ephemerides.csv # Planetary parameters queried from exo.MAST
101
+ ```
102
+
103
+ ## Usage Notes
104
+ - `TransitFetcher` does **not** perform transit fitting or parameter inference of any kind.
105
+ It is intended for automatic extraction of individual transit events to be subsequently analyzed using
106
+ arbitrary methods and software, particularly geared towards transit timing variation (TTV) studies.
107
+ - `TransitFetcher` currently uses `lightkurve.SearchResult.download_all()` for MAST light curve downloads.
108
+ While direct bulk downloads via `astroquery.mast` may be supported in the future, `TransitFetcher` currently does not,
109
+ and so you may see yourself rate limited if you were to fetch many target light curves using a for loop.
110
+ - It is highly recommended to keep `normalize_flux` as `False` (default) to preserve original flux values.
111
+ `TransitFetcher` uses a Savitzky-Golay filter (polynomial degree 2) with a window length of at least
112
+ 4x the transit duration or 25 hours (51 for Kepler and 751 for TESS), which may be unreliable for some transits.
113
+ Users should always manually inspect folded transit plots if `normalize_flux` is `True`.
114
+
115
+ # To-do
116
+ - [ ] Bulk TESS-Kepler MAST query download for `target` argument as list of planets
117
+ - [ ] Input checking/validation
118
+ - [ ] K2 mission support
@@ -0,0 +1,97 @@
1
+ # TransitFetcher
2
+ An automated space-based (Kepler/TESS) exoplanet transit retrieval and preprocessing pipeline.
3
+
4
+ Simply provide a host star name (e.g. Kepler-10), then `TransitFetcher` automatically downloads and extracts
5
+ all individual transit light curves (from MAST via `lightkurve`) for known transiting planets in the system!
6
+
7
+ # Installation
8
+ Install the latest stable release from PyPI:
9
+ ```bash
10
+ pip install transitfetcher
11
+ ```
12
+
13
+ # Usage
14
+
15
+ TransitFetcher only has one function: `fetch()`, which retrieves and (optionally) plots various transit light curves. For example,
16
+
17
+ ```python
18
+ from transitfetcher import fetch
19
+
20
+ fetch("Kepler-10")
21
+ ```
22
+
23
+ ## Function Parameters
24
+
25
+ ```python
26
+ fetch(
27
+ target,
28
+ output_root=None,
29
+ includes=["Kepler", "TESS"],
30
+ normalize_flux=False,
31
+ plot_entire_lightcurve=True,
32
+ plot_individual_transits=True,
33
+ plot_folded_transits=True,
34
+ plot_riverplot=True,
35
+ generate_transitfit_csvs=False
36
+ )
37
+ ```
38
+
39
+ | Parameter | Type | Default | Description | Notes |
40
+ |---|---|---|---|---|
41
+ | `target` | `str` | Required | Target name or identifier. | Do not include planet letters (e.g. `"Kepler-10"` NOT `"Kepler-10 b"`). |
42
+ | `output_root` | `str` or `Path` | `None` | Root directory for output files. | `None` defaults to the current working directory. |
43
+ | `includes` | `list[str]` | `["Kepler", "TESS"]` | Missions to include when searching for transit data. | Only accepts `"Kepler"` and/or `"TESS"`. |
44
+ | `normalize_flux` | `bool` | `False` | Prioritize flux-detrended data (by Savitzky-Golay filtering) when processing transits. | |
45
+ | `plot_entire_lightcurve` | `bool` | `True` | Generate unfolded light curve plots by quarter/sector. | |
46
+ | `plot_individual_transits` | `bool` | `True` | Generate plots for individual transit events. | |
47
+ | `plot_folded_transits` | `bool` | `True` | Generate phase-folded transit plots by quarter/sector. | Always uses detrended data |
48
+ | `plot_riverplot` | `bool` | `True` | Generate transit river plots by mission. | Always uses detrended data |
49
+ | `generate_transitfit_csvs` | `bool` | `False` | Generate configuration CSV files for `TransitFit`. | |
50
+
51
+ ## Output
52
+
53
+ For each target, `TransitFetcher` creates a dedicated output directory containing the retrieved light curves, extracted transit events, plots, and other auxiliary files.
54
+ Directories containing planet-specific outputs (`folded_transit_plots`, `individual_transit_csv`, `individual_transit_plot`, and `transitfit_configs`)
55
+ are further organized into sub-directories for each known transiting planet in the system.
56
+
57
+ ```text
58
+ TransitFetcher_<target>/
59
+ ├── folded_transit_plots/ # Phase-folded light curves per planet (always detrended)
60
+ │ ├── <planet_1>/
61
+ │ ├── <planet_2>/
62
+ │ └── ...
63
+ ├── individual_transit_csv/ # Individual transit CSVs (detrended if normalize_flux=True)
64
+ │ ├── <planet_1>/
65
+ │ ├── <planet_2>/
66
+ │ └── ...
67
+ ├── individual_transit_plot/ # Individual transit plots (detrended if normalize_flux=True)
68
+ │ ├── <planet_1>/
69
+ │ ├── <planet_2>/
70
+ │ └── ...
71
+ ├── lightcurve_plots/ # Full mission light curve plots (detrended if normalize_flux=True)
72
+ ├── river_plots/ # River plots for each mission per planet (always detrended)
73
+ ├── transitfit_configs/ # Configuration files for further TransitFit use
74
+ │ ├── <planet_1>/
75
+ │ ├── <planet_2>/
76
+ │ └── ...
77
+ ├── <target>_lc_flattened.csv # Combined detrended light curve
78
+ ├── <target>_lc_unflattened.csv # Combined original light curve
79
+ └── <target>_transit_ephemerides.csv # Planetary parameters queried from exo.MAST
80
+ ```
81
+
82
+ ## Usage Notes
83
+ - `TransitFetcher` does **not** perform transit fitting or parameter inference of any kind.
84
+ It is intended for automatic extraction of individual transit events to be subsequently analyzed using
85
+ arbitrary methods and software, particularly geared towards transit timing variation (TTV) studies.
86
+ - `TransitFetcher` currently uses `lightkurve.SearchResult.download_all()` for MAST light curve downloads.
87
+ While direct bulk downloads via `astroquery.mast` may be supported in the future, `TransitFetcher` currently does not,
88
+ and so you may see yourself rate limited if you were to fetch many target light curves using a for loop.
89
+ - It is highly recommended to keep `normalize_flux` as `False` (default) to preserve original flux values.
90
+ `TransitFetcher` uses a Savitzky-Golay filter (polynomial degree 2) with a window length of at least
91
+ 4x the transit duration or 25 hours (51 for Kepler and 751 for TESS), which may be unreliable for some transits.
92
+ Users should always manually inspect folded transit plots if `normalize_flux` is `True`.
93
+
94
+ # To-do
95
+ - [ ] Bulk TESS-Kepler MAST query download for `target` argument as list of planets
96
+ - [ ] Input checking/validation
97
+ - [ ] K2 mission support
@@ -0,0 +1,48 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61.0,<69.0", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "transitfetcher"
7
+ version = "1.0.0"
8
+ description = "A Python Package for Retrieving Exoplanet Transit Light Curves"
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = { text = "MIT" }
12
+
13
+ keywords = [
14
+ "astronomy",
15
+ "exoplanets",
16
+ "transit",
17
+ "light-curve",
18
+ "tess",
19
+ "kepler",
20
+ "astrophysics"
21
+ ]
22
+
23
+ classifiers = [
24
+ "Programming Language :: Python :: 3",
25
+ "Operating System :: OS Independent",
26
+ ]
27
+
28
+ authors = [
29
+ { name = "Chatdanai Sawangwong", email = "chatdanai.saw@gmail.com" }
30
+ ]
31
+
32
+ dependencies = [
33
+ "lightkurve",
34
+ "numpy",
35
+ "pandas",
36
+ "matplotlib",
37
+ "requests"
38
+ ]
39
+
40
+ [project.urls]
41
+ Homepage = "https://github.com/chatdanai-s/TransitFetcher"
42
+ BugTracker = "https://github.com/chatdanai-s/TransitFetcher/issues"
43
+ Documentation = "https://github.com/chatdanai-s/TransitFetcher"
44
+
45
+ [tool.setuptools.packages.find]
46
+ where = ["."]
47
+ include = ["transitfetcher*"]
48
+ exclude = ["__pycache__", "tests", "docs"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,12 @@
1
+ import sys
2
+ from pathlib import Path
3
+ sys.path.insert(0, str(Path(__file__).resolve().parents[1]))
4
+
5
+ from transitfetcher import fetch
6
+
7
+ targets = ["Kepler-522"]
8
+ output_root = r'C:\Users\WBS\Documents\TransitFetcher_test_output'
9
+
10
+ for target in targets:
11
+ fetch(target, output_root=output_root, includes=['Kepler', 'TESS'],
12
+ normalize_flux=False, generate_transitfit_csvs=True)
@@ -0,0 +1,75 @@
1
+ from . import pipeline as tf_pipeline
2
+ import pandas as pd
3
+
4
+ def fetch(target,
5
+ output_root=None,
6
+ includes=['Kepler', 'TESS'],
7
+ normalize_flux=False,
8
+ plot_entire_lightcurve=True,
9
+ plot_individual_transits=True,
10
+ plot_folded_transits=True,
11
+ plot_riverplot=True,
12
+ generate_transitfit_csvs=False):
13
+
14
+ print(f'===== TransitFetcher started for {target} =====')
15
+
16
+ # Locate output folder
17
+ output_folder = tf_pipeline.get_output_folder(target, output_root)
18
+
19
+ # Fetch transit ephmerides from exo.mast
20
+ tf_pipeline.fetch_transit_ephemerides(target, output_folder)
21
+
22
+ # Fetch light curves from MAST via lightkurve
23
+ if isinstance(includes, str):
24
+ includes = [includes]
25
+ for mission in includes:
26
+ tf_pipeline.fetch_lightcurves(target, mission, output_folder)
27
+
28
+ # Concatenate fetched lightcurves
29
+ lc_folder = output_folder / "lightcurves_flattened"
30
+ lc_list = [f.name for f in lc_folder.glob("*.csv")]
31
+ if (len(lc_list) == 0):
32
+ print(f'===== TransitFetcher completed for {target} (No lightcurves downloaded) =====')
33
+ return
34
+
35
+ tf_pipeline.concatenate_lightcurves(lc_list, output_folder)
36
+
37
+ # Import concatenated lightcurves
38
+ if (normalize_flux == False):
39
+ ulc = pd.read_csv(output_folder / f"{target}_lc_unflattened.csv")
40
+ else:
41
+ ulc = None
42
+
43
+ if (normalize_flux == True) or (plot_folded_transits == True) or (plot_riverplot == True):
44
+ flc = pd.read_csv(output_folder / f"{target}_lc_flattened.csv")
45
+ else:
46
+ flc = None
47
+
48
+ lcs = {'ulc': ulc, 'flc': flc} # Store as dict
49
+
50
+ # Plot lightcurves by quarter/sector
51
+ if plot_entire_lightcurve == True:
52
+ tf_pipeline.plot_lightcurves(target, lcs, normalize_flux, output_folder)
53
+
54
+ # Iterate per planet in system
55
+ planet_df = pd.read_csv(output_folder / f"{target}_transit_ephemerides.csv")
56
+ for _, row in planet_df.iterrows():
57
+ # Terminate immediately if transit doesn't exist
58
+ if row["transit_flag"] == False:
59
+ continue
60
+
61
+ # Fetch individual transits and optionally make diagonostic plots
62
+ tf_pipeline.fetch_individual_transits(lcs, normalize_flux, row, output_folder,
63
+ plot_individual_transits,
64
+ plot_folded_transits)
65
+
66
+ # River plot (Useful for large TTVs)
67
+ if plot_riverplot == True:
68
+ tf_pipeline.plot_river(flc, row, output_folder)
69
+
70
+ # Generate TransitFit configuration files
71
+ if generate_transitfit_csvs == True:
72
+ tf_pipeline.create_transitfit_configs(row, output_folder)
73
+
74
+ print(f'===== TransitFetcher completed for {target} =====\n')
75
+ return
@@ -0,0 +1,16 @@
1
+ import shutil
2
+ from pathlib import Path
3
+ import lightkurve as lk
4
+
5
+
6
+ def clean_lightkurve_cache():
7
+ """
8
+ Deletes the entire Lightkurve download cache.
9
+ """
10
+ cache_dir = Path(lk.config.get_cache_dir())
11
+
12
+ if cache_dir.exists():
13
+ shutil.rmtree(cache_dir)
14
+ print(f"Deleted Lightkurve cache: {cache_dir}")
15
+ else:
16
+ print("Lightkurve cache does not exist.")