AstroModel2D

class sofia_redux.scan.source_models.astro_model_2d.AstroModel2D(info, reduction=None)[source]

Bases: SourceModel

Initialize an astronomical 2D model of the source.

The AstroModel2D is an abstract class that extends the SourceModel to represent an astronomical source. This includes a spherical grid onto which the source should be projected.

Parameters:
infosofia_redux.scan.info.info.Info

The Info object which should belong to this source model.

reductionsofia_redux.scan.reduction.reduction.Reduction, optional

The reduction for which this source model should be applied.

Attributes Summary

DEFAULT_PNG_SIZE

MAX_X_OR_Y_SIZE

projection

Return the grid projection.

reference

Return the reference coordinate for the source model grid.

shape

Return the data shape.

size_x

Return the size of the data in the x-direction.

size_y

Return the size of the data in the y-direction.

Methods Summary

add_frames_from_integration(integration, ...)

Add frames from an integration to the source model.

add_integration(integration[, signal_mode])

Add an integration to the source model.

add_pixels_from_integration(integration, ...)

Add pixels to the source model.

add_points(frames, pixels, frame_gains, ...)

Add points to the source model.

base_footprint(pixels)

Return the base footprint of the source model.

calculate_coupling(integration, pixels, ...)

Don't know

clear_all_memory()

Clear all memory references prior to deletion.

copy([with_contents])

Return a copy of the 2D astronomical model.

covariant_points()

Return the covariant points.

create_from(scans[, assign_scans])

Initialize model from scans.

create_grid()

Create the grid instance for the astronomical model.

create_lookup(integration)

Create the source indices for integration frames.

find_outliers(max_distance)

Find and return outlier scans based on distance from median position.

find_slewing(max_distance)

Return all scans that have a slew greater than a certain distance.

flag_outside(projection, integration, map_range)

Flag points that are outside of the specified map range.

get_core_name()

Return the core name for the source model.

get_default_file_name()

Return the default file name for the FITS source model output.

get_map_2d()

Return a 2-D map.

get_memory_footprint(pixels)

Return the memory footprint.

get_pixel_footprint()

Return the pixel footprint of the source model.

get_pixelization_smoothing()

Return the pixelation smoothing FWHM.

get_point_size()

Return the point size of the source model.

get_reduction_footprint(pixels)

Return the reduction memory footprint.

get_reference()

Return the reference pixel of the source model WCS.

get_requested_smoothing([smooth_spec])

Get the requested smoothing for a given specification.

get_sample_points(frames, pixels, ...)

Return the sample gains for integration frames and given pixels.

get_smoothing(smooth)

Get the smoothing FWHM given a smoothing specification.

get_source_size()

Return the source size of the source model.

get_table_entry(name)

Return a parameter value for a given name.

index()

Store the map indices for fast lookup later.

is_adding_to_master()

Don't know

is_empty()

Return whether the source map is empty.

is_valid()

Return whether the source model is valid.

merge_accumulate(other)

Merge another source with this one.

parallel_safe_flag_outside(args, ...)

Flag points that are outside specified map range for an integration.

parallel_safe_integration_range(args, ...)

Return the range of the integration coordinates for all integrations.

pixel_index_to_source_index(pixel_indices)

Return the 1-D source index for a pixel index.

pixels()

Return the number of pixels in the source model.

process_final()

Don't know

reset_processing()

Reset the source processing.

search_corners([determine_scan_range])

Determine the extent of the source model.

set_data_shape(shape)

Set the data shape.

set_size()

Set the size of the source model.

set_smoothing(smoothing)

Set the model smoothing.

set_sync_gains(integration, pixels, source_gains)

Set the sync gains for the source model (set to current source gains).

source_index_to_pixel_index(source_indices)

Convert 1-D source indices to 2-D pixel indices.

sync_integration(integration[, signal_mode])

Remove source from integration frame data.

sync_pixels(integration, pixels, source_gains)

Remove the source from pixels.

sync_source_gains(frames, pixels, ...)

Remove the source from all but the blind channels.

update_smoothing()

Update the model smoothing from the configuration.

write(path)

Write the source to file.

write_fits(filename)

Write the results to a FITS file.

write_image_png(image, file_name[, dpi])

Write a PNG of an image.

write_png(map_2d, file_name)

Write a PNG of the map.

Attributes Documentation

DEFAULT_PNG_SIZE = 300
MAX_X_OR_Y_SIZE = 5000
projection

Return the grid projection.

Returns:
SphericalProjection
reference

Return the reference coordinate for the source model grid.

Returns:
SphericalCoordinates

The reference coordinates for the source model grid.

shape

Return the data shape.

Returns:
tuple (int)
size_x

Return the size of the data in the x-direction.

Returns:
int
size_y

Return the size of the data in the y-direction.

Returns:
int

Methods Documentation

add_frames_from_integration(integration, pixels, source_gains, signal_mode=None)[source]

Add frames from an integration to the source model.

Parameters:
integrationIntegration

The integration to add.

pixelsChannelGroup

The channels (pixels) to add to the source model.

source_gainsnumpy.ndarray (float)

The source gains for the all channels (pixels). Should be of shape (all_channels,).

signal_modeFrameFlagTypes, optional

The signal mode flag, indicating which signal should be used to extract the frame source gains. Typically, TOTAL_POWER and will be taken as the signal mode of this map if not supplied.

Returns:
mapping_framesint

The number of frames that contributed towards mapping.

add_integration(integration, signal_mode=None)[source]

Add an integration to the source model.

The integration NEFD is calculated, and then frames are added via AstroModel2D.add_frames_from_integration(). A filter correction is applied on the first source generation only.

Parameters:
integrationIntegration
signal_modestr or int or FrameFlagTypes, optional

The signal mode for which to extract source gains from integration frames. Typically, TOTAL_POWER.

Returns:
None
add_pixels_from_integration(integration, pixels, source_gains, signal_mode)[source]

Add pixels to the source model.

This performs the same task as AstroModel2D.add_frames_from_integration().

Parameters:
integrationIntegration

The integration to add.

pixelsChannelGroup

The channels (pixels) to add to the source model.

source_gainsnumpy.ndarray (float)

The source gains for the all channels (pixels). Should be of shape (all_channels,).

signal_modeFrameFlagTypes

The signal mode flag, indicating which signal should be used to extract the frame source gains. Typically, TOTAL_POWER.

Returns:
mapping_framesint

The number of frames that contributed towards mapping.

abstract add_points(frames, pixels, frame_gains, source_gains)[source]

Add points to the source model.

Parameters:
framesFrames

The frames to add to the source model.

pixelsChannelGroup

The channels (pixels) to add to the source model.

frame_gainsnumpy.ndarray (float)

The gain values for all frames of shape (n_frames,).

source_gainsnumpy.ndarray (float)

The channel source gains for all channels of shape (all_channels,).

Returns:
mapping_framesint

The number of valid mapping frames added for the model.

abstract base_footprint(pixels)[source]

Return the base footprint of the source model.

Parameters:
pixelsint
Returns:
int
abstract calculate_coupling(integration, pixels, source_gains, sync_gains)[source]

Don’t know

Parameters:
integration
pixels
source_gains
sync_gains
Returns:
None
clear_all_memory()[source]

Clear all memory references prior to deletion.

Returns:
None
copy(with_contents=True)[source]

Return a copy of the 2D astronomical model.

Parameters:
with_contentsbool, optional

If True, return a true copy of the source model. Otherwise, just return a basic version with the necessary meta data.

Returns:
AstroModel2D
abstract covariant_points()[source]

Return the covariant points.

Returns:
float
create_from(scans, assign_scans=True)[source]

Initialize model from scans.

Sets the model scans to those provided, and the source model for each scan as this. All integration gains are normalized to the first scan. If the first scan is non-sidereal, the system will be forced to an equatorial frame.

Parameters:
scanslist (Scan)

A list of scans from which to create the model.

assign_scansbool, optional

If True, assign the scans to this source model. Otherwise, there will be no hard link between the scans and source model.

Returns:
None
create_grid()[source]

Create the grid instance for the astronomical model.

Returns:
None
create_lookup(integration)[source]

Create the source indices for integration frames.

The source indices contain 1-D lookup values for the pixel indices of a sample on the source model. The map indices are stored in the integration frames as the 1-D source_index attribute, and the 2-D map_index attribute.

Parameters:
integrationIntegration

The integration for which to create source indices.

Returns:
None
find_outliers(max_distance)[source]

Find and return outlier scans based on distance from median position.

Returns all scans that deviate from the median equatorial position of all scans by >= max_distance.

Parameters:
max_distanceunits.Quantity

The maximum angular separation from a scan from the median equatorial position of all scans.

Returns:
outlier_scanslist (Scan)

A list of outlier scans.

find_slewing(max_distance)[source]

Return all scans that have a slew greater than a certain distance.

Parameters:
max_distanceunits.Quantity

The maximum angular slew. Any scans that have a map span greater than this limit will be added to the output scan list.

Returns:
slewing_scanslist (Scan)

The scans with a slew greater than max_distance.

classmethod flag_outside(projection, integration, map_range)[source]

Flag points that are outside of the specified map range.

Integration frame samples that are outside of the supplied map_range will be flagged with the SAMPLE_SKIP frame flag.

Parameters:
projectionProjection2D
integrationIntegration
map_rangeCoordinate2D

The map range containing the minimum (x, y) and maximum (x, y) coordinates of the map of shape (n_frames, n_channels).

Returns:
None
get_core_name()[source]

Return the core name for the source model.

Returns:
core_namestr
get_default_file_name()[source]

Return the default file name for the FITS source model output.

Returns:
filenamestr
abstract get_map_2d()[source]

Return a 2-D map.

Returns:
Map
get_memory_footprint(pixels)[source]

Return the memory footprint.

Parameters:
pixelsint
Returns:
bytesint
abstract get_pixel_footprint()[source]

Return the pixel footprint of the source model.

Returns:
int
get_pixelization_smoothing()[source]

Return the pixelation smoothing FWHM.

The returned value is:

sqrt(pixel_area * (8 ln(2)) / 2pi)

Returns:
pixel_fwhmunits.Quantity
get_point_size()[source]

Return the point size of the source model.

Returns:
units.Quantity
get_reduction_footprint(pixels)[source]

Return the reduction memory footprint.

The reduction memory footprint includes the composite map, plus one copy for each thread, plus the base image.

Parameters:
pixelsint
Returns:
bytesint
get_reference()[source]

Return the reference pixel of the source model WCS.

Returns:
numpy.ndarray (float)

The (x, y) reference position of the source model.

get_requested_smoothing(smooth_spec=None)[source]

Get the requested smoothing for a given specification.

Parameters:
smooth_specstr or float, optional

The type of smoothing to retrieve.

Returns:
fwhmunits.Quantity

The FWHM of the Gaussian smoothing kernel.

get_sample_points(frames, pixels, frame_gains, source_gains)[source]

Return the sample gains for integration frames and given pixels.

Parameters:
framesFrames

The integration frames for which to generate sample data.

pixelsChannelGroup

The channel group for which to derive sample gains. The size of the group should be n_channels.

frame_gainsnumpy.ndarray (float)

The gain values for all frames of shape (n_frames,).

source_gainsnumpy.ndarray (float)

The channel source gains for all channels of shape (all_channels,).

Returns:
mapping_frames, data gains, weights, indices5-tuple (int, array+)

The total number of mapping frames and the cross product of integration frame gains and source gains as an array of shape (n_frames, n_channels). Any invalid frames/sample flags will result in a NaN gain value for the sample in question. Invalid indices will be represented by -1 values, and invalid weights will be zero-valued. The shape of the output indices will be (n_dimensions, n_frames, n_channels).

get_smoothing(smooth)[source]

Get the smoothing FWHM given a smoothing specification.

Either a float value or one of the following strings may be supplied:

‘beam’: 1 * instrument FWHM ‘halfbeam’: 0.5 * instrument FWHM ‘2/3beam’: instrument FWHM / 1.5 ‘minimal’: 0.3 * instrument FWHM ‘optimal’: either (1 * instrument FWHM), or the smooth.optimal value

If the pixelization FWHM is greater than the calculated FWHM, it will be returned instead. The pixelization FWHM is defined as:

pix_FWHM = sqrt(pixel_area * (8 ln(2)) / 2pi)

Parameters:
smoothstr or float

The FWHM for which to smooth to in units of the instrument size unit (float), or one of the following string: {‘beam’, ‘halfbeam’, ‘2/3beam’, ‘minimal’, ‘optimal’}.

Returns:
FWHMunits.Quantity

The FWHM of the Gaussian smoothing kernel.

get_source_size()[source]

Return the source size of the source model.

Returns:
units.Quantity
get_table_entry(name)[source]

Return a parameter value for a given name.

Parameters:
namestr

The name of the parameter.

Returns:
value
index()[source]

Store the map indices for fast lookup later.

The map indices are stored in the map_index attribute of the integration frames, and also as a 1-D map in the source_index attribute of the integration frames.

Returns:
None
is_adding_to_master()[source]

Don’t know

Returns:
bool
abstract is_empty()[source]

Return whether the source map is empty.

Returns:
bool
is_valid()[source]

Return whether the source model is valid.

Returns:
bool
abstract merge_accumulate(other)[source]

Merge another source with this one.

Parameters:
otherAstroModel2D
Returns:
None
classmethod parallel_safe_flag_outside(args, integration_number)[source]

Flag points that are outside specified map range for an integration.

This function is safe for use with multiprocessing.multitask(). Flagging occurs by marking the integration frame samples with the SAMPLE_SKIP frame flag.

Parameters:
args3-tuple

args[0] = integrations (list (Integration)) args[1] = projection (Projection2D) args[2] = map_range (Coordinate2D)

integration_numberint

The index of the integration to flag in args[0].

Returns:
None
classmethod parallel_safe_integration_range(args, integration_number)[source]

Return the range of the integration coordinates for all integrations.

Parameters:
args2-tuple

args[0] = list of integrations (list (Integration)). args[1] = projection (Projection2D).

integration_numberint

The integration number for which to find the range.

Returns:
integration_range4-tuple

A tuple of the for (min_x, max_x, min_y, max_y).

pixel_index_to_source_index(pixel_indices)[source]

Return the 1-D source index for a pixel index.

Parameters:
pixel_indicesnumpy.ndarray (int)

The pixel indices of shape (2, shape,) containing the (x_index, y_index) pixel indices.

Returns:
source_indicesnumpy.ndarray (int)

The 1-D source indices of shape (shape,).

pixels()[source]

Return the number of pixels in the source model.

Returns:
int
abstract process_final()[source]

Don’t know

Returns:
None
reset_processing()[source]

Reset the source processing.

Sets the source generation and integration time to zero, and resets the smoothing to that referenced in the configuration under the ‘smooth’ keyword value.

Returns:
None
search_corners(determine_scan_range=False)[source]

Determine the extent of the source model.

If the map range is specified in the configuration via ‘map.size’, this will be returned, but also result in integration frame samples being flagged with the SAMPLE_SKIP flag if outside this range.

Otherwise, the map range will be determined from the span of sample coordinates projected onto the model grid over all scans and integrations in the model. An attempt will be made to determine this using the perimeter pixels (near the edge of the detector array).

This will also set the scan map range for each scan if ‘map.size’ is not set.

Parameters:
determine_scan_rangebool, optional

If True, only determine the map ranges for all scans rather than check for the ‘map.size’ configuration instruction. I.e., do not perform any flagging.

Returns:
map_rangeCoordinate2D

A coordinate of shape (2,) containing the minimum and maximum x and y coordinates.

abstract set_data_shape(shape)[source]

Set the data shape.

Parameters:
shapetuple (int)
Returns:
None
set_size()[source]

Set the size of the source model.

Determines the grid resolution, the size of the grid dimensions in (x, y) pixels, and the reference index of the grid. The grid resolution is determined from the ‘grid’ keyword value in the configuration or one fifth of the instrument point size. The map size is determined from the span of coordinates over all scan integrations.

Returns:
None
set_smoothing(smoothing)[source]

Set the model smoothing.

Parameters:
smoothingunits.Quantity
Returns:
None
static set_sync_gains(integration, pixels, source_gains)[source]

Set the sync gains for the source model (set to current source gains).

Parameters:
integrationIntegration
pixelsChannelGroup

The channels (pixels) for which to set sync gains.

source_gainsnumpy.ndarray (float)

The source gains to set as sync gains. Should be of shape (all_channels,).

Returns:
None
source_index_to_pixel_index(source_indices)[source]

Convert 1-D source indices to 2-D pixel indices.

Parameters:
source_indicesnumpy.ndarray (int)

The source indices of shape (shape,).

Returns:
pixel_indicesnumpy.ndarray (int)

The pixel indices of shape (2, shape,) containing the (x_index, y_index) pixel indices.

sync_integration(integration, signal_mode=None)[source]

Remove source from integration frame data.

Parameters:
integrationIntegration
signal_modeFrameFlagTypes, optional

The signal mode flag, indicating which signal should be used to extract the frame source gains. Typically, TOTAL_POWER.

Returns:
None
sync_pixels(integration, pixels, source_gains, signal_mode=None)[source]

Remove the source from pixels.

Parameters:
integrationIntegration
pixelsChannelGroup
source_gainsnumpy.ndarray (float)

The integration channel source gains of shape (all_channels,)

signal_modeFrameFlagTypes, optional

The signal mode flag, indicating which signal should be used to extract the frame source gains. Typically, TOTAL_POWER.

Returns:
None
abstract sync_source_gains(frames, pixels, frame_gains, source_gains, sync_gains)[source]

Remove the source from all but the blind channels.

This is the same as sync(exposure, pixel, index, fg, sourcegain, integration.sourcesyncgain).

Parameters:
framesFrames
pixelsChannels or ChannelGroup
frame_gainsnumpy.ndarray (float)
source_gainsnumpy.ndarray (float)
sync_gainsnumpy.ndarray (float)
Returns:
None
update_smoothing()[source]

Update the model smoothing from the configuration.

Returns:
None
write(path)[source]

Write the source to file.

Performing a write operation will write various products to the path directory. If any intermediate.<id>.fits file is found it will be delete

Parameters:
pathstr

The directory to write to.

Returns:
None
abstract write_fits(filename)[source]

Write the results to a FITS file.

Parameters:
filenamestr
Returns:
None
write_image_png(image, file_name, dpi=100)[source]

Write a PNG of an image.

Parameters:
imagesofia_redux.scan.source_models.maps.image_2d.Image2D

The image to write as a PNG

file_namestr

The file path to write the PNG to.

dpiint or float, optional

The Dots-Per-Inch resolution for the PNG output.

Returns:
None
write_png(map_2d, file_name)[source]

Write a PNG of the map.

Parameters:
map_2dMap2D
file_namestr

The file path to write the PNG to.

Returns:
None