edges.cal.spectra

Module dealing with calibration spectra and thermistor measurements.

class edges.cal.spectra.LoadSpectrum(*, q: GSData, variance: GSData | None = None, temp_ave: ArrayLike | Quantity | None)[source]

A class representing a measured spectrum from some Load averaged over time.

Parameters:
  • q (pygsdata.gsdata.GSData) – The measured power-ratios of the three-position switch averaged over time.

  • variance (pygsdata.gsdata.GSData | None) – The variance of a single time-integration as a function of frequency.

  • temp_ave (astropy.units.quantity.Quantity) – The average measured physical temperature of the load while taking spectra.

property averaged_q: ndarray

Ratio of powers averaged over time.

Notes

The formula is

\[Q = (P_source - P_load)/(P_noise - P_load)\]
between_freqs(f_low: ~typing.Annotated[~astropy.units.quantity.Quantity, PhysicalType('frequency')], f_high: ~typing.Annotated[~astropy.units.quantity.Quantity, PhysicalType('frequency')] = <Quantity inf MHz>)[source]

Return a new LoadSpectrum that is masked between new frequencies.

property freqs: Annotated[Quantity, PhysicalType('frequency')]

The frequencies at which the spectrum is measured.

classmethod from_file(path: str | Path | Group)

Load an HDF5 file as a given type.

classmethod from_loaddef(loaddef: ~edges.io.calobsdef.LoadDefEDGES2 | ~edges.io.calobsdef3.LoadDefEDGES3 | None = None, templog: ~pathlib.Path | None = None, specfiles: list[~pathlib.Path] | None = None, thermistor: ~pathlib.Path | None = None, load_name: str | None = None, f_low=<Quantity 40. MHz>, f_high=<Quantity inf MHz>, f_range_keep: tuple[~typing.Annotated[~astropy.units.quantity.Quantity, PhysicalType('frequency')], ~typing.Annotated[~astropy.units.quantity.Quantity, PhysicalType('frequency')]] | None = None, freq_bin_size=1, ignore_times: int | ~typing.Annotated[~astropy.units.quantity.Quantity, Unit("%")] | ~typing.Annotated[~astropy.units.quantity.Quantity, Unit("s")] = <Quantity 5. %>, temperature_range: ~typing.Annotated[~astropy.units.quantity.Quantity, PhysicalType('temperature')] | tuple[~typing.Annotated[~astropy.units.quantity.Quantity, PhysicalType('temperature')], ~typing.Annotated[~astropy.units.quantity.Quantity, PhysicalType('temperature')]] | None = None, frequency_smoothing: str = 'bin', time_coordinate_swpos: int = 0, invalidate_cache: bool = False, cache_dir: ~pathlib.Path | None = None, temperature: ~typing.Annotated[~astropy.units.quantity.Quantity, PhysicalType('temperature')] | None = None, allow_closest_time: bool = True) Self[source]

Instantiate the class from a given load name and directory.

Note that either loaddef must be given, or specfiles and load_name and one of thermistor, templog or temperature must be given.

The bandwidth is limited twice: once when reading in the raw spectra, and once at the end when returning the final LoadSpectrum. Any frequency averaging is done on the spectra after the initial bandwidth cut, but before the final frequency cut. TThe first cut is defined via f_low and f_high, while the final cut is defined via f_range_keep.

Parameters:
  • loaddef – A LoadDefEDGES2 or LoadDefEDGES3 instance defining the files containing raw spectra for this load. If None, specfiles and load_name must be given.

  • templog – Path to a temperature log CSV file. Only used if loaddef is None and not required if temperature is given or thermistor is given.

  • specfiles – A list of paths to raw spectrum files. Only used if loaddef is None.

  • thermistor – Path to a thermistor CSV file. Only used if loaddef is None. Defines the “true” physical temperature of the load during the observation.

  • load_name – The name of the load. Only used if loaddef is None.

  • f_low – The lowest frequency to read in (before any other processing).

  • f_high – The highest frequency to read in (before any other processing).

  • f_range_keep – An optional tuple of (f_low, f_high) frequencies to keep in the final LoadSpectrum. This is applied after any frequency averaging.

  • freq_bin_size – The size of frequency bins to average over, in numbers of channels.

  • ignore_times – Times to ignore at the start of the observation. See edges.io.templogs.ignore_ntimes() for details.

  • temperature_range – If given, only use data where the thermistor temperature is within this range. Can either be a single temperature (in which case it is treated as a +/- around the median temperature), or a tuple of (T_low, T_high).

  • frequency_smoothing – How to average frequency bins together. Default is to merely bin them directly. Other options are ‘gauss’ to convolve with Gaussian then downsample (this is the same as the legacy pipeline).

  • time_coordinate_swpos – Which switch position to use when deciding whether to ignore a time according to the ignore_times parameter. Setting to 2 will ignore a full integration only if all three switch positions are to be ignored.

  • invalidate_cache – If True, do not use any cached spectra even if they exist.

  • cache_dir – If given, a directory in which to cache the integrated spectra for future use.

  • temperature – If given, the average physical temperature of the load during the observation. Only used if loaddef is None and thermistor is None.

  • allow_closest_time – If True, when finding the mean temperature from a temperature log, allow using the closest time if no times are strictly within the observation time range.

Returns:

LoadSpectrum

property variance_q: ndarray

Variance of Q across time (see averaged_q).

write(path: str | Path | Group)

Write an attrs class to HDF5.

edges.cal.spectra.flag_data_outside_temperature_range(temperature_range: Annotated[Quantity, PhysicalType('temperature')] | tuple[Annotated[Quantity, PhysicalType('temperature')], Annotated[Quantity, PhysicalType('temperature')]], spec_times: Time, thermistor: ThermistorReadings) ndarray[tuple[Any, ...], dtype[bool]][source]

Get a mask that flags data outside a temperature range.

edges.cal.spectra.get_ave_and_var_spec(data: ~pygsdata.gsdata.GSData, thermistor: ~edges.cal.thermistor.ThermistorReadings | None = None, frequency_smoothing: str = 'gauss', f_low: ~typing.Annotated[~astropy.units.quantity.Quantity, PhysicalType('frequency')] = <Quantity 0. MHz>, f_high: ~typing.Annotated[~astropy.units.quantity.Quantity, PhysicalType('frequency')] = <Quantity inf MHz>, ignore_times: int | ~typing.Annotated[~astropy.units.quantity.Quantity, Unit("%")] | ~typing.Annotated[~astropy.units.quantity.Quantity, Unit("s")] = 0, freq_bin_size: int = 1, temperature_range: ~typing.Annotated[~astropy.units.quantity.Quantity, PhysicalType('temperature')] | tuple[~typing.Annotated[~astropy.units.quantity.Quantity, PhysicalType('temperature')], ~typing.Annotated[~astropy.units.quantity.Quantity, PhysicalType('temperature')]] | None = None, time_coordinate_swpos: int | tuple[int, int] = 0) tuple[GSData, GSData][source]

Get the mean and variance of the spectra.

Parameters:

frequency_smoothing – How to average frequency bins together. Default is to merely bin them directly. Other options are ‘gauss’ to do Gaussian filtering (this is the same as Alan’s C pipeline).