preface-spearnet 2.0.0b2__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.
Files changed (31) hide show
  1. preface_spearnet-2.0.0b2/LICENSE +21 -0
  2. preface_spearnet-2.0.0b2/PKG-INFO +163 -0
  3. preface_spearnet-2.0.0b2/README.md +137 -0
  4. preface_spearnet-2.0.0b2/preface/P1_Cutter.py +89 -0
  5. preface_spearnet-2.0.0b2/preface/P1_ExoplanetseuImpactMerger.py +52 -0
  6. preface_spearnet-2.0.0b2/preface/P1_ImpactMerger.py +59 -0
  7. preface_spearnet-2.0.0b2/preface/P1_ModCheck.py +175 -0
  8. preface_spearnet-2.0.0b2/preface/P1_RankMaker.py +296 -0
  9. preface_spearnet-2.0.0b2/preface/P1_ViabilitySplitter.py +77 -0
  10. preface_spearnet-2.0.0b2/preface/P1_WorkingTEPSetBuilder.py +340 -0
  11. preface_spearnet-2.0.0b2/preface/P2_MultiprocessingProcess.py +934 -0
  12. preface_spearnet-2.0.0b2/preface/P2_MultiprocessingWrapper.py +371 -0
  13. preface_spearnet-2.0.0b2/preface/P2_PostCleaner.py +156 -0
  14. preface_spearnet-2.0.0b2/preface/__init__.py +243 -0
  15. preface_spearnet-2.0.0b2/preface/configs.py +505 -0
  16. preface_spearnet-2.0.0b2/preface/unused_code/P1_InputCheck.py +182 -0
  17. preface_spearnet-2.0.0b2/preface/unused_code/P1_SpecCutter.py +50 -0
  18. preface_spearnet-2.0.0b2/preface/unused_code/P2MP_Process_NoMP.py +934 -0
  19. preface_spearnet-2.0.0b2/preface/unused_code/P2MP_Wrapper.py +131 -0
  20. preface_spearnet-2.0.0b2/preface/unused_code/P2MP_Wrapper_Datacenter_NoMP.py +158 -0
  21. preface_spearnet-2.0.0b2/preface/unused_code/P2TimeSplitter.py +141 -0
  22. preface_spearnet-2.0.0b2/preface/unused_code/PipelineMasterShell.py +98 -0
  23. preface_spearnet-2.0.0b2/preface/unused_code/old_moon_lut_generator.py +180 -0
  24. preface_spearnet-2.0.0b2/preface/unused_code/test-Mark.py +75 -0
  25. preface_spearnet-2.0.0b2/preface_spearnet.egg-info/PKG-INFO +163 -0
  26. preface_spearnet-2.0.0b2/preface_spearnet.egg-info/SOURCES.txt +29 -0
  27. preface_spearnet-2.0.0b2/preface_spearnet.egg-info/dependency_links.txt +1 -0
  28. preface_spearnet-2.0.0b2/preface_spearnet.egg-info/requires.txt +11 -0
  29. preface_spearnet-2.0.0b2/preface_spearnet.egg-info/top_level.txt +1 -0
  30. preface_spearnet-2.0.0b2/pyproject.toml +59 -0
  31. preface_spearnet-2.0.0b2/setup.cfg +4 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 - Present: Chatdanai Sawangwong and contributors.
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,163 @@
1
+ Metadata-Version: 2.1
2
+ Name: preface_spearnet
3
+ Version: 2.0.0b2
4
+ Summary: An Automated Pipeline for the Selection of Transmission Spectroscopy Candidates
5
+ Author-email: Chatdanai Sawangwong <chatdanai.saw@gmail.com>, Supachai Awiphan <supachai@narit.or.th>, Orarik Tasuya <orarik@narit.or.th>, Napaporn A-thano <napaporn@narit.or.th>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/chatdanai-s/PREFACE
8
+ Project-URL: BugTracker, https://github.com/chatdanai-s/PREFACE/issues
9
+ Keywords: astronomy,exoplanets,transmission-spectroscopy,observation-planning,target-selection,astrophysics,pipeline
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Operating System :: OS Independent
12
+ Requires-Python: >=3.9
13
+ Description-Content-Type: text/markdown
14
+ License-File: LICENSE
15
+ Requires-Dist: numpy>=2.1.0
16
+ Requires-Dist: pandas>=2.2.3
17
+ Requires-Dist: matplotlib>=3.9.2
18
+ Requires-Dist: astropy>=7.1.0
19
+ Requires-Dist: scipy>=1.13.1
20
+ Requires-Dist: python-dateutil>=2.9.0
21
+ Requires-Dist: joblib>=1.4.2
22
+ Requires-Dist: tqdm>=4.67.0
23
+ Requires-Dist: ephem>=4.2.1
24
+ Requires-Dist: timezonefinder>=8.2.4
25
+ Requires-Dist: pyarrow>=24.0.0
26
+
27
+ # PREFACE
28
+
29
+ **P**rioritization and **R**anking of **E**xoplanets **F**or **A**stronomical **C**haracterization and **E**xploration (**PREFACE**) is a Python package for selection of promising exoplanet transmission spectroscopy observations based on their expected scientific return and observational feasibility.
30
+
31
+ ---
32
+
33
+ ## To-do List
34
+ As this project is work in progress, here is the current to-do list:
35
+ - [ ] Fix a bug where the moonlight noise metric calculation sometimes return NaN
36
+ - [ ] Finish documentation
37
+ - [ ] (Maybe) Determine the default moonlight amplification factor that more properly and sensibly punishes full moon nights
38
+ - [ ] (Maybe) Reduce multiprocessing overhead
39
+ - [ ] (Maybe) Month- and location-dependent aerosol scattering parameters via end-to-end AERONET data retrieval
40
+
41
+ ---
42
+
43
+ ## Installation
44
+
45
+ Install the latest stable release from PyPI:
46
+ ```bash
47
+ pip install preface_spearnet
48
+ ```
49
+
50
+ ---
51
+
52
+ ## Usage
53
+
54
+ Using `preface` consists of four steps:
55
+
56
+ 1. Configure the observing instrument with `TelescopeConfigurations`.
57
+ 2. Define the observing window and output options with `OutputConfigurations`.
58
+ 3. Optionally configure moonlight modelling and multiprocessing with `MoonlightNoiseConfigurations` and `MultiprocessingConfigurations`.
59
+ 4. Execute the complete pipeline with `run_preface()`.
60
+
61
+ Input validation is performed automatically before pipeline execution.
62
+
63
+ Full documentation (configuration reference, PREFACE workflow and output descriptions, and API) is available at **[preface-spearnet.readthedocs.io](https://preface-spearnet.readthedocs.io)**.
64
+
65
+ ### Example
66
+
67
+ ```python
68
+ import datetime as dt
69
+ from preface import run_preface
70
+ from preface.configs import (
71
+ TelescopeConfigurations,
72
+ OutputConfigurations,
73
+ MoonlightNoiseConfigurations,
74
+ MultiprocessingConfigurations,
75
+ )
76
+
77
+ ObsStart = dt.datetime(2025, 10, 1)
78
+ ObsEnd = dt.datetime(2026, 5, 31)
79
+ OutputFolder = r"C:\PREFACE_Output"
80
+
81
+ TelescopeConfigs = TelescopeConfigurations(
82
+ instrument="TNT ULTRASPEC",
83
+ filter_name="r",
84
+ run_mode="Half_Well",
85
+ toggle_sky_noise=True,
86
+ toggle_defocus=False
87
+ )
88
+
89
+ OutputConfigs = OutputConfigurations(
90
+ observation_start=ObsStart,
91
+ observation_end=ObsEnd,
92
+ output_folder=OutputFolder,
93
+ metric_mode="Rank",
94
+ viable_cumulative_cut=0.97
95
+ )
96
+
97
+ MoonlightConfigs = MoonlightNoiseConfigurations(
98
+ toggle_moonlight_noise=True,
99
+ scattering_aod=0.2,
100
+ absorption_aod=0.3,
101
+ asymmetry_factor=0.6,
102
+ moonlight_amplification_factor=5,
103
+ toggle_graph_outputs=True,
104
+ event_weight_graph_threshold=0.75
105
+ )
106
+
107
+ MultiprocessingConfigs = MultiprocessingConfigurations(
108
+ toggle_multiprocessing=True,
109
+ cores_to_leave_out=2
110
+ )
111
+
112
+ run_preface(
113
+ TelescopeConfigurations=TelescopeConfigs,
114
+ OutputConfigurations=OutputConfigs,
115
+ MoonlightNoiseConfigurations=MoonlightConfigs,
116
+ MultiprocessingConfigurations=MultiprocessingConfigs
117
+ )
118
+ ```
119
+
120
+ ---
121
+ ## Authors
122
+
123
+ **Jake Staberg Morgan** (Original author)
124
+
125
+ **Chatdanai Sawangwong** (Current maintainer)\
126
+ email: chatdanai.saw@gmail.com
127
+
128
+ **Supachai Awiphan**\
129
+ email: supachai@narit.or.th
130
+
131
+ **Orarik Tasuya**\
132
+ email: orarik@narit.or.th
133
+
134
+ **Napaporn A-thano**\
135
+ email: napaporn@narit.or.th
136
+
137
+ <!-- ---
138
+
139
+ ## Citation
140
+
141
+ If you use **PREFACE** in academic work, please cite the associated publications:
142
+
143
+ ```bibtex
144
+ @software{NameYear_PREFACE,
145
+ author = {Authors},
146
+ title = {Title},
147
+ year = {Year},
148
+ publisher = {Publisher}
149
+ }
150
+ ```
151
+
152
+ ```bibtex
153
+ @phdthesis{Morgan2020_SPEARNET,
154
+ author = {Morgan, Jake S.},
155
+ title = {SPEARNET: A Pilot Exoplanet Transmission Spectroscopy Survey},
156
+ school = {The University of Manchester},
157
+ year = {2020},
158
+ type = {PhD thesis},
159
+ date = {2020-11-18},
160
+ month = nov,
161
+ url = {https://research.manchester.ac.uk/en/studentTheses/spearnet-a-pilot-exoplanet-transmission-spectroscopy-survey}
162
+ }
163
+ ``` -->
@@ -0,0 +1,137 @@
1
+ # PREFACE
2
+
3
+ **P**rioritization and **R**anking of **E**xoplanets **F**or **A**stronomical **C**haracterization and **E**xploration (**PREFACE**) is a Python package for selection of promising exoplanet transmission spectroscopy observations based on their expected scientific return and observational feasibility.
4
+
5
+ ---
6
+
7
+ ## To-do List
8
+ As this project is work in progress, here is the current to-do list:
9
+ - [ ] Fix a bug where the moonlight noise metric calculation sometimes return NaN
10
+ - [ ] Finish documentation
11
+ - [ ] (Maybe) Determine the default moonlight amplification factor that more properly and sensibly punishes full moon nights
12
+ - [ ] (Maybe) Reduce multiprocessing overhead
13
+ - [ ] (Maybe) Month- and location-dependent aerosol scattering parameters via end-to-end AERONET data retrieval
14
+
15
+ ---
16
+
17
+ ## Installation
18
+
19
+ Install the latest stable release from PyPI:
20
+ ```bash
21
+ pip install preface_spearnet
22
+ ```
23
+
24
+ ---
25
+
26
+ ## Usage
27
+
28
+ Using `preface` consists of four steps:
29
+
30
+ 1. Configure the observing instrument with `TelescopeConfigurations`.
31
+ 2. Define the observing window and output options with `OutputConfigurations`.
32
+ 3. Optionally configure moonlight modelling and multiprocessing with `MoonlightNoiseConfigurations` and `MultiprocessingConfigurations`.
33
+ 4. Execute the complete pipeline with `run_preface()`.
34
+
35
+ Input validation is performed automatically before pipeline execution.
36
+
37
+ Full documentation (configuration reference, PREFACE workflow and output descriptions, and API) is available at **[preface-spearnet.readthedocs.io](https://preface-spearnet.readthedocs.io)**.
38
+
39
+ ### Example
40
+
41
+ ```python
42
+ import datetime as dt
43
+ from preface import run_preface
44
+ from preface.configs import (
45
+ TelescopeConfigurations,
46
+ OutputConfigurations,
47
+ MoonlightNoiseConfigurations,
48
+ MultiprocessingConfigurations,
49
+ )
50
+
51
+ ObsStart = dt.datetime(2025, 10, 1)
52
+ ObsEnd = dt.datetime(2026, 5, 31)
53
+ OutputFolder = r"C:\PREFACE_Output"
54
+
55
+ TelescopeConfigs = TelescopeConfigurations(
56
+ instrument="TNT ULTRASPEC",
57
+ filter_name="r",
58
+ run_mode="Half_Well",
59
+ toggle_sky_noise=True,
60
+ toggle_defocus=False
61
+ )
62
+
63
+ OutputConfigs = OutputConfigurations(
64
+ observation_start=ObsStart,
65
+ observation_end=ObsEnd,
66
+ output_folder=OutputFolder,
67
+ metric_mode="Rank",
68
+ viable_cumulative_cut=0.97
69
+ )
70
+
71
+ MoonlightConfigs = MoonlightNoiseConfigurations(
72
+ toggle_moonlight_noise=True,
73
+ scattering_aod=0.2,
74
+ absorption_aod=0.3,
75
+ asymmetry_factor=0.6,
76
+ moonlight_amplification_factor=5,
77
+ toggle_graph_outputs=True,
78
+ event_weight_graph_threshold=0.75
79
+ )
80
+
81
+ MultiprocessingConfigs = MultiprocessingConfigurations(
82
+ toggle_multiprocessing=True,
83
+ cores_to_leave_out=2
84
+ )
85
+
86
+ run_preface(
87
+ TelescopeConfigurations=TelescopeConfigs,
88
+ OutputConfigurations=OutputConfigs,
89
+ MoonlightNoiseConfigurations=MoonlightConfigs,
90
+ MultiprocessingConfigurations=MultiprocessingConfigs
91
+ )
92
+ ```
93
+
94
+ ---
95
+ ## Authors
96
+
97
+ **Jake Staberg Morgan** (Original author)
98
+
99
+ **Chatdanai Sawangwong** (Current maintainer)\
100
+ email: chatdanai.saw@gmail.com
101
+
102
+ **Supachai Awiphan**\
103
+ email: supachai@narit.or.th
104
+
105
+ **Orarik Tasuya**\
106
+ email: orarik@narit.or.th
107
+
108
+ **Napaporn A-thano**\
109
+ email: napaporn@narit.or.th
110
+
111
+ <!-- ---
112
+
113
+ ## Citation
114
+
115
+ If you use **PREFACE** in academic work, please cite the associated publications:
116
+
117
+ ```bibtex
118
+ @software{NameYear_PREFACE,
119
+ author = {Authors},
120
+ title = {Title},
121
+ year = {Year},
122
+ publisher = {Publisher}
123
+ }
124
+ ```
125
+
126
+ ```bibtex
127
+ @phdthesis{Morgan2020_SPEARNET,
128
+ author = {Morgan, Jake S.},
129
+ title = {SPEARNET: A Pilot Exoplanet Transmission Spectroscopy Survey},
130
+ school = {The University of Manchester},
131
+ year = {2020},
132
+ type = {PhD thesis},
133
+ date = {2020-11-18},
134
+ month = nov,
135
+ url = {https://research.manchester.ac.uk/en/studentTheses/spearnet-a-pilot-exoplanet-transmission-spectroscopy-survey}
136
+ }
137
+ ``` -->
@@ -0,0 +1,89 @@
1
+ # Part 4.1 of overall pipeline.
2
+ # Takes in WorkingTEPSet, calculates exposure times, cadences and ranks for a chosen calibration telescope/filter combination.
3
+ # This then provides the cut-off to be subsequently used in the wider pipeline.
4
+ # This cut-off must be chosen by the user - at present, a physically-motivated cut is not possible.
5
+ # Outputs a small .csv of D_min values for wider use.
6
+ import pandas as pd
7
+ import numpy as np
8
+
9
+ #The central rank-making function.
10
+ def RankMaker(CSV_core_folder, CSV_intermediate_folder,
11
+ scope_df, instrument, filter_name, run_mode, toggle_sky_noise, toggle_defocus, metric_mode, viable_cumulative_cut):
12
+
13
+ # Parameters for RankMaker for calibrating instruments
14
+ if run_mode == 'Spectral_Half_Well':
15
+ Inst_cal = 'VLT FORS2 (200kHz) 600RI+19' # Calibrating instrument
16
+ Filter_cal = '600RI+19'
17
+ SkyNoise_cal = toggle_sky_noise
18
+ Defocus_cal = toggle_defocus
19
+
20
+ elif run_mode == 'IR_Half_Well':
21
+ Inst_cal = 'VLT KMOS_HK'
22
+ Filter_cal = 'HK'
23
+ SkyNoise_cal = True
24
+ Defocus_cal = toggle_defocus
25
+
26
+ else: # Half_Well Run_Mode
27
+ Inst_cal = instrument
28
+ Filter_cal = filter_name
29
+ SkyNoise_cal = toggle_sky_noise
30
+ Defocus_cal = toggle_defocus
31
+
32
+ cal_idx = np.where(scope_df['Telescope'] == Inst_cal)[0][0] # Index of calibrating Inst
33
+
34
+ sky_noise_text = 'Y-SkyNoise' if SkyNoise_cal else 'N-SkyNoise'
35
+ defocus_text = 'Y-Defocus' if Defocus_cal else 'N-Defocus'
36
+ calibrator_csv_path = (
37
+ CSV_intermediate_folder / "ranked_tep_sets"
38
+ / f"RankedTEPSet_{Inst_cal}_{Filter_cal}-band_for_{run_mode}_{sky_noise_text}_{defocus_text}.csv"
39
+ )
40
+ rankcut_csv_path = (
41
+ CSV_intermediate_folder / "minranks_cut_sets"
42
+ / f"minRanks_{Inst_cal}_{Filter_cal}-band_for_{run_mode}_{sky_noise_text}_{defocus_text}_{viable_cumulative_cut*100}%_cut.csv"
43
+ )
44
+ (CSV_intermediate_folder / "minranks_cut_sets").mkdir(parents=True, exist_ok=True)
45
+
46
+ # Run RankMaker on Calibrating instrument if configuration is different
47
+ different_calibrating_configuration = (Inst_cal != instrument) or (Filter_cal != filter_name) \
48
+ or (SkyNoise_cal != toggle_sky_noise) or (Defocus_cal != toggle_defocus)
49
+
50
+ if different_calibrating_configuration == True:
51
+ import preface.P1_RankMaker as P1_RankMaker
52
+ print("[Cutter] Running RankMaker on calibrating instrument...")
53
+ P1_RankMaker.RankMaker(CSV_core_folder, CSV_intermediate_folder,
54
+ scope_df, cal_idx, Inst_cal, Filter_cal, run_mode, SkyNoise_cal, Defocus_cal)
55
+
56
+ df_cal = pd.read_csv(calibrator_csv_path, skipinitialspace=True)
57
+
58
+
59
+ # 'Index' column is only there to make the CSV look like the legacy ver as much as possible.
60
+ # This is the list to store cut thresholds.
61
+ RMin_cols = ['Index', 'RMin_Rank', 'RMin_Habitable_Rank',
62
+ 'RMin_Multi_Transit_Rank', 'RMin_Multi_Transit_Habitable_Rank']
63
+ RMin_vals = [1]
64
+
65
+ def CumCutter(metric_col):
66
+ # Sort by chosen column (signal strength parameter), high to low.
67
+ df_cal_temp = df_cal.sort_values(by=metric_col, ascending=False)[[metric_col]] # [[col]] keeps dj a dataframe
68
+ df_cal_temp.reset_index(inplace=True)
69
+ df_cal_temp['CumSum'] = df_cal_temp[metric_col].cumsum() # Cumulative sum calculation
70
+ df_cal_temp['CumSumFrac'] = df_cal_temp['CumSum'] / df_cal_temp['CumSum'].max()
71
+
72
+ df_cal_temp = df_cal_temp[df_cal_temp['CumSumFrac'] <= viable_cumulative_cut]
73
+ RMin = df_cal_temp[metric_col].min()
74
+ RMin_vals.append(RMin)
75
+
76
+ # For loop on all metrics
77
+ for metric in ['Rank', 'Habitable_Rank', 'Multi_Transit_Rank', 'Multi_Transit_Habitable_Rank']:
78
+ CumCutter(metric)
79
+
80
+
81
+ # Brings together into DataFrame and provides cutoff value
82
+ df = pd.DataFrame([RMin_vals], columns=RMin_cols)
83
+ Rmin = df[f'RMin_{metric_mode}'][0]
84
+
85
+ # Write to CSV.
86
+ df.to_csv(rankcut_csv_path, index=False)
87
+ print(rf'[Cutter] {viable_cumulative_cut*100}% cuts for {Inst_cal}, {Filter_cal}-band for {run_mode}, {sky_noise_text}, {defocus_text} generated.')
88
+
89
+ return Rmin
@@ -0,0 +1,52 @@
1
+ # Part 2.2 of overall pipeline.
2
+ # Further b-values can be retrieved from exoplanets.eu, particularly for new objects.
3
+
4
+ import pandas as pd
5
+ from preface.P1_ImpactMerger import BWriter
6
+
7
+ # Main function
8
+
9
+ def ExoeuImpacts(CSV_core_folder):
10
+ # Locate files
11
+ tep_with_exob_csv_path = CSV_core_folder / 'FullTEPSetWithExoOrgImpacts.csv'
12
+ exoplanets_eu_csv_path = CSV_core_folder / 'exoplaneteu_catalog.csv'
13
+ tep_with_allb_csv_path = CSV_core_folder / 'FullTEPSetWithAllImpacts.csv'
14
+
15
+
16
+ # Takes in FullTEPSet, processes names to find those with missing b.
17
+ df_tep_exob = pd.read_csv(tep_with_exob_csv_path)
18
+ df_tep_exob.insert(1, 'Planet_temp', df_tep_exob['Planet']) # Temporary column
19
+
20
+ df_tep_exob['Planet'] = df_tep_exob['Planet'].replace({'-00':'-', '-0':'-',
21
+ '_00':'_', '_0':'_'},
22
+ regex=True)
23
+ df_tep_exob['Planet'] = df_tep_exob.apply(lambda row: BWriter(row), axis=1)
24
+
25
+
26
+ # Takes in table of transiting planets from exoplanets.eu, processes names to find b values
27
+ colnames = ['name', 'impact_parameter']
28
+ df_eu = pd.read_csv(exoplanets_eu_csv_path, usecols=colnames)
29
+ df_eu.rename(columns={'name': 'Planet',
30
+ 'impact_parameter': 'Impact Parameter_from_eu'},
31
+ inplace=True)
32
+
33
+ # This scheme is not perfect yet, needs polishing
34
+ df_eu['Planet'] = df_eu['Planet'].replace({'AU Mic ':'AU_Mic_',
35
+ 'A b':'b', ' A':'', ' B':'', ' (AB)':'',
36
+ r'([A-Z]) ': r'\1_',
37
+ ' ':'',
38
+ 'EPIC_22881391b':'EPIC_228813918b'
39
+ },
40
+ regex=True)
41
+
42
+
43
+ # Append impact parameter to missing values in original dataframe then export
44
+ df_tep_allb = pd.merge(df_tep_exob, df_eu, on='Planet', how='left')
45
+ df_tep_allb['Impact Parameter'] = df_tep_allb['Impact Parameter'].fillna(df_tep_allb['Impact Parameter_from_eu'])
46
+ df_tep_allb = df_tep_allb.drop(columns=['Planet', 'Impact Parameter_from_eu'])
47
+ df_tep_allb = df_tep_allb.rename(columns={'Planet_temp': 'Planet'}) # Recover old planet names
48
+
49
+ # Reads back out with:
50
+ df_tep_allb.to_csv(tep_with_allb_csv_path, index=False)
51
+
52
+ print('[ExoplanetseuImpactMerger] Impact parameters from exoplanets.eu recovered.')
@@ -0,0 +1,59 @@
1
+ # Part 2.1 of overall pipeline.
2
+ # TEPCat does not store impact parameters, so they must be corralled from elsewhere.
3
+
4
+ import pandas as pd
5
+
6
+ # Small function to massage names such that both catalogues use same naming convention.
7
+ def BWriter(row):
8
+ if row['Planet'][-1].isdigit() == True:
9
+ row['Planet'] = row['Planet'] + 'b'
10
+
11
+ return row['Planet']
12
+
13
+ # Main function
14
+ def ExoOrgImpacts(CSV_core_folder):
15
+ # Locate files
16
+ fulltepset_csv_path = CSV_core_folder / 'FullTEPSet.csv'
17
+ exoorglist_csv_path = CSV_core_folder / 'ExoOrgList.csv'
18
+ tep_with_exoorg_csv_path = CSV_core_folder / 'FullTEPSetWithExoOrgImpacts.csv'
19
+
20
+
21
+ # Takes in all names in FullTEPSet and processes them.
22
+ df_fulltep = pd.read_csv(fulltepset_csv_path)
23
+ df_fulltep.insert(1, 'Planet_temp', df_fulltep['Planet']) # Temporary column to be used in final planet name
24
+
25
+ # Setup planet column as key
26
+ df_fulltep['Planet'] = df_fulltep['Planet'].replace({'-00':'-', '-0':'-',
27
+ '_00':'_', '_0':'_'},
28
+ regex=True
29
+ )
30
+ df_fulltep['Planet'] = df_fulltep.apply(lambda row: BWriter(row), axis=1)
31
+
32
+
33
+ # Takes in table of transiting planets from exoplanets.org
34
+ # exoplanets.org is a catalogue built by hand, so no auto-updater here.
35
+ # Also, exoplanets.org is not updated with planets published after June 2018
36
+ colnames = ['NAME', 'B']
37
+ df_exoorg = pd.read_csv(exoorglist_csv_path, usecols=colnames)
38
+ df_exoorg.rename(columns={'NAME': 'Planet', 'B': 'Impact Parameter'}, inplace=True)
39
+
40
+ # Process planet names before merging
41
+ df_exoorg['Planet'] = df_exoorg['Planet'].replace({'55 Cnc e':'55_Cnc_e', 'OGLE2':'OGLE',
42
+ 'BD +20 594': 'K2-56b',
43
+ r'([A-Z]) ': r'\1_',
44
+ 'A b':'b',
45
+ ' ':''
46
+ },
47
+ regex=True
48
+ )
49
+
50
+
51
+ # Append impact parameter to original dataframe
52
+ df_combined = pd.merge(df_fulltep, df_exoorg, on='Planet', how='left')
53
+ df_combined = df_combined.drop('Planet', axis=1) # Recover old planet names
54
+ df_combined = df_combined.rename(columns={'Planet_temp': 'Planet'})
55
+
56
+ # Export
57
+ df_combined.to_csv(tep_with_exoorg_csv_path, index=False)
58
+
59
+ print('[ImpactMerger] Impact parameters from exoplanets.org recovered.')