pyEDITH 1.7.0__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.
Files changed (35) hide show
  1. {pyedith-1.7.0/src/pyEDITH.egg-info → pyedith-1.7.2}/PKG-INFO +2 -2
  2. {pyedith-1.7.0 → pyedith-1.7.2}/README.md +1 -1
  3. {pyedith-1.7.0 → pyedith-1.7.2}/pyproject.toml +1 -1
  4. {pyedith-1.7.0 → pyedith-1.7.2}/src/pyEDITH/astrophysical_scene.py +12 -10
  5. {pyedith-1.7.0 → pyedith-1.7.2}/src/pyEDITH/components/detectors.py +12 -10
  6. {pyedith-1.7.0 → pyedith-1.7.2}/src/pyEDITH/components/telescopes.py +3 -2
  7. {pyedith-1.7.0 → pyedith-1.7.2}/src/pyEDITH/exposure_time_calculator.py +27 -38
  8. {pyedith-1.7.0 → pyedith-1.7.2}/src/pyEDITH/observation.py +9 -10
  9. {pyedith-1.7.0 → pyedith-1.7.2}/src/pyEDITH/observatory.py +2 -2
  10. {pyedith-1.7.0 → pyedith-1.7.2}/src/pyEDITH/parse_input.py +11 -1
  11. {pyedith-1.7.0 → pyedith-1.7.2}/src/pyEDITH/utils.py +48 -2
  12. {pyedith-1.7.0 → pyedith-1.7.2/src/pyEDITH.egg-info}/PKG-INFO +2 -2
  13. {pyedith-1.7.0 → pyedith-1.7.2}/tests/test_astrophysical_scene.py +14 -14
  14. {pyedith-1.7.0 → pyedith-1.7.2}/tests/test_exposure_time_calculator.py +8 -7
  15. {pyedith-1.7.0 → pyedith-1.7.2}/tests/test_observatory.py +2 -2
  16. {pyedith-1.7.0 → pyedith-1.7.2}/tests/test_parse_input.py +47 -0
  17. {pyedith-1.7.0 → pyedith-1.7.2}/tests/test_utils.py +234 -0
  18. {pyedith-1.7.0 → pyedith-1.7.2}/LICENSE +0 -0
  19. {pyedith-1.7.0 → pyedith-1.7.2}/setup.cfg +0 -0
  20. {pyedith-1.7.0 → pyedith-1.7.2}/src/pyEDITH/__init__.py +0 -0
  21. {pyedith-1.7.0 → pyedith-1.7.2}/src/pyEDITH/cli.py +0 -0
  22. {pyedith-1.7.0 → pyedith-1.7.2}/src/pyEDITH/components/coronagraphs.py +0 -0
  23. {pyedith-1.7.0 → pyedith-1.7.2}/src/pyEDITH/units.py +0 -0
  24. {pyedith-1.7.0 → pyedith-1.7.2}/src/pyEDITH.egg-info/SOURCES.txt +0 -0
  25. {pyedith-1.7.0 → pyedith-1.7.2}/src/pyEDITH.egg-info/dependency_links.txt +0 -0
  26. {pyedith-1.7.0 → pyedith-1.7.2}/src/pyEDITH.egg-info/entry_points.txt +0 -0
  27. {pyedith-1.7.0 → pyedith-1.7.2}/src/pyEDITH.egg-info/requires.txt +0 -0
  28. {pyedith-1.7.0 → pyedith-1.7.2}/src/pyEDITH.egg-info/top_level.txt +0 -0
  29. {pyedith-1.7.0 → pyedith-1.7.2}/tests/test_cli.py +0 -0
  30. {pyedith-1.7.0 → pyedith-1.7.2}/tests/test_coronagraphs.py +0 -0
  31. {pyedith-1.7.0 → pyedith-1.7.2}/tests/test_detectors.py +0 -0
  32. {pyedith-1.7.0 → pyedith-1.7.2}/tests/test_init.py +0 -0
  33. {pyedith-1.7.0 → pyedith-1.7.2}/tests/test_observation.py +0 -0
  34. {pyedith-1.7.0 → pyedith-1.7.2}/tests/test_telescopes.py +0 -0
  35. {pyedith-1.7.0 → 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.0
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/
@@ -27,7 +27,7 @@ Requires-Dist: pooch; extra == "test"
27
27
  Dynamic: license-file
28
28
 
29
29
  <p align="center">
30
- <img src="docs/source/_static/pyEDITH.png" alt="pyEDITH logo">
30
+ <img src="docs/source/_static/pyEDITH-removebg-preview.png" alt="pyEDITH logo">
31
31
  </p>
32
32
 
33
33
  <p align="center">
@@ -1,5 +1,5 @@
1
1
  <p align="center">
2
- <img src="docs/source/_static/pyEDITH.png" alt="pyEDITH logo">
2
+ <img src="docs/source/_static/pyEDITH-removebg-preview.png" alt="pyEDITH logo">
3
3
  </p>
4
4
 
5
5
  <p align="center">
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "pyEDITH"
3
- version = "1.7.0"
3
+ version = "1.7.2"
4
4
  authors = [
5
5
  { name = "Eleonora Alei", email = "eleonora.alei@nasa.gov" },
6
6
  { name = "Miles Currie", email = "miles.h.currie@nasa.gov" },
@@ -164,7 +164,9 @@ def calc_flux_zero_point(
164
164
  equivalencies=u.spectral_density(lambd),
165
165
  )
166
166
 
167
- logger.info(f"Flux zero point calculated at {lambd} in units of {f0.unit}")
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 nlambd).
197
+ Wavelength in microns (vector of length nlambda).
196
198
  lambdmag : Quantity
197
- Apparent magnitude of stars at each lambd (array nlambd).
199
+ Apparent magnitude of stars at each lambd (array nlambda).
198
200
  F0lambd : Quantity
199
- Flux zero point at wavelength lambd (vector of length nlambd).
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 nlambd, where nlambd is the length of lambd."
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
- nlambd = len(lambd)
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 nlambd).
264
+ Wavelengths in microns (vector of length nlambda).
263
265
  F0 : Quantity
264
- Flux zero points at wavelengths lambd (vector of length nlambd).
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 (nlambd, nstars).
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
- nlambd = len(lambd)
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, nlambd array)
114
- "RN": [0.0] * READ_NOISE, # Read noise (counts pix^-1 read^-1, nlambd array)
115
- "tread": [1000] * READ_TIME, # Read time (s, nlambd array)
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, nlambd array)
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, nlambd array)
230
- "RN": None, # Read noise (counts pix^-1 read^-1, nlambd array)
231
- "tread": [1000] * READ_TIME, # Read time (s, nlambd array) # TO ADD TO YAML
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, nlambd array) # TO ADD TO YAML
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, nlambd array)
316
+ ) # Dark current (counts pix^-1 s^-1, nlambda array)
316
317
 
317
- # Dark current (counts pix^-1 s^-1, nlambd array)
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 (nlambd array) [made up from EAC1-ish]
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 (nlambd array)
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
@@ -425,7 +425,6 @@ def calculate_CRnf(
425
425
  throughput: u.Quantity,
426
426
  dlambda: u.Quantity,
427
427
  nchannels: int,
428
- SNR: u.Quantity,
429
428
  noisefloor: u.Quantity,
430
429
  ) -> u.Quantity:
431
430
  """
@@ -452,8 +451,6 @@ def calculate_CRnf(
452
451
  Bandwidth [um]
453
452
  nchannels : int
454
453
  Number of channels
455
- SNR : float
456
- Signal-to-noise ratio
457
454
  noisefloor : u.Quantity
458
455
  Noise floor level [dimensionless]
459
456
 
@@ -464,15 +461,12 @@ def calculate_CRnf(
464
461
  """
465
462
 
466
463
  return (
467
- SNR
468
- * (F0 * Fs_over_F0 * area * throughput * dlambda * nchannels / (pixscale**2))
469
- * noisefloor
470
- )
464
+ F0 * Fs_over_F0 * area * throughput * dlambda * nchannels / (pixscale**2)
465
+ ) * noisefloor # Update 1.7.1: SNR now moved outside of this function
471
466
 
472
467
 
473
468
  def calculate_CRnf_ez(
474
469
  CRbez: u.Quantity,
475
- SNR: u.Quantity,
476
470
  ez_PPF: u.Quantity,
477
471
  ) -> u.Quantity:
478
472
  """
@@ -486,8 +480,6 @@ def calculate_CRnf_ez(
486
480
  ----------
487
481
  CRbez : u.Quantity
488
482
  Count rate of the exozodi [photons / s]
489
- SNR : float
490
- Signal-to-noise ratio
491
483
  ez_PPF : u.Quantity
492
484
  Post-processing factor for exozodi [dimensionless]
493
485
 
@@ -497,7 +489,7 @@ def calculate_CRnf_ez(
497
489
  Exozodi noise floor count rate [photons / s]
498
490
  """
499
491
 
500
- return SNR * CRbez / ez_PPF
492
+ return CRbez / ez_PPF # Update 1.7.1: SNR now moved outside of this function
501
493
 
502
494
 
503
495
  def measure_coronagraph_performance_at_IWA(
@@ -689,53 +681,55 @@ def calculate_exposure_time_or_snr(
689
681
  lod,
690
682
  observation.wavelength.to(LENGTH),
691
683
  observatory.telescope.diameter.to(LENGTH),
692
- ) # shape (nlambd,), units rad
684
+ ) # shape (nlambda,), units rad
693
685
  lod_rad_arr = u.Quantity(np.atleast_1d(lod_rad_arr.value), lod_rad_arr.unit)
694
- lod_arcsec_arr = lod_rad_arr.to(ARCSEC) # shape (nlambd,)
686
+ lod_arcsec_arr = lod_rad_arr.to(ARCSEC) # shape (nlambda,)
695
687
 
696
688
  # --- Detector pixel scale in λ/D (one value per wavelength) ---
697
689
  detpixscale_lod_arr = arcsec_to_lambda_d(
698
690
  observatory.detector.pixscale_mas.to(ARCSEC),
699
691
  observation.wavelength.to(LENGTH),
700
692
  observatory.telescope.diameter.to(LENGTH),
701
- ) # shape (nlambd,), units LAMBDA_D
693
+ ) # shape (nlambda,), units LAMBDA_D
702
694
  detpixscale_lod_arr = u.Quantity(
703
695
  np.atleast_1d(detpixscale_lod_arr.value), detpixscale_lod_arr.unit
704
696
  )
705
697
 
706
698
  # --- Planet pixel position in the coronagraph image (one per wavelength) ---
707
699
  # pixscale_rad: [LAMBDA_D] * [rad/LAMBDA_D] = [rad/pix]
708
- pixscale_rad_arr = observatory.coronagraph.pixscale * lod_rad_arr # shape (nlambd,)
700
+ pixscale_rad_arr = (
701
+ observatory.coronagraph.pixscale * lod_rad_arr
702
+ ) # shape (nlambda,)
709
703
  oneopixscale_arcsec_arr = (1 * PIXEL) / pixscale_rad_arr.to(
710
704
  ARCSEC
711
- ) # shape (nlambd,) [pix/arcsec]
705
+ ) # shape (nlambda,) [pix/arcsec]
712
706
 
713
707
  ix_arr = (
714
708
  scene.xp * oneopixscale_arcsec_arr + observatory.coronagraph.xcenter
715
- ).value # shape (nlambd,), float pixel indices
709
+ ).value # shape (nlambda,), float pixel indices
716
710
  iy_arr = (
717
711
  scene.yp * oneopixscale_arcsec_arr + observatory.coronagraph.ycenter
718
- ).value # shape (nlambd,), float pixel indices
712
+ ).value # shape (nlambda,), float pixel indices
719
713
 
720
714
  ix_arr = np.atleast_1d(ix_arr)
721
715
  iy_arr = np.atleast_1d(iy_arr)
722
716
 
723
717
  # Integer (floored) pixel indices for coronagraph map lookups
724
- ix_int = np.floor(ix_arr).astype(int) # shape (nlambd,)
725
- iy_int = np.floor(iy_arr).astype(int) # shape (nlambd,)
718
+ ix_int = np.floor(ix_arr).astype(int) # shape (nlambda,)
719
+ iy_int = np.floor(iy_arr).astype(int) # shape (nlambda,)
726
720
 
727
721
  # --- Pixel validity mask (checks if the planet is within coronagraph pixels) ---
728
722
  npix = observatory.coronagraph.npix
729
723
  pixel_valid_mask = np.atleast_1d(
730
724
  (ix_int >= 0) & (ix_int < npix) & (iy_int >= 0) & (iy_int < npix)
731
- ) # shape (nlambd,), bool
725
+ ) # shape (nlambda,), bool
732
726
 
733
727
  # Clamp indices so fancy indexing never goes out of bounds on invalid channels
734
728
  # (values for those channels will be masked out anyway)
735
729
  ix_safe = np.clip(ix_int, 0, npix - 1)
736
730
  iy_safe = np.clip(iy_int, 0, npix - 1)
737
731
 
738
- # --- Vectorized coronagraph map lookups [shape (nlambd,)] ---
732
+ # --- Vectorized coronagraph map lookups [shape (nlambda,)] ---
739
733
 
740
734
  # NOTE: noisefloor_interp: technically the Y axis
741
735
  # is rows and the X axis is columns,
@@ -755,14 +749,14 @@ def calculate_exposure_time_or_snr(
755
749
  # NOTE: npsfratios == 1 in practice; iratio = 0 throughout.
756
750
  iratio = 0 # only one psf truncation ratio supported
757
751
 
758
- # omega_lod at the planet position, shape (nlambd,)
752
+ # omega_lod at the planet position, shape (nlambda,)
759
753
  omega_lod_at_planet = u.Quantity(
760
754
  np.atleast_1d(
761
755
  observatory.coronagraph.omega_lod[iy_safe, ix_safe, iratio].value
762
756
  ),
763
757
  observatory.coronagraph.omega_lod.unit,
764
758
  )
765
- # photometric aperture throughput at the planet position, shape (nlambd,)
759
+ # photometric aperture throughput at the planet position, shape (nlambda,)
766
760
  Upsilon_at_planet = np.atleast_1d(
767
761
  observatory.coronagraph.photometric_aperture_throughput[
768
762
  iy_safe, ix_safe, iratio
@@ -772,7 +766,7 @@ def calculate_exposure_time_or_snr(
772
766
  # -----------------------------------------------------------------------
773
767
  # Measure coronagraph performance close to IWA
774
768
  # -----------------------------------------------------------------------
775
- # Compute per wavelength via the existing helper (now vectorized over nlambd
769
+ # Compute per wavelength via the existing helper (now vectorized over nlambda
776
770
  # because measure_coronagraph_performance_at_IWA accepts scalar oneopixscale;
777
771
  # we call it in a list-comprehension to preserve the existing function signature) #TODO update after validation
778
772
 
@@ -787,7 +781,7 @@ def calculate_exposure_time_or_snr(
787
781
  observatory.coronagraph.ycenter,
788
782
  oneopixscale_arcsec_arr[ilambd],
789
783
  )
790
- for ilambd in range(observation.nlambd)
784
+ for ilambd in range(observation.nlambda)
791
785
  ]
792
786
 
793
787
  # Convert to Quantity arrays
@@ -1011,12 +1005,7 @@ def calculate_exposure_time_or_snr(
1011
1005
  observation.photon_counts["CRbd"] = CRbd_arr.value
1012
1006
 
1013
1007
  # --- NOISE FLOOR ---
1014
- # NOTE when calculating the SNR, we set snr_for_nf to 1 to calculate the noise
1015
- # factor ratio (i.e. we assume SNR =1 so that we can use it for the snr calculation later)
1016
- snr_for_nf = (
1017
- observation.SNR if mode == "exposure_time" else np.ones(observation.nlambd)
1018
- )
1019
-
1008
+ # Calculate CRnf without SNR. Update 1.7.1: SNR now moved outside of this function
1020
1009
  CRnf_s_arr = (
1021
1010
  calculate_CRnf(
1022
1011
  scene.F0,
@@ -1026,7 +1015,6 @@ def calculate_exposure_time_or_snr(
1026
1015
  observatory.total_throughput,
1027
1016
  deltalambda_nm,
1028
1017
  observatory.coronagraph.nchannels,
1029
- snr_for_nf,
1030
1018
  noisefloor_at_planet,
1031
1019
  )
1032
1020
  * omega_lod_at_planet
@@ -1035,7 +1023,6 @@ def calculate_exposure_time_or_snr(
1035
1023
 
1036
1024
  CRnf_ez_arr = calculate_CRnf_ez(
1037
1025
  CRbez_arr * omega_lod_at_planet.value,
1038
- snr_for_nf,
1039
1026
  scene.ez_PPF,
1040
1027
  )
1041
1028
  observation.photon_counts["CRnf_ez"] = CRnf_ez_arr.value
@@ -1063,7 +1050,9 @@ def calculate_exposure_time_or_snr(
1063
1050
  if mode == "exposure_time":
1064
1051
  cp_arr = (
1065
1052
  (CRp_arr + observation.CRb_multiplier * CRb_arr)
1066
- / (CRp_arr * CRp_arr - CRnf_arr * CRnf_arr)
1053
+ / (
1054
+ CRp_arr * CRp_arr - observation.SNR**2 * CRnf_arr * CRnf_arr
1055
+ ) # Update 1.7.1: SNR now outside CRnf
1067
1056
  * u.electron
1068
1057
  )
1069
1058
 
@@ -1155,7 +1144,7 @@ def calculate_exposure_time_or_snr(
1155
1144
  below_noise_floor = np.atleast_1d(
1156
1145
  (pixel_valid_mask & phot_aperture_valid_mask & (CRp_arr <= CRnf_arr))
1157
1146
  if mode == "exposure_time"
1158
- else np.zeros(observation.nlambd, dtype=bool)
1147
+ else np.zeros(observation.nlambda, dtype=bool)
1159
1148
  )
1160
1149
  if np.any(below_noise_floor):
1161
1150
  logger.error(
@@ -1185,7 +1174,7 @@ def calculate_exposure_time_or_snr(
1185
1174
  sciencetime_arr = (
1186
1175
  observation.SNR**2 * cp_arr
1187
1176
  if mode == "exposure_time"
1188
- else u.Quantity(np.zeros(observation.nlambd), u.s)
1177
+ else u.Quantity(np.zeros(observation.nlambda), u.s)
1189
1178
  )
1190
1179
 
1191
1180
  observation.validation_variables = {
@@ -1246,7 +1235,7 @@ def calculate_exposure_time_or_snr(
1246
1235
  "CRbth": CRbth_arr * omega_lod_at_planet,
1247
1236
  "CRb": CRb_arr,
1248
1237
  "CRbd": CRbd_arr,
1249
- "CRnf": CRnf_arr,
1238
+ "CRnf": CRnf_arr, # Now stored WITHOUT SNR factor
1250
1239
  # --- results ---
1251
1240
  "sciencetime": sciencetime_arr,
1252
1241
  "exptime": observation.exptime if mode == "exposure_time" else None,
@@ -20,7 +20,7 @@ class Observation:
20
20
  -----------
21
21
  wavelength : np.ndarray
22
22
  Wavelength array (in microns).
23
- nlambd : int
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 # nlambd array #unit: micron
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 # nlambd array #unit: micron
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 # nlambd array #unit: micron
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.nlambd = len(self.wavelength)
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 # nlambd array
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.nlambd), 0.0) * TIME
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.nlambd), 0.0) * DIMENSIONLESS
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
- "nlambd": int,
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": "eac1_optimal_order_6_1d", # will download from the database
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": "eac1_optimal_order_6_1d", # temporary, will be replaced by a more suitable one
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.0
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/
@@ -27,7 +27,7 @@ Requires-Dist: pooch; extra == "test"
27
27
  Dynamic: license-file
28
28
 
29
29
  <p align="center">
30
- <img src="docs/source/_static/pyEDITH.png" alt="pyEDITH logo">
30
+ <img src="docs/source/_static/pyEDITH-removebg-preview.png" alt="pyEDITH logo">
31
31
  </p>
32
32
 
33
33
  <p align="center">
@@ -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
- nlambd = len(parameters["wavelength"])
840
- assert len(scene.Fzodi_list) == nlambd
841
- assert len(scene.Fexozodi_list) == nlambd
842
- assert len(scene.Fbinary_list) == nlambd
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
- nlambd = len(wavelength)
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.nlambd
1230
- assert len(scene.Fzodi_list) == observation.nlambd
1231
- assert len(scene.Fexozodi_list) == observation.nlambd
1232
- assert len(scene.Fbinary_list) == observation.nlambd
1233
- assert len(scene.Fp_over_Fs) == observation.nlambd
1234
- assert len(scene.Fs_over_F0) == observation.nlambd
1235
- assert len(scene.mag) == observation.nlambd
1236
- assert len(scene.deltamag) == observation.nlambd
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
- nlambd = len(wavelength)
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.nlambd = 1
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.nlambd), 0.0) * TIME
51
- observation.fullsnr = np.full((observation.nlambd), 0.0) * DIMENSIONLESS
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
 
@@ -369,15 +369,16 @@ def test_calculate_CRnf():
369
369
  throughput = 0.35910000000000003 * ELECTRON / PHOTON_COUNT
370
370
  dlambda = 100 * u.nm
371
371
  nchannels = 2
372
- SNR = 7
373
372
  noisefloor = 7.25659425003725e-18 * DIMENSIONLESS
374
373
 
375
374
  result = calculate_CRnf(
376
- F0, Fs_over_F0, area, pixscale, throughput, dlambda, nchannels, SNR, noisefloor
375
+ F0, Fs_over_F0, area, pixscale, throughput, dlambda, nchannels, noisefloor
377
376
  )
378
377
 
379
378
  assert result.unit == (u.electron / u.s)
380
- assert np.isclose(result.value, 1.7763531e-6)
379
+ assert np.isclose(
380
+ result.value, 2.5376479000e-07
381
+ ) # Value changed because of Update 1.7.1: SNR now outside CRnf
381
382
 
382
383
 
383
384
  def test_calculate_t_photon_count():
@@ -581,7 +582,7 @@ def test_calculate_exposure_time_bandwidth_restriction_warning(
581
582
  ):
582
583
  """Test that exceeding coronagraph bandwidth triggers warning."""
583
584
  mock_observation.wavelength = [0.5] * u.um
584
- mock_observation.nlambd = 1
585
+ mock_observation.nlambda = 1
585
586
  mock_observatory.observing_mode = "IMAGER"
586
587
  mock_observatory.coronagraph.bandwidth = 1.0
587
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.nlambd = 1
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.nlambd = 2
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