pyEDITH 1.7.1__tar.gz → 1.7.2__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.
- {pyedith-1.7.1/src/pyEDITH.egg-info → pyedith-1.7.2}/PKG-INFO +1 -1
- {pyedith-1.7.1 → pyedith-1.7.2}/pyproject.toml +1 -1
- {pyedith-1.7.1 → pyedith-1.7.2}/src/pyEDITH/astrophysical_scene.py +12 -10
- {pyedith-1.7.1 → pyedith-1.7.2}/src/pyEDITH/components/detectors.py +12 -10
- {pyedith-1.7.1 → pyedith-1.7.2}/src/pyEDITH/components/telescopes.py +3 -2
- {pyedith-1.7.1 → pyedith-1.7.2}/src/pyEDITH/exposure_time_calculator.py +19 -17
- {pyedith-1.7.1 → pyedith-1.7.2}/src/pyEDITH/observation.py +9 -10
- {pyedith-1.7.1 → pyedith-1.7.2}/src/pyEDITH/observatory.py +2 -2
- {pyedith-1.7.1 → pyedith-1.7.2}/src/pyEDITH/parse_input.py +11 -1
- {pyedith-1.7.1 → pyedith-1.7.2}/src/pyEDITH/utils.py +48 -2
- {pyedith-1.7.1 → pyedith-1.7.2/src/pyEDITH.egg-info}/PKG-INFO +1 -1
- {pyedith-1.7.1 → pyedith-1.7.2}/tests/test_astrophysical_scene.py +14 -14
- {pyedith-1.7.1 → pyedith-1.7.2}/tests/test_exposure_time_calculator.py +4 -4
- {pyedith-1.7.1 → pyedith-1.7.2}/tests/test_observatory.py +2 -2
- {pyedith-1.7.1 → pyedith-1.7.2}/tests/test_parse_input.py +47 -0
- {pyedith-1.7.1 → pyedith-1.7.2}/tests/test_utils.py +234 -0
- {pyedith-1.7.1 → pyedith-1.7.2}/LICENSE +0 -0
- {pyedith-1.7.1 → pyedith-1.7.2}/README.md +0 -0
- {pyedith-1.7.1 → pyedith-1.7.2}/setup.cfg +0 -0
- {pyedith-1.7.1 → pyedith-1.7.2}/src/pyEDITH/__init__.py +0 -0
- {pyedith-1.7.1 → pyedith-1.7.2}/src/pyEDITH/cli.py +0 -0
- {pyedith-1.7.1 → pyedith-1.7.2}/src/pyEDITH/components/coronagraphs.py +0 -0
- {pyedith-1.7.1 → pyedith-1.7.2}/src/pyEDITH/units.py +0 -0
- {pyedith-1.7.1 → pyedith-1.7.2}/src/pyEDITH.egg-info/SOURCES.txt +0 -0
- {pyedith-1.7.1 → pyedith-1.7.2}/src/pyEDITH.egg-info/dependency_links.txt +0 -0
- {pyedith-1.7.1 → pyedith-1.7.2}/src/pyEDITH.egg-info/entry_points.txt +0 -0
- {pyedith-1.7.1 → pyedith-1.7.2}/src/pyEDITH.egg-info/requires.txt +0 -0
- {pyedith-1.7.1 → pyedith-1.7.2}/src/pyEDITH.egg-info/top_level.txt +0 -0
- {pyedith-1.7.1 → pyedith-1.7.2}/tests/test_cli.py +0 -0
- {pyedith-1.7.1 → pyedith-1.7.2}/tests/test_coronagraphs.py +0 -0
- {pyedith-1.7.1 → pyedith-1.7.2}/tests/test_detectors.py +0 -0
- {pyedith-1.7.1 → pyedith-1.7.2}/tests/test_init.py +0 -0
- {pyedith-1.7.1 → pyedith-1.7.2}/tests/test_observation.py +0 -0
- {pyedith-1.7.1 → pyedith-1.7.2}/tests/test_telescopes.py +0 -0
- {pyedith-1.7.1 → pyedith-1.7.2}/tests/test_units.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pyEDITH
|
|
3
|
-
Version: 1.7.
|
|
3
|
+
Version: 1.7.2
|
|
4
4
|
Summary: Exposure Direct Imaging Timer for HWO (Python Version)
|
|
5
5
|
Author-email: Eleonora Alei <eleonora.alei@nasa.gov>, Miles Currie <miles.h.currie@nasa.gov>, Corey Spohn <corey.a.spohn@nasa.gov>
|
|
6
6
|
Project-URL: Homepage, https://github.com/HabitableWorldsObservatory/pyEDITH/
|
|
@@ -164,7 +164,9 @@ def calc_flux_zero_point(
|
|
|
164
164
|
equivalencies=u.spectral_density(lambd),
|
|
165
165
|
)
|
|
166
166
|
|
|
167
|
-
logger.info(
|
|
167
|
+
logger.info(
|
|
168
|
+
f"Flux zero point calculated at lambda of interest in units of {f0.unit}"
|
|
169
|
+
)
|
|
168
170
|
|
|
169
171
|
return f0
|
|
170
172
|
|
|
@@ -192,11 +194,11 @@ def calc_exozodi_flux(
|
|
|
192
194
|
nexozodis : Quantity
|
|
193
195
|
Number of exozodis for each star.
|
|
194
196
|
lambd : Quantity
|
|
195
|
-
Wavelength in microns (vector of length
|
|
197
|
+
Wavelength in microns (vector of length nlambda).
|
|
196
198
|
lambdmag : Quantity
|
|
197
|
-
Apparent magnitude of stars at each lambd (array
|
|
199
|
+
Apparent magnitude of stars at each lambd (array nlambda).
|
|
198
200
|
F0lambd : Quantity
|
|
199
|
-
Flux zero point at wavelength lambd (vector of length
|
|
201
|
+
Flux zero point at wavelength lambd (vector of length nlambda).
|
|
200
202
|
|
|
201
203
|
Returns
|
|
202
204
|
-------
|
|
@@ -208,7 +210,7 @@ def calc_exozodi_flux(
|
|
|
208
210
|
if len(lambd) > 1:
|
|
209
211
|
if len(lambd) != lambdmag.shape[0]:
|
|
210
212
|
raise ValueError(
|
|
211
|
-
"ERROR. lambdmag must have dimensions nstars x
|
|
213
|
+
"ERROR. lambdmag must have dimensions nstars x nlambda, where nlambda is the length of lambd."
|
|
212
214
|
)
|
|
213
215
|
|
|
214
216
|
vmag_1zodi = (
|
|
@@ -222,7 +224,7 @@ def calc_exozodi_flux(
|
|
|
222
224
|
|
|
223
225
|
# Now, multiply by the ratio of the star's counts received at lambd to those
|
|
224
226
|
# received at V band
|
|
225
|
-
|
|
227
|
+
nlambda = len(lambd)
|
|
226
228
|
|
|
227
229
|
flux_exozodi_lambd = (
|
|
228
230
|
nexozodis
|
|
@@ -259,9 +261,9 @@ def calc_zodi_flux(
|
|
|
259
261
|
ra : Quantity
|
|
260
262
|
Right ascension of targets in degrees (J2000 equatorial coordinate).
|
|
261
263
|
lambd : Quantity
|
|
262
|
-
Wavelengths in microns (vector of length
|
|
264
|
+
Wavelengths in microns (vector of length nlambda).
|
|
263
265
|
F0 : Quantity
|
|
264
|
-
Flux zero points at wavelengths lambd (vector of length
|
|
266
|
+
Flux zero points at wavelengths lambd (vector of length nlambda).
|
|
265
267
|
|
|
266
268
|
Returns
|
|
267
269
|
-------
|
|
@@ -270,7 +272,7 @@ def calc_zodi_flux(
|
|
|
270
272
|
This is equivalent to 10^(-0.4*magOmega_ZL).
|
|
271
273
|
- Multiply by F0 to get photons s^-1 cm^-2 arcsec^-2 nm^-1
|
|
272
274
|
- Multiply by energy of photons to get erg s^-1 cm^-2 arcsec^-2 nm^-1
|
|
273
|
-
The output array has dimensions (
|
|
275
|
+
The output array has dimensions (nlambda, nstars).
|
|
274
276
|
|
|
275
277
|
Raises
|
|
276
278
|
------
|
|
@@ -447,7 +449,7 @@ def calc_zodi_flux(
|
|
|
447
449
|
I90fabsfco = I90fabsfco / F0
|
|
448
450
|
|
|
449
451
|
# Calculate final zodi flux
|
|
450
|
-
|
|
452
|
+
nlambda = len(lambd)
|
|
451
453
|
flux_zodi = f * I90fabsfco
|
|
452
454
|
|
|
453
455
|
return flux_zodi # 1/arcsec^2 (UNITS OF SPECTRAL RADIANCE)
|
|
@@ -110,11 +110,11 @@ class ToyModelDetector(Detector):
|
|
|
110
110
|
"pixscale_mas": None, # Detector pixel scale in milliarcseconds.
|
|
111
111
|
"npix_multiplier": 1
|
|
112
112
|
* DIMENSIONLESS, # Number of detector pixels per image plane "pixel".
|
|
113
|
-
"DC": [3e-5] * DARK_CURRENT, # Dark current (counts pix^-1 s^-1,
|
|
114
|
-
"RN": [0.0] * READ_NOISE, # Read noise (counts pix^-1 read^-1,
|
|
115
|
-
"tread": [1000] * READ_TIME, # Read time (s,
|
|
113
|
+
"DC": [3e-5] * DARK_CURRENT, # Dark current (counts pix^-1 s^-1, nlambda array)
|
|
114
|
+
"RN": [0.0] * READ_NOISE, # Read noise (counts pix^-1 read^-1, nlambda array)
|
|
115
|
+
"tread": [1000] * READ_TIME, # Read time (s, nlambda array)
|
|
116
116
|
"CIC": [1.3e-3]
|
|
117
|
-
* CLOCK_INDUCED_CHARGE, # Clock-induced charge (counts pix^-1 photon_count^-1,
|
|
117
|
+
* CLOCK_INDUCED_CHARGE, # Clock-induced charge (counts pix^-1 photon_count^-1, nlambda array)
|
|
118
118
|
"QE": [0.9] * QUANTUM_EFFICIENCY, # Quantum efficiency of detector
|
|
119
119
|
"dQE": [0.75]
|
|
120
120
|
* DIMENSIONLESS, # Effective QE due to degradation, cosmic ray effects, readout inefficiencies
|
|
@@ -176,6 +176,7 @@ class ToyModelDetector(Detector):
|
|
|
176
176
|
"QE",
|
|
177
177
|
"dQE",
|
|
178
178
|
]
|
|
179
|
+
|
|
179
180
|
self.DEFAULT_CONFIG.update(
|
|
180
181
|
{
|
|
181
182
|
key: parse_input.normalize_list_shapes(
|
|
@@ -226,11 +227,11 @@ class EACDetector(Detector):
|
|
|
226
227
|
"pixscale_mas": None, # Detector pixel scale in milliarcseconds.
|
|
227
228
|
"npix_multiplier": 1
|
|
228
229
|
* DIMENSIONLESS, # Number of detector pixels per image plane "pixel".
|
|
229
|
-
"DC": None, # Dark current (counts pix^-1 s^-1,
|
|
230
|
-
"RN": None, # Read noise (counts pix^-1 read^-1,
|
|
231
|
-
"tread": [1000] * READ_TIME, # Read time (s,
|
|
230
|
+
"DC": None, # Dark current (counts pix^-1 s^-1, nlambda array)
|
|
231
|
+
"RN": None, # Read noise (counts pix^-1 read^-1, nlambda array)
|
|
232
|
+
"tread": [1000] * READ_TIME, # Read time (s, nlambda array) # TO ADD TO YAML
|
|
232
233
|
"CIC": [0]
|
|
233
|
-
* CLOCK_INDUCED_CHARGE, # Clock-induced charge (counts pix^-1 photon_count^-1,
|
|
234
|
+
* CLOCK_INDUCED_CHARGE, # Clock-induced charge (counts pix^-1 photon_count^-1, nlambda array) # TO ADD TO YAML
|
|
234
235
|
"QE": None, # Quantum efficiency of detector
|
|
235
236
|
"dQE": None, # Effective QE due to degradation, cosmic ray effects, readout inefficiencies
|
|
236
237
|
}
|
|
@@ -312,9 +313,9 @@ class EACDetector(Detector):
|
|
|
312
313
|
)
|
|
313
314
|
self.DEFAULT_CONFIG["DC"] = (
|
|
314
315
|
dc_arr * DARK_CURRENT
|
|
315
|
-
) # Dark current (counts pix^-1 s^-1,
|
|
316
|
+
) # Dark current (counts pix^-1 s^-1, nlambda array)
|
|
316
317
|
|
|
317
|
-
# Dark current (counts pix^-1 s^-1,
|
|
318
|
+
# Dark current (counts pix^-1 s^-1, nlambda array)
|
|
318
319
|
|
|
319
320
|
rn_arr = np.empty_like(mediator.get_observation_parameter("wavelength").value)
|
|
320
321
|
rn_arr[mediator.get_observation_parameter("wavelength") < 1 * WAVELENGTH] = (
|
|
@@ -400,6 +401,7 @@ class EACDetector(Detector):
|
|
|
400
401
|
allow_override=set(
|
|
401
402
|
set(parameters.get("overrides", [])) & self.LOCKED_KEYS
|
|
402
403
|
), # finds the keys that should be locked but that the user wants to override
|
|
404
|
+
rebinned_wavelength=mediator.get_observation_parameter("wavelength").value,
|
|
403
405
|
)
|
|
404
406
|
|
|
405
407
|
# USED ONLY TO VALIDATE ETCs
|
|
@@ -111,7 +111,7 @@ class ToyModelTelescope(Telescope):
|
|
|
111
111
|
"toverhead_fixed": 8.25e3 * TIME, # fixed overhead time (seconds,scalar)
|
|
112
112
|
"toverhead_multi": 1.1 * DIMENSIONLESS, # multiplicative overhead time (scalar)
|
|
113
113
|
"telescope_optical_throughput": [0.823]
|
|
114
|
-
* DIMENSIONLESS, # Optical throughput (
|
|
114
|
+
* DIMENSIONLESS, # Optical throughput (nlambda array) [made up from EAC1-ish]
|
|
115
115
|
"temperature": 290 * TEMPERATURE,
|
|
116
116
|
"T_contamination": 0.95 * DIMENSIONLESS,
|
|
117
117
|
}
|
|
@@ -200,7 +200,7 @@ class EACTelescope(Telescope):
|
|
|
200
200
|
* TIME, # fixed overhead time (seconds,scalar) ### NOTE default for now
|
|
201
201
|
"toverhead_multi": 1.1
|
|
202
202
|
* DIMENSIONLESS, # multiplicative overhead time (scalar) ### NOTE default for now
|
|
203
|
-
"telescope_optical_throughput": None, # Optical throughput (
|
|
203
|
+
"telescope_optical_throughput": None, # Optical throughput (nlambda array)
|
|
204
204
|
"T_contamination": 1.0
|
|
205
205
|
* DIMENSIONLESS, # Effective throughput factor to budget for contamination; NOTE: missing from YAML files
|
|
206
206
|
"temperature": 290
|
|
@@ -297,6 +297,7 @@ class EACTelescope(Telescope):
|
|
|
297
297
|
allow_override=set(
|
|
298
298
|
set(parameters.get("overrides", [])) & self.LOCKED_KEYS
|
|
299
299
|
), # finds the keys that should be locked but that the user wants to override
|
|
300
|
+
rebinned_wavelength=mediator.get_observation_parameter("wavelength").value,
|
|
300
301
|
)
|
|
301
302
|
|
|
302
303
|
# Derived parameters
|
|
@@ -681,53 +681,55 @@ def calculate_exposure_time_or_snr(
|
|
|
681
681
|
lod,
|
|
682
682
|
observation.wavelength.to(LENGTH),
|
|
683
683
|
observatory.telescope.diameter.to(LENGTH),
|
|
684
|
-
) # shape (
|
|
684
|
+
) # shape (nlambda,), units rad
|
|
685
685
|
lod_rad_arr = u.Quantity(np.atleast_1d(lod_rad_arr.value), lod_rad_arr.unit)
|
|
686
|
-
lod_arcsec_arr = lod_rad_arr.to(ARCSEC) # shape (
|
|
686
|
+
lod_arcsec_arr = lod_rad_arr.to(ARCSEC) # shape (nlambda,)
|
|
687
687
|
|
|
688
688
|
# --- Detector pixel scale in λ/D (one value per wavelength) ---
|
|
689
689
|
detpixscale_lod_arr = arcsec_to_lambda_d(
|
|
690
690
|
observatory.detector.pixscale_mas.to(ARCSEC),
|
|
691
691
|
observation.wavelength.to(LENGTH),
|
|
692
692
|
observatory.telescope.diameter.to(LENGTH),
|
|
693
|
-
) # shape (
|
|
693
|
+
) # shape (nlambda,), units LAMBDA_D
|
|
694
694
|
detpixscale_lod_arr = u.Quantity(
|
|
695
695
|
np.atleast_1d(detpixscale_lod_arr.value), detpixscale_lod_arr.unit
|
|
696
696
|
)
|
|
697
697
|
|
|
698
698
|
# --- Planet pixel position in the coronagraph image (one per wavelength) ---
|
|
699
699
|
# pixscale_rad: [LAMBDA_D] * [rad/LAMBDA_D] = [rad/pix]
|
|
700
|
-
pixscale_rad_arr =
|
|
700
|
+
pixscale_rad_arr = (
|
|
701
|
+
observatory.coronagraph.pixscale * lod_rad_arr
|
|
702
|
+
) # shape (nlambda,)
|
|
701
703
|
oneopixscale_arcsec_arr = (1 * PIXEL) / pixscale_rad_arr.to(
|
|
702
704
|
ARCSEC
|
|
703
|
-
) # shape (
|
|
705
|
+
) # shape (nlambda,) [pix/arcsec]
|
|
704
706
|
|
|
705
707
|
ix_arr = (
|
|
706
708
|
scene.xp * oneopixscale_arcsec_arr + observatory.coronagraph.xcenter
|
|
707
|
-
).value # shape (
|
|
709
|
+
).value # shape (nlambda,), float pixel indices
|
|
708
710
|
iy_arr = (
|
|
709
711
|
scene.yp * oneopixscale_arcsec_arr + observatory.coronagraph.ycenter
|
|
710
|
-
).value # shape (
|
|
712
|
+
).value # shape (nlambda,), float pixel indices
|
|
711
713
|
|
|
712
714
|
ix_arr = np.atleast_1d(ix_arr)
|
|
713
715
|
iy_arr = np.atleast_1d(iy_arr)
|
|
714
716
|
|
|
715
717
|
# Integer (floored) pixel indices for coronagraph map lookups
|
|
716
|
-
ix_int = np.floor(ix_arr).astype(int) # shape (
|
|
717
|
-
iy_int = np.floor(iy_arr).astype(int) # shape (
|
|
718
|
+
ix_int = np.floor(ix_arr).astype(int) # shape (nlambda,)
|
|
719
|
+
iy_int = np.floor(iy_arr).astype(int) # shape (nlambda,)
|
|
718
720
|
|
|
719
721
|
# --- Pixel validity mask (checks if the planet is within coronagraph pixels) ---
|
|
720
722
|
npix = observatory.coronagraph.npix
|
|
721
723
|
pixel_valid_mask = np.atleast_1d(
|
|
722
724
|
(ix_int >= 0) & (ix_int < npix) & (iy_int >= 0) & (iy_int < npix)
|
|
723
|
-
) # shape (
|
|
725
|
+
) # shape (nlambda,), bool
|
|
724
726
|
|
|
725
727
|
# Clamp indices so fancy indexing never goes out of bounds on invalid channels
|
|
726
728
|
# (values for those channels will be masked out anyway)
|
|
727
729
|
ix_safe = np.clip(ix_int, 0, npix - 1)
|
|
728
730
|
iy_safe = np.clip(iy_int, 0, npix - 1)
|
|
729
731
|
|
|
730
|
-
# --- Vectorized coronagraph map lookups [shape (
|
|
732
|
+
# --- Vectorized coronagraph map lookups [shape (nlambda,)] ---
|
|
731
733
|
|
|
732
734
|
# NOTE: noisefloor_interp: technically the Y axis
|
|
733
735
|
# is rows and the X axis is columns,
|
|
@@ -747,14 +749,14 @@ def calculate_exposure_time_or_snr(
|
|
|
747
749
|
# NOTE: npsfratios == 1 in practice; iratio = 0 throughout.
|
|
748
750
|
iratio = 0 # only one psf truncation ratio supported
|
|
749
751
|
|
|
750
|
-
# omega_lod at the planet position, shape (
|
|
752
|
+
# omega_lod at the planet position, shape (nlambda,)
|
|
751
753
|
omega_lod_at_planet = u.Quantity(
|
|
752
754
|
np.atleast_1d(
|
|
753
755
|
observatory.coronagraph.omega_lod[iy_safe, ix_safe, iratio].value
|
|
754
756
|
),
|
|
755
757
|
observatory.coronagraph.omega_lod.unit,
|
|
756
758
|
)
|
|
757
|
-
# photometric aperture throughput at the planet position, shape (
|
|
759
|
+
# photometric aperture throughput at the planet position, shape (nlambda,)
|
|
758
760
|
Upsilon_at_planet = np.atleast_1d(
|
|
759
761
|
observatory.coronagraph.photometric_aperture_throughput[
|
|
760
762
|
iy_safe, ix_safe, iratio
|
|
@@ -764,7 +766,7 @@ def calculate_exposure_time_or_snr(
|
|
|
764
766
|
# -----------------------------------------------------------------------
|
|
765
767
|
# Measure coronagraph performance close to IWA
|
|
766
768
|
# -----------------------------------------------------------------------
|
|
767
|
-
# Compute per wavelength via the existing helper (now vectorized over
|
|
769
|
+
# Compute per wavelength via the existing helper (now vectorized over nlambda
|
|
768
770
|
# because measure_coronagraph_performance_at_IWA accepts scalar oneopixscale;
|
|
769
771
|
# we call it in a list-comprehension to preserve the existing function signature) #TODO update after validation
|
|
770
772
|
|
|
@@ -779,7 +781,7 @@ def calculate_exposure_time_or_snr(
|
|
|
779
781
|
observatory.coronagraph.ycenter,
|
|
780
782
|
oneopixscale_arcsec_arr[ilambd],
|
|
781
783
|
)
|
|
782
|
-
for ilambd in range(observation.
|
|
784
|
+
for ilambd in range(observation.nlambda)
|
|
783
785
|
]
|
|
784
786
|
|
|
785
787
|
# Convert to Quantity arrays
|
|
@@ -1142,7 +1144,7 @@ def calculate_exposure_time_or_snr(
|
|
|
1142
1144
|
below_noise_floor = np.atleast_1d(
|
|
1143
1145
|
(pixel_valid_mask & phot_aperture_valid_mask & (CRp_arr <= CRnf_arr))
|
|
1144
1146
|
if mode == "exposure_time"
|
|
1145
|
-
else np.zeros(observation.
|
|
1147
|
+
else np.zeros(observation.nlambda, dtype=bool)
|
|
1146
1148
|
)
|
|
1147
1149
|
if np.any(below_noise_floor):
|
|
1148
1150
|
logger.error(
|
|
@@ -1172,7 +1174,7 @@ def calculate_exposure_time_or_snr(
|
|
|
1172
1174
|
sciencetime_arr = (
|
|
1173
1175
|
observation.SNR**2 * cp_arr
|
|
1174
1176
|
if mode == "exposure_time"
|
|
1175
|
-
else u.Quantity(np.zeros(observation.
|
|
1177
|
+
else u.Quantity(np.zeros(observation.nlambda), u.s)
|
|
1176
1178
|
)
|
|
1177
1179
|
|
|
1178
1180
|
observation.validation_variables = {
|
|
@@ -20,7 +20,7 @@ class Observation:
|
|
|
20
20
|
-----------
|
|
21
21
|
wavelength : np.ndarray
|
|
22
22
|
Wavelength array (in microns).
|
|
23
|
-
|
|
23
|
+
nlambda : int
|
|
24
24
|
Number of wavelength points.
|
|
25
25
|
SNR : np.ndarray
|
|
26
26
|
Desired bulk SNR.
|
|
@@ -94,7 +94,7 @@ class Observation:
|
|
|
94
94
|
if parameters["observing_mode"] == "IMAGER":
|
|
95
95
|
self.wavelength = (
|
|
96
96
|
parameters["wavelength"] * WAVELENGTH
|
|
97
|
-
) # wavelength #
|
|
97
|
+
) # wavelength # nlambda array #unit: micron
|
|
98
98
|
# IMAGER has no meaningful bin widths for regridding; broadcast-only
|
|
99
99
|
self.delta_wavelength = None
|
|
100
100
|
|
|
@@ -104,7 +104,7 @@ class Observation:
|
|
|
104
104
|
):
|
|
105
105
|
self.wavelength = (
|
|
106
106
|
parameters["wavelength"] * WAVELENGTH
|
|
107
|
-
) # wavelength #
|
|
107
|
+
) # wavelength # nlambda array #unit: micron
|
|
108
108
|
IFS_resolution = self.wavelength / np.gradient(
|
|
109
109
|
self.wavelength
|
|
110
110
|
) # calculate the resolution from the wavelength grid
|
|
@@ -133,14 +133,14 @@ class Observation:
|
|
|
133
133
|
)
|
|
134
134
|
self.wavelength = (
|
|
135
135
|
new_lam * WAVELENGTH
|
|
136
|
-
) # wavelength #
|
|
136
|
+
) # wavelength # nlambda array #unit: micron
|
|
137
137
|
self.delta_wavelength = new_dlam * WAVELENGTH
|
|
138
138
|
|
|
139
139
|
# ------------------------------------------------------------------
|
|
140
140
|
# Length of the current resolved grid. Any per-wavelength parameter is
|
|
141
141
|
# aligned against this via regrid_to_grid.
|
|
142
142
|
# ------------------------------------------------------------------
|
|
143
|
-
self.
|
|
143
|
+
self.nlambda = len(self.wavelength)
|
|
144
144
|
|
|
145
145
|
# Target bin widths (as plain floats) for the regrid branch, if defined.
|
|
146
146
|
to_delta = (
|
|
@@ -156,10 +156,9 @@ class Observation:
|
|
|
156
156
|
parameters["snr"] * DIMENSIONLESS,
|
|
157
157
|
from_wavelength=self._input_wavelength,
|
|
158
158
|
to_wavelength=self.wavelength.value,
|
|
159
|
-
to_delta_wavelength=to_delta,
|
|
160
159
|
name="snr",
|
|
161
160
|
interpolation="1d",
|
|
162
|
-
) # signal to noise #
|
|
161
|
+
) # signal to noise # nlambda array
|
|
163
162
|
|
|
164
163
|
self.CRb_multiplier = float(parameters["CRb_multiplier"])
|
|
165
164
|
|
|
@@ -173,10 +172,10 @@ class Observation:
|
|
|
173
172
|
"""
|
|
174
173
|
|
|
175
174
|
# Initialize some arrays needed for outputs...
|
|
176
|
-
self.exptime = np.full((self.
|
|
175
|
+
self.exptime = np.full((self.nlambda), 0.0) * TIME
|
|
177
176
|
|
|
178
177
|
# only used for snr calculation
|
|
179
|
-
self.fullsnr = np.full((self.
|
|
178
|
+
self.fullsnr = np.full((self.nlambda), 0.0) * DIMENSIONLESS
|
|
180
179
|
|
|
181
180
|
def validate_configuration(self):
|
|
182
181
|
"""
|
|
@@ -194,7 +193,7 @@ class Observation:
|
|
|
194
193
|
"""
|
|
195
194
|
expected_args = {
|
|
196
195
|
"wavelength": WAVELENGTH,
|
|
197
|
-
"
|
|
196
|
+
"nlambda": int,
|
|
198
197
|
"SNR": DIMENSIONLESS,
|
|
199
198
|
"CRb_multiplier": float,
|
|
200
199
|
}
|
|
@@ -56,12 +56,12 @@ class Observatory(ABC): # abstract class
|
|
|
56
56
|
},
|
|
57
57
|
"EAC1": {
|
|
58
58
|
"telescope": "EAC1",
|
|
59
|
-
"coronagraph": "
|
|
59
|
+
"coronagraph": "eac1_aavc_2d", # will download from the database
|
|
60
60
|
"detector": "EAC1",
|
|
61
61
|
},
|
|
62
62
|
"EAC5": {
|
|
63
63
|
"telescope": "EAC5",
|
|
64
|
-
"coronagraph": "
|
|
64
|
+
"coronagraph": "eac1_aavc_2d", # temporary, will be replaced by a more suitable one
|
|
65
65
|
"detector": "EAC5",
|
|
66
66
|
},
|
|
67
67
|
}
|
|
@@ -103,6 +103,16 @@ def parse_input_file(
|
|
|
103
103
|
"Secondary flag is True but no secondary variables found in the input file."
|
|
104
104
|
)
|
|
105
105
|
|
|
106
|
+
# Check that observing_mode is present and valid
|
|
107
|
+
if "observing_mode" not in variables:
|
|
108
|
+
raise KeyError(
|
|
109
|
+
"Required parameter 'observing_mode' is not provided in the input file."
|
|
110
|
+
)
|
|
111
|
+
if variables["observing_mode"] not in ["IMAGER", "IFS"]:
|
|
112
|
+
raise ValueError(
|
|
113
|
+
f"Invalid observing mode '{variables['observing_mode']}'. Must be 'IMAGER' or 'IFS'."
|
|
114
|
+
)
|
|
115
|
+
|
|
106
116
|
# Handle IFS mode
|
|
107
117
|
if variables.get("observing_mode") == "IFS":
|
|
108
118
|
required_columns = ["wavelength", "Fstar_10pc", "Fp/Fs"]
|
|
@@ -166,7 +176,7 @@ def parse_input_file(
|
|
|
166
176
|
return variables, secondary_variables
|
|
167
177
|
|
|
168
178
|
|
|
169
|
-
def normalize_list_shapes(parameters, key, default_len):
|
|
179
|
+
def normalize_list_shapes(parameters, key, default_len=1):
|
|
170
180
|
"""
|
|
171
181
|
Normalize the *shape* of a user-supplied parameter without binding it to a
|
|
172
182
|
wavelength grid that may later change.
|
|
@@ -138,6 +138,7 @@ def fill_parameters(
|
|
|
138
138
|
default_parameters: dict,
|
|
139
139
|
locked_keys: set = None,
|
|
140
140
|
allow_override: set = None,
|
|
141
|
+
rebinned_wavelength: list = None,
|
|
141
142
|
) -> None:
|
|
142
143
|
"""
|
|
143
144
|
Populate class object attributes with user parameters or default values.
|
|
@@ -163,6 +164,7 @@ def fill_parameters(
|
|
|
163
164
|
correspond to a key in ``default_parameters`` raises a ValueError,
|
|
164
165
|
to catch typos rather than silently ignoring them.
|
|
165
166
|
"""
|
|
167
|
+
|
|
166
168
|
if locked_keys is None:
|
|
167
169
|
locked_keys = set()
|
|
168
170
|
if allow_override is None:
|
|
@@ -183,6 +185,50 @@ def fill_parameters(
|
|
|
183
185
|
return u.Quantity(user_value, default_value.unit)
|
|
184
186
|
return user_value
|
|
185
187
|
|
|
188
|
+
# Step 0: ensure that all the overrides parameters have the correct length
|
|
189
|
+
for key in allow_override:
|
|
190
|
+
if (
|
|
191
|
+
key in parameters
|
|
192
|
+
): # the user actually provided the value, otherwise nothing will happen
|
|
193
|
+
param_value = parameters[key]
|
|
194
|
+
|
|
195
|
+
# Extract value and unit if it's a Quantity
|
|
196
|
+
if isinstance(param_value, u.Quantity):
|
|
197
|
+
param_unit = param_value.unit
|
|
198
|
+
param_array = param_value.value
|
|
199
|
+
else:
|
|
200
|
+
param_unit = None
|
|
201
|
+
param_array = param_value
|
|
202
|
+
|
|
203
|
+
if isinstance(param_array, (np.ndarray, list)) and len(param_array) > 1:
|
|
204
|
+
if len(param_array) == len(
|
|
205
|
+
parameters["wavelength"]
|
|
206
|
+
): # Rebin only parameters that are supposed to be nlambda
|
|
207
|
+
logger.info(
|
|
208
|
+
f"Before overriding: rebinning {key} array to regridded lambda..."
|
|
209
|
+
)
|
|
210
|
+
rebinned_values = regrid_to_grid(
|
|
211
|
+
param_array,
|
|
212
|
+
from_wavelength=parameters["wavelength"],
|
|
213
|
+
to_wavelength=rebinned_wavelength,
|
|
214
|
+
name=key,
|
|
215
|
+
interpolation="1d",
|
|
216
|
+
)
|
|
217
|
+
# Reattach unit if original was a Quantity
|
|
218
|
+
if param_unit is not None:
|
|
219
|
+
parameters[key] = rebinned_values * param_unit
|
|
220
|
+
else:
|
|
221
|
+
parameters[key] = rebinned_values
|
|
222
|
+
else:
|
|
223
|
+
raise ValueError(
|
|
224
|
+
f"Before overriding: {key} does not have length equal to input wavelength. Please check your inputs."
|
|
225
|
+
)
|
|
226
|
+
else:
|
|
227
|
+
logger.info(
|
|
228
|
+
f"Before overriding: {key} is a scalar and won't be rebinned."
|
|
229
|
+
)
|
|
230
|
+
|
|
231
|
+
# Step 1: replace overrides when possible
|
|
186
232
|
for key, default_value in default_parameters.items():
|
|
187
233
|
is_locked = key in locked_keys
|
|
188
234
|
is_overridden = key in allow_override
|
|
@@ -925,7 +971,7 @@ def regrid_to_grid(
|
|
|
925
971
|
values,
|
|
926
972
|
from_wavelength,
|
|
927
973
|
to_wavelength,
|
|
928
|
-
to_delta_wavelength=None,
|
|
974
|
+
to_delta_wavelength=None, # (only needed for Gaussian interpolation)
|
|
929
975
|
*, # Forces all subsequent parameters to be keyword-only (must be called as name="value")
|
|
930
976
|
name: str = "parameter",
|
|
931
977
|
interpolation: str = "1d", # 1d or Gaussian
|
|
@@ -953,7 +999,7 @@ def regrid_to_grid(
|
|
|
953
999
|
to_wavelength : array-like
|
|
954
1000
|
The target (resolved) wavelength grid, i.e. ``observation.wavelength``.
|
|
955
1001
|
to_delta_wavelength : array-like, optional
|
|
956
|
-
Bin widths of the target grid, required only when a regrid is needed.
|
|
1002
|
+
Bin widths of the target grid, required only when a regrid is needed. (only used for Gaussian interpolation)
|
|
957
1003
|
name : str, optional
|
|
958
1004
|
Name used in log messages.
|
|
959
1005
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: pyEDITH
|
|
3
|
-
Version: 1.7.
|
|
3
|
+
Version: 1.7.2
|
|
4
4
|
Summary: Exposure Direct Imaging Timer for HWO (Python Version)
|
|
5
5
|
Author-email: Eleonora Alei <eleonora.alei@nasa.gov>, Miles Currie <miles.h.currie@nasa.gov>, Corey Spohn <corey.a.spohn@nasa.gov>
|
|
6
6
|
Project-URL: Homepage, https://github.com/HabitableWorldsObservatory/pyEDITH/
|
|
@@ -836,10 +836,10 @@ def test_calculate_zodi_exozodi_correct_array_lengths():
|
|
|
836
836
|
scene.load_configuration(parameters)
|
|
837
837
|
scene.calculate_zodi_exozodi(parameters)
|
|
838
838
|
|
|
839
|
-
|
|
840
|
-
assert len(scene.Fzodi_list) ==
|
|
841
|
-
assert len(scene.Fexozodi_list) ==
|
|
842
|
-
assert len(scene.Fbinary_list) ==
|
|
839
|
+
nlambda = len(parameters["wavelength"])
|
|
840
|
+
assert len(scene.Fzodi_list) == nlambda
|
|
841
|
+
assert len(scene.Fexozodi_list) == nlambda
|
|
842
|
+
assert len(scene.Fbinary_list) == nlambda
|
|
843
843
|
|
|
844
844
|
|
|
845
845
|
def test_calculate_zodi_exozodi_flux_values():
|
|
@@ -1194,7 +1194,7 @@ def test_regrid_spectra_basic_functionality():
|
|
|
1194
1194
|
|
|
1195
1195
|
class MockObservation:
|
|
1196
1196
|
wavelength = np.linspace(0.5, 1.7, 100) * WAVELENGTH
|
|
1197
|
-
|
|
1197
|
+
nlambda = len(wavelength)
|
|
1198
1198
|
delta_wavelength = np.gradient(wavelength)
|
|
1199
1199
|
_input_wavelength = parameters["wavelength"]
|
|
1200
1200
|
|
|
@@ -1226,14 +1226,14 @@ def test_regrid_spectra_basic_functionality():
|
|
|
1226
1226
|
scene.regrid_spectra(observation)
|
|
1227
1227
|
|
|
1228
1228
|
# Check that all arrays match observation wavelength grid
|
|
1229
|
-
assert len(scene.F0) == observation.
|
|
1230
|
-
assert len(scene.Fzodi_list) == observation.
|
|
1231
|
-
assert len(scene.Fexozodi_list) == observation.
|
|
1232
|
-
assert len(scene.Fbinary_list) == observation.
|
|
1233
|
-
assert len(scene.Fp_over_Fs) == observation.
|
|
1234
|
-
assert len(scene.Fs_over_F0) == observation.
|
|
1235
|
-
assert len(scene.mag) == observation.
|
|
1236
|
-
assert len(scene.deltamag) == observation.
|
|
1229
|
+
assert len(scene.F0) == observation.nlambda
|
|
1230
|
+
assert len(scene.Fzodi_list) == observation.nlambda
|
|
1231
|
+
assert len(scene.Fexozodi_list) == observation.nlambda
|
|
1232
|
+
assert len(scene.Fbinary_list) == observation.nlambda
|
|
1233
|
+
assert len(scene.Fp_over_Fs) == observation.nlambda
|
|
1234
|
+
assert len(scene.Fs_over_F0) == observation.nlambda
|
|
1235
|
+
assert len(scene.mag) == observation.nlambda
|
|
1236
|
+
assert len(scene.deltamag) == observation.nlambda
|
|
1237
1237
|
|
|
1238
1238
|
|
|
1239
1239
|
def test_regrid_spectra_preserves_units():
|
|
@@ -1246,7 +1246,7 @@ def test_regrid_spectra_preserves_units():
|
|
|
1246
1246
|
|
|
1247
1247
|
class MockObservation:
|
|
1248
1248
|
wavelength = np.linspace(0.5, 1.7, 100) * WAVELENGTH
|
|
1249
|
-
|
|
1249
|
+
nlambda = len(wavelength)
|
|
1250
1250
|
delta_wavelength = np.gradient(wavelength)
|
|
1251
1251
|
_input_wavelength = parameters["wavelength"]
|
|
1252
1252
|
|
|
@@ -44,11 +44,11 @@ def mock_observation():
|
|
|
44
44
|
observation.delta_wavelength = u.Quantity([0.5 * 0.2], u.micron)
|
|
45
45
|
observation.SNR = u.Quantity([7], DIMENSIONLESS)
|
|
46
46
|
observation.CRb_multiplier = 2
|
|
47
|
-
observation.
|
|
47
|
+
observation.nlambda = 1
|
|
48
48
|
observation.tp = 0.0 * u.s
|
|
49
49
|
# Initialize some arrays needed for outputs...
|
|
50
|
-
observation.exptime = np.full((observation.
|
|
51
|
-
observation.fullsnr = np.full((observation.
|
|
50
|
+
observation.exptime = np.full((observation.nlambda), 0.0) * TIME
|
|
51
|
+
observation.fullsnr = np.full((observation.nlambda), 0.0) * DIMENSIONLESS
|
|
52
52
|
|
|
53
53
|
return observation
|
|
54
54
|
|
|
@@ -582,7 +582,7 @@ def test_calculate_exposure_time_bandwidth_restriction_warning(
|
|
|
582
582
|
):
|
|
583
583
|
"""Test that exceeding coronagraph bandwidth triggers warning."""
|
|
584
584
|
mock_observation.wavelength = [0.5] * u.um
|
|
585
|
-
mock_observation.
|
|
585
|
+
mock_observation.nlambda = 1
|
|
586
586
|
mock_observatory.observing_mode = "IMAGER"
|
|
587
587
|
mock_observatory.coronagraph.bandwidth = 1.0
|
|
588
588
|
mock_observatory.coronagraph.coronagraph_spectral_resolution = 10
|
|
@@ -174,7 +174,7 @@ def mock_observation_imager():
|
|
|
174
174
|
obs.wavelength = u.Quantity([0.5], u.micron)
|
|
175
175
|
obs.SNR = u.Quantity([7], DIMENSIONLESS)
|
|
176
176
|
obs.CRb_multiplier = 2
|
|
177
|
-
obs.
|
|
177
|
+
obs.nlambda = 1
|
|
178
178
|
obs.tp = 0.0 * u.s
|
|
179
179
|
obs.exptime = u.Quantity([0.0], u.s)
|
|
180
180
|
obs.fullsnr = u.Quantity([0.0], DIMENSIONLESS)
|
|
@@ -190,7 +190,7 @@ def mock_observation_ifs():
|
|
|
190
190
|
obs.wavelength = u.Quantity([0.5, 0.6], u.micron)
|
|
191
191
|
obs.SNR = u.Quantity([7, 7], DIMENSIONLESS)
|
|
192
192
|
obs.CRb_multiplier = 2
|
|
193
|
-
obs.
|
|
193
|
+
obs.nlambda = 2
|
|
194
194
|
obs.exptime = u.Quantity([0.0, 0.0], u.s)
|
|
195
195
|
obs.fullsnr = u.Quantity([0.0, 0.0], DIMENSIONLESS)
|
|
196
196
|
return obs
|
|
@@ -64,6 +64,35 @@ def ifs_input_file_valid():
|
|
|
64
64
|
os.unlink(tmp.name)
|
|
65
65
|
|
|
66
66
|
|
|
67
|
+
@pytest.fixture
|
|
68
|
+
def ifs_input_file_no_observing_mode():
|
|
69
|
+
"""Fixture providing an input file without observing mode."""
|
|
70
|
+
with tempfile.NamedTemporaryFile(mode="w", delete=False, suffix=".edith") as tmp:
|
|
71
|
+
tmp.write("""
|
|
72
|
+
wavelength = [0.5, 0.6, 0.7]
|
|
73
|
+
Fstar_10pc = [1e-8, 1e-8, 1e-8]
|
|
74
|
+
Fp/Fs = [1e-10, 1e-10, 1e-10]
|
|
75
|
+
""")
|
|
76
|
+
tmp.flush()
|
|
77
|
+
yield tmp.name
|
|
78
|
+
os.unlink(tmp.name)
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
@pytest.fixture
|
|
82
|
+
def ifs_input_file_wrong_observing_mode():
|
|
83
|
+
"""Fixture providing an input file with wrong observing mode."""
|
|
84
|
+
with tempfile.NamedTemporaryFile(mode="w", delete=False, suffix=".edith") as tmp:
|
|
85
|
+
tmp.write("""
|
|
86
|
+
observing_mode = 'Invalid'
|
|
87
|
+
wavelength = [0.5, 0.6, 0.7]
|
|
88
|
+
Fstar_10pc = [1e-8, 1e-8, 1e-8]
|
|
89
|
+
Fp/Fs = [1e-10, 1e-10, 1e-10]
|
|
90
|
+
""")
|
|
91
|
+
tmp.flush()
|
|
92
|
+
yield tmp.name
|
|
93
|
+
os.unlink(tmp.name)
|
|
94
|
+
|
|
95
|
+
|
|
67
96
|
@pytest.fixture
|
|
68
97
|
def ifs_input_file_missing_keys():
|
|
69
98
|
"""Fixture providing an IFS mode input file with missing required keys."""
|
|
@@ -170,6 +199,24 @@ def test_parse_input_file_ifs_valid(ifs_input_file_valid):
|
|
|
170
199
|
# ============================================================================
|
|
171
200
|
|
|
172
201
|
|
|
202
|
+
def test_parse_input_file_no_observing_mode(ifs_input_file_no_observing_mode):
|
|
203
|
+
"""Test parsing an input file without observing_mode."""
|
|
204
|
+
with pytest.raises(
|
|
205
|
+
KeyError,
|
|
206
|
+
match="Required parameter 'observing_mode' is not provided in the input file.",
|
|
207
|
+
):
|
|
208
|
+
parse_input_file(ifs_input_file_no_observing_mode, secondary_flag=False)
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
def test_parse_input_file_wrong_observing_mode(ifs_input_file_wrong_observing_mode):
|
|
212
|
+
"""Test parsing an input file without observing_mode."""
|
|
213
|
+
with pytest.raises(
|
|
214
|
+
ValueError,
|
|
215
|
+
match="Invalid observing mode 'Invalid'. Must be 'IMAGER' or 'IFS'.",
|
|
216
|
+
):
|
|
217
|
+
parse_input_file(ifs_input_file_wrong_observing_mode, secondary_flag=False)
|
|
218
|
+
|
|
219
|
+
|
|
173
220
|
def test_parse_input_file_imager_multi_wavelength_error(
|
|
174
221
|
sample_input_file_imager_multi_wavelength,
|
|
175
222
|
):
|
|
@@ -1592,3 +1592,237 @@ def test_fill_parameters_override_disjoint_sets():
|
|
|
1592
1592
|
fill_parameters(
|
|
1593
1593
|
test_object, parameters, default_parameters, locked_keys, allow_override
|
|
1594
1594
|
)
|
|
1595
|
+
|
|
1596
|
+
|
|
1597
|
+
# ============================================================================
|
|
1598
|
+
# Tests for fill_parameters - STEP 0: Rebinning override parameters
|
|
1599
|
+
# ============================================================================
|
|
1600
|
+
|
|
1601
|
+
|
|
1602
|
+
def test_fill_parameters_rebin_array_override(test_object, caplog):
|
|
1603
|
+
"""Test that array override parameters (like DC) are rebinned to match resolved wavelength."""
|
|
1604
|
+
parameters = {
|
|
1605
|
+
"wavelength": np.array([0.5, 0.550, 0.60, 0.650, 0.700]) * WAVELENGTH,
|
|
1606
|
+
"DC": np.array([1e-3, 1.5e-3, 2e-3, 2.5e-3, 1.5e-3]) * DARK_CURRENT,
|
|
1607
|
+
}
|
|
1608
|
+
rebinned_wavelength = np.array([0.5, 0.6, 0.7]) * WAVELENGTH
|
|
1609
|
+
default_parameters = {
|
|
1610
|
+
"wavelength": np.array([0.5, 0.6, 0.7]) * WAVELENGTH,
|
|
1611
|
+
"DC": np.array([1e-3, 1e-3, 1e-3]) * DARK_CURRENT,
|
|
1612
|
+
}
|
|
1613
|
+
locked_keys = {"DC"}
|
|
1614
|
+
allow_override = {"DC"}
|
|
1615
|
+
|
|
1616
|
+
with caplog.at_level(logging.INFO):
|
|
1617
|
+
fill_parameters(
|
|
1618
|
+
test_object,
|
|
1619
|
+
parameters,
|
|
1620
|
+
default_parameters,
|
|
1621
|
+
locked_keys,
|
|
1622
|
+
allow_override,
|
|
1623
|
+
rebinned_wavelength,
|
|
1624
|
+
)
|
|
1625
|
+
|
|
1626
|
+
# Should be rebinned to match rebinned_wavelength length
|
|
1627
|
+
assert len(test_object.DC) == len(rebinned_wavelength)
|
|
1628
|
+
assert np.array_equal(test_object.DC, [1e-3, 2e-3, 1.5e-3] * DARK_CURRENT)
|
|
1629
|
+
assert isinstance(test_object.DC, u.Quantity)
|
|
1630
|
+
assert test_object.DC.unit == DARK_CURRENT
|
|
1631
|
+
assert "Before overriding: rebinning DC array" in caplog.text
|
|
1632
|
+
assert "explicitly overridden" in caplog.text
|
|
1633
|
+
|
|
1634
|
+
|
|
1635
|
+
def test_fill_parameters_skip_scalar_override(test_object, caplog):
|
|
1636
|
+
"""Test that scalar override parameters (like diameter) are not rebinned."""
|
|
1637
|
+
parameters = {
|
|
1638
|
+
"wavelength": np.array([0.5, 0.550, 0.60, 0.650, 0.700]) * WAVELENGTH,
|
|
1639
|
+
"diameter": 4.0 * LENGTH,
|
|
1640
|
+
}
|
|
1641
|
+
rebinned_wavelength = np.array([0.5, 0.6, 0.7]) * WAVELENGTH
|
|
1642
|
+
default_parameters = {
|
|
1643
|
+
"wavelength": np.array([0.5, 0.6, 0.7]) * WAVELENGTH,
|
|
1644
|
+
"diameter": 2.4 * LENGTH,
|
|
1645
|
+
}
|
|
1646
|
+
locked_keys = {"diameter"}
|
|
1647
|
+
allow_override = {"diameter"}
|
|
1648
|
+
|
|
1649
|
+
with caplog.at_level(logging.INFO):
|
|
1650
|
+
fill_parameters(
|
|
1651
|
+
test_object,
|
|
1652
|
+
parameters,
|
|
1653
|
+
default_parameters,
|
|
1654
|
+
locked_keys,
|
|
1655
|
+
allow_override,
|
|
1656
|
+
rebinned_wavelength,
|
|
1657
|
+
)
|
|
1658
|
+
|
|
1659
|
+
# Scalar should remain scalar and use user value
|
|
1660
|
+
assert test_object.diameter == 4.0 * LENGTH
|
|
1661
|
+
assert "diameter is a scalar and won't be rebinned" in caplog.text
|
|
1662
|
+
assert "explicitly overridden" in caplog.text
|
|
1663
|
+
|
|
1664
|
+
|
|
1665
|
+
def test_fill_parameters_mixed_overrides(test_object, caplog):
|
|
1666
|
+
"""Test rebinning with both array (DC) and scalar (diameter) overrides."""
|
|
1667
|
+
parameters = {
|
|
1668
|
+
"wavelength": np.array([0.5, 0.550, 0.60, 0.650, 0.700]) * WAVELENGTH,
|
|
1669
|
+
"DC": np.array([1e-3, 1.5e-3, 2e-3, 2.5e-3, 1.5e-3]) * DARK_CURRENT,
|
|
1670
|
+
"diameter": 4.0 * u.m,
|
|
1671
|
+
}
|
|
1672
|
+
rebinned_wavelength = np.array([0.5, 0.6, 0.7]) * WAVELENGTH
|
|
1673
|
+
default_parameters = {
|
|
1674
|
+
"wavelength": np.array([0.5, 0.6, 0.7]) * WAVELENGTH,
|
|
1675
|
+
"DC": np.array([1e-3, 1e-3, 1e-3]) * DARK_CURRENT,
|
|
1676
|
+
"diameter": 2.4 * u.m,
|
|
1677
|
+
}
|
|
1678
|
+
locked_keys = {"DC", "diameter"}
|
|
1679
|
+
allow_override = {"DC", "diameter"}
|
|
1680
|
+
|
|
1681
|
+
with caplog.at_level(logging.INFO):
|
|
1682
|
+
fill_parameters(
|
|
1683
|
+
test_object,
|
|
1684
|
+
parameters,
|
|
1685
|
+
default_parameters,
|
|
1686
|
+
locked_keys,
|
|
1687
|
+
allow_override,
|
|
1688
|
+
rebinned_wavelength,
|
|
1689
|
+
)
|
|
1690
|
+
|
|
1691
|
+
# DC should be rebinned
|
|
1692
|
+
assert len(test_object.DC) == len(rebinned_wavelength)
|
|
1693
|
+
assert np.array_equal(test_object.DC, [1e-3, 2e-3, 1.5e-3] * DARK_CURRENT)
|
|
1694
|
+
assert isinstance(test_object.DC, u.Quantity)
|
|
1695
|
+
assert test_object.DC.unit == DARK_CURRENT
|
|
1696
|
+
assert "Before overriding: rebinning DC array" in caplog.text
|
|
1697
|
+
|
|
1698
|
+
# diameter should remain scalar
|
|
1699
|
+
assert test_object.diameter == 4.0 * LENGTH
|
|
1700
|
+
assert "diameter is a scalar and won't be rebinned" in caplog.text
|
|
1701
|
+
|
|
1702
|
+
|
|
1703
|
+
def test_fill_parameters_mixed_overrides_non_quantities(test_object, caplog):
|
|
1704
|
+
"""Test rebinning with both array (DC) and scalar (diameter) overrides."""
|
|
1705
|
+
parameters = {
|
|
1706
|
+
"wavelength": np.array([0.5, 0.550, 0.60, 0.650, 0.700]),
|
|
1707
|
+
"DC": np.array([1e-3, 1.5e-3, 2e-3, 2.5e-3, 1.5e-3]),
|
|
1708
|
+
"diameter": 4.0,
|
|
1709
|
+
}
|
|
1710
|
+
rebinned_wavelength = np.array([0.5, 0.6, 0.7]) * WAVELENGTH
|
|
1711
|
+
default_parameters = {
|
|
1712
|
+
"wavelength": np.array([0.5, 0.6, 0.7]) * WAVELENGTH,
|
|
1713
|
+
"DC": np.array([1e-3, 1e-3, 1e-3]) * DARK_CURRENT,
|
|
1714
|
+
"diameter": 2.4 * u.m,
|
|
1715
|
+
}
|
|
1716
|
+
locked_keys = {"DC", "diameter"}
|
|
1717
|
+
allow_override = {"DC", "diameter"}
|
|
1718
|
+
|
|
1719
|
+
with caplog.at_level(logging.INFO):
|
|
1720
|
+
fill_parameters(
|
|
1721
|
+
test_object,
|
|
1722
|
+
parameters,
|
|
1723
|
+
default_parameters,
|
|
1724
|
+
locked_keys,
|
|
1725
|
+
allow_override,
|
|
1726
|
+
rebinned_wavelength,
|
|
1727
|
+
)
|
|
1728
|
+
|
|
1729
|
+
# DC should be rebinned
|
|
1730
|
+
assert len(test_object.DC) == len(rebinned_wavelength)
|
|
1731
|
+
assert np.array_equal(test_object.DC, [1e-3, 2e-3, 1.5e-3] * DARK_CURRENT)
|
|
1732
|
+
assert isinstance(test_object.DC, u.Quantity)
|
|
1733
|
+
assert test_object.DC.unit == DARK_CURRENT
|
|
1734
|
+
assert "Before overriding: rebinning DC array" in caplog.text
|
|
1735
|
+
|
|
1736
|
+
# diameter should remain scalar
|
|
1737
|
+
assert test_object.diameter == 4.0 * LENGTH
|
|
1738
|
+
assert "diameter is a scalar and won't be rebinned" in caplog.text
|
|
1739
|
+
|
|
1740
|
+
|
|
1741
|
+
def test_fill_parameters_error_wrong_length_array(test_object, caplog):
|
|
1742
|
+
"""Test that arrays with length != wavelength fail."""
|
|
1743
|
+
parameters = {
|
|
1744
|
+
"wavelength": np.array([0.5, 0.550, 0.60, 0.650, 0.700]) * WAVELENGTH,
|
|
1745
|
+
"DC": np.array([1e-3, 1.5e-3, 1.5e-3]) * DARK_CURRENT,
|
|
1746
|
+
}
|
|
1747
|
+
rebinned_wavelength = np.array([0.5, 0.6, 0.7]) * WAVELENGTH
|
|
1748
|
+
default_parameters = {
|
|
1749
|
+
"wavelength": np.array([0.5, 0.6, 0.7]) * WAVELENGTH,
|
|
1750
|
+
"DC": np.array([1e-3, 1e-3, 1e-3]) * DARK_CURRENT,
|
|
1751
|
+
}
|
|
1752
|
+
locked_keys = {"DC"}
|
|
1753
|
+
allow_override = {"DC"}
|
|
1754
|
+
|
|
1755
|
+
with pytest.raises(
|
|
1756
|
+
ValueError,
|
|
1757
|
+
match="Before overriding: DC does not have length equal to input wavelength. Please check your inputs.",
|
|
1758
|
+
):
|
|
1759
|
+
fill_parameters(
|
|
1760
|
+
test_object,
|
|
1761
|
+
parameters,
|
|
1762
|
+
default_parameters,
|
|
1763
|
+
locked_keys,
|
|
1764
|
+
allow_override,
|
|
1765
|
+
rebinned_wavelength,
|
|
1766
|
+
)
|
|
1767
|
+
|
|
1768
|
+
|
|
1769
|
+
def test_fill_parameters_override_not_provided(test_object, caplog):
|
|
1770
|
+
"""Test that override parameters not provided by user are not processed in STEP 0."""
|
|
1771
|
+
parameters = {
|
|
1772
|
+
"wavelength": np.array([0.5, 0.550, 0.60, 0.650, 0.700]) * WAVELENGTH,
|
|
1773
|
+
# DC intentionally not provided
|
|
1774
|
+
}
|
|
1775
|
+
rebinned_wavelength = np.array([0.5, 0.6, 0.7]) * WAVELENGTH
|
|
1776
|
+
default_parameters = {
|
|
1777
|
+
"wavelength": np.array([0.5, 0.6, 0.7]) * WAVELENGTH,
|
|
1778
|
+
"DC": np.array([1e-3, 1e-3, 1e-3]) * DARK_CURRENT,
|
|
1779
|
+
}
|
|
1780
|
+
locked_keys = {"DC"}
|
|
1781
|
+
allow_override = {"DC"}
|
|
1782
|
+
|
|
1783
|
+
with caplog.at_level(logging.INFO):
|
|
1784
|
+
fill_parameters(
|
|
1785
|
+
test_object,
|
|
1786
|
+
parameters,
|
|
1787
|
+
default_parameters,
|
|
1788
|
+
locked_keys,
|
|
1789
|
+
allow_override,
|
|
1790
|
+
rebinned_wavelength,
|
|
1791
|
+
)
|
|
1792
|
+
|
|
1793
|
+
# Should use default value (not rebinned since user didn't provide it)
|
|
1794
|
+
assert np.array_equal(test_object.DC, default_parameters["DC"])
|
|
1795
|
+
# No rebinning message for DC
|
|
1796
|
+
assert "Before overriding: rebinning DC" not in caplog.text
|
|
1797
|
+
|
|
1798
|
+
|
|
1799
|
+
# def test_fill_parameters_step0_integration_with_step1(test_object, caplog):
|
|
1800
|
+
# """Test that rebinned DC from STEP 0 is correctly applied as override in STEP 1."""
|
|
1801
|
+
# parameters = {
|
|
1802
|
+
# "wavelength": np.array([500, 600, 700]) * u.nm,
|
|
1803
|
+
# "DC": np.array([1e-3, 2e-3, 1.5e-3]) * u.electron / u.s / u.pix,
|
|
1804
|
+
# }
|
|
1805
|
+
# rebinned_wavelength = np.array([500, 550, 600, 650, 700]) * u.nm
|
|
1806
|
+
# default_parameters = {
|
|
1807
|
+
# "wavelength": np.array([500, 600, 700]) * u.nm,
|
|
1808
|
+
# "DC": 1e-3 * u.electron / u.s / u.pix,
|
|
1809
|
+
# }
|
|
1810
|
+
# locked_keys = {"DC"}
|
|
1811
|
+
# allow_override = {"DC"}
|
|
1812
|
+
|
|
1813
|
+
# with caplog.at_level(logging.WARNING):
|
|
1814
|
+
# fill_parameters(
|
|
1815
|
+
# test_object,
|
|
1816
|
+
# parameters,
|
|
1817
|
+
# default_parameters,
|
|
1818
|
+
# locked_keys,
|
|
1819
|
+
# allow_override,
|
|
1820
|
+
# rebinned_wavelength,
|
|
1821
|
+
# )
|
|
1822
|
+
|
|
1823
|
+
# # Check that DC was rebinned then applied as override
|
|
1824
|
+
# assert len(test_object.DC) == len(rebinned_wavelength)
|
|
1825
|
+
# assert isinstance(test_object.DC, u.Quantity)
|
|
1826
|
+
# assert test_object.DC.unit == u.electron / u.s / u.pix
|
|
1827
|
+
# # Should see the override warning from STEP 1
|
|
1828
|
+
# assert "explicitly overridden" in caplog.text
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|