ranch package

Subpackages

Submodules

ranch.structures module

class ranch.structures.Cube(data: ndarray, header: Header)[source]

Bases: Struct

Radio astronomy data cube

Initializer.

Parameters:
  • data (np.ndarray) – Data array.

  • header (fits.Header) – FITS header.

change_axes_order(order: str) Cube | Map

TODO

filter(kernel: ndarray, filtering_mode: str = 'linear', padding_mode: str = 'constant', cval: float = 0)

TODO

filter_channels(kernel: ndarray, filtering_mode: str = 'linear', padding_mode: str = 'constant', cval: float = 0)

TODO

filter_pixels(kernel: ndarray, filtering_mode: str = 'linear', padding_mode: str = 'constant', cval: float = 0)

TODO

static from_maps(maps: Sequence[Map]) Cube

Returns a cube builded by concatening maps in maps sequences.

Parameters:

maps (Sequence[Map]) – Sequence of maps of same shape. Must not be empty.

Returns:

cube – Output cube with same spatial shape than elements of maps.

Return type:

Cube

static from_profiles(profiles: Sequence[Sequence[Profile]]) Cube

Returns a cube builded by concatening maps in maps sequences.

Parameters:

profiles (Sequence[Sequence[Profile]]) – Sequence of sequence of profiles of same shape. The sequence must not be empty and each sub-sequence must also not be empty. profiles[i][j] is the pixel of the i-th row and the j-th column.

Returns:

cube – Output cube with same spectral shape than elements of profiles.

Return type:

Cube

get_channel(z: int | float, unit='index') Map

TODO

get_channels(z: Sequence[int | float], unit='index') List[Map]

TODO

get_pixel(xy: Tuple[int | float], unit='index') Profile

TODO

get_pixels(xy: Sequence[Tuple[int | float]], unit='index') List[Profile]

TODO

integral(ppv_mask: Cube | None = None, ignore_nans: bool = True) Map

Returns the integral of cube over it spectral axis. Output unit is [cube unit] * km/s.

Parameters:

cube (Cube) – Input line cube.

Returns:

integ – Output map such that integ.nx == cube.nx and integ.ny == cube.ny.

Return type:

Map

map_from(value: float = 0.0)

Returns a map with the same x and y axis than cube filled with value.

Parameters:

cube (Cube) – Input cube.

Returns:

out – Output map.

Return type:

Map

noise_map(signal_mask: slice | List[slice], unit='index') Map

Returns the noise map (pixel-wise standard deviation of noise) of cube by hiding the velocity channels containing signal. If every channel contains signal, the noise map will be filled with NaNs.

Parameters:
  • cube (Cube) – Input line cube.

  • signal_mask (slice | list[slice]) – Intervals of channels to hide. Only step of 1 is supported.

  • unit (str, optional) – Describe how to read the bound values of signal_mask. Must be ‘index’, ‘velocity’ or ‘frequency’. If unit == ‘index’, the values are numpy indexes (starting from 0). If unit == ‘velocity’, the values are in km/s. If unit == ‘frequency’, the values are in GHz.

Returns:

noise_map – Noise map of cube.

Return type:

Map

property nx: int

Length of cube x axis

property ny: int

Length of cube y axis

property nz: int

Length of cube z axis

plot_channel(z: int | float, unit: str = 'index', **kwargs)

TODO

plot_pixel(xy: tuple[int, float], unit: str = 'index', **kwargs)

TODO

profile_from(value: float = 0.0)

Returns a profile with the same z axis than cube filled with value.

Parameters:

cube (Cube) – Input cube.

Returns:

out – Output profile.

Return type:

Profile

reduce_spatial(x_interv: slice | None = None, y_interv: slice | None = None, unit: str = 'index') Cube | Map

x_interv must be a slice (indices begin to zero) y_interv must be a slice (indices begin to zero) unit must be ‘index’ or ‘angle’

reduce_spectral(z_interv: slice | None = None, unit: str = 'index') Cube | Profile

z_interv must be a slice (indices begin to zero) unit must be ‘index’, ‘velocity’ or ‘frequency’

save_channel_plot(z: int | float, filename: str, unit: str = 'index', path: str | None = None, **kwargs) None

TODO

save_pixel_plot(xy: tuple[int] | tuple[float], filename: str, unit: str = 'index', path: str | None = None, **kwargs) None

TODO

show_channel(z: int | float, unit: str = 'index', **kwargs) None

TODO

show_pixel(xy: tuple[int] | tuple[float], unit: str = 'index', **kwargs) None

TODO

spectrum() Profile

Returns the mean spectrum of cube ,i.e., the channel-wise average.

Parameters:

cube (Cube) – Input line cube.

Returns:

spectrum – Output spectrum such that spectrum.nz == cube.nz.

Return type:

Profile

x_axis(unit: Literal['index', 'angle'] = 'index') ndarray

TODO

y_axis(unit: Literal['index', 'angle'] = 'index') ndarray

TODO

z_axis(unit: Literal['index', 'velocity', 'frequency'] = 'index') ndarray

TODO

class ranch.structures.Map(data: ndarray, header: Header)[source]

Bases: Struct

Radio astronomy data map

Initializer.

Parameters:
  • data (np.ndarray) – Data array.

  • header (fits.Header) – FITS header.

change_axes_order(order: str) Cube | Map

TODO

filter(kernel: ndarray, filtering_mode: str = 'linear', padding_mode: str = 'constant', cval: float = 0)

TODO

property nx: int

Length of cube x axis

property ny: int

Length of cube y axis

plot(ax: ~matplotlib.axes._axes.Axes | None = None, label_unit: str = 'angle', no_logical=False, norm: ~matplotlib.colors.Normalize | None = None, cmap: str | ~matplotlib.colors.Colormap = <matplotlib.colors.LinearSegmentedColormap object>, vmin: float | None = None, vmax: float | None = None)

Plots a map. Returns the figure axis and the colorbar.

reduce_spatial(x_interv: slice | None = None, y_interv: slice | None = None, unit: str = 'index') Cube | Map

x_interv must be a slice (indices begin to zero) y_interv must be a slice (indices begin to zero) unit must be ‘index’ or ‘angle’

save_plot(filename: str, path: str | None = None, **kwargs) None

TODO

show(**kwargs) None

TODO

x_axis(unit: Literal['index', 'angle'] = 'index') ndarray

TODO

y_axis(unit: Literal['index', 'angle'] = 'index') ndarray

TODO

class ranch.structures.Profile(data: ndarray, header: Header)[source]

Bases: Struct

Radio astronomy data profile

Initializer.

Parameters:
  • data (np.ndarray) – Data array.

  • header (fits.Header) – FITS header.

filter(kernel: ndarray, filtering_mode: str = 'linear', padding_mode: str = 'constant', cval: float = 0)

TODO

property nz: int

Length of cube z axis

plot(ax: Axes | None = None, label_unit: str = 'velocity', logy: bool = False, linestyle: str | None = 'solid', color: str | None = 'k', linewidth: float | None = 1.5, label: str | None = None)

Plot a profile. Returns the figure axis.

reduce_spectral(z_interv: slice | None = None, unit: str = 'index') Cube | Profile

z_interv must be a slice (indices begin to zero) unit must be ‘index’, ‘velocity’ or ‘frequency’

save_plot(filename: str, path: str | None = None, **kwargs) None

TODO

show(**kwargs) None

TODO

z_axis(unit: Literal['index', 'velocity', 'frequency'] = 'index') ndarray

TODO

class ranch.structures.Struct(data: ndarray, header: Header)[source]

Bases: ABC

Radio astronomy multidimensional data

Initializer.

Parameters:
  • data (np.ndarray) – Data array.

  • header (fits.Header) – FITS header.

abs() Struct

Element-wise absolute value operator.

Parameters:

input (Cube | Map | Profile) – Input structure.

Returns:

out – Output structure.

Return type:

Cube | Map | Profile

additive_noise(noise_type: Literal['gaussian', 'uniform'], std: Struct | float = 1.0) Struct

Return the input structure degraded with an additive noise of type noise_type.

Parameters:
  • input (Cube | Map | Profile) – Input structure.

  • noise_type (str) – Type of noise. Must be ‘gaussian’ or ‘uniform’.

  • std (Cube | Map | Profile) – Standard deviation of noise.

Returns:

res – Noisy structure.

Return type:

Cube | Map | Profile

all(output_type: ~typing.Type[~ranch.structures.Map | ~ranch.structures.Profile | float] = <class 'float'>) Map | Profile | float

Returns True if input.data contains only non-zero elements over the considered axis.

Parameters:
  • input (struct.Struct) – Input multidimensional data.

  • output_type (Type[Map] | Type[Profile] | Type[float]) – Type of output data. Determine the axis over which the operator has to be applied.

  • operator – Operation on numpy array that reduce the number of dimensions.

Returns:

Resulting data of type output_type.

Return type:

Map | Profile | float

any(output_type: ~typing.Type[~ranch.structures.Map | ~ranch.structures.Profile | float] = <class 'float'>) bool

Returns True if input.data contains at least one non-zero elements over the considered axis.

Parameters:
  • input (struct.Struct) – Input multidimensional data.

  • output_type (Type[Map] | Type[Profile] | Type[float]) – Type of output data. Determine the axis over which the operator has to be applied.

  • operator – Operation on numpy array that reduce the number of dimensions.

Returns:

Resulting data of type output_type.

Return type:

Map | Profile | float

apply_element_wise(fun: Callable[[ndarray], ndarray]) Struct

Apply the element-wise operator fun on the input structure.

Parameters:
  • input (Cube | Map | Profile) – Input structure.

  • fun (Callable[[np.ndarray], ndarray]) – Element-wise operator.

Returns:

out – Output structure.

Return type:

Cube | Map | Profile

arccos()

Element-wise inverse cosine operator.

Parameters:

input (Cube | Map | Profile) – Input structure.

Returns:

out – Output structure.

Return type:

Cube | Map | Profile

arccosh()

Element-wise inverse hyperbolic cosine operator.

Parameters:

input (Cube | Map | Profile) – Input structure.

Returns:

out – Output structure.

Return type:

Cube | Map | Profile

arcsin()

Element-wise inverse sine operator.

Parameters:

input (Cube | Map | Profile) – Input structure.

Returns:

out – Output structure.

Return type:

Cube | Map | Profile

arcsinh()

Element-wise inverse hyperbolic sine operator.

Parameters:

input (Cube | Map | Profile) – Input structure.

Returns:

out – Output structure.

Return type:

Cube | Map | Profile

arctan()

Element-wise inverse tangent operator.

Parameters:

input (Cube | Map | Profile) – Input structure.

Returns:

out – Output structure.

Return type:

Cube | Map | Profile

arctanh()

Element-wise inverse hyperbolic tangent operator.

Parameters:

input (Cube | Map | Profile) – Input structure.

Returns:

out – Output structure.

Return type:

Cube | Map | Profile

argmax(output_type: ~typing.Type[~ranch.structures.Map | ~ranch.structures.Profile | float] = <class 'float'>, ignore_nans: bool = True) Struct | Tuple[int] | int

Computes an argmax value over the needed axes to obtain a data of type output_type. In case of multiple occurrences of the maximum values, the indices corresponding to the first occurrence are returned.

Parameters:
  • input (struct.Struct) – Input multidimensional data.

  • output_type (Type[Map] | Type[Profile] | Type[float]) – Type of output data. Determine the axis over which the operator has to be applied.

  • operator – Operation on numpy array that reduce the number of dimensions.

Returns:

Resulting data of type output_type.

Return type:

Map | Profile | float

argmin(output_type: ~typing.Type[~ranch.structures.Map | ~ranch.structures.Profile | float] = <class 'float'>, ignore_nans: bool = True) Struct | Tuple[int] | int

Computes an argmin over the needed axes to obtain a data of type output_type. In case of multiple occurrences of the minimum values, the indices corresponding to the first occurrence are returned.

Parameters:
  • input (struct.Struct) – Input multidimensional data.

  • output_type (Type[Map] | Type[Profile] | Type[float]) – Type of output data. Determine the axis over which the operator has to be applied.

  • operator – Operation on numpy array that reduce the number of dimensions.

Returns:

Resulting data of type output_type.

Return type:

Map | Profile | float

astype(dtype: Literal['float', 'double']) Struct

Return the input structure with floating type ‘float’ or ‘double’. Note that there is no function as_int or as_float because structures are always of type float.

Parameters:
  • input (Cube | Map | Profile) – Input structure.

  • dtype (str) – Floating type of output data. Must be ‘float’ or ‘double’.

Returns:

out – Output structure.

Return type:

Cube | Map | Profile

cbrt() Struct

Element-wise cube root operator.

Parameters:

input (Cube | Map | Profile) – Input structure.

Returns:

out – Output structure.

Return type:

Cube | Map | Profile

clip(vmin: float | None, vmax: float | None) Struct

TODO

closing(se: ndarray) Struct

TODO

copy() Struct

Returns a copy of input.

Parameters:

input (Cube | Map | Profile) – Input structure.

Returns:

out – Output structure.

Return type:

Cube | Map | Profile

cos()

Element-wise cosine operator.

Parameters:

input (Cube | Map | Profile) – Input structure.

Returns:

out – Output structure.

Return type:

Cube | Map | Profile

cosh()

Element-wise hyperbolic cosine operator.

Parameters:

input (Cube | Map | Profile) – Input structure.

Returns:

out – Output structure.

Return type:

Cube | Map | Profile

data: ndarray

Data array

dilation(se: ndarray) Struct

TODO

erosion(se: ndarray) Struct

TODO

exp()

Element-wise exponential operator.

Parameters:

input (Cube | Map | Profile) – Input structure.

Returns:

out – Output structure.

Return type:

Cube | Map | Profile

flatten()

Shortcut for input.data.flatten().

Parameters:

input (Cube | Map | Profile) – Structure.

Returns:

1D numpy array extracted from structure data.

Return type:

np.ndarray

classmethod from_fits(filename: str, path: str | None = None, axes: str | None = None) Struct

Load an inputect of type cls from file filename/path.

Parameters:
  • cls (Type[Cube] | Type[Map] | Type[Profile]) – Type of structure to create.

  • filename (str) – Filename of FITS file to load. Extension can be ommited. Handle both .fits or .fits.gz files, but notice that .gz files take longer to load.

  • path (str, optional) – Path to the FITS file.

  • axes (str, optional) – Order of axes. Must be ‘xyz’, ‘yxz’, ‘zxy’, ‘zyx’, ‘xy’, ‘yx’ or None.

Returns:

out – Output structure.

Return type:

Cube | Map | Profile

classmethod from_numpy(array: ndarray, header: Header, axes: str | None = None) Struct

Create an inputect of type cls from numpy array array and astropy header header.

Parameters:
  • cls (Type[Cube] | Type[Map] | Type[Profile]) – Type of structure to create.

  • array (np.ndarray) – Data of structure to create. Must be 1D if cls is Profile, 2D if cls is Map and 3D if cls is Cube.

  • header (fits.Header) – Astropy fits header. Can be taken from another cube or created by hand.

  • axes (str, optional) – Order of axes. Must be ‘xyz’, ‘yxz’, ‘zxy’, ‘zyx’, ‘xy’, ‘yx’ or None.

Returns:

out – Created structure.

Return type:

Cube | Map | Profile

gradient(se: ndarray) Struct

TODO

header: Header

FITS header

is_logical() bool

TODO

isfinite() Profile

Return a structure similar to input where a sample is 1 if input same sample is finite and 0 if is not. A finite element is a value different of nan, inf or neginf. This function is the opposite to isnan because inf and neginf are automatically casted to nan in structures constructors. So in practice : isnan(input) == ~isfinite(input).

Parameters:

input (Cube | Map | Profile) – Input structure.

Returns:

out – Output structure.

Return type:

Cube | Map | Profile

isnan() Struct

Return a structure similar to input where a sample is 1 if input same sample is nan and 0 if is not.

Parameters:

input (Cube | Map | Profile) – Input structure.

Returns:

out – Output structure.

Return type:

Cube | Map | Profile

kde(axis: Literal['spatial', 'spectral'] | None = None, h: float | ndarray | None = None, t: ndarray | None = None, t_bounds: Tuple[float] | None = None, t_step: float = 0.05) Tuple[ndarray]

If axis == ‘spectral’ then the kde is computed over the spectral axis i.e. pixel-wise. Use a gaussian kernel of parameter h

Parameters:
  • input (Cube | Map | Profile) – Input structure.

  • axis (str, optional) – Axis over which to compute the PDF. Must be set only if input is an instance of Cube. If axis is None, the PDF is computed over all the flattened structure so the output pdf is a 1D-array

  • h (float or ndarray, optional) – Kernel parameter. Must be a scalar if input is an instance of Map or Profile. If input is an instance of Cube, h must be an array of shape (nz,) if axis == ‘spectral’ or (ny, nx) if axis == ‘spatial’.

  • t (ndarray, optional) – Variable of the estimated PDF. Must be set if a specific range of value is needed.

  • t_bounds (tuple of float, optional) – Bounds of t. Ignored if t is not None. Default : None.

  • t_step (float, optional) – Step between two values of t. Ignored if t is not None. Default : 0.05. If t_step is not compatible with t_step, the right bound could be modified.

Returns:

  • t (ndarray) – Variable of the estimated PDF.

  • pdf (ndarray) – Estimated PDF.

laplacian(se: ndarray) Struct

TODO

log(base: float | None = None)

Element-wise logarithm operator.

Parameters:
  • input (Cube | Map | Profile) – Input structure.

  • base (float | None, optional) – Base of the logarithm (by default natural logarithm). Must a positive number.

Returns:

out – Output structure.

Return type:

Cube | Map | Profile

max(output_type: ~typing.Type[~ranch.structures.Map | ~ranch.structures.Profile | float] = <class 'float'>, ignore_nans: bool = True) Struct | float

Computes the maximum value over the needed axes to obtain a data of type output_type.

Parameters:
  • input (struct.Struct) – Input multidimensional data.

  • output_type (Type[Map] | Type[Profile] | Type[float]) – Type of output data. Determine the axis over which the operator has to be applied.

  • operator – Operation on numpy array that reduce the number of dimensions.

Returns:

Resulting data of type output_type.

Return type:

Map | Profile | float

mean(output_type: ~typing.Type[~ranch.structures.Map | ~ranch.structures.Profile | float] = <class 'float'>, ignore_nans: bool = True) Struct | float

Computes the mean value over the needed axes to obtain a data of type output_type.

Parameters:
  • input (struct.Struct) – Input multidimensional data.

  • output_type (Type[Map] | Type[Profile] | Type[float]) – Type of output data. Determine the axis over which the operator has to be applied.

  • operator – Operation on numpy array that reduce the number of dimensions.

Returns:

Resulting data of type output_type.

Return type:

Map | Profile | float

median(output_type: ~typing.Type[~ranch.structures.Map | ~ranch.structures.Profile | float] = <class 'float'>, ignore_nans: bool = True) Struct | float

Computes median value over the needed axes to obtain a data of type output_type.

Parameters:
  • input (struct.Struct) – Input multidimensional data.

  • output_type (Type[Map] | Type[Profile] | Type[float]) – Type of output data. Determine the axis over which the operator has to be applied.

  • operator – Operation on numpy array that reduce the number of dimensions.

Returns:

Resulting data of type output_type.

Return type:

Map | Profile | float

min(output_type: ~typing.Type[~ranch.structures.Map | ~ranch.structures.Profile | float] = <class 'float'>, ignore_nans: bool = True) Struct | float

Computes the minimum value over the needed axes to obtain a data of type output_type.

Parameters:
  • input (struct.Struct) – Input multidimensional data.

  • output_type (Type[Map] | Type[Profile] | Type[float]) – Type of output data. Determine the axis over which the operator has to be applied.

  • operator – Operation on numpy array that reduce the number of dimensions.

Returns:

Resulting data of type output_type.

Return type:

Map | Profile | float

moment(order: int, centered: bool = True, output_type: ~typing.Type[~ranch.structures.Map | ~ranch.structures.Profile | float] = <class 'float'>, ignore_nans: bool = True) Struct | float

Computes the statistical moment of order order over the needed axes to obtain a data of type output_type. If centered is True, the centered moment is computed.

Parameters:
  • input (struct.Struct) – Input multidimensional data.

  • order (int) – Order of the statistical moment.

  • centered (bool) – Whether the centered moment is computed. Default: True.

  • output_type (Type[Map] | Type[Profile] | Type[float]) – Type of output data. Determine the axis over which the operator has to be applied.

  • operator – Operation on numpy array that reduce the number of dimensions.

Returns:

Resulting data of type output_type.

Return type:

Map | Profile | float

multiplicative_noise(noise_type: Literal['gaussian', 'uniform'], std: Struct | float = 1.0) Struct

Return the input structure degraded with a multiplicative noise of type noise_type.

Parameters:
  • input (Cube | Map | Profile) – Input structure.

  • noise_type (str) – Type of noise. Must be ‘gaussian’ or ‘uniform’.

  • std (Cube | Map | Profile) – Standard deviation of noise.

Returns:

res – Noisy structure.

Return type:

Cube | Map | Profile

normalize(axis: Literal['spectral', 'spatial', 'all'] = 'all', training_subset: Struct | None = None, alternative_mode: bool = False) Tuple[Struct | float, ...]

If alternative_mode is False, return a modified version of input with every values between 0 and 1. If alternative_mode is True, return a modified version of input with every values between -1 and 1.

classmethod ones(header: Header) Struct

Create an inputect of type cls fill with ones from astropy header header.

Parameters:
  • cls (Type[Cube] | Type[Map] | Type[Profile]) – Type of structure to create.

  • header (fits.Header) – Astropy fits header. Can be taken from another cube or created by hand.

Returns:

out – Output structure.

Return type:

Cube | Map | Profile

ones_like() Struct

Returns a structure with the same shape than input filled with ones.

Parameters:

input (Cube | Map | Profile) – Input structure

Returns:

out – Output structure

Return type:

Cube | Map | Profile

opening(se: ndarray) Struct

TODO

percentile(p: float, output_type: ~typing.Type[~ranch.structures.Map | ~ranch.structures.Profile | float] = <class 'float'>, ignore_nans: bool = True) Struct | float

Computes the percentile p over the needed axes to obtain a data of type output_type.

Parameters:
  • input (struct.Struct) – Input multidimensional data.

  • p (float) – Percentile (between 0 and 100).

  • output_type (Type[Map] | Type[Profile] | Type[float]) – Type of output data. Determine the axis over which the operator has to be applied.

  • operator – Operation on numpy array that reduce the number of dimensions.

Returns:

Resulting data of type output_type.

Return type:

Map | Profile | float

plot_hist(bins: int | str = 'auto', ax: Axes | None = None, logx: bool = False, logy: bool = False, density: bool = False, color: str | None = None, xlim: tuple | None = None, ylim: tuple | None = None) Tuple[ndarray, ndarray, Axes]

TODO

plot_hist2d(input2: ~ranch.structures.Struct, bins: int | tuple | str = 'auto', ax: ~matplotlib.axes._axes.Axes | None = None, logx: bool = False, logy: bool = False, logz: bool = False, density: bool = False, plot_identity: bool = False, cmap: str | ~matplotlib.colors.Colormap = <matplotlib.colors.LinearSegmentedColormap object>, scatter: bool = False, scatter_threshold: int = 1, zeros_to_nans: bool = True, xlim: tuple | None = None, ylim: tuple | None = None, vmin: float | None = None, vmax: float | None = None) Tuple[ndarray, Tuple[ndarray, ndarray], Axes]

Plot a 2-dimensional histogram of two structures of same shape input1 and input2.

Parameters:
  • input1 (Cube | Map | Profile.) – Structure whose data will be plotted on the x axis.

  • input2 (Cube | Map | Profile.) – Structure whose data will be plotted on the y axis.

  • bins (int | tuple | str, optional.) – Number of bins. If it is an integer, then the same number of bins is used for each axis. If it is a tuple, then we assume that the format is (bins_x, bins_y). If bins is a string, then the number of bins is automatically computed (default: ‘auto’). For more information, refer to numpy.histogram_bin_edges.

  • ax (Axes, optional.) – Matplotlib axis to plot the histogram. If ax is None, then matplotlib.pyplot.gca() is used. Default: None.

  • logx (bool, optional.) – If True, then the x axis is plotted in log scale. Default: False.

  • logy (bool, optional.) – If True, then the y axis is plotted in log scale. Default: False.

  • logz (bool, optional.) – If True, then the colorbar is in log scale. Default: False.

  • density (bool, optional.) – If True, then the density is plotted. Else, the standard counting of samples by bin is plotted. Default: False.

  • plot_identity (bool, optional.) – If True, then the y=x line is plotted on the figure. Default: False.

  • cmap (str, optional) – Default: default_colormap.

  • scatter (bool, optional.) – If True, the samples that are less than 2 per bins are displayed individually (using matplotlib.pyplot.scatter) instead of being included in the histogram. Default: False.

  • scatter_threshold (int, optional.) – The minimum number of pixel by bins necessary to be plotted as an histogram and not as a scatter plot. Must be positive. Default: 1.

  • zeros_to_nans (bool, optional.) – If True, then the bins without samples are plotted as nan. Default: True.

  • xlim (tuple | None, optional.) – X axis limits for matplotlib.pyplot.xlim. Default: None.

  • ylim (tuple | None, optional.) – Y axis limits for matplotlib.pyplot.ylim. Default: None.

  • vmin (float, optional.) – Minimum value for colormap. Default: None.

  • vmax (float, optional.) – Maximum value for colormap. Default: None.

Returns:

  • H (ndarray) – Matrix of 2-dimensional histogram.

  • edges (tuple of ndarray) – Tuple of x and y axis bins (xedges, yedges)

  • ax (Axes) – Matplotlib axis.

ptp(output_type: ~typing.Type[~ranch.structures.Map | ~ranch.structures.Profile | float] = <class 'float'>, ignore_nans: bool = True) Struct | float

Computes the peak-to-peak value over the needed axes to obtain a data of type output_type.

Parameters:
  • input (struct.Struct) – Input multidimensional data.

  • output_type (Type[Map] | Type[Profile] | Type[float]) – Type of output data. Determine the axis over which the operator has to be applied.

  • operator – Operation on numpy array that reduce the number of dimensions.

Returns:

Resulting data of type output_type.

Return type:

Map | Profile | float

quantile(q: float, output_type: ~typing.Type[~ranch.structures.Map | ~ranch.structures.Profile | float] = <class 'float'>, ignore_nans: bool = True) Struct | float

Computes the quantile q over the needed axes to obtain a data of type output_type.

Parameters:
  • input (struct.Struct) – Input multidimensional data.

  • q (float) – Quantile (between 0 and 1).

  • output_type (Type[Map] | Type[Profile] | Type[float]) – Type of output data. Determine the axis over which the operator has to be applied.

  • operator – Operation on numpy array that reduce the number of dimensions.

Returns:

Resulting data of type output_type.

Return type:

Map | Profile | float

rms(output_type: ~typing.Type[~ranch.structures.Map | ~ranch.structures.Profile | float] = <class 'float'>, ignore_nans: bool = True) Struct | float

Computes the root mean squared (RMS) value over the needed axes to obtain a data of type output_type.

Parameters:
  • input (struct.Struct) – Input multidimensional data.

  • output_type (Type[Map] | Type[Profile] | Type[float]) – Type of output data. Determine the axis over which the operator has to be applied.

  • operator – Operation on numpy array that reduce the number of dimensions.

Returns:

Resulting data of type output_type.

Return type:

Map | Profile | float

save_fits(filename: str, path: str | None = None, overwrite=False) None

Save input structure in a FITS file. The extension of the file can be ommited.

save_hist(filename: str, path: str | None = None, **kwargs)

TODO

save_hist2d(input2: Struct, filename: str, path: str | None = None, **kwargs)

TODO

scale(axis: Literal['spectral', 'spatial', 'all'] = 'all', training_subset: Struct | None = None, alternative_mode: bool = False) Tuple[Map | Profile | float, ...]

If alternative_mode is False, return a modified version of input where every value is between -1 and 1 If alternative_mode is True, raise a NotImplementedError

property shape: tuple[int]

Shape of the data

show_hist(**kwargs)

TODO

show_hist2d(input2: Struct, **kwargs)

TODO

sin()

Element-wise sine operator.

Parameters:

input (Cube | Map | Profile) – Input structure.

Returns:

out – Output structure.

Return type:

Cube | Map | Profile

sinh()

Element-wise hyperbolic sine operator.

Parameters:

input (Cube | Map | Profile) – Input structure.

Returns:

out – Output structure.

Return type:

Cube | Map | Profile

property size: int

Number of scalars in the cube.

sqrt() Struct

Element-wise square root operator.

Parameters:

input (Cube | Map | Profile) – Input structure.

Returns:

out – Output structure.

Return type:

Cube | Map | Profile

standardize(axis: Literal['spectral', 'spatial', 'all'] = 'all', training_subset: Struct | None = None, alternative_mode: bool = False) Tuple[Struct, ...]

If alternative_mode is False, return a modified version of input with mean 0 and standart deviation 1. If alternative_mode is True, return a modified version of input with mean 0 but same standart deviation.

std(output_type: ~typing.Type[~ranch.structures.Map | ~ranch.structures.Profile | float] = <class 'float'>, ignore_nans: bool = True) Struct | float

Computes the standard deviation over the needed axes to obtain a data of type output_type.

Parameters:
  • input (struct.Struct) – Input multidimensional data.

  • output_type (Type[Map] | Type[Profile] | Type[float]) – Type of output data. Determine the axis over which the operator has to be applied.

  • operator – Operation on numpy array that reduce the number of dimensions.

Returns:

Resulting data of type output_type.

Return type:

Map | Profile | float

sum(output_type: ~typing.Type[~ranch.structures.Map | ~ranch.structures.Profile | float] = <class 'float'>, ignore_nans: bool = True) Struct | float

Computes a sum over the needed axes to obtain a data of type output_type.

Parameters:
  • input (struct.Struct) – Input multidimensional data.

  • output_type (Type[Map] | Type[Profile] | Type[float]) – Type of output data. Determine the axis over which the operator has to be applied.

  • operator – Operation on numpy array that reduce the number of dimensions.

Returns:

Resulting data of type output_type.

Return type:

Map | Profile | float

tan()

Element-wise tangent operator.

Parameters:

input (Cube | Map | Profile) – Input structure.

Returns:

out – Output structure.

Return type:

Cube | Map | Profile

tanh()

Element-wise hyperbolic tangent operator.

Parameters:

input (Cube | Map | Profile) – Input structure.

Returns:

out – Output structure.

Return type:

Cube | Map | Profile

to_numpy(item: str) ndarray

TODO

unnormalize(a: Map | Profile | float, b: Struct | float, alternative_mode: bool = False) Struct

TODO

unscale(s: Struct | float, alternative_mode: bool = False)

TODO

unstandardize(mu: Struct | float, sigma: Struct | float, alternative_mode: bool = False) Struct

TODO

var(output_type: ~typing.Type[~ranch.structures.Map | ~ranch.structures.Profile | float] = <class 'float'>, ignore_nans: bool = True) Struct | float

Computes the variance over the needed axes to obtain a data of type output_type.

Parameters:
  • input (struct.Struct) – Input multidimensional data.

  • output_type (Type[Map] | Type[Profile] | Type[float]) – Type of output data. Determine the axis over which the operator has to be applied.

  • operator – Operation on numpy array that reduce the number of dimensions.

Returns:

Resulting data of type output_type.

Return type:

Map | Profile | float

where(input_1: Struct | float, input_2: Struct | float) Struct

TODO

classmethod zeros(header: Header) Struct

Create an inputect of type cls fill with zeros from astropy header header.

Parameters:
  • cls (Type[Cube] | Type[Map] | Type[Profile]) – Type of structure to create.

  • header (fits.Header) – Astropy fits header. Can be taken from another cube or created by hand.

Returns:

out – Output structure.

Return type:

Cube | Map | Profile

zeros_like()

Returns a structure with the same shape than input filled with zeros.

Parameters:

input (Cube | Map | Profile) – Input structure

Returns:

out – Output structure

Return type:

Cube | Map | Profile

Module contents

ranch module