exosim.models.signal#

Classes#

Signal

This class handles data cubes. The cube axes are time (0), spatial (1) and spectral (2) directions.

Sed

It's a Signal class with data having units of \([W m^{-2} \mu m^{-1}]\)

Radiance

It's a Signal class with data having units of \([W m^{-2} \mu m^{-1} sr^{-1}]\)

CountsPerSecond

It's a Signal class with data having units of \([ct/s]\)

Counts

It's a Signal class with data having units of \([ct]\)

Adu

It's a Signal class with data having units of \([adu/s]\)

Dimensionless

It's a Signal class with data having no units

Module Contents#

class Signal(spectral=[0] * u.um, data=None, time=[0] * u.hr, data_units=None, spatial=[0] * u.um, shape=None, cached=False, output=None, output_path=None, dataset_name=None, metadata=None, dtype=np.float64)[source]#

Bases: exosim.log.Logger

This class handles data cubes. The cube axes are time (0), spatial (1) and spectral (2) directions.

Variables:
  • spectral (ndarray) – spectral direction grid.

  • data (ndarray) – data table. It has 3 axes: 0. time axis, 1. spatial axis, 2. spectral axis.

  • dataset (h5py.Dataset) – If cached mode is enabled, it contains the data table. It has 3 axes: 0. time axis, 1. spatial axis, 2. spectral axis.

  • time (ndarray) – time grid.

  • spatial (ndarray) – spatial direction grid.

  • spectral_units (str) – define the spectral direction units. Default is um

  • data_units (str) – define the data units.

  • time_units (str) – define the time direction units. Default is hr.

  • spatial_units (str) – define the spatial direction units. Default is um.

  • cached (bool) – it tells if cache mode is enabled.

  • output (str or HDF5Output) – h5py open file used for caching

  • dataset_name (h5py.Dataset) – h5py dataset used to store the data

  • output_path (str) – path where is stored the dataset inside the output file.

  • metadata (dict) – signal metadata attached to the class

Parameters:
  • spectral (exosim.utils.types.ArrayType) –

  • data (exosim.utils.types.ArrayType) –

  • time (exosim.utils.types.ArrayType) –

  • data_units (exosim.utils.types.UnitType) –

  • spatial (exosim.utils.types.ArrayType) –

  • shape (tuple[int, int, int]) –

  • cached (bool) –

  • output (str) –

  • output_path (str) –

  • dataset_name (str) –

  • metadata (dict) –

  • dtype (numpy.dtype) –

Notes

To understand caching mode, please look to CachedData

to(units)[source]#

It converts the Signal data into the desired units.

Parameters:

units (Unit) – desired unit

Return type:

None

Examples

>>> import numpy as np
>>> import astropy.units as u
>>> from exosim.models.signal import Signal
>>> wl = np.linspace(0.1, 1, 10) * u.m
>>> time_grid = np.linspace(1, 5, 10) * u.s
>>> data = np.random.random_sample((10, 1, 10))*u.m**2
>>> signal = Signal(spectral=wl, data=data, time=time_grid)
>>> signal.to(u.cm**2)
spectral_rebin(new_wavelength, fill_value=0.0, **kwargs)[source]#

It bins the class data over the spectral direction and changes the wavelegth attributes. This method is based on rebin.

Parameters:
  • new_wavelength (ndarray or Quantity) – new wavelength grid. If no units are attached is considered expressed in ‘um’

  • fill_value (float or Quantity) – filla value for empry bins. If no units are attached is considered expressed in ‘um’.

Return type:

None

Examples

>>> from exosim.models.signal import Signal
>>> import numpy as np
>>> import astropy.units as u

We first define the initial values:

>>> wavelength = np.linspace(0.1, 1, 10) * u.um
>>> data = np.ones((10, 1, 10))
>>> time_grid = np.linspace(1, 5, 10) * u.hr
>>> signal = Signal(spectral=wavelength, data=data, time=time_grid)
>>> print(signal.data.shape)
(10,1,10)

We now interpolates at a finer wavelength grid:

>>> new_wl = np.linspace(0.1, 1, 20) * u.um
>>> signal.spectral_rebin(new_wl)
>>> print(signal.data.shape)
(10,1,20)

We now bin down the to a new wavelength grid:

>>> signal = Signal(spectral=wavelength, data=data, time=time_grid)
>>> new_wl = np.linspace(0.1, 1, 5) * u.um
>>> signal.spectral_rebin(new_wl)
>>> print(signal.data.shape)
(10,1,5)
temporal_rebin(new_time, fill_value='extrapolate', **kwargs)[source]#

It bins the class data over the temporal direction and changes the time attributes. This method is based on rebin.

Parameters:

new_time (ndarray or Quantity) – new time grid. If no units are attached is considered expressed in ‘hr’

Return type:

None

Examples

>>> from exosim.models.signal import Signal
>>> import numpy as np
>>> import astropy.units as u

We first define the initial values:

>>> wavelength = np.linspace(0.1, 1, 10) * u.um
>>> data = np.ones((10, 1, 10))
>>> time_grid = np.linspace(1, 5, 10) * u.hr
>>> signal = Signal(spectral=wavelength, data=data, time=time_grid)
>>> print(signal.data.shape)
(10,1,10)

We now interpolates at a finer time grid:

>>> new_time = np.linspace(1, 5, 20) * u.hr
>>> signal.temporal_rebin(new_time)
>>> print(signal.data.shape)
(20,1,10)

We now bin down the to a new wavelength grid:

>>> signal = Signal(spectral=wavelength, data=data, time=time_grid)
>>> new_time = np.linspace(1, 5, 5) * u.hr
>>> signal.temporal_rebin(new_time)
>>> print(signal.data.shape)
(5,1,10)
write(output=None, name=None)[source]#

It writes the Signal class into an Output. The signal class is stored as a dictionary.

Parameters:
  • output (Output) – container to use to write the class

  • name (str) – name to use to store

Return type:

None

Examples

>>> from exosim.models.signal import Signal
>>> import numpy as np
>>> import astropy.units as u

We first define the initial values:

>>> wavelength = np.linspace(0.1, 1, 10) * u.um
>>> data = np.ones((10, 1, 10))
>>> time_grid = np.linspace(1, 5, 10) * u.hr
>>> signal = Signal(spectral=wavelength, data=data, time=time_grid)

Then we store it in a test output HDF5 file

>>> from exosim.output.hdf5.hdf5 import HDF5Output
>>> output = os.path.join(test_dir, 'output_test.h5')
>>> with HDF5Output(output) as o:
>>>     signal.write(o, 'test_signal')

Inside the file is now stored a dictionary like the one we can obtain by

>>> dict(signal)
get_slice(start_time, end_time)[source]#

It returnes the data relative to a time slice:

Parameters:
  • start_time (float or Quantity) – if a float is given, it’s assume to be expressed in hours.

  • end_time (float or Quantity) – if a float is given, it’s assume to be expressed in hours.

Return type:

ndarray

set_slice(start_time, end_time, data)[source]#

It replaces the class data values in a specific a time slice:

Parameters:
  • start_time (float or Quantity) – if a float is given, it’s assume to be expressed in hours.

  • end_time (float or Quantity) – if a float is given, it’s assume to be expressed in hours.

  • data (ndarray) – data to use as replacement for the existing ones.

Return type:

None

copy(**kwargs)[source]#

It returns a copy of the class.

Parameters:

kwargs (dict) – Dictionary of parameters to overwrite. The paramaters that can be included in the list are cached, metadata, dataset_name, ‘output`, output_path.

Return type:

Signal

Examples

>>> import numpy as np
>>> import astropy.units as u
>>> from exosim.models.signal import Signal
>>> wl = np.linspace(0.1, 1, 10) * u.um
>>> data = np.random.random_sample((10, 1, 10))
>>> time_grid = np.linspace(1, 5, 10) * u.hr
>>> signal = Signal(spectral=wl, data=data, time=time_grid)
>>> signal_new = signal.copy()
class Sed(spectral=[0] * u.um, data=None, time=[0] * u.hr, spatial=[0] * u.um, *args, **kwargs)[source]#

Bases: Signal

It’s a Signal class with data having units of \([W m^{-2} \mu m^{-1}]\)

Parameters:
  • spectral (exosim.utils.types.ArrayType) –

  • data (exosim.utils.types.ArrayType) –

  • time (exosim.utils.types.ArrayType) –

  • spatial (exosim.utils.types.ArrayType) –

class Radiance(spectral=[0] * u.um, data=None, time=[0] * u.hr, spatial=[0] * u.um, *args, **kwargs)[source]#

Bases: Signal

It’s a Signal class with data having units of \([W m^{-2} \mu m^{-1} sr^{-1}]\)

Parameters:
  • spectral (exosim.utils.types.ArrayType) –

  • data (exosim.utils.types.ArrayType) –

  • time (exosim.utils.types.ArrayType) –

  • spatial (exosim.utils.types.ArrayType) –

class CountsPerSecond(spectral=[0] * u.um, data=None, time=[0] * u.hr, spatial=[0] * u.um, *args, **kwargs)[source]#

Bases: Signal

It’s a Signal class with data having units of \([ct/s]\)

Parameters:
  • spectral (exosim.utils.types.ArrayType) –

  • data (exosim.utils.types.ArrayType) –

  • time (exosim.utils.types.ArrayType) –

  • spatial (exosim.utils.types.ArrayType) –

class Counts(spectral=[0] * u.um, data=None, time=[0] * u.hr, spatial=[0] * u.um, *args, **kwargs)[source]#

Bases: Signal

It’s a Signal class with data having units of \([ct]\)

Parameters:
  • spectral (exosim.utils.types.ArrayType) –

  • data (exosim.utils.types.ArrayType) –

  • time (exosim.utils.types.ArrayType) –

  • spatial (exosim.utils.types.ArrayType) –

class Adu(spectral=[0] * u.um, data=None, time=[0] * u.hr, spatial=[0] * u.um, *args, **kwargs)[source]#

Bases: Signal

It’s a Signal class with data having units of \([adu/s]\)

Parameters:
  • spectral (exosim.utils.types.ArrayType) –

  • data (exosim.utils.types.ArrayType) –

  • time (exosim.utils.types.ArrayType) –

  • spatial (exosim.utils.types.ArrayType) –

class Dimensionless(spectral=[0] * u.um, data=None, time=[0] * u.hr, spatial=[0] * u.um, *args, **kwargs)[source]#

Bases: Signal

It’s a Signal class with data having no units

Parameters:
  • spectral (exosim.utils.types.ArrayType) –

  • data (exosim.utils.types.ArrayType) –

  • time (exosim.utils.types.ArrayType) –

  • spatial (exosim.utils.types.ArrayType) –