ranch.core package

Submodules

ranch.core.header module

Header module

ranch.core.header.bound_coordinates(header: Header, absolute: bool = False)[source]

Returns the absolute coordinates bounds

ranch.core.header.bound_frequencies(header: Header)[source]

Returns the min and max frequencies

ranch.core.header.bound_velocities(header: Header)[source]

Returns the min and max velocities

ranch.core.header.change_coordinates(header, x=None, y=None, z=None) Header[source]

Coordinates must begin at 0

ranch.core.header.check_header(data, header)[source]

Returns True if data is compatible with the header, else raise a ValueError

ranch.core.header.coordinates_to_indices(header: Header, x: float | ndarray, y: float | ndarray, absolute: bool = False)[source]

TODO

ranch.core.header.create_header(struct: str, ref_header: Header | None = None, nx: int | None = None, ny: int | None = None, nz: int | None = None) Header[source]

TODO

ranch.core.header.frequency_to_index(header: Header, f: float | ndarray)[source]

Returns the velocity channel index (beginning at 0) corresponding to a frequency f

ranch.core.header.index_to_frequency(header: Header, k: int | ndarray)[source]

Returns the frequency of the k-th spectal image (beginning at 0)

ranch.core.header.index_to_velocity(header: Header, k: int | ndarray)[source]

Returns the velocity of the k-th spectral image by Doppler effect (beginning at 0)

ranch.core.header.indices_to_coordinates(header: Header, i: int | ndarray, j: int | ndarray, absolute: bool = False)[source]

Returns the absolute coordinates in degrees of the (i,j) point in pixels (beginning at 0)

ranch.core.header.merge_headers(header_1: Header, header_2: Header)[source]

Returns a header compatible with header_1 and header_2. The returned header can have a different number of axis than the inputs.

ranch.core.header.move_header_axes(header: Header, order: Literal['xyz', 'yxz', 'zxy', 'zyx', 'xy', 'yx']) Header[source]

Return a version of header where the order of axes if xyz. Input header axes order is order.

ranch.core.header.remove_header_axis(header: Header, axis: str) Header[source]

Axis must be ‘spatial’ or ‘spectral’. Header must be a cube header i.e. have header[‘NAXIS’] = 3.

ranch.core.header.update_header(data: ndarray, header: Header)[source]

Updates header cards to match data. Data and header are first verified by check_header i.e. their dimensions must match. Missing cards are also added to avoid future errors.

ranch.core.header.velocity_to_index(header: Header, v: float | ndarray)[source]

Returns the velocity channel index (beginning at 0) corresponding to a velocity v

ranch.core.math module

ranch.core.math.abs(input: Cube) Cube[source]
ranch.core.math.abs(input: Map) Map
ranch.core.math.abs(input: Profile) Profile

Element-wise absolute value operator.

Parameters:

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

Returns:

out – Output structure.

Return type:

Cube | Map | Profile

ranch.core.math.arccos(input: Cube) Cube[source]
ranch.core.math.arccos(input: Map) Map
ranch.core.math.arccos(input: Profile) Profile

Element-wise inverse cosine operator.

Parameters:

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

Returns:

out – Output structure.

Return type:

Cube | Map | Profile

ranch.core.math.arccosh(input: Cube) Cube[source]
ranch.core.math.arccosh(input: Map) Map
ranch.core.math.arccosh(input: Profile) Profile

Element-wise inverse hyperbolic cosine operator.

Parameters:

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

Returns:

out – Output structure.

Return type:

Cube | Map | Profile

ranch.core.math.arcsin(input: Cube) Cube[source]
ranch.core.math.arcsin(input: Map) Map
ranch.core.math.arcsin(input: Profile) Profile

Element-wise inverse sine operator.

Parameters:

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

Returns:

out – Output structure.

Return type:

Cube | Map | Profile

ranch.core.math.arcsinh(input: Cube) Cube[source]
ranch.core.math.arcsinh(input: Map) Map
ranch.core.math.arcsinh(input: Profile) Profile

Element-wise inverse hyperbolic sine operator.

Parameters:

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

Returns:

out – Output structure.

Return type:

Cube | Map | Profile

ranch.core.math.arctan(input: Cube) Cube[source]
ranch.core.math.arctan(input: Map) Map
ranch.core.math.arctan(input: Profile) Profile

Element-wise inverse tangent operator.

Parameters:

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

Returns:

out – Output structure.

Return type:

Cube | Map | Profile

ranch.core.math.arctanh(input: Cube) Cube[source]
ranch.core.math.arctanh(input: Map) Map
ranch.core.math.arctanh(input: Profile) Profile

Element-wise inverse hyperbolic tangent operator.

Parameters:

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

Returns:

out – Output structure.

Return type:

Cube | Map | Profile

ranch.core.math.cbrt(input: Cube) Cube[source]
ranch.core.math.cbrt(input: Map) Map
ranch.core.math.cbrt(input: Profile) Profile

Element-wise cube root operator.

Parameters:

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

Returns:

out – Output structure.

Return type:

Cube | Map | Profile

ranch.core.math.cos(input: Cube) Cube[source]
ranch.core.math.cos(input: Map) Map
ranch.core.math.cos(input: Profile) Profile

Element-wise cosine operator.

Parameters:

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

Returns:

out – Output structure.

Return type:

Cube | Map | Profile

ranch.core.math.cosh(input: Cube) Cube[source]
ranch.core.math.cosh(input: Map) Map
ranch.core.math.cosh(input: Profile) Profile

Element-wise hyperbolic cosine operator.

Parameters:

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

Returns:

out – Output structure.

Return type:

Cube | Map | Profile

ranch.core.math.exp(input: Cube) Cube[source]
ranch.core.math.exp(input: Map) Map
ranch.core.math.exp(input: Profile) Profile

Element-wise exponential operator.

Parameters:

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

Returns:

out – Output structure.

Return type:

Cube | Map | Profile

ranch.core.math.log(input: Cube, base: float | None = None) Cube[source]
ranch.core.math.log(input: Map, base: float | None = None) Map
ranch.core.math.log(input: Profile, base: float | None = None) Profile

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

ranch.core.math.sin(input: Cube) Cube[source]
ranch.core.math.sin(input: Map) Map
ranch.core.math.sin(input: Profile) Profile

Element-wise sine operator.

Parameters:

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

Returns:

out – Output structure.

Return type:

Cube | Map | Profile

ranch.core.math.sinh(input: Cube) Cube[source]
ranch.core.math.sinh(input: Map) Map
ranch.core.math.sinh(input: Profile) Profile

Element-wise hyperbolic sine operator.

Parameters:

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

Returns:

out – Output structure.

Return type:

Cube | Map | Profile

ranch.core.math.sqrt(input: Cube) Cube[source]
ranch.core.math.sqrt(input: Map) Map
ranch.core.math.sqrt(input: Profile) Profile

Element-wise square root operator.

Parameters:

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

Returns:

out – Output structure.

Return type:

Cube | Map | Profile

ranch.core.math.tan(input: Cube) Cube[source]
ranch.core.math.tan(input: Map) Map
ranch.core.math.tan(input: Profile) Profile

Element-wise tangent operator.

Parameters:

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

Returns:

out – Output structure.

Return type:

Cube | Map | Profile

ranch.core.math.tanh(input: Cube) Cube[source]
ranch.core.math.tanh(input: Map) Map
ranch.core.math.tanh(input: Profile) Profile

Element-wise hyperbolic tangent operator.

Parameters:

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

Returns:

out – Output structure.

Return type:

Cube | Map | Profile

ranch.core.util module

ranch.core.util.apply_element_wise(input: Cube, fun: Callable[[ndarray], ndarray]) Cube[source]
ranch.core.util.apply_element_wise(input: Map, fun: Callable[[ndarray], ndarray]) Map
ranch.core.util.apply_element_wise(input: Profile, fun: Callable[[ndarray], ndarray]) Profile

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

ranch.core.util.astype(input: Cube, dtype: Literal['float', 'double']) Cube[source]
ranch.core.util.astype(input: Map, dtype: Literal['float', 'double']) Map
ranch.core.util.astype(input: Profile, dtype: Literal['float', 'double']) Profile

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

ranch.core.util.change_axes_order(input: Cube, order: Literal['xyz', 'yxz', 'zxy', 'zyx']) Cube[source]
ranch.core.util.change_axes_order(input: Map, order: Literal['xy', 'yx']) Map

TODO

ranch.core.util.clip(input: Cube, vmin: float | None, vmax: float | None) Cube[source]
ranch.core.util.clip(input: Map, vmin: float | None, vmax: float | None) Map
ranch.core.util.clip(input: Profile, vmin: float | None, vmax: float | None) Profile

TODO

ranch.core.util.copy(input: Cube) Cube[source]
ranch.core.util.copy(input: Map) Map
ranch.core.util.copy(input: Profile) Profile

Returns a copy of input.

Parameters:

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

Returns:

out – Output structure.

Return type:

Cube | Map | Profile

ranch.core.util.cube_from(map: Map, profile: Profile, value: float = 0.0)[source]

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

Parameters:
  • map (Map) – Input map.

  • profile (Profile) – Input profile.

Returns:

cube – Output cube.

Return type:

Cube

ranch.core.util.cube_from_maps(maps: Sequence[Map]) Cube[source]

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

ranch.core.util.cube_from_profiles(profiles: Sequence[Sequence[Profile]]) Cube[source]

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

ranch.core.util.from_fits(cls: Type[Cube], filename: str, path: str = None, axes=Optional[Literal['xyz', 'yxz', 'zxy', 'zyx']]) Cube[source]
ranch.core.util.from_fits(cls: Type[Map], filename: str, path: str = None, axes: Literal['xy', 'yx'] | None = None) Map
ranch.core.util.from_fits(cls: Type[Profile], filename: str, path: str = None, axes: None = None) Profile

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

ranch.core.util.from_numpy(cls: Type[Cube], array: ndarray, header: Header, axes: Literal['xyz', 'yxz', 'zxy', 'zyx'] | None = None) Cube[source]
ranch.core.util.from_numpy(cls: Type[Map], array: ndarray, header: Header, axes: Literal['xy', 'yx'] | None = None) Map
ranch.core.util.from_numpy(cls: Type[Profile], array: ndarray, header: Header, axes: None = None) Profile

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

ranch.core.util.is_logical(input: Struct) bool[source]

TODO

ranch.core.util.isfinite(input: Cube) Cube[source]
ranch.core.util.isfinite(input: Map) Map
ranch.core.util.isfinite(input: Profile) 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

ranch.core.util.isnan(input: Cube) Cube[source]
ranch.core.util.isnan(input: Map) Map
ranch.core.util.isnan(input: Profile) Profile

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

ranch.core.util.map_from(cube: Cube, value: float = 0.0)[source]

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

ranch.core.util.nan_to_num(input: Cube, value: float = 0.0) Cube[source]
ranch.core.util.nan_to_num(input: Map, value: float = 0.0) Map
ranch.core.util.nan_to_num(input: Profile, value: float = 0.0) Profile

Returns a copy of input where the nans have been replaced by value.

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

  • value (float, optional) – Value to replace nans elements. Default : 0.

Returns:

out – Output structure.

Return type:

Cube | Map | Profile

ranch.core.util.ones(cls: Type[Cube], header: Header) Cube[source]
ranch.core.util.ones(cls: Type[Map], header: Header) Map
ranch.core.util.ones(cls: Type[Profile], header: Header) Profile

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

ranch.core.util.ones_like(input: Cube) Cube[source]
ranch.core.util.ones_like(input: Map) Map
ranch.core.util.ones_like(input: Profile) Profile

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

ranch.core.util.profile_from(cube: Cube, value: float = 0.0)[source]

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

ranch.core.util.stack_numpy(arrays: Sequence[ndarray]) ndarray[source]

TODO

ranch.core.util.to_numpy(input: Struct, item: str) ndarray[source]

TODO

ranch.core.util.where(bool_input: Cube, input_1: Cube | float, input_2: Cube | float) Cube[source]
ranch.core.util.where(bool_input: Map, input_1: Map | float, input_2: Map | float) Map
ranch.core.util.where(bool_input: Profile, input_1: Profile | float, input_2: Profile | float) Profile

TODO

ranch.core.util.x_axis(input: Map | Cube, unit: Literal['index', 'angle'] = 'index') ndarray[source]

TODO

ranch.core.util.y_axis(input: Map | Cube, unit: Literal['index', 'angle'] = 'index') ndarray[source]

TODO

ranch.core.util.z_axis(input: Profile | Cube, unit: Literal['index', 'velocity', 'frequency'] = 'index') ndarray[source]

TODO

ranch.core.util.zeros(cls: Type[Cube], header: Header) Cube[source]
ranch.core.util.zeros(cls: Type[Map], header: Header) Map
ranch.core.util.zeros(cls: Type[Profile], header: Header) Profile

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

ranch.core.util.zeros_like(input: Cube) Cube[source]
ranch.core.util.zeros_like(input: Map) Map
ranch.core.util.zeros_like(input: Profile) Profile

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