Coordinate

class sofia_redux.scan.coordinate_systems.coordinate.Coordinate(coordinates=None, unit=None, copy=True)[source]

Bases: ABC

Initialize a coordinate.

The Coordinate class is a generic container to store and operate on a set of coordinates.

Parameters:
coordinateslist or tuple or array-like or units.Quantity, optional

The coordinates used to populate the object during initialization.

unitstr or units.Unit or units.Quantity, optional

The units of the internal coordinates.

copybool, optional

If True, populate these coordinates with a copy of coordinates rather than the actual coordinates.

Attributes Summary

default_dimensions

empty_copy_skip_attributes

Return attributes that are set to None on an empty copy.

length

Return the Euclidean distance of the coordinates from (0, 0).

ndim

Return the number of dimensions for the coordinate.

shape

Return the shape of the coordinates.

singular

Return if the coordinates are scalar in nature (not an array).

size

Return the number of coordinates.

Methods Summary

add(coordinates)

Add other coordinates to these.

apply_coordinate_mask_function(coordinates, func)

Apply a masking function to a given set of coordinates.

broadcast_to(thing)

Broadcast to a new shape if possible.

change_unit(unit)

Change the coordinate units.

check_coordinate_units(coordinates)

Check the coordinate units and update parameters if necessary.

convert_factor(factor)

Returns a float factor in the correct units for multiplication.

convert_from(coordinates)

Convert coordinates from another or same system to this.

convert_to(coordinates)

Convert these coordinates to another coordinate system.

copy()

Return a copy of the Coordinate.

copy_coordinates(coordinates)

Copy the coordinates from another system to this system.

correct_factor_dimensions(factor, array)

Corrects the factor dimensionality prior to an array +-/* etc.

empty_copy()

Return an unpopulated instance of the coordinates.

fill(value[, indices])

Fill the coordinates with the given value.

get_class([class_name])

Return a coordinate class for a given name.

get_indices(indices)

Return selected data for given indices.

get_instance([class_name])

Return a coordinate instance for a given name.

insert_blanks(insert_indices)

Insert blank (NaN) values at the requested indices.

is_finite()

Check whether coordinates are finite.

is_infinite()

Check whether coordinates are infinite.

is_nan()

Check whether coordinates are NaN.

is_null()

Check whether coordinates are zero.

mean()

Return the mean coordinates.

merge(other)

Append other coordinates to the end of these.

nan([indices])

Set all coordinates to NaN.

paste(coordinates, indices)

Paste new coordinate values at the given indices.

scale(factor)

Scale the coordinates by a factor.

set(coordinates[, copy])

Set the coordinates.

set_shape(shape[, empty])

Set the shape of the coordinates.

set_shape_from_coordinates(coordinates[, ...])

Set the new shape and units from the given coordinates.

set_singular([empty])

Create a single coordinate.

shift(n[, fill_value])

Shift the coordinates by a given number of elements.

subtract(coordinates)

Subtract other coordinates from these.

zero([indices])

Set all coordinates to zero.

Attributes Documentation

default_dimensions = 1
empty_copy_skip_attributes

Return attributes that are set to None on an empty copy.

Returns:
attributesset (str)
length

Return the Euclidean distance of the coordinates from (0, 0).

Returns:
distancefloat or numpy.ndarray or astropy.units.Quantity
ndim

Return the number of dimensions for the coordinate.

Returns:
int
shape

Return the shape of the coordinates.

Returns:
tuple (int)
singular

Return if the coordinates are scalar in nature (not an array).

Returns:
bool
size

Return the number of coordinates.

Returns:
int

Methods Documentation

add(coordinates)[source]

Add other coordinates to these.

Parameters:
coordinatesCoordinate
Returns:
None
static apply_coordinate_mask_function(coordinates, func)[source]

Apply a masking function to a given set of coordinates.

Parameters:
coordinatesunits.Quantity or numpy.ndarray

The coordinates to check. Must consist of an array with 2 or more dimensions. I.e., of shape (ndim, x1, x2, …).

funcfunction

A function that returns a boolean mask given a numpy array. For these purposes, it should take in a two dimensional array of shape (ndim, n) where n = product(x1, x2, …).

Returns:
masknumpy.ndarray (bool)

The boolean mask output by func of shape (x1, x2, …).

broadcast_to(thing)[source]

Broadcast to a new shape if possible.

If the coordinates are singular (a single coordinate value in each dimension), broadcasts that single value to a new shape in the internal coordinates.

Parameters:
thingnumpy.ndarray or tuple (int)

An array from which to determine the broadcast shape, or a tuple containing the broadcast shape.

Returns:
None
change_unit(unit)[source]

Change the coordinate units.

Parameters:
unitstr or units.Unit
Returns:
None
check_coordinate_units(coordinates)[source]

Check the coordinate units and update parameters if necessary.

This method takes in a set of coordinates and returns a more standardized version consistent with these coordinates. Coordinate units will be converted to these coordinates, or if no units exist for these coordinates, they will be inferred from the input coordinates.

If the given coordinates are a Coordinate subclass, they will be converted to the current units, and any other array like input will be converted to an numpy array or units.Quantity depending on whether units for these coordinates have been defined (or inferred from coordinates).

Parameters:
coordinateslist or tuple or numpy.ndarray or units.Quantity or None

The coordinates to check.

Returns:
coordinates, originalnumpy.ndarray or units.Quantity or Coordinate

Returns the coordinates in the same unit as the coordinates, and whether the coordinates are the original coordinates.

convert_factor(factor)[source]

Returns a float factor in the correct units for multiplication.

If the current coordinates are not quantities, they will be converted to such if the factor is a quantity. Otherwise, the factor scaled to units of the coordinates will be returned.

Parameters:
factorfloat or numpy.ndarray or units.Quantity
Returns:
factorfloat or numpy.ndarray (float)
convert_from(coordinates)[source]

Convert coordinates from another or same system to this.

Parameters:
coordinatesCoordinate
Returns:
None
convert_to(coordinates)[source]

Convert these coordinates to another coordinate system.

Parameters:
coordinatesCoordinate
Returns:
None
copy()[source]

Return a copy of the Coordinate.

Returns:
Coordinate
copy_coordinates(coordinates)[source]

Copy the coordinates from another system to this system.

Parameters:
coordinatesCoordinate
Returns:
None
static correct_factor_dimensions(factor, array)[source]

Corrects the factor dimensionality prior to an array +-/* etc.

Frame operations are frequently of the form result = factor op array where factor is of shape (n_frames,) and array is of shape (n_frames, …). This procedure updates the factor shape so that array operations are possible. E.g., if factor is of shape (5,) and array is of shape (5, 10), then the output factor will be of shape (5, 1) and allow the two arrays to operate with each other.

Parameters:
factorint or float or numpy.ndarray or astropy.units.Quantity

The factor to check.

arraynumpy.ndarray or astropy.units.Quantity or Coordinate

The array to check against

Returns:
working_factornumpy.ndarray or astropy.units.Quantity
empty_copy()[source]

Return an unpopulated instance of the coordinates.

Returns:
Coordinate
fill(value, indices=None)[source]

Fill the coordinates with the given value.

Parameters:
valueint or float or units.Quantity

The value with which to fill the coordinates.

indicesslice or numpy.ndarray (int or bool), optional

The indices to set to NaN.

Returns:
None
classmethod get_class(class_name=None)[source]

Return a coordinate class for a given name.

Parameters:
class_namestr, optional

The name of the class not including the “Coordinates” suffix. The default is this class.

Returns:
coordinate_classclass``
get_indices(indices)[source]

Return selected data for given indices.

Parameters:
indicesslice or list or int or numpy.ndarray (int)

The indices to extract.

Returns:
Coordinate
classmethod get_instance(class_name=None)[source]

Return a coordinate instance for a given name.

Parameters:
class_namestr, optional

The name of the class not including the “Coordinates” suffix. The default is this class.

Returns:
objectCoordinate2D or SphericalCoordinates or CelestialCoordinates
insert_blanks(insert_indices)[source]

Insert blank (NaN) values at the requested indices.

Follows the logic of numpy.insert().

Parameters:
insert_indicesnumpy.ndarray (int)
Returns:
None
is_finite()[source]

Check whether coordinates are finite.

Returns:
bool or numpy.ndarray (bool)
is_infinite()[source]

Check whether coordinates are infinite.

Returns:
bool or numpy.ndarray (bool)
is_nan()[source]

Check whether coordinates are NaN.

Returns:
bool or numpy.ndarray (bool)
is_null()[source]

Check whether coordinates are zero.

Returns:
bool or numpy.ndarray (bool)
mean()[source]

Return the mean coordinates.

Returns:
mean_coordinatesCoordinate
merge(other)[source]

Append other coordinates to the end of these.

Parameters:
otherCoordinate
Returns:
None
nan(indices=None)[source]

Set all coordinates to NaN.

Parameters:
indicesslice or numpy.ndarray (int or bool), optional

The indices to set to NaN.

Returns:
None
paste(coordinates, indices)[source]

Paste new coordinate values at the given indices.

Parameters:
coordinatesCoordinate
indicesnumpy.ndarray (int)
Returns:
None
scale(factor)[source]

Scale the coordinates by a factor.

Parameters:
factorint or float or Coordinate or iterable or np.ndarray

If a Coordinate is supplied, it must be singular.

Returns:
None
set(coordinates, copy=True)[source]

Set the coordinates.

Parameters:
coordinatesnumpy.ndarray or list
copybool, optional

If True, copy the coordinates. Otherwise do a reference.

Returns:
None
set_shape(shape, empty=False)[source]

Set the shape of the coordinates.

If the current coordinates are blank, dimensionality will be inferred from the input shape. If a single integer value or 1-tuple is passed in, the number of dimensions will be set to 1. Otherwise, the dimensionality will be permanently set to the first element of shape.

Parameters:
shapeint or tuple (int)
emptybool, optional

If True, create an empty array. Otherwise, create a zeroed array.

Returns:
None
set_shape_from_coordinates(coordinates, single_dimension=False, empty=False, change_unit=True)[source]

Set the new shape and units from the given coordinates.

The dimensionality of this coordinate will be determined from the input coordinates if not previously defined. Otherwise, any previously determined dimensionality will remain fixed and cannot be altered.

Parameters:
coordinatesnumpy.ndarray (float) or astropy.units.Quantity
single_dimensionbool, optional

If True, the coordinates consist of data from only one of the dimensions. Note that this is only applicable if the current dimensionality has been determined. If False, the shape of the coordinates will be determined from coordinates[0]. In the case where coordinates.ndim <= 1, the new shape will be set to a singular value.

emptybool, optional

If True and a new array should be created, that array will be empty. Otherwise, a zero array will be created.

change_unitbool, optional

If True, allow the unit to be updated.

Returns:
None
set_singular(empty=False)[source]

Create a single coordinate.

Parameters:
emptybool, optional

If True, create an empty coordinate array. Otherwise, create a zeroed array.

Returns:
None
shift(n, fill_value=nan)[source]

Shift the coordinates by a given number of elements.

Parameters:
nint
fill_valuefloat or int or units.Quantity, optional
Returns:
None
subtract(coordinates)[source]

Subtract other coordinates from these.

Parameters:
coordinatesCoordinate
Returns:
None
zero(indices=None)[source]

Set all coordinates to zero.

Parameters:
indicesslice or numpy.ndarray (int or bool), optional

The indices to set to zero.

Returns:
None