tessapps 0.2.4__tar.gz → 0.2.6__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: tessapps
3
- Version: 0.2.4
3
+ Version: 0.2.6
4
4
  Summary: TESS Aperture Photometry Pollution eStimator
5
5
  Author: Leonidas Liponis
6
6
  Requires-Python: >=3.9
@@ -22,13 +22,13 @@ Import-Name: tessapps
22
22
 
23
23
  # TESS Aperture Photometry Pollution eStimator [![PyPI](https://img.shields.io/pypi/v/tessapps)](https://pypi.org/project/tessapps/)
24
24
 
25
+ *Note: this module is not yet fully developed. For commercial use, please wait for v1.0.0. It is expected to be in development for at least another month.*
26
+
25
27
  ## Description
26
28
 
27
29
  A python module that calculates a contamination factor in the aperture region of a tpf based on the relative flux of the background stars and the target.
28
30
 
29
- <p align="center">
30
- <img src="https://github.com/leolip128/tessapps/blob/main/examples/HAT-P-1.png" alt="HAT-P-1 example" style="width:63.21%; height:auto;">
31
- </p>
31
+ ![TESSAPPS Example: HAT-P-1](https://codeberg.org/leolip128/tessapps/raw/branch/main/examples/HAT-P-1.png "title")
32
32
 
33
33
  ## Prerequisites
34
34
 
@@ -54,19 +54,30 @@ import tessapps as tapps
54
54
 
55
55
  tapps.run()
56
56
 
57
- >>> [0.42325, 0.00191]
57
+ >>> [0.57675, 0.00191]
58
58
  ```
59
59
 
60
- The first number is 1 minus the contamination factor, and the second is its error. Here is a more realistic example with CoRoT-1 (also in the example images):
60
+ The first number is the contamination factor, and the second is its error. Here is a more realistic example with CoRoT-1 (also in the example images):
61
61
 
62
62
  ```
63
63
  import lightkurve as lk
64
64
  import tessapps as tapps
65
65
 
66
66
  tpf_CoRoT_1 = lk.search_targetpixelfile('CoRoT 1')[1].download()
67
- flux, error = tapps.run(tpf_CoRoT_1, result=True)
67
+ contamination, error = tapps.run(tpf_CoRoT_1, result=True)
68
+
69
+ >>> The background contributes (2.249 ± 0.020)% of the total flux in the aperture region.
70
+ ```
68
71
 
69
- >>> The target star contributes (97.751 ± 0.020)% of the total flux.
72
+ Alternatively, from a terminal:
73
+ ```
74
+ tapps --tpf tpf_file
75
+ python3 -m tessapps --tpf tpf_file
76
+ ```
77
+
78
+ And also:
79
+ ```
80
+ tapps --tpf tpf_file --result --sigma=1
70
81
  ```
71
82
 
72
83
  ## File Organization
@@ -105,7 +116,7 @@ Leonidas Liponis
105
116
 
106
117
  ## Links
107
118
 
108
- Github page: https://github.com/leolip128/tessapps
119
+ Codeberg page: https://codeberg.org/leolip128/tessapps
109
120
 
110
121
  PyPI page: https://pypi.org/project/tessapps/
111
122
 
@@ -120,6 +131,8 @@ No LLMs were used in the making of this project. All code was generated and veri
120
131
  - add description
121
132
  - specify dependencies' versions
122
133
  - add options to run the module
134
+ - redo examples since they reference the flux instead of the contamination factor
135
+ - add the scoring function
123
136
  - add more stuff in this to-do list
124
137
 
125
138
  ## Notes
@@ -1,12 +1,12 @@
1
1
  # TESS Aperture Photometry Pollution eStimator [![PyPI](https://img.shields.io/pypi/v/tessapps)](https://pypi.org/project/tessapps/)
2
2
 
3
+ *Note: this module is not yet fully developed. For commercial use, please wait for v1.0.0. It is expected to be in development for at least another month.*
4
+
3
5
  ## Description
4
6
 
5
7
  A python module that calculates a contamination factor in the aperture region of a tpf based on the relative flux of the background stars and the target.
6
8
 
7
- <p align="center">
8
- <img src="https://github.com/leolip128/tessapps/blob/main/examples/HAT-P-1.png" alt="HAT-P-1 example" style="width:63.21%; height:auto;">
9
- </p>
9
+ ![TESSAPPS Example: HAT-P-1](https://codeberg.org/leolip128/tessapps/raw/branch/main/examples/HAT-P-1.png "title")
10
10
 
11
11
  ## Prerequisites
12
12
 
@@ -32,19 +32,30 @@ import tessapps as tapps
32
32
 
33
33
  tapps.run()
34
34
 
35
- >>> [0.42325, 0.00191]
35
+ >>> [0.57675, 0.00191]
36
36
  ```
37
37
 
38
- The first number is 1 minus the contamination factor, and the second is its error. Here is a more realistic example with CoRoT-1 (also in the example images):
38
+ The first number is the contamination factor, and the second is its error. Here is a more realistic example with CoRoT-1 (also in the example images):
39
39
 
40
40
  ```
41
41
  import lightkurve as lk
42
42
  import tessapps as tapps
43
43
 
44
44
  tpf_CoRoT_1 = lk.search_targetpixelfile('CoRoT 1')[1].download()
45
- flux, error = tapps.run(tpf_CoRoT_1, result=True)
45
+ contamination, error = tapps.run(tpf_CoRoT_1, result=True)
46
+
47
+ >>> The background contributes (2.249 ± 0.020)% of the total flux in the aperture region.
48
+ ```
46
49
 
47
- >>> The target star contributes (97.751 ± 0.020)% of the total flux.
50
+ Alternatively, from a terminal:
51
+ ```
52
+ tapps --tpf tpf_file
53
+ python3 -m tessapps --tpf tpf_file
54
+ ```
55
+
56
+ And also:
57
+ ```
58
+ tapps --tpf tpf_file --result --sigma=1
48
59
  ```
49
60
 
50
61
  ## File Organization
@@ -83,7 +94,7 @@ Leonidas Liponis
83
94
 
84
95
  ## Links
85
96
 
86
- Github page: https://github.com/leolip128/tessapps
97
+ Codeberg page: https://codeberg.org/leolip128/tessapps
87
98
 
88
99
  PyPI page: https://pypi.org/project/tessapps/
89
100
 
@@ -98,6 +109,8 @@ No LLMs were used in the making of this project. All code was generated and veri
98
109
  - add description
99
110
  - specify dependencies' versions
100
111
  - add options to run the module
112
+ - redo examples since they reference the flux instead of the contamination factor
113
+ - add the scoring function
101
114
  - add more stuff in this to-do list
102
115
 
103
116
  ## Notes
@@ -16,7 +16,7 @@ dependencies = ["numpy", "scipy", "matplotlib", "astropy", "astroquery", "lightk
16
16
  dev = ["bump-my-version", "flit"]
17
17
 
18
18
  [tool.bumpversion]
19
- current_version = "0.2.4"
19
+ current_version = "0.2.6"
20
20
  commit = false
21
21
  tag = false
22
22
  allow_dirty = true
@@ -29,6 +29,7 @@ Homepage = "https://codeberg.org/leolip128/tessapps"
29
29
  Repository = "https://codeberg.org/leolip128/tessapps"
30
30
 
31
31
  [project.scripts]
32
+ tapps = "tessapps.main:main"
32
33
  tessapps = "tessapps.main:main"
33
34
 
34
35
  [tool.flit.module]
@@ -0,0 +1 @@
1
+ # Test file
@@ -2,5 +2,5 @@
2
2
 
3
3
  from tessapps.main import run
4
4
 
5
- __version__ = "0.2.4"
5
+ __version__ = "0.2.6"
6
6
  __all__ = ["run"]
@@ -42,12 +42,16 @@ def contribution_calculator(tpf, data, sigma, digits, result): # this funct
42
42
  target_field, target_field_error, target_total_flux, target_total_error = target_gaussian_field(tpf, data, sigma)
43
43
 
44
44
  background_contribution = background_total_flux / (background_total_flux + target_total_flux) # the observed field is ideally the sum of the two
45
- target_contribution = target_total_flux / (background_total_flux + target_total_flux) # in reality both will be biased in some way
45
+ # target_contribution = target_total_flux / (background_total_flux + target_total_flux) # in reality both will be biased in some way
46
+ # target_contribution = 1 - background_contribution (alternatively)
46
47
 
47
48
  error_term = 1 / (background_total_flux + target_total_flux)**2
48
49
  total_error = error_term * np.sqrt((background_total_flux * target_total_error)**2 + (target_total_flux * background_total_error)**2)
49
50
 
51
+ contamination_factor = np.round(background_contribution, digits + 2)
52
+ contamination_error = np.round(total_error, digits + 2)
53
+
50
54
  if result:
51
- print(f"The target star contributes ({100 * target_contribution :.{digits}f} ± {100 * total_error :.{digits}f})% of the total flux.")
55
+ print(f"The background contributes ({100 * contamination_factor} ± {100 * contamination_error})% of the total flux in the aperture region.")
52
56
 
53
- return np.round(target_contribution, digits + 2), np.round(total_error, digits + 2)
57
+ return contamination_factor, contamination_error
@@ -0,0 +1,58 @@
1
+ import warnings
2
+ from erfa import ErfaWarning
3
+ warnings.filterwarnings("ignore", category=ErfaWarning) # suppresses: ErfaWarning: ERFA function "pmsafe" yielded 134 of "distance overridden (Note 6)"
4
+ warnings.filterwarnings("ignore", message=".*tpfmodel submodule is not available.*") # full warning: UserWarning: Warning: the tpfmodel submodule is not available without oktopus installed, which requires a current version of autograd. See #1452 for details.
5
+
6
+ import lightkurve as lk
7
+ import numpy as np
8
+ from scipy import integrate
9
+ import astropy.units as u
10
+ from astropy.table import Table
11
+ from astropy.time import Time
12
+ from astropy.coordinates import SkyCoord
13
+ from astropy.wcs.utils import proj_plane_pixel_scales
14
+ from astroquery.mast import Catalogs
15
+
16
+ import matplotlib.pyplot as plt
17
+ from pathlib import Path
18
+ from argparse import ArgumentParser
19
+
20
+ import tessapps.tpf_to_nearby_stars as ttns
21
+ import tessapps.nearby_stars_to_data as nstd
22
+ import tessapps.data_to_contamination as dtc
23
+
24
+ def run(tpf=None, pixel_overshoot=1, sigma=1, digits=3, info=False, result=False, plot=False, output_directory="tessapps-results"):
25
+ if tpf is None: tpf = lk.search_targetpixelfile("HAT-P-1", mission="TESS", sector=84, exptime=120).download()
26
+ stars = ttns.tpf_to_nearby_stars(tpf, pixel_overshoot, info)
27
+ data = nstd.data_builder(tpf, stars)
28
+ contamination_factor, contamination_error = dtc.contribution_calculator(tpf, data, sigma, digits, result)
29
+
30
+ # print(data[:6])
31
+
32
+ if plot:
33
+ fig, ax = plt.subplots(figsize=(8, 8))
34
+ tpf.plot(ax=ax, aperture_mask=tpf.pipeline_mask)
35
+ text = f"The background contributes ({100 * contamination_factor} ± {100 * contamination_error})% of the total flux in the aperture region."
36
+ fig.text(0.5 , 0.01, text, ha="center", fontsize=12)
37
+ out_path = Path(f"{output_directory}/TIC_{tpf.targetid}.png")
38
+ out_path.parent.mkdir(parents=True, exist_ok=True)
39
+ fig.savefig(out_path, dpi=200, bbox_inches="tight")
40
+ plt.show
41
+ return [float(contamination_factor), float(contamination_error)]
42
+
43
+ def main(argv=None):
44
+ parser = ArgumentParser() # prog="tapps" could be set for logs (consistency)
45
+ parser.add_argument("--tpf", default=None) # None means use the default file (see tapps.run)
46
+ parser.add_argument("--overshoot", type=float, default=1) # default is 1 pixel more diagonally
47
+ parser.add_argument("--sigma", type=float, default=1) # default can vary
48
+ parser.add_argument("--digits", type=int, default=3) # the contamination factor is rounded to this many digits
49
+ parser.add_argument("--info", action="store_true") # search info as found in tpf_to_nearby_stars module
50
+ parser.add_argument("--result", action="store_true") # type this to print the result (a single line, see tapps.run)
51
+ parser.add_argument("--plot", action="store_true") # this makes plots like in the examples
52
+ parser.add_argument("--out-dir", default="tapps-results") # configures the output directory
53
+ args = parser.parse_args(argv)
54
+
55
+ tpf, pixel_overshoot, sigma, digits = args.tpf, args.overshoot, args.sigma, args.digits # these two lines are for clarity
56
+ info, result, plot, directory = args.info, args.result, args.plot, args.out_dir # helps to keep the last line short
57
+
58
+ run(tpf, pixel_overshoot, sigma, digits, info, result, plot, directory) # run tessapps
@@ -1,40 +0,0 @@
1
- # import warnings
2
- # from erfa import ErfaWarning
3
- # warnings.filterwarnings("ignore", category=ErfaWarning)
4
- # warnings.filterwarnings("ignore", message=".*tpfmodel submodule is not available.*")
5
-
6
- import lightkurve as lk
7
- import numpy as np
8
- from scipy import integrate
9
- import astropy.units as u
10
- from astropy.table import Table
11
- from astropy.time import Time
12
- from astropy.coordinates import SkyCoord
13
- from astropy.wcs.utils import proj_plane_pixel_scales
14
- from astroquery.mast import Catalogs
15
-
16
- import matplotlib.pyplot as plt
17
- from pathlib import Path
18
-
19
- import tessapps.tpf_to_nearby_stars as ttns
20
- import tessapps.nearby_stars_to_data as nstd
21
- import tessapps.data_to_contamination as dtc
22
-
23
- def run(tpf=None, pixel_overshoot=1, sigma=1, digits=3, info=False, result=False, plot=False, output_directory="tessapps-results"):
24
- if tpf is None: tpf = lk.search_targetpixelfile("HAT-P-1", mission="TESS", sector=84, exptime=120).download()
25
- stars = ttns.tpf_to_nearby_stars(tpf, pixel_overshoot, info)
26
- data = nstd.data_builder(tpf, stars)
27
- target_contribution, total_error = dtc.contribution_calculator(tpf, data, sigma, digits, result)
28
-
29
- # print(data[:6])
30
-
31
- if plot:
32
- fig, ax = plt.subplots(figsize=(8, 8))
33
- tpf.plot(ax=ax, aperture_mask=tpf.pipeline_mask)
34
- text = f"Target star contributes ({100 * target_contribution :.{digits}f} ± {100 * total_error :.{digits}f})% of the total flux"
35
- fig.text(0.5 , 0.01, text, ha="center", fontsize=14)
36
- out_path = Path(f"{output_directory}/TIC_{tpf.targetid}.png")
37
- out_path.parent.mkdir(parents=True, exist_ok=True)
38
- fig.savefig(out_path, dpi=200, bbox_inches="tight")
39
- plt.show
40
- return [float(target_contribution), float(total_error)]
File without changes