Skip to content

Spectral Response

Atmosphere

Bases: Spectral_Response

Source code in AIS/Spectral_Response/spectral_response.py
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
class Atmosphere(Spectral_Response):
    CSV_FILE_NAME = "atmosphere_profile.csv"
    ATM_EXTINCTION_FILE = "willton.csv"

    def __init__(self) -> None:

        super().__init__()
        self.BASE_PATH = os.path.join(self.BASE_PATH, "atmosphere")
        return

    def get_spectral_response(
        self,
        obj_wavelength: ndarray,
        air_mass: int | float = 1,
        sky_condition: str = "photometric",
    ) -> ndarray:
        """Return the spectral response.

        Parameters
        ----------
        obj_wavelength: array like
            The wavelength interval, in nm, of the object.
        air_mass: int, float
            The air mass.
        sky_condition: ['photometric', 'regular', 'good']
            The condition of the sky.

        Returns
        -------
        array like:
            The spectral response of the optical system.

        """
        ss = pd.read_csv(
            os.path.join(self.BASE_PATH, self.ATM_EXTINCTION_FILE), dtype=np.float64
        )
        spectral_response = 10 ** (-0.43428 * air_mass * ss[sky_condition])
        spectral_response = self._interpolate_spectral_response(
            ss["Wavelength (nm)"], spectral_response, obj_wavelength
        )
        spectral_response[spectral_response > 1] = 1

        return spectral_response

    def apply_spectral_response(
        self,
        obj_wavelength: ndarray,
        sed: ndarray,
        air_mass: int | float,
        sky_condition: str = "photometric",
    ) -> ndarray:
        """Apply the spectral response.

        Parameters
        ----------
        obj_wavelength: array like
            The wavelength interval, in nm, of the object.
        sed: array like
            The Spectral Energy Distribution (SED) of the object.
        air_mass: int, float.
            The air mass in the light path.
        sky_condition: ['photometric', 'regular', 'good'].
            The condition of the sky during the observation.

        Returns
        -------
        reduced_sed: array like
            The Spectral Energy Distribution (SED) of the object subtracted from the loses
            related to the spectral response of the system.
        """
        self._verify_var_in_interval(air_mass, "air_mass", var_max=3)
        self._check_var_in_a_list(
            sky_condition, "sky_condition", ["photometric", "regular", "good"]
        )
        spectral_response = self.get_spectral_response(
            obj_wavelength, air_mass, sky_condition
        )

        sed = spectral_response * sed

        return sed

    def _func(self, wavelength_interv: ndarray, C: float) -> ndarray:
        csv_file_name = os.path.join(self.BASE_PATH, self.CSV_FILE_NAME)
        sys_wavelength, spectral_response = self._read_csv_file(csv_file_name)
        spl = interp1d(
            sys_wavelength, spectral_response, bounds_error=False, kind="cubic"
        )
        return spl(wavelength_interv) * C

    @staticmethod
    def _interpolate_spectral_response(
        wavelength, spectral_response, obj_wavelength
    ) -> ndarray:
        spl = interp1d(
            wavelength,
            spectral_response,
            bounds_error=False,
            fill_value="extrapolate",
            kind="linear",
        )

        return spl(obj_wavelength)

apply_spectral_response(obj_wavelength, sed, air_mass, sky_condition='photometric')

Apply the spectral response.

Parameters:

Name Type Description Default
obj_wavelength ndarray

The wavelength interval, in nm, of the object.

required
sed ndarray

The Spectral Energy Distribution (SED) of the object.

required
air_mass int | float

The air mass in the light path.

required
sky_condition str

The condition of the sky during the observation.

'photometric'

Returns:

Name Type Description
reduced_sed array like

The Spectral Energy Distribution (SED) of the object subtracted from the loses related to the spectral response of the system.

Source code in AIS/Spectral_Response/spectral_response.py
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
def apply_spectral_response(
    self,
    obj_wavelength: ndarray,
    sed: ndarray,
    air_mass: int | float,
    sky_condition: str = "photometric",
) -> ndarray:
    """Apply the spectral response.

    Parameters
    ----------
    obj_wavelength: array like
        The wavelength interval, in nm, of the object.
    sed: array like
        The Spectral Energy Distribution (SED) of the object.
    air_mass: int, float.
        The air mass in the light path.
    sky_condition: ['photometric', 'regular', 'good'].
        The condition of the sky during the observation.

    Returns
    -------
    reduced_sed: array like
        The Spectral Energy Distribution (SED) of the object subtracted from the loses
        related to the spectral response of the system.
    """
    self._verify_var_in_interval(air_mass, "air_mass", var_max=3)
    self._check_var_in_a_list(
        sky_condition, "sky_condition", ["photometric", "regular", "good"]
    )
    spectral_response = self.get_spectral_response(
        obj_wavelength, air_mass, sky_condition
    )

    sed = spectral_response * sed

    return sed

get_spectral_response(obj_wavelength, air_mass=1, sky_condition='photometric')

Return the spectral response.

Parameters:

Name Type Description Default
obj_wavelength ndarray

The wavelength interval, in nm, of the object.

required
air_mass int | float

The air mass.

1
sky_condition str

The condition of the sky.

'photometric'

Returns:

Type Description
array like:

The spectral response of the optical system.

Source code in AIS/Spectral_Response/spectral_response.py
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
def get_spectral_response(
    self,
    obj_wavelength: ndarray,
    air_mass: int | float = 1,
    sky_condition: str = "photometric",
) -> ndarray:
    """Return the spectral response.

    Parameters
    ----------
    obj_wavelength: array like
        The wavelength interval, in nm, of the object.
    air_mass: int, float
        The air mass.
    sky_condition: ['photometric', 'regular', 'good']
        The condition of the sky.

    Returns
    -------
    array like:
        The spectral response of the optical system.

    """
    ss = pd.read_csv(
        os.path.join(self.BASE_PATH, self.ATM_EXTINCTION_FILE), dtype=np.float64
    )
    spectral_response = 10 ** (-0.43428 * air_mass * ss[sky_condition])
    spectral_response = self._interpolate_spectral_response(
        ss["Wavelength (nm)"], spectral_response, obj_wavelength
    )
    spectral_response[spectral_response > 1] = 1

    return spectral_response

Channel

Bases: Spectral_Response

Source code in AIS/Spectral_Response/spectral_response.py
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
class Channel(Spectral_Response):

    POL_OPTICAL_COMPONENTS = {
        "analyzer": "analyzer.csv",
        "retarder": "retarder.csv",
    }
    PHOT_OPTICAL_COMPONENTS = {
        "collimator": "collimator.csv",
        "dichroic": "dichroic.csv",
        "camera": "camera.csv",
        "ccd": "ccd.csv",
    }
    POLARIZER_ANGLE = 0

    def __init__(self, channel_id: int) -> None:
        """Initialize the class.

        Parameters
        ----------

        channel_id: int
            The channel ID of the camera.
        """

        super().__init__()
        self.channel_id = channel_id
        self.BASE_PATH = os.path.join(self.BASE_PATH, "channel")
        return

    def get_spectral_response(
        self, obj_wavelength: ndarray, csv_file_name: str
    ) -> ndarray:
        """Return the spectral response.

        Parameters
        ----------
        obj_wavelength: array like
            The wavelength interval, in nm, of the object.
        csv_file_name: str
            The name of the csv file that contains the spectral response
            of the optical component.

        Returns
        -------
        array like:
            The spectral response of the optical system.
        """
        self.CSV_FILE_NAME = csv_file_name
        return super().get_spectral_response(obj_wavelength)

    def write_sparc4_operation_mode(
        self,
        acquisition_mode: str,
        calibration_wheel: str = "",
        retarder_waveplate: str = "half",
        retarder_waveplate_angle: float = 0,
    ) -> None:
        """Write the operation mode of the SPARC4.

        Parameters
        ----------
        acquisition_mode: ['polarimetry', 'photometry']
            The acquisition mode of the channel. If the acquisition mode is polarimetry,
            the polarimetric configuration must be provided.

        calibration_wheel: ["polarizer", "ideal-polarizer", "ideal-depolarizer", "depolarizer"], optional
            The optical component of the calibration wheel.
            This parameter provides to the user the options of using
            the real or the ideal versions
            of the optical components of the calibration wheel.
            Based on the provided value, AIS
            will apply the correspondent Stoke matrix.
            It should be highlighted that the transmission
            of the optical component still be applied.

        retarder_waveplate: ["ideal-half", "half", "ideal-quarter", "quarter"], optional
            The waveplate for polarimetric measurements.

        retarder_waveplate_angle: float, optional
            The angle of the retarder waveplate in degrees.
            If the acquisition mode of SPARC4 is polarimetry,
            the retarder waveplate angle should be provided.
        """
        self.acquisition_mode = acquisition_mode
        self.calibration_wheel = calibration_wheel
        self.retarder_waveplate = retarder_waveplate
        self.retarder_waveplate_angle = retarder_waveplate_angle
        self._verify_sparc4_operation_mode()
        return

    def apply_spectral_response(self, sed: ndarray, obj_wavelength: ndarray) -> ndarray:
        """Apply the spectral response.

        Parameters
        ----------
        sed: array like
            The Spectral Energy Distribution (SED) of the object.
        obj_wavelength: array like
            The wavelength interval, in nm, of the object.

        Returns
        ------
        array like:
            The Spectral Energy Distribution (SED) of the object subtracted
            from the loses related to the spectral response of the system.
        """
        self.sed = sed[0]
        self.obj_wavelength = obj_wavelength
        if self.acquisition_mode == "polarimetry":
            self.sed = sed
            self._apply_polarimetric_spectral_response()

        self._apply_photometric_spectral_response()

        return self.sed

    def _apply_photometric_spectral_response(self) -> None:
        for csv_file in self.PHOT_OPTICAL_COMPONENTS.values():
            if csv_file != "collimator.csv":
                csv_file = os.path.join(f"Channel {self.channel_id}", csv_file)
            spectral_response = self.get_spectral_response(
                self.obj_wavelength, csv_file
            )
            self.sed = spectral_response * self.sed
        return

    def _apply_polarimetric_spectral_response(self) -> None:
        for csv_file in self.POL_OPTICAL_COMPONENTS.values():
            spectral_response = self.get_spectral_response(
                self.obj_wavelength, csv_file
            )
            self.sed = spectral_response * self.sed
        #  ? Pode isso: fiz o teste uma vez e deu a mesma coisa

        if self.calibration_wheel != "":
            self._apply_calibration_wheel()
        self._apply_retarder_waveplate()
        self._apply_analyzer()
        return

    def _apply_calibration_wheel(self) -> None:
        if "depolarizer" in self.calibration_wheel:
            self._apply_depolarizer()
        elif "polarizer" in self.calibration_wheel:
            self._apply_polarizer()
        else:
            raise ValueError(
                f"The calibration wheel {self.calibration_wheel} is not valid."
            )

        return

    def _apply_polarizer(self) -> None:
        spectral_response = self.get_spectral_response(
            self.obj_wavelength, "polarizer.csv"
        )
        if self.calibration_wheel == "ideal-polarizer":
            self._apply_ideal_polarizer(spectral_response)
        elif self.calibration_wheel == "polarizer":
            self._apply_real_polarizer(spectral_response)
        else:
            raise ValueError(
                f"A wrong value was provided for the polarizer: {self.calibration_wheel}"
            )

    def _apply_ideal_polarizer(self, spectral_response) -> None:
        self.sed = spectral_response * self.sed
        polarizer_matrix = calculate_polarizer_matrix(self.POLARIZER_ANGLE)
        self.sed = apply_matrix(polarizer_matrix, self.sed)

    def _apply_real_polarizer(self, spectral_response) -> None:
        contrast_ratio = self._get_spectral_response_custom(
            "polarizer_contrast_ratio.csv", "Contrast ratio"
        )
        for idx, transx in enumerate(spectral_response):
            contrast = contrast_ratio[idx]
            transy = transx / contrast
            total_transmission = sqrt(transx + transy)
            theta = np.rad2deg(atan2(1, sqrt(contrast)))
            polarizer_matrix = total_transmission * calculate_polarizer_matrix(
                self.POLARIZER_ANGLE + theta
            )
            self.sed[:, idx] = np.transpose(polarizer_matrix.dot(self.sed[:, idx]))

    # def _apply_real_polarizer_1(self, spectral_response) -> None:
    #     contrast_ratio = self._get_spectral_response_custom(
    #         "polarizer_contrast_ratio.csv", "Contrast ratio"
    #     )
    #     for idx, transmission in enumerate(spectral_response):
    #         contrast = contrast_ratio[idx]
    #         theta = np.rad2deg(atan(1 / sqrt(contrast)))
    #         total_transmission = transmission * (1 + 1 / contrast)
    #         polarizer_matrix = calculate_polarizer_matrix(self.POLARIZER_ANGLE + theta)
    #         self.sed[:, idx] = total_transmission * np.transpose(
    #             polarizer_matrix.dot(self.sed[:, idx])
    #         )
    #         self.sed[1, idx] *= 1 - 1 / contrast  # ? ta certo isso

    def _apply_depolarizer(self) -> None:
        spectral_response = self.get_spectral_response(
            self.obj_wavelength, "depolarizer.csv"
        )
        if self.calibration_wheel == "ideal-depolarizer":
            self._apply_ideal_depolarizer(spectral_response)
        elif self.calibration_wheel == "depolarizer":
            self._apply_real_depolarizer(spectral_response)
        else:
            raise ValueError(
                f"A wrong value was provided for the depolarizer: {self.calibration_wheel}"
            )

        return

    def _apply_ideal_depolarizer(self, spectral_response) -> None:
        tmp = self.sed
        self.sed = np.zeros((4, tmp.shape[1]))
        self.sed[0] = tmp[0] * spectral_response

    def _apply_real_depolarizer(self, spectral_response) -> None:
        # * Estou aplicando 2 matrizes? Elas estão separadas de 45º?
        self.sed = spectral_response * self.sed
        for idx, wavelength in enumerate(self.obj_wavelength):
            depolarizer_matrix = calculate_depolarizer_matrix(wavelength)
            self.sed[:, idx] = np.transpose(depolarizer_matrix.dot(self.sed[:, idx]))

    def _apply_retarder_waveplate(self) -> None:
        if self.retarder_waveplate[:5] == "ideal":
            self._apply_ideal_waveplate()
        elif self.retarder_waveplate in ["half", "quarter"]:
            self._apply_real_waveplate()
        else:
            raise ValueError(
                f"A wrong value was provided for the depolarizer: {self.retarder_waveplate}"
            )
        return

    def _apply_real_waveplate(self) -> None:
        phase_difference = (
            self._get_spectral_response_custom(
                f"retarder_phase_diff_{self.retarder_waveplate}.csv", "Retardance"
            )
            * 360
        )
        for idx, phase in enumerate(phase_difference):
            RETARDER_MATRIX = calculate_retarder_matrix(
                phase, self.retarder_waveplate_angle
            )
            self.sed[:, idx] = np.transpose(RETARDER_MATRIX.dot(self.sed[:, idx]))

    def _apply_ideal_waveplate(self) -> None:
        if "half" in self.retarder_waveplate:
            phase = 180
        elif "quarter" in self.retarder_waveplate:
            phase = 90
        else:
            raise ValueError(
                f"A wrong value has been provided for the retarder waveplate: {self.retarder_waveplate}"
            )
        RETARDER_MATRIX = calculate_retarder_matrix(
            phase, self.retarder_waveplate_angle
        )
        self.sed = apply_matrix(RETARDER_MATRIX, self.sed)

    def _apply_analyzer(self) -> None:
        ORD_RAY_MATRIX = calculate_polarizer_matrix(self.POLARIZER_ANGLE)
        temp_1 = apply_matrix(ORD_RAY_MATRIX, copy(self.sed))
        EXTRA_ORD_RAY_MATRIX = calculate_polarizer_matrix(self.POLARIZER_ANGLE + 90)
        temp_2 = apply_matrix(EXTRA_ORD_RAY_MATRIX, copy(self.sed))
        self.sed = np.stack((temp_1[0], temp_2[0]))

    def _verify_sparc4_operation_mode(self) -> None:
        if self.acquisition_mode == "photometry":
            pass
        elif self.acquisition_mode == "polarimetry":
            self._check_var_in_a_list(
                self.calibration_wheel,
                "calibration wheel",
                [
                    "polarizer",
                    "depolarizer",
                    "ideal-polarizer",
                    "ideal-depolarizer",
                    "",
                ],
            )

            self._check_var_in_a_list(
                self.retarder_waveplate,
                "retarder waveplate",
                ["half", "quarter", "ideal-half", "ideal-quarter"],
            )
        else:
            raise ValueError(
                f"The SPARC4 acquisition mode should be 'photometry' or 'polarimetry': {self.acquisition_mode}."
            )
        return

    def _get_spectral_response_custom(self, csv_file: str, column_name: str) -> ndarray:
        csv_file_name = os.path.join(self.BASE_PATH, csv_file)
        ss = pd.read_csv(csv_file_name)
        sys_wavelength, spectral_response = np.asarray(
            ss["Wavelength (nm)"]
        ), np.asarray(ss[column_name])

        spectral_response = self._interpolate_spectral_response(
            sys_wavelength, spectral_response
        )

        return spectral_response

    def _interpolate_spectral_response(self, wavelength, spectral_response) -> ndarray:
        spl = splrep(
            wavelength,
            spectral_response,
        )
        spectral_response = splev(self.obj_wavelength, spl)
        spectral_response[spectral_response < 0] = 0
        return spectral_response

__init__(channel_id)

Initialize the class.

Parameters:

Name Type Description Default
channel_id int

The channel ID of the camera.

required
Source code in AIS/Spectral_Response/spectral_response.py
313
314
315
316
317
318
319
320
321
322
323
324
325
326
def __init__(self, channel_id: int) -> None:
    """Initialize the class.

    Parameters
    ----------

    channel_id: int
        The channel ID of the camera.
    """

    super().__init__()
    self.channel_id = channel_id
    self.BASE_PATH = os.path.join(self.BASE_PATH, "channel")
    return

apply_spectral_response(sed, obj_wavelength)

Apply the spectral response.

Parameters:

Name Type Description Default
sed ndarray

The Spectral Energy Distribution (SED) of the object.

required
obj_wavelength ndarray

The wavelength interval, in nm, of the object.

required

Returns:

Type Description
array like:

The Spectral Energy Distribution (SED) of the object subtracted from the loses related to the spectral response of the system.

Source code in AIS/Spectral_Response/spectral_response.py
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
def apply_spectral_response(self, sed: ndarray, obj_wavelength: ndarray) -> ndarray:
    """Apply the spectral response.

    Parameters
    ----------
    sed: array like
        The Spectral Energy Distribution (SED) of the object.
    obj_wavelength: array like
        The wavelength interval, in nm, of the object.

    Returns
    ------
    array like:
        The Spectral Energy Distribution (SED) of the object subtracted
        from the loses related to the spectral response of the system.
    """
    self.sed = sed[0]
    self.obj_wavelength = obj_wavelength
    if self.acquisition_mode == "polarimetry":
        self.sed = sed
        self._apply_polarimetric_spectral_response()

    self._apply_photometric_spectral_response()

    return self.sed

get_spectral_response(obj_wavelength, csv_file_name)

Return the spectral response.

Parameters:

Name Type Description Default
obj_wavelength ndarray

The wavelength interval, in nm, of the object.

required
csv_file_name str

The name of the csv file that contains the spectral response of the optical component.

required

Returns:

Type Description
array like:

The spectral response of the optical system.

Source code in AIS/Spectral_Response/spectral_response.py
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
def get_spectral_response(
    self, obj_wavelength: ndarray, csv_file_name: str
) -> ndarray:
    """Return the spectral response.

    Parameters
    ----------
    obj_wavelength: array like
        The wavelength interval, in nm, of the object.
    csv_file_name: str
        The name of the csv file that contains the spectral response
        of the optical component.

    Returns
    -------
    array like:
        The spectral response of the optical system.
    """
    self.CSV_FILE_NAME = csv_file_name
    return super().get_spectral_response(obj_wavelength)

write_sparc4_operation_mode(acquisition_mode, calibration_wheel='', retarder_waveplate='half', retarder_waveplate_angle=0)

Write the operation mode of the SPARC4.

Parameters:

Name Type Description Default
acquisition_mode str

The acquisition mode of the channel. If the acquisition mode is polarimetry, the polarimetric configuration must be provided.

required
calibration_wheel str

The optical component of the calibration wheel. This parameter provides to the user the options of using the real or the ideal versions of the optical components of the calibration wheel. Based on the provided value, AIS will apply the correspondent Stoke matrix. It should be highlighted that the transmission of the optical component still be applied.

''
retarder_waveplate str

The waveplate for polarimetric measurements.

'half'
retarder_waveplate_angle float

The angle of the retarder waveplate in degrees. If the acquisition mode of SPARC4 is polarimetry, the retarder waveplate angle should be provided.

0
Source code in AIS/Spectral_Response/spectral_response.py
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
def write_sparc4_operation_mode(
    self,
    acquisition_mode: str,
    calibration_wheel: str = "",
    retarder_waveplate: str = "half",
    retarder_waveplate_angle: float = 0,
) -> None:
    """Write the operation mode of the SPARC4.

    Parameters
    ----------
    acquisition_mode: ['polarimetry', 'photometry']
        The acquisition mode of the channel. If the acquisition mode is polarimetry,
        the polarimetric configuration must be provided.

    calibration_wheel: ["polarizer", "ideal-polarizer", "ideal-depolarizer", "depolarizer"], optional
        The optical component of the calibration wheel.
        This parameter provides to the user the options of using
        the real or the ideal versions
        of the optical components of the calibration wheel.
        Based on the provided value, AIS
        will apply the correspondent Stoke matrix.
        It should be highlighted that the transmission
        of the optical component still be applied.

    retarder_waveplate: ["ideal-half", "half", "ideal-quarter", "quarter"], optional
        The waveplate for polarimetric measurements.

    retarder_waveplate_angle: float, optional
        The angle of the retarder waveplate in degrees.
        If the acquisition mode of SPARC4 is polarimetry,
        the retarder waveplate angle should be provided.
    """
    self.acquisition_mode = acquisition_mode
    self.calibration_wheel = calibration_wheel
    self.retarder_waveplate = retarder_waveplate
    self.retarder_waveplate_angle = retarder_waveplate_angle
    self._verify_sparc4_operation_mode()
    return

Spectral_Response

Source code in AIS/Spectral_Response/spectral_response.py
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
class Spectral_Response:

    BASE_PATH = os.path.join(os.path.dirname(__file__))
    CSV_FILE_NAME = "csv_file.csv"

    def __init__(self) -> None:
        """Initialize the class."""
        return

    @staticmethod
    def _check_var_in_a_list(var, var_name, _list) -> None:
        if var not in _list:
            raise ValueError(f"The allowed values for the {var_name} are: {_list}")

    @staticmethod
    def _verify_var_in_interval(var, var_name, var_min=0, var_max=2**32) -> None:
        if var <= var_min or var >= var_max:
            raise ValueError(
                f"The {var_name} must be in the interval [{var_min},{var_max}]: {var}."
            )

    @staticmethod
    def _read_csv_file(csv_file_name) -> tuple[ndarray]:
        ss = pd.read_csv(csv_file_name, dtype=np.float64)
        return np.array(ss["Wavelength (nm)"]), np.array(ss["Transmitance (%)"]) / 100

    def _interpolate_spectral_response(self, wavelength, spectral_response) -> ndarray:
        b = PchipInterpolator(wavelength, spectral_response)
        spectral_response = b(self.obj_wavelength)

        return spectral_response

    def get_spectral_response(self, obj_wavelength: ndarray) -> ndarray:
        """Return the spectral response.

        Parameters
        ----------
        obj_wavelength: array like.
            Wavelength interval of the object in nm.

        Returns
        -------
        spectral_response: array like.
            The spectral response of the optical system.
        """
        self.obj_wavelength = obj_wavelength
        csv_file_name = os.path.join(self.BASE_PATH, self.CSV_FILE_NAME)
        sys_wavelength, spectral_response = self._read_csv_file(csv_file_name)
        spectral_response = self._interpolate_spectral_response(
            sys_wavelength, spectral_response
        )

        return spectral_response

    def apply_spectral_response(self, obj_wavelength: ndarray, sed: ndarray) -> ndarray:
        """Apply the spectral response.

        Parameters
        ----------
        obj_wavelength: array like.
            The wavelength interval, in nm, of the object.
        sed: array like.
            The Spectral Energy Distribution (SED) of the object.

        Returns
        -------
        array like:
            The Spectral Energy Distribution (SED) of the object subtracted
            from the loses related to the spectral response of the system.
        """
        spectral_response = self.get_spectral_response(obj_wavelength)
        sed = sed * spectral_response

        return sed

__init__()

Initialize the class.

Source code in AIS/Spectral_Response/spectral_response.py
33
34
35
def __init__(self) -> None:
    """Initialize the class."""
    return

apply_spectral_response(obj_wavelength, sed)

Apply the spectral response.

Parameters:

Name Type Description Default
obj_wavelength ndarray

The wavelength interval, in nm, of the object.

required
sed ndarray

The Spectral Energy Distribution (SED) of the object.

required

Returns:

Type Description
array like:

The Spectral Energy Distribution (SED) of the object subtracted from the loses related to the spectral response of the system.

Source code in AIS/Spectral_Response/spectral_response.py
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
def apply_spectral_response(self, obj_wavelength: ndarray, sed: ndarray) -> ndarray:
    """Apply the spectral response.

    Parameters
    ----------
    obj_wavelength: array like.
        The wavelength interval, in nm, of the object.
    sed: array like.
        The Spectral Energy Distribution (SED) of the object.

    Returns
    -------
    array like:
        The Spectral Energy Distribution (SED) of the object subtracted
        from the loses related to the spectral response of the system.
    """
    spectral_response = self.get_spectral_response(obj_wavelength)
    sed = sed * spectral_response

    return sed

get_spectral_response(obj_wavelength)

Return the spectral response.

Parameters:

Name Type Description Default
obj_wavelength ndarray

Wavelength interval of the object in nm.

required

Returns:

Name Type Description
spectral_response array like.

The spectral response of the optical system.

Source code in AIS/Spectral_Response/spectral_response.py
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
def get_spectral_response(self, obj_wavelength: ndarray) -> ndarray:
    """Return the spectral response.

    Parameters
    ----------
    obj_wavelength: array like.
        Wavelength interval of the object in nm.

    Returns
    -------
    spectral_response: array like.
        The spectral response of the optical system.
    """
    self.obj_wavelength = obj_wavelength
    csv_file_name = os.path.join(self.BASE_PATH, self.CSV_FILE_NAME)
    sys_wavelength, spectral_response = self._read_csv_file(csv_file_name)
    spectral_response = self._interpolate_spectral_response(
        sys_wavelength, spectral_response
    )

    return spectral_response

Telescope

Bases: Spectral_Response

Source code in AIS/Spectral_Response/spectral_response.py
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
class Telescope(Spectral_Response):
    CSV_FILE_NAME = "aluminium_curve.csv"
    ADJUSMENT_COEFFS = {"20230328": (0.86, 0.95), "20230329": (0.998, 0.995)}

    def __init__(self) -> None:
        super().__init__()
        self.BASE_PATH = os.path.join(self.BASE_PATH, "telescope")
        return

    def get_spectral_response(
        self, obj_wavelength: ndarray, date: str = "20230329"
    ) -> ndarray:
        """Return the spectral response.

        Parameters
        ---------
        obj_wavelength: array like
            Wavelength interval of the object in nm.

        date: ['20230329', '20230328'], optional
            Date of the transmission curve of the telescope.

        Returns
        ------
        array like:
            The spectral response of the optical system.
        """
        spectral_response = super().get_spectral_response(obj_wavelength)
        primary_coeff, secondary_coeff = self.ADJUSMENT_COEFFS[date]
        return spectral_response**2 * primary_coeff * secondary_coeff

    def apply_spectral_response(
        self, obj_wavelength: ndarray, sed: ndarray, date: str = "20230329"
    ) -> ndarray:
        """Apply the spectral response.

        Parameters
        ----------
        obj_wavelength: array like
            The wavelength interval, in nm, of the object.

        sed: array like
            The Spectral Energy Distribution (SED) of the object.

        date: ['20230329', '20230328'], optional
            Date of the transmission curve of the telescope.

        Returns
        -------
        reduced_sed: array like
            The Spectral Energy Distribution (SED) of the object subtracted
            from the loses related to the spectral response of the system.
        """
        spectral_response = self.get_spectral_response(obj_wavelength, date)
        sed = sed * spectral_response

        return sed

apply_spectral_response(obj_wavelength, sed, date='20230329')

Apply the spectral response.

Parameters:

Name Type Description Default
obj_wavelength ndarray

The wavelength interval, in nm, of the object.

required
sed ndarray

The Spectral Energy Distribution (SED) of the object.

required
date str

Date of the transmission curve of the telescope.

'20230329'

Returns:

Name Type Description
reduced_sed array like

The Spectral Energy Distribution (SED) of the object subtracted from the loses related to the spectral response of the system.

Source code in AIS/Spectral_Response/spectral_response.py
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
def apply_spectral_response(
    self, obj_wavelength: ndarray, sed: ndarray, date: str = "20230329"
) -> ndarray:
    """Apply the spectral response.

    Parameters
    ----------
    obj_wavelength: array like
        The wavelength interval, in nm, of the object.

    sed: array like
        The Spectral Energy Distribution (SED) of the object.

    date: ['20230329', '20230328'], optional
        Date of the transmission curve of the telescope.

    Returns
    -------
    reduced_sed: array like
        The Spectral Energy Distribution (SED) of the object subtracted
        from the loses related to the spectral response of the system.
    """
    spectral_response = self.get_spectral_response(obj_wavelength, date)
    sed = sed * spectral_response

    return sed

get_spectral_response(obj_wavelength, date='20230329')

Return the spectral response.

Parameters:

Name Type Description Default
obj_wavelength ndarray

Wavelength interval of the object in nm.

required
date str

Date of the transmission curve of the telescope.

'20230329'

Returns:

Type Description
array like:

The spectral response of the optical system.

Source code in AIS/Spectral_Response/spectral_response.py
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
def get_spectral_response(
    self, obj_wavelength: ndarray, date: str = "20230329"
) -> ndarray:
    """Return the spectral response.

    Parameters
    ---------
    obj_wavelength: array like
        Wavelength interval of the object in nm.

    date: ['20230329', '20230328'], optional
        Date of the transmission curve of the telescope.

    Returns
    ------
    array like:
        The spectral response of the optical system.
    """
    spectral_response = super().get_spectral_response(obj_wavelength)
    primary_coeff, secondary_coeff = self.ADJUSMENT_COEFFS[date]
    return spectral_response**2 * primary_coeff * secondary_coeff