phise 0.1.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.
- phise-0.1.0/PKG-INFO +69 -0
- phise-0.1.0/README.md +48 -0
- phise-0.1.0/pyproject.toml +41 -0
- phise-0.1.0/setup.cfg +4 -0
- phise-0.1.0/src/phise/__init__.py +23 -0
- phise-0.1.0/src/phise/classes/__init__.py +22 -0
- phise-0.1.0/src/phise/classes/camera.py +247 -0
- phise-0.1.0/src/phise/classes/companion.py +189 -0
- phise-0.1.0/src/phise/classes/context.py +1272 -0
- phise-0.1.0/src/phise/classes/interferometer.py +354 -0
- phise-0.1.0/src/phise/classes/kernel_nuller.py +517 -0
- phise-0.1.0/src/phise/classes/mmi.py +126 -0
- phise-0.1.0/src/phise/classes/target.py +216 -0
- phise-0.1.0/src/phise/classes/telescope.py +119 -0
- phise-0.1.0/src/phise/modules/__init__.py +6 -0
- phise-0.1.0/src/phise/modules/coordinates.py +132 -0
- phise-0.1.0/src/phise/modules/ml.py +180 -0
- phise-0.1.0/src/phise/modules/mmi.py +38 -0
- phise-0.1.0/src/phise/modules/phase.py +54 -0
- phise-0.1.0/src/phise/modules/signals.py +45 -0
- phise-0.1.0/src/phise/modules/test_statistics.py +280 -0
- phise-0.1.0/src/phise.egg-info/PKG-INFO +69 -0
- phise-0.1.0/src/phise.egg-info/SOURCES.txt +24 -0
- phise-0.1.0/src/phise.egg-info/dependency_links.txt +1 -0
- phise-0.1.0/src/phise.egg-info/requires.txt +12 -0
- phise-0.1.0/src/phise.egg-info/top_level.txt +1 -0
phise-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: phise
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Package for tunable kernel nulling / interferometry utilities (phise)
|
|
5
|
+
Author-email: Vincent Foriel <vincent.foriel@gmail.com>, VForiel <vince.lrf@gmail.com>, VForiel <vincent.foriel@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Requires-Python: ==3.11.*
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
Requires-Dist: numpy>=1.26.4
|
|
10
|
+
Requires-Dist: matplotlib>=3.10.3
|
|
11
|
+
Requires-Dist: astropy>=7.1.0
|
|
12
|
+
Requires-Dist: scipy>=1.16.0
|
|
13
|
+
Requires-Dist: ipywidgets>=8.1.7
|
|
14
|
+
Requires-Dist: sympy>=1.14.0
|
|
15
|
+
Requires-Dist: fitter>=1.7.1
|
|
16
|
+
Requires-Dist: numba>=0.61.2
|
|
17
|
+
Requires-Dist: LRFutils>=0.1.2
|
|
18
|
+
Requires-Dist: nbformat>=5.10.4
|
|
19
|
+
Requires-Dist: pip>=25.1.1
|
|
20
|
+
Requires-Dist: gitpython>=3.1.44
|
|
21
|
+
|
|
22
|
+
## PHISE — PHotonic Interferometric Simulation for Exoplanets
|
|
23
|
+
|
|
24
|
+
PHISE is a Python package for simulation and analysis of interferometric instruments using layered photonic chips. It provides high-level classes (telescopes, interferometer, kernel nuller, camera, target scene) and numerical modules (propagation, coordinates, MMI recombiners, test statistics) to build scenarios, simulate the instrument chain, and visualize responses (transmission maps, projected baselines, null/dark/bright outputs, etc.).
|
|
25
|
+
|
|
26
|
+
The repository also ships demo notebooks and a complete documentation
|
|
27
|
+
|
|
28
|
+
> **Note**
|
|
29
|
+
> PHISE is currently under active development and is still a part of a PhD research project. The API and functionalities may change at any time.
|
|
30
|
+
|
|
31
|
+
## Requirements and installation
|
|
32
|
+
|
|
33
|
+
- Python 3.11 or upper.
|
|
34
|
+
- Main dependencies: numpy, astropy, scipy, matplotlib, numba, ipywidgets, sympy, LRFutils, etc. (handled automatically).
|
|
35
|
+
|
|
36
|
+
Two installation paths:
|
|
37
|
+
|
|
38
|
+
1) Conda environment (recommended)
|
|
39
|
+
|
|
40
|
+
```powershell
|
|
41
|
+
conda env create -f environment.yml
|
|
42
|
+
conda activate phise
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
2) pip editable install (dev mode)
|
|
46
|
+
|
|
47
|
+
```powershell
|
|
48
|
+
pip install -e .
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
## Documentation
|
|
52
|
+
|
|
53
|
+
A complete documentation is available at https://phise.readthedocs.io/
|
|
54
|
+
|
|
55
|
+
## Design notes
|
|
56
|
+
|
|
57
|
+
- Physical quantities are handled with `astropy.units` and validated in property setters to ensure unit consistency.
|
|
58
|
+
- Heavy computations rely on `numpy` and `numba` where appropriate.
|
|
59
|
+
- High-level methods (`Context`) automatically propagate parameter changes (e.g., recompute projected positions and photon flux).
|
|
60
|
+
|
|
61
|
+
## Credits
|
|
62
|
+
|
|
63
|
+
- Lead author: Vincent Foriel.
|
|
64
|
+
- If you use PHISE in scientific work, please cite the repository and/or your related publications.
|
|
65
|
+
|
|
66
|
+
## Questions, bugs, contributions
|
|
67
|
+
|
|
68
|
+
Issues and contributions are welcome. Feel free to propose improvements (docs, tests, examples, new utilities in `modules/`, etc.) by opening an issue or a pull request.
|
|
69
|
+
|
phise-0.1.0/README.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
## PHISE — PHotonic Interferometric Simulation for Exoplanets
|
|
2
|
+
|
|
3
|
+
PHISE is a Python package for simulation and analysis of interferometric instruments using layered photonic chips. It provides high-level classes (telescopes, interferometer, kernel nuller, camera, target scene) and numerical modules (propagation, coordinates, MMI recombiners, test statistics) to build scenarios, simulate the instrument chain, and visualize responses (transmission maps, projected baselines, null/dark/bright outputs, etc.).
|
|
4
|
+
|
|
5
|
+
The repository also ships demo notebooks and a complete documentation
|
|
6
|
+
|
|
7
|
+
> **Note**
|
|
8
|
+
> PHISE is currently under active development and is still a part of a PhD research project. The API and functionalities may change at any time.
|
|
9
|
+
|
|
10
|
+
## Requirements and installation
|
|
11
|
+
|
|
12
|
+
- Python 3.11 or upper.
|
|
13
|
+
- Main dependencies: numpy, astropy, scipy, matplotlib, numba, ipywidgets, sympy, LRFutils, etc. (handled automatically).
|
|
14
|
+
|
|
15
|
+
Two installation paths:
|
|
16
|
+
|
|
17
|
+
1) Conda environment (recommended)
|
|
18
|
+
|
|
19
|
+
```powershell
|
|
20
|
+
conda env create -f environment.yml
|
|
21
|
+
conda activate phise
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
2) pip editable install (dev mode)
|
|
25
|
+
|
|
26
|
+
```powershell
|
|
27
|
+
pip install -e .
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Documentation
|
|
31
|
+
|
|
32
|
+
A complete documentation is available at https://phise.readthedocs.io/
|
|
33
|
+
|
|
34
|
+
## Design notes
|
|
35
|
+
|
|
36
|
+
- Physical quantities are handled with `astropy.units` and validated in property setters to ensure unit consistency.
|
|
37
|
+
- Heavy computations rely on `numpy` and `numba` where appropriate.
|
|
38
|
+
- High-level methods (`Context`) automatically propagate parameter changes (e.g., recompute projected positions and photon flux).
|
|
39
|
+
|
|
40
|
+
## Credits
|
|
41
|
+
|
|
42
|
+
- Lead author: Vincent Foriel.
|
|
43
|
+
- If you use PHISE in scientific work, please cite the repository and/or your related publications.
|
|
44
|
+
|
|
45
|
+
## Questions, bugs, contributions
|
|
46
|
+
|
|
47
|
+
Issues and contributions are welcome. Feel free to propose improvements (docs, tests, examples, new utilities in `modules/`, etc.) by opening an issue or a pull request.
|
|
48
|
+
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "phise"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "Package for tunable kernel nulling / interferometry utilities (phise)"
|
|
5
|
+
authors = [
|
|
6
|
+
{name = "Vincent Foriel", email = "vincent.foriel@gmail.com"},
|
|
7
|
+
{name = "VForiel", email = "vince.lrf@gmail.com"},
|
|
8
|
+
{name = "VForiel", email = "vincent.foriel@gmail.com"},
|
|
9
|
+
]
|
|
10
|
+
dependencies = [
|
|
11
|
+
"numpy>=1.26.4",
|
|
12
|
+
"matplotlib>=3.10.3",
|
|
13
|
+
"astropy>=7.1.0",
|
|
14
|
+
"scipy>=1.16.0",
|
|
15
|
+
"ipywidgets>=8.1.7",
|
|
16
|
+
"sympy>=1.14.0",
|
|
17
|
+
"fitter>=1.7.1",
|
|
18
|
+
"numba>=0.61.2",
|
|
19
|
+
"LRFutils>=0.1.2",
|
|
20
|
+
"nbformat>=5.10.4",
|
|
21
|
+
"pip>=25.1.1",
|
|
22
|
+
"gitpython>=3.1.44",
|
|
23
|
+
]
|
|
24
|
+
requires-python = "==3.11.*"
|
|
25
|
+
readme = "README.md"
|
|
26
|
+
license = {text = "MIT"}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
[tool.pdm]
|
|
30
|
+
distribution = false
|
|
31
|
+
|
|
32
|
+
[build-system]
|
|
33
|
+
requires = ["setuptools>=61.0", "wheel"]
|
|
34
|
+
build-backend = "setuptools.build_meta"
|
|
35
|
+
|
|
36
|
+
[tool.setuptools]
|
|
37
|
+
package-dir = {"" = "src"}
|
|
38
|
+
|
|
39
|
+
[tool.setuptools.packages.find]
|
|
40
|
+
where = ["src"]
|
|
41
|
+
include = ["phise*"]
|
phise-0.1.0/setup.cfg
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
from .classes import *
|
|
2
|
+
from .modules import *
|
|
3
|
+
|
|
4
|
+
import os
|
|
5
|
+
|
|
6
|
+
# Get version from pyproject.toml
|
|
7
|
+
try:
|
|
8
|
+
import toml
|
|
9
|
+
pyproject_file = os.path.join(os.path.dirname(__file__), '../..', 'pyproject.toml')
|
|
10
|
+
with open(pyproject_file, 'r') as f:
|
|
11
|
+
pyproject = toml.load(f)
|
|
12
|
+
__version__ = pyproject['project']['version']
|
|
13
|
+
except Exception as e:
|
|
14
|
+
print("❌ Error: Could not retrieve version information.")
|
|
15
|
+
print(f"ℹ️ {e}")
|
|
16
|
+
|
|
17
|
+
# Try to get current commit (if in a git repo)
|
|
18
|
+
try:
|
|
19
|
+
import subprocess
|
|
20
|
+
commit = subprocess.check_output(['git', 'rev-parse', 'HEAD']).decode('ascii').strip()
|
|
21
|
+
__version__ += f"+{commit[:7]}"
|
|
22
|
+
except Exception:
|
|
23
|
+
pass
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"""Module d'agrégation des classes principales du package `phise.classes`.
|
|
2
|
+
|
|
3
|
+
Ce module ré-exporte les classes de plus haut niveau utilisées dans la
|
|
4
|
+
simulation (Companion, Target, Telescope, KernelNuller, Interferometer,
|
|
5
|
+
Context, Camera) afin de permettre des importations simplifiées :
|
|
6
|
+
|
|
7
|
+
>>> from phise.classes import Camera, Telescope
|
|
8
|
+
"""
|
|
9
|
+
from . import companion
|
|
10
|
+
from .companion import Companion
|
|
11
|
+
from . import target
|
|
12
|
+
from .target import Target
|
|
13
|
+
from . import telescope
|
|
14
|
+
from .telescope import Telescope
|
|
15
|
+
from . import kernel_nuller
|
|
16
|
+
from .kernel_nuller import KernelNuller
|
|
17
|
+
from . import interferometer
|
|
18
|
+
from .interferometer import Interferometer
|
|
19
|
+
from . import context
|
|
20
|
+
from .context import Context
|
|
21
|
+
from . import camera
|
|
22
|
+
from .camera import Camera
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
"""Gestion d'une caméra virtuelle pour la simulation d'interférométrie.
|
|
2
|
+
|
|
3
|
+
Ce module fournit la classe Camera qui représente un capteur simple utilisé
|
|
4
|
+
pour convertir des champs électriques complexes (visibilités) en un nombre
|
|
5
|
+
de photons détectés pendant une durée d'exposition. La classe est volontairement
|
|
6
|
+
minimaliste et conçue pour être utilisée par un objet `Interferometer` (type
|
|
7
|
+
indiqué dans les annotations) qui agit comme parent.
|
|
8
|
+
|
|
9
|
+
Principales responsabilités
|
|
10
|
+
- stocker le temps d'exposition (attribut `e`) sous la forme d'une
|
|
11
|
+
quantité Astropy en secondes;
|
|
12
|
+
- simuler la détection de photons via la méthode `acquire_pixel` à partir
|
|
13
|
+
d'un tableau de champs électriques complexes ;
|
|
14
|
+
- supporter un mode `ideal` (pas de bruit, valeur entière tronquée)
|
|
15
|
+
ou un mode réaliste (bruit de Poisson / approximations gaussiennes pour
|
|
16
|
+
grands nombres de photons).
|
|
17
|
+
|
|
18
|
+
Classe exposée
|
|
19
|
+
- Camera
|
|
20
|
+
|
|
21
|
+
Exemple minimal
|
|
22
|
+
---------------
|
|
23
|
+
>>> from phise.classes.camera import Camera
|
|
24
|
+
>>> import numpy as np
|
|
25
|
+
>>> import astropy.units as u
|
|
26
|
+
>>> cam = Camera(e=0.5 * u.s, ideal=False, name='CamSim')
|
|
27
|
+
>>> psi = np.array([1+0j, 0.5+0.5j]) # champs électriques complexes
|
|
28
|
+
>>> n = cam.acquire_pixel(psi)
|
|
29
|
+
|
|
30
|
+
Erreurs levées
|
|
31
|
+
- TypeError si `e` n'est pas une `astropy.units.Quantity` ou si `ideal`
|
|
32
|
+
/ `name` ne sont pas des types attendus.
|
|
33
|
+
- ValueError si `e` ne peut pas être converti en unité de temps.
|
|
34
|
+
|
|
35
|
+
Notes
|
|
36
|
+
- Les valeurs d'entrée et sortie sont minimales par conception :
|
|
37
|
+
- `ψ` (psi) est attendu comme un numpy.ndarray de nombres complexes où
|
|
38
|
+
|ψ|^2 donne un flux en s^-1 par élément ;
|
|
39
|
+
- `acquire_pixel` retourne un entier correspondant au nombre de photons
|
|
40
|
+
détectés pendant l'exposition `e`.
|
|
41
|
+
"""
|
|
42
|
+
from __future__ import annotations
|
|
43
|
+
from typing import TYPE_CHECKING, Optional
|
|
44
|
+
if TYPE_CHECKING:
|
|
45
|
+
from .interferometer import Interferometer
|
|
46
|
+
import numpy as np
|
|
47
|
+
import astropy.units as u
|
|
48
|
+
import numba as nb
|
|
49
|
+
import math
|
|
50
|
+
|
|
51
|
+
class Camera:
|
|
52
|
+
"""Représentation d'une caméra virtuelle utilisée pour la détection de photons.
|
|
53
|
+
|
|
54
|
+
Cette classe encapsule des paramètres simples d'un capteur (temps
|
|
55
|
+
d'exposition, nom, mode idéal) et fournit une méthode pour convertir
|
|
56
|
+
des champs électriques complexes en nombre de photons détectés durant
|
|
57
|
+
l'exposition.
|
|
58
|
+
"""
|
|
59
|
+
|
|
60
|
+
__slots__ = ('_parent_interferometer', '_e', '_name', '_ideal')
|
|
61
|
+
|
|
62
|
+
def __init__(self, e: Optional[u.Quantity] = None, ideal: bool = False, name: str = 'Unnamed Camera'):
|
|
63
|
+
"""Initialise la caméra.
|
|
64
|
+
|
|
65
|
+
Paramètres
|
|
66
|
+
----------
|
|
67
|
+
e : Optional[astropy.units.Quantity]
|
|
68
|
+
Temps d'exposition. Doit être une quantité avec une unité de temps
|
|
69
|
+
(par exemple ``1 * u.s``). Si ``None`` la valeur par défaut ``1 s``
|
|
70
|
+
est utilisée lorsque possible.
|
|
71
|
+
ideal : bool
|
|
72
|
+
Si True, la caméra est considérée idéale et renverra la valeur
|
|
73
|
+
entière attendue sans bruit (tronquée). Si False, un bruit de
|
|
74
|
+
comptage (Poisson) est simulé.
|
|
75
|
+
name : str
|
|
76
|
+
Nom lisible pour la caméra.
|
|
77
|
+
|
|
78
|
+
Exceptions
|
|
79
|
+
----------
|
|
80
|
+
TypeError
|
|
81
|
+
Si ``ideal`` n'est pas un booléen ou si ``name`` n'est pas une
|
|
82
|
+
chaîne de caractères.
|
|
83
|
+
ValueError
|
|
84
|
+
Si la quantité ``e`` ne peut pas être convertie en unité de
|
|
85
|
+
temps.
|
|
86
|
+
"""
|
|
87
|
+
self._parent_interferometer = None
|
|
88
|
+
# avoid evaluating `1 * u.s` at import time which may fail when astropy is mocked
|
|
89
|
+
if e is None:
|
|
90
|
+
try:
|
|
91
|
+
e = 1 * u.s
|
|
92
|
+
except Exception:
|
|
93
|
+
e = None
|
|
94
|
+
self.e = e
|
|
95
|
+
self.ideal = ideal
|
|
96
|
+
self.name = name
|
|
97
|
+
|
|
98
|
+
def __str__(self) -> str:
|
|
99
|
+
res = f'Camera "{self.name}"\n'
|
|
100
|
+
res += f' Exposure time: {self.e:.2f}'
|
|
101
|
+
return res
|
|
102
|
+
|
|
103
|
+
def __repr__(self) -> str:
|
|
104
|
+
return self.__str__()
|
|
105
|
+
|
|
106
|
+
@property
|
|
107
|
+
def e(self) -> u.Quantity:
|
|
108
|
+
"""Temps d'exposition de la caméra en secondes.
|
|
109
|
+
|
|
110
|
+
Retourne une ``astropy.units.Quantity`` exprimée en secondes. L'accesseur
|
|
111
|
+
n'effectue pas de conversion supplémentaire ; la conversion est gérée
|
|
112
|
+
dans le setter.
|
|
113
|
+
"""
|
|
114
|
+
return self._e
|
|
115
|
+
|
|
116
|
+
@e.setter
|
|
117
|
+
def e(self, e: u.Quantity):
|
|
118
|
+
"""Définit le temps d'exposition.
|
|
119
|
+
|
|
120
|
+
Paramètres
|
|
121
|
+
----------
|
|
122
|
+
e : astropy.units.Quantity
|
|
123
|
+
Quantité représentant un temps (ex : ``0.5 * u.s``).
|
|
124
|
+
|
|
125
|
+
Exceptions
|
|
126
|
+
----------
|
|
127
|
+
TypeError
|
|
128
|
+
Si ``e`` n'est pas un ``astropy.units.Quantity``.
|
|
129
|
+
ValueError
|
|
130
|
+
Si la quantité ne peut pas être convertie en une unité de temps.
|
|
131
|
+
"""
|
|
132
|
+
if not isinstance(e, u.Quantity):
|
|
133
|
+
raise TypeError('e must be an astropy Quantity')
|
|
134
|
+
try:
|
|
135
|
+
e = e.to(u.s)
|
|
136
|
+
except u.UnitConversionError:
|
|
137
|
+
raise ValueError('e must be in a time unit')
|
|
138
|
+
self._e = e
|
|
139
|
+
|
|
140
|
+
@property
|
|
141
|
+
def parent_interferometer(self) -> Interferometer:
|
|
142
|
+
"""Référence en lecture seule vers l'interféromètre parent.
|
|
143
|
+
|
|
144
|
+
Le setter est en lecture seule et l'attribut doit être configuré par
|
|
145
|
+
l'objet parent (ex. une instance d'``Interferometer``) si nécessaire.
|
|
146
|
+
"""
|
|
147
|
+
return self._parent_interferometer
|
|
148
|
+
|
|
149
|
+
@parent_interferometer.setter
|
|
150
|
+
def parent_interferometer(self, _):
|
|
151
|
+
"""Tentative d'écriture interdite pour `parent_interferometer`.
|
|
152
|
+
|
|
153
|
+
Cette propriété est en lecture seule ; toute affectation directe
|
|
154
|
+
déclenche une exception.
|
|
155
|
+
"""
|
|
156
|
+
raise ValueError('parent_interferometer is read-only')
|
|
157
|
+
|
|
158
|
+
@property
|
|
159
|
+
def ideal(self) -> bool:
|
|
160
|
+
"""Indique si la caméra est en mode idéal (sans bruit).
|
|
161
|
+
|
|
162
|
+
Retourne ``True`` lorsque le bruit de détection est désactivé. Le mode
|
|
163
|
+
idéal est utile pour des tests déterministes.
|
|
164
|
+
"""
|
|
165
|
+
return self._ideal
|
|
166
|
+
|
|
167
|
+
@ideal.setter
|
|
168
|
+
def ideal(self, ideal: bool):
|
|
169
|
+
"""Définit le mode idéal de la caméra.
|
|
170
|
+
|
|
171
|
+
Paramètres
|
|
172
|
+
----------
|
|
173
|
+
ideal : bool
|
|
174
|
+
``True`` pour un capteur sans bruit, ``False`` pour simuler le
|
|
175
|
+
bruit de comptage.
|
|
176
|
+
|
|
177
|
+
Exceptions
|
|
178
|
+
----------
|
|
179
|
+
TypeError
|
|
180
|
+
Si ``ideal`` n'est pas un booléen.
|
|
181
|
+
"""
|
|
182
|
+
if not isinstance(ideal, bool):
|
|
183
|
+
raise TypeError('ideal must be a boolean')
|
|
184
|
+
self._ideal = ideal
|
|
185
|
+
|
|
186
|
+
@property
|
|
187
|
+
def name(self) -> str:
|
|
188
|
+
"""Nom lisible de la caméra.
|
|
189
|
+
|
|
190
|
+
Retourne une chaîne de caractères représentant le nom de l'objet.
|
|
191
|
+
"""
|
|
192
|
+
return self._name
|
|
193
|
+
|
|
194
|
+
@name.setter
|
|
195
|
+
def name(self, name: str):
|
|
196
|
+
"""Définit le nom de la caméra.
|
|
197
|
+
|
|
198
|
+
Paramètres
|
|
199
|
+
----------
|
|
200
|
+
name : str
|
|
201
|
+
Nom lisible. Une ``TypeError`` est levée si ``name`` n'est pas une
|
|
202
|
+
chaîne.
|
|
203
|
+
"""
|
|
204
|
+
if not isinstance(name, str):
|
|
205
|
+
raise TypeError('name must be a string')
|
|
206
|
+
self._name = name
|
|
207
|
+
|
|
208
|
+
def acquire_pixel(self, ψ: np.ndarray[complex]) -> int:
|
|
209
|
+
"""Simule l'acquisition d'un pixel à partir de champs électriques.
|
|
210
|
+
|
|
211
|
+
La méthode calcule le nombre moyen de photons attendus comme la somme
|
|
212
|
+
des puissances |ψ|^2 multipliée par le temps d'exposition ``e``. Puis
|
|
213
|
+
elle simule la détection selon le mode :
|
|
214
|
+
|
|
215
|
+
- si ``ideal`` : retourne la valeur entière tronquée de l'espérance
|
|
216
|
+
(déterministe) ;
|
|
217
|
+
- sinon : pour des espérances raisonnables (<= 2e9) on tire d'une loi
|
|
218
|
+
de Poisson ; pour des espérances très grandes on utilise une
|
|
219
|
+
approximation gaussienne pour éviter des problèmes de performance.
|
|
220
|
+
|
|
221
|
+
Paramètres
|
|
222
|
+
----------
|
|
223
|
+
ψ : numpy.ndarray de nombres complexes
|
|
224
|
+
Tableau 1D (ou broadcastable) contenant les amplitudes complexes
|
|
225
|
+
du champ électrique (unités : s**(-1/2)).
|
|
226
|
+
|
|
227
|
+
Retour
|
|
228
|
+
-----
|
|
229
|
+
int
|
|
230
|
+
Nombre de photons détectés pendant l'exposition.
|
|
231
|
+
|
|
232
|
+
Remarques
|
|
233
|
+
---------
|
|
234
|
+
- La méthode retourne un entier >= 0. Les détails numériques (seuil
|
|
235
|
+
2e9) sont choisis empiriquement pour basculer vers une approximation
|
|
236
|
+
normale lorsque la loi de Poisson devient coûteuse.
|
|
237
|
+
- Pour des usages reproductibles, régler le germe du générateur aléatoire
|
|
238
|
+
avant d'appeler la méthode (par ex. via ``np.random.seed(...)``).
|
|
239
|
+
"""
|
|
240
|
+
expected_photons = np.sum(np.abs(ψ) ** 2) * self.e.to(u.s).value
|
|
241
|
+
if self.ideal:
|
|
242
|
+
detected_photons = int(expected_photons)
|
|
243
|
+
elif expected_photons <= 2000000000.0:
|
|
244
|
+
detected_photons = np.random.poisson(expected_photons)
|
|
245
|
+
else:
|
|
246
|
+
detected_photons = int(expected_photons + np.random.normal(0, math.sqrt(expected_photons)))
|
|
247
|
+
return detected_photons
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"""Représentation d'un compagnon ponctuel dans le plan du ciel.
|
|
2
|
+
|
|
3
|
+
Ce module définit la classe `Companion` qui modélise une source ponctuelle
|
|
4
|
+
(non résolue) entourant une étoile hôte. Un compagnon est caractérisé par
|
|
5
|
+
sa *contraste* par rapport à l'étoile, sa séparation angulaire et son
|
|
6
|
+
angle parallactique.
|
|
7
|
+
|
|
8
|
+
La classe effectue des validations simples sur les unités (utilise
|
|
9
|
+
``astropy.units``) et expose des propriétés en lecture/écriture pour les
|
|
10
|
+
paramètres physiques. La relation vers l'objet parent (`Target`) est
|
|
11
|
+
en lecture seule.
|
|
12
|
+
|
|
13
|
+
Exemple
|
|
14
|
+
-------
|
|
15
|
+
>>> from phise.classes.companion import Companion
|
|
16
|
+
>>> import astropy.units as u
|
|
17
|
+
>>> comp = Companion(c=1e-3, θ=100*u.mas, α=0.1*u.rad, name='b')
|
|
18
|
+
>>> print(comp)
|
|
19
|
+
"""
|
|
20
|
+
from __future__ import annotations
|
|
21
|
+
from typing import TYPE_CHECKING
|
|
22
|
+
if TYPE_CHECKING:
|
|
23
|
+
from target import Target
|
|
24
|
+
from astropy import units as u
|
|
25
|
+
|
|
26
|
+
class Companion:
|
|
27
|
+
"""Source ponctuelle représentant un compagnon astronomique.
|
|
28
|
+
|
|
29
|
+
Paramètres principaux
|
|
30
|
+
- c : contraste (float, positif) par rapport à l'étoile hôte
|
|
31
|
+
- θ : séparation angulaire (astropy.Quantity, ex : milliarcsecondes)
|
|
32
|
+
- α : angle parallactique (astropy.Quantity, ex : radians)
|
|
33
|
+
- name : nom lisible (str)
|
|
34
|
+
|
|
35
|
+
La classe valide les unités de ``θ`` et ``α`` lors de l'affectation
|
|
36
|
+
et convertit respectivement ``θ`` en milliarcsecondes (mas) et ``α`` en
|
|
37
|
+
radians pour un stockage interne cohérent.
|
|
38
|
+
"""
|
|
39
|
+
|
|
40
|
+
__slots__ = ('_parent_target', '_c', '_θ', '_α', '_name')
|
|
41
|
+
|
|
42
|
+
def __init__(self, c: float, θ: u.Quantity, α: u.Quantity, name: str = 'Unnamed Companion'):
|
|
43
|
+
"""Initialise un compagnon ponctuel.
|
|
44
|
+
|
|
45
|
+
Paramètres
|
|
46
|
+
----------
|
|
47
|
+
c : float
|
|
48
|
+
Contraste du compagnon par rapport à l'étoile hôte (doit être >= 0).
|
|
49
|
+
θ : astropy.units.Quantity
|
|
50
|
+
Séparation angulaire (par ex. ``100 * u.mas``).
|
|
51
|
+
α : astropy.units.Quantity
|
|
52
|
+
Angle parallactique (par ex. ``0.1 * u.rad``).
|
|
53
|
+
name : str, optionnel
|
|
54
|
+
Nom lisible du compagnon.
|
|
55
|
+
|
|
56
|
+
Exceptions
|
|
57
|
+
----------
|
|
58
|
+
TypeError
|
|
59
|
+
Si les types fournis ne correspondent pas aux attentes.
|
|
60
|
+
ValueError
|
|
61
|
+
Si des valeurs physiques invalides sont fournies (p.ex. contraste négatif).
|
|
62
|
+
"""
|
|
63
|
+
self._parent_target = None
|
|
64
|
+
self.θ = θ
|
|
65
|
+
self.α = α
|
|
66
|
+
self.c = c
|
|
67
|
+
self.name = name
|
|
68
|
+
|
|
69
|
+
def __repr__(self) -> str:
|
|
70
|
+
return self.__str__()
|
|
71
|
+
|
|
72
|
+
def __str__(self) -> str:
|
|
73
|
+
res = f'Companion "{self.name}"\n'
|
|
74
|
+
res += f' Contrast: {self.c:.2f}\n'
|
|
75
|
+
res += f' Angular separation: {self.θ:.2f}\n'
|
|
76
|
+
res += f' Parallactic angle: {self.α:.2f}'
|
|
77
|
+
return res
|
|
78
|
+
|
|
79
|
+
@property
|
|
80
|
+
def c(self) -> float:
|
|
81
|
+
"""Contraste du compagnon (nombre sans dimension).
|
|
82
|
+
|
|
83
|
+
Retourne la valeur flottante du contraste, toujours positive.
|
|
84
|
+
"""
|
|
85
|
+
return self._c
|
|
86
|
+
|
|
87
|
+
@c.setter
|
|
88
|
+
def c(self, c: float):
|
|
89
|
+
"""Définit le contraste du compagnon.
|
|
90
|
+
|
|
91
|
+
Paramètres
|
|
92
|
+
----------
|
|
93
|
+
c : float
|
|
94
|
+
Contraste (>= 0). Une ``TypeError`` est levée si ``c`` n'est ni int ni float.
|
|
95
|
+
"""
|
|
96
|
+
if not isinstance(c, (int, float)):
|
|
97
|
+
raise TypeError('c must be a float')
|
|
98
|
+
if c < 0:
|
|
99
|
+
raise ValueError('c must be positive')
|
|
100
|
+
self._c = float(c)
|
|
101
|
+
|
|
102
|
+
@property
|
|
103
|
+
def θ(self) -> u.Quantity:
|
|
104
|
+
"""Séparation angulaire du compagnon (astropy.Quantity en mas).
|
|
105
|
+
|
|
106
|
+
La valeur renvoyée est une quantité en milliarcsecondes (mas).
|
|
107
|
+
"""
|
|
108
|
+
return self._θ
|
|
109
|
+
|
|
110
|
+
@θ.setter
|
|
111
|
+
def θ(self, θ: u.Quantity):
|
|
112
|
+
"""Définit la séparation angulaire.
|
|
113
|
+
|
|
114
|
+
Paramètres
|
|
115
|
+
----------
|
|
116
|
+
θ : astropy.units.Quantity
|
|
117
|
+
Quantité d'angle (ex : ``100 * u.mas`` ou ``0.1 * u.arcsec``).
|
|
118
|
+
"""
|
|
119
|
+
if not isinstance(θ, u.Quantity):
|
|
120
|
+
raise TypeError('θ must be an astropy Quantity')
|
|
121
|
+
try:
|
|
122
|
+
θ = θ.to(u.mas)
|
|
123
|
+
except u.UnitConversionError:
|
|
124
|
+
raise ValueError('θ must be an angle')
|
|
125
|
+
self._θ = θ
|
|
126
|
+
|
|
127
|
+
@property
|
|
128
|
+
def α(self) -> u.Quantity:
|
|
129
|
+
"""Angle parallactique du compagnon (astropy.Quantity en radians).
|
|
130
|
+
|
|
131
|
+
La valeur renvoyée est une quantité en radians.
|
|
132
|
+
"""
|
|
133
|
+
return self._α
|
|
134
|
+
|
|
135
|
+
@α.setter
|
|
136
|
+
def α(self, α: u.Quantity):
|
|
137
|
+
"""Définit l'angle parallactique.
|
|
138
|
+
|
|
139
|
+
Paramètres
|
|
140
|
+
----------
|
|
141
|
+
α : astropy.units.Quantity
|
|
142
|
+
Quantité d'angle (par ex. ``0.1 * u.rad`` ou ``10 * u.deg``).
|
|
143
|
+
"""
|
|
144
|
+
if not isinstance(α, u.Quantity):
|
|
145
|
+
raise TypeError('α must be an astropy Quantity')
|
|
146
|
+
try:
|
|
147
|
+
α = α.to(u.rad)
|
|
148
|
+
except u.UnitConversionError:
|
|
149
|
+
raise ValueError('α must be an angle')
|
|
150
|
+
self._α = α
|
|
151
|
+
|
|
152
|
+
@property
|
|
153
|
+
def parent_target(self) -> Target:
|
|
154
|
+
"""Référence en lecture seule vers l'objet `Target` parent.
|
|
155
|
+
|
|
156
|
+
Toute tentative d'affectation directe déclenche une erreur ; la
|
|
157
|
+
relation doit être établie par l'objet parent.
|
|
158
|
+
"""
|
|
159
|
+
return self._parent_target
|
|
160
|
+
|
|
161
|
+
@parent_target.setter
|
|
162
|
+
def parent_target(self, target: Target):
|
|
163
|
+
"""Propriété en écriture désactivée pour `parent_target`.
|
|
164
|
+
|
|
165
|
+
L'accès en écriture provoque une exception pour signaler que
|
|
166
|
+
l'association doit être gérée par l'objet parent.
|
|
167
|
+
"""
|
|
168
|
+
raise ValueError('parent_target is read-only')
|
|
169
|
+
|
|
170
|
+
@property
|
|
171
|
+
def name(self) -> str:
|
|
172
|
+
"""Nom lisible du compagnon.
|
|
173
|
+
|
|
174
|
+
Retourne une chaîne de caractères.
|
|
175
|
+
"""
|
|
176
|
+
return self._name
|
|
177
|
+
|
|
178
|
+
@name.setter
|
|
179
|
+
def name(self, name: str):
|
|
180
|
+
"""Définit le nom du compagnon.
|
|
181
|
+
|
|
182
|
+
Paramètres
|
|
183
|
+
----------
|
|
184
|
+
name : str
|
|
185
|
+
Nom lisible. ``TypeError`` si non-str.
|
|
186
|
+
"""
|
|
187
|
+
if not isinstance(name, str):
|
|
188
|
+
raise TypeError('name must be a string')
|
|
189
|
+
self._name = name
|