Grid2D

class sofia_redux.scan.coordinate_systems.grid.grid_2d.Grid2D[source]

Bases: Grid

Initialize a 2-dimensional abstract grid.

The grid is used to convert from 2D coordinates to offsets in relation to a specified reference onto a regular grid, and the reverse operation.

Forward transform: grid projection -> offsets -> coordinates Reverse transform: coordinates -> offsets -> grid projection

Attributes Summary

fits_x_unit

Return the unit for the X axis data.

fits_y_unit

Return the unit for the Y axis data.

inverse_transform

Return the inverse transform matrix for the grid.

projection

Return the grid projection.

rectilinear

Return whether the grid is rectilinear.

reference_index

Return the reference index for the grid.

transform

Return the transform matrix for the grid.

x_axis

Return the x-axis of the grid.

y_axis

Return the y-axis of the grid.

Methods Summary

calculate_inverse_transform()

Calculate the inverse transform for the grid (calculate i from m).

coordinates_at(grid_indices[, coordinates])

Return the coordinates at given grid indices.

copy()

Return a copy of the Grid2D.

edit_header(header)

Edit a FITS header with the grid information.

for_resolution(resolution)

Return a Grid2D for a given resolution.

from_header(header[, alt])

Create a grid instance from a header.

get_coordinate_index(coordinates[, indices])

Get the indices of the given coordinates.

get_coordinate_instance_for(name)

Return a coordinate instance for the given name.

get_coordinates(indices[, coordinates])

Get the coordinates at the given grid indices.

get_default_coordinate_instance()

Return a coordinate for the dimensions of the grid.

get_default_unit()

Return the default unit for the grid.

get_dimensions()

Return the number of grid dimensions.

get_grid_2d_instance_for(ctype_1, ctype_2)

Return a Grid2D instance for the given FITS coordinate types.

get_inverse_transform()

Return the inverse transform matrix for the grid.

get_offset(indices[, offset])

Get coordinate offsets from the given grid indices.

get_offset_index(offsets[, indices])

Get the grid indices of the given offsets.

get_pixel_area()

Return the area of one pixel on the grid.

get_pixel_size()

Return the pixel size in (x, y).

get_pixel_size_x()

Return the pixel size in the x-direction.

get_pixel_size_y()

Return the pixel size in the y-direction.

get_projection()

Return the grid projection.

get_reference()

Return the reference position of the grid.

get_reference_index()

Return the reference index of the reference position on the grid.

get_resolution()

Return the grid resolution in (x, y).

get_transform()

Return the transform matrix for the grid.

index_of(coordinates[, grid_indices])

Return the index of a coordinate on the grid.

index_to_offset(grid_indices[, in_place])

Convert grid indices to offset positions.

is_ecliptic()

Return whether the reference coordinate is an ecliptic coordinate.

is_equatorial()

Return whether the reference coordinate is an equatorial coordinate.

is_galactic()

Return whether the reference coordinate is a Galactic coordinate.

is_horizontal()

Return whether the reference coordinate is a horizontal coordinate.

is_reverse_x()

Returns if the x-axis is reversed.

is_reverse_y()

Returns if the y-axis is reversed.

is_super_galactic()

Return whether the reference coordinate is a super Galactic coordinate.

local_affine_transform(grid_indices)

Perform a local affine transform using the forward m matrix.

offset_to_index(offset[, in_place])

Convert an offset to a grid location.

parse_header(header)

Parse a FITS header and apply to the grid.

parse_projection(header)

Parse the projection from the header.

rotate(angle)

Rotate the grid by a given angle.

set_defaults()

Set the default values for the grid.

set_projection(value)

Set the grid projection.

set_reference(value)

Set the reference position of the grid.

set_reference_index(value)

Set the reference index of the reference position on the grid.

set_resolution(resolution)

Set the grid resolution.

set_transform(m)

Set the transform matrix for the grid.

to_coordinate2d(value)

Convert a value to a Coordinate2D object.

to_string()

Return a string representation of the grid.

toggle_native(offset[, in_place])

Reverse the x and y axis of native offsets if axes are reversed.

Attributes Documentation

fits_x_unit

Return the unit for the X axis data.

Returns:
units.Unit
fits_y_unit

Return the unit for the Y axis data.

Returns:
units.Unit
inverse_transform

Return the inverse transform matrix for the grid.

Returns:
inumpy.ndarray or units.Quantity
projection

Return the grid projection.

Returns:
Projection2D
rectilinear

Return whether the grid is rectilinear.

Returns:
bool
reference_index

Return the reference index for the grid.

Returns:
Coordinate2D
transform

Return the transform matrix for the grid.

Returns:
mnumpy.ndarray or units.Quantity
x_axis

Return the x-axis of the grid.

Returns:
CoordinateAxis
y_axis

Return the y-axis of the grid.

Returns:
CoordinateAxis

Methods Documentation

calculate_inverse_transform()[source]

Calculate the inverse transform for the grid (calculate i from m).

Returns:
None
coordinates_at(grid_indices, coordinates=None)[source]

Return the coordinates at given grid indices.

Parameters:
grid_indicesCoordinate2D

The grid indices for which to find coordinates.

coordinatesCoordinate2D, optional

Optional output coordinates to hold the result.

Returns:
Coordinate2D
copy()[source]

Return a copy of the Grid2D.

Returns:
Grid2D
edit_header(header)[source]

Edit a FITS header with the grid information.

Parameters:
headerfits.Header
Returns:
None
for_resolution(resolution)[source]

Return a Grid2D for a given resolution.

Parameters:
resolutionastropy.units.Quantity or numpy.ndarray or Coordinate2D
Returns:
gridGrid2D
classmethod from_header(header, alt='')[source]

Create a grid instance from a header.

Parameters:
headerfits.Header

The FITS header from which to create the grid.

altstr, optional

The alternate coordinate system designation.

Returns:
Grid2D
get_coordinate_index(coordinates, indices=None)[source]

Get the indices of the given coordinates.

Parameters:
coordinatesCoordinate2D

The coordinates for which to find grid indices.

indicesCoordinate2D, optional

Optional output coordinates to return. If not created, a fresh Coordinate2D instance will be used.

Returns:
indicesCoordinate2D

The grid indices.

classmethod get_coordinate_instance_for(name)[source]

Return a coordinate instance for the given name.

Parameters:
namestr
Returns:
Coordinate2D
get_coordinates(indices, coordinates=None)[source]

Get the coordinates at the given grid indices.

Parameters:
indicesCoordinate2D
coordinatesCoordinate2D, optional

Optional coordinates in which to store the output coordinates.

Returns:
coordinatesCoordinates2D
classmethod get_default_coordinate_instance()[source]

Return a coordinate for the dimensions of the grid.

Returns:
Coordinate2D
get_default_unit()[source]

Return the default unit for the grid.

Returns:
None or units.Unit
get_dimensions()[source]

Return the number of grid dimensions.

Returns:
n_dimensionsint
classmethod get_grid_2d_instance_for(ctype_1, ctype_2)[source]

Return a Grid2D instance for the given FITS coordinate types.

A suitable grid instance will be returned depending on the provided CTYPE values. If any CTYPE value is not recognized, a FlatGrid2D instance will be returned. In cases where a spherical system is recognized, a SphericalGrid will be returned.

CTYPE values should be 8 characters in length, divided into 2 segments of 4 characters each. The first set should give the type of world coordinates, and the second set should provide the type of projection geometry. The first set is left justified, with hyphens filling in any blank characters to the right, and the second set should be right justified with hyphens filling in any blank characters to the left. For example, ‘RA—TAN’ or ‘GLON-AIT’.

Note that in addition to the standard FITS CTYPE standards, the LON and LAT coordinate systems are also recognized. E.g., ‘LAT–TAN’. xLON, xyLN, xLAT, xyLT coordinate systems are also recognized, where x and y indicate arbitrary (but matching across longitude and latitude) characters.

Parameters:
ctype_1str or None

The type of the first world coordinate axis.

ctype_2str or None

The type of the second world coordinate axis.

Returns:
Grid2D
get_inverse_transform()[source]

Return the inverse transform matrix for the grid.

Returns:
inumpy.ndarray or units.Quantity
get_offset(indices, offset=None)[source]

Get coordinate offsets from the given grid indices.

Parameters:
indicesCoordinate2D

The grid indices.

offsetCoordinate2D, optional

Optional coordinates in which to store the results.

Returns:
offsetCoordinate2D
get_offset_index(offsets, indices=None)[source]

Get the grid indices of the given offsets.

Parameters:
offsetsCoordinate2D

The offsets for which to find indices.

indicesCoordinate2D

Optional coordinates in which to place the results.

Returns:
indicesCoordinate2D

The grid indices.

get_pixel_area()[source]

Return the area of one pixel on the grid.

Returns:
areafloat or units.Quantity
get_pixel_size()[source]

Return the pixel size in (x, y).

Returns:
resolutionCoordinate2D
get_pixel_size_x()[source]

Return the pixel size in the x-direction.

Returns:
sizefloat or units.Quantity
get_pixel_size_y()[source]

Return the pixel size in the y-direction.

Returns:
sizefloat or units.Quantity
get_projection()[source]

Return the grid projection.

Returns:
projectionProjection2D
get_reference()[source]

Return the reference position of the grid.

Returns:
referenceCoordinate2D
get_reference_index()[source]

Return the reference index of the reference position on the grid.

Returns:
indexCoordinate2D
get_resolution()[source]

Return the grid resolution in (x, y).

Returns:
resolutionCoordinate2D
get_transform()[source]

Return the transform matrix for the grid.

Returns:
mnumpy.ndarray or units.Quantity
index_of(coordinates, grid_indices=None)[source]

Return the index of a coordinate on the grid.

Parameters:
coordinatesCoordinate2D

The “true” coordinates.

grid_indicesCoordinate2D, optional

The output coordinates that will hold the result.

Returns:
grid_indicesCoordinate2D
index_to_offset(grid_indices, in_place=False)[source]

Convert grid indices to offset positions.

Parameters:
grid_indicesCoordinate2D
in_placebool, optional

If True, updates offset in-place. Otherwise, a new instance is returned.

Returns:
offsetCoordinate2D
is_ecliptic()[source]

Return whether the reference coordinate is an ecliptic coordinate.

Returns:
eclipticbool
is_equatorial()[source]

Return whether the reference coordinate is an equatorial coordinate.

Returns:
equatorialbool
is_galactic()[source]

Return whether the reference coordinate is a Galactic coordinate.

Returns:
galacticbool
is_horizontal()[source]

Return whether the reference coordinate is a horizontal coordinate.

Returns:
horizontalbool
is_reverse_x()[source]

Returns if the x-axis is reversed.

Returns:
bool
is_reverse_y()[source]

Returns if the y-axis is reversed.

Returns:
bool
is_super_galactic()[source]

Return whether the reference coordinate is a super Galactic coordinate.

Returns:
super_galacticbool
local_affine_transform(grid_indices)[source]

Perform a local affine transform using the forward m matrix.

The transformed coordinates are of the form:

new = (m @ coordinates) - reference_index

Parameters:
grid_indices: Coordinate2D
Returns:
transformed_indicesnumpy.ndarray or units.Quantity
offset_to_index(offset, in_place=False)[source]

Convert an offset to a grid location.

Parameters:
offsetCoordinate2D
in_placebool, optional

If True, updates offset in-place. Otherwise, a new instance is returned.

Returns:
indexCoordinate2D
parse_header(header)[source]

Parse a FITS header and apply to the grid.

Parameters:
headerfits.Header
Returns:
None
abstract parse_projection(header)[source]

Parse the projection from the header.

Parameters:
headerfits.Header
Returns:
None
rotate(angle)[source]

Rotate the grid by a given angle.

This effectively rotates the transformation matrices (m and i).

Parameters:
angleunits.Quantity

The angle of rotation.

Returns:
None
set_defaults()[source]

Set the default values for the grid.

Returns:
None
set_projection(value)[source]

Set the grid projection.

Parameters:
valueProjection2D
Returns:
None
set_reference(value)[source]

Set the reference position of the grid.

Parameters:
valueCoordinate2D

The reference coordinate to set.

Returns:
None
set_reference_index(value)[source]

Set the reference index of the reference position on the grid.

Parameters:
valueCoordinate2D
Returns:
None
set_resolution(resolution)[source]

Set the grid resolution.

Parameters:
resolutionCoordinate2D or float or numpy.ndarray or units.Quantity

The resolution to set.

Returns:
None
set_transform(m)[source]

Set the transform matrix for the grid.

Parameters:
mnumpy.ndarray or units.Quantity
Returns:
None
static to_coordinate2d(value)[source]

Convert a value to a Coordinate2D object.

Parameters:
valueint or float or numpy.ndarray or units.Quantity or Coordinate2D
Returns:
Coordinate2D
to_string()[source]

Return a string representation of the grid.

Returns:
str
toggle_native(offset, in_place=True)[source]

Reverse the x and y axis of native offsets if axes are reversed.

Scales reversed axis by -1.

Parameters:
offsetCoordinate2D
in_placebool, optional

If True, toggle in-place, otherwise return a copy.

Returns:
Coordinate2D