PixelMap

class sofia_redux.scan.source_models.pixel_map.PixelMap(info, reduction=None)[source]

Bases: AstroModel2D

Initialize a PixelMap source model.

The pixel map source model consists of a collection of AstroIntensityMap models, each containing a astronomical map generated from a single pixel of the observing instrument. They are primarily designed to measure pixel offsets from a known source.

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

referenced_attributes

Return attributes that are referenced with a standard copy operation.

shape

Return the shape of the map.

Methods Summary

add_model_data(other[, weight])

Add an increment source model data onto the current model.

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

Add points to the pixel maps.

base_footprint(pixels)

Returns the base footprint over all pixel maps.

calculate_coupling(integration, pixels, ...)

Not implemented for pixel maps

calculate_pixel_data([smooth])

Calculate pixel position offsets and couplings.

clear_all_memory()

Clear all memory references prior to deletion.

clear_content()

Clear the data in all pixel maps.

clear_process_brief()

Remove all process brief information.

copy([with_contents])

Return a copy of the pixel map.

count_points()

Return the number of points in the model.

covariant_points()

Return the number of points in the smoothing beam of all maps.

create_from(scans[, assign_scans])

Initialize model from scans.

create_lookup(integration)

Create the source indices for integration frames.

get_map_2d()

Return the 2D map.

get_parallel()

Return the number of parallel threads for the pixel maps.

get_pixel_footprint()

Returns the Number of bytes per pixel over all pixel maps.

get_source_name()

Return the source name for the pixel map.

get_unit()

Return the map data unit.

is_adding_to_master()

Return whether this map is adding to a master map during accumulation.

is_empty()

Return whether this pixel map has no data.

merge_accumulate(other)

Merge another pixel map with this one.

no_parallel()

Disable parallel processing for each pixel map.

parallel_safe_add_points(args, pixel_number)

Add points for a single pixel map.

parallel_safe_calculate_pixel_data(args, ...)

Fit a peak to a single pixel.

parallel_safe_merge_accumulate(args, pixel_index)

Merge a single pixel map onto another.

parallel_safe_process_final(args, pixel_index)

Perform the final processing steps for a single pixel map.

parallel_safe_sync_source_gains(args, ...)

Remove the source from all pixel maps.

process()

Process the source model.

process_final()

Perform the final processing steps for each pixel map.

process_scan(scan)

Process a scan.

reset_processing()

Reset the source processing.

set_base()

Set the base to the map (copy of).

set_data_shape(shape)

Set the shape of the map.

set_parallel(threads)

Set the number of parallel operations for the pixel map.

sync_source_gains(frames, pixels, ...)

Remove the map source from frame data for all pixel maps.

write(path)

Write the source to file.

write_fits(filename)

Write the results to a FITS file.

write_pixel_data([path])

Write the pixel data to file.

Attributes Documentation

referenced_attributes

Return attributes that are referenced with a standard copy operation.

Returns:
set (str)
shape

Return the shape of the map.

Note that this is in numpy (y, x) order.

Returns:
tuple of int

Methods Documentation

add_model_data(other, weight=1.0)[source]

Add an increment source model data onto the current model.

Parameters:
otherPixelMap

The source model increment.

weightfloat, optional

The weight of the source model increment.

Returns:
None
add_points(frames, pixels, frame_gains, source_gains)[source]

Add points to the pixel maps.

This may be an extremely time consuming and memory intensive endeavour. A map is created and stored for each mapping pixel in the detector channels.

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.

base_footprint(pixels)[source]

Returns the base footprint over all pixel maps.

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

Not implemented for pixel maps

calculate_pixel_data(smooth=False)[source]

Calculate pixel position offsets and couplings.

Pixel positions and couplings will be stored in the channel data of the first scan in the source model. Fits to the peak are calculated using AstroIntensityMap.get_peak_source() to determine the x and y position of the peak as well as the amplitude. The couplings are determined as:

coupling = peak.amplitude / median(peak.amplitude)

taking the median over all available instrument pixels.

Parameters:
smoothbool, optional

If True, smooth the map to the instrument peak resolution before fitting.

Returns:
None
clear_all_memory()[source]

Clear all memory references prior to deletion.

Returns:
None
clear_content()[source]

Clear the data in all pixel maps.

Returns:
None
clear_process_brief()[source]

Remove all process brief information.

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

Return a copy of the pixel map.

Parameters:
with_contentsbool, optional

If True, include all pixel maps in the copy.

Returns:
PixelMap
count_points()[source]

Return the number of points in the model.

Returns:
int
covariant_points()[source]

Return the number of points in the smoothing beam of all maps.

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_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.

Unlike other types of source maps, the PixelMap does not take pixel positions into account, so we are solely dealing with timestream positions relative to a (0, 0) pixel position for all channels. This means we only need to calculate positions for a single channel with position (0, 0)

Parameters:
integrationIntegration

The integration for which to create source indices.

Returns:
None
get_map_2d()[source]

Return the 2D map.

This is not valid for a pixel map.

Returns:
None
get_parallel()[source]

Return the number of parallel threads for the pixel maps.

Returns:
threadsint
get_pixel_footprint()[source]

Returns the Number of bytes per pixel over all pixel maps.

This is probably no longer relevant and just copies CRUSH.

Returns:
int
get_source_name()[source]

Return the source name for the pixel map.

Returns:
namestr
get_unit()[source]

Return the map data unit.

Returns:
units.Quantity or units.Unit

If a Quantity is returned, the value represents a scaling factor.

is_adding_to_master()[source]

Return whether this map is adding to a master map during accumulation.

Returns:
bool
is_empty()[source]

Return whether this pixel map has no data.

Returns:
bool
merge_accumulate(other)[source]

Merge another pixel map with this one.

Parameters:
otherPixelMap
Returns:
None
no_parallel()[source]

Disable parallel processing for each pixel map.

Returns:
None
classmethod parallel_safe_add_points(args, pixel_number)[source]

Add points for a single pixel map.

This function is safe for multitask().

Parameters:
args7-tuple
A tuple of arguments where:

args[0] - template (AstroIntensityMap) args[1] - pixel_maps (dict) args[2] - fixed_indices (array) (n_pixels,) args[2] - frame_data (array) (n_frames, n_pixels) args[3] - sample_gains (array) (n_frames, n_pixels) args[4] - sample_weights (array) (n_frames, n_pixels) args[5] - dt (float) args[6] - sample_indices (array) (2, n_frames, n_pixels)

pixel_numberint

The pixel index for the pixel map.

Returns:
pixel_maps2-tuple

A tuple of the form (fixed_index, pixel_map).

classmethod parallel_safe_calculate_pixel_data(args, pixel_number)[source]

Fit a peak to a single pixel.

This function is safe for multitask(). The peak for any single pixel is determined using AstroIntensityMap.get_peak_source().

Parameters:
args7-tuple
A tuple of arguments where:

args[0] - pixel_maps (dict) args[1] - smooth (bool) args[2] - point_size (units.Quantity) args[3] - degree (int) args[4] - reduce_degrees (bool)

pixel_numberint

The pixel fixed index for the pixel map.

Returns:
gaussian_modelEllipticalSource or None
classmethod parallel_safe_merge_accumulate(args, pixel_index)[source]

Merge a single pixel map onto another.

This function is safe for multitask().

Parameters:
args2-tuple
A tuple of arguments where:

args[0] - pixel_maps (dict) args[1] - other_maps (dict)

pixel_indexint

The pixel fixed index for the pixel map to merge

Returns:
fixed_index, pixel_mapint, AstroIntensityMap

The fixed pixel index and merged pixel map.

classmethod parallel_safe_process_final(args, pixel_index)[source]

Perform the final processing steps for a single pixel map.

Parameters:
args1-tuple
A tuple of arguments where:

args[0] - pixel_maps (dict)

pixel_indexint

The pixel fixed index for the pixel map to merge

Returns:
pixel_index, pixel_mapint, AstroIntensityMap

The pixel index and updated pixel map.

classmethod parallel_safe_sync_source_gains(args, pixel_number)[source]

Remove the source from all pixel maps.

This function is safe for multitask().

Parameters:
args6-tuple
A tuple of arguments where:

args[0] - pixel_maps (dict) args[1] - frames (Frames) args[2] - pixels (ChannelGroup) args[3] - frame_gains (array) (n_frames,) args[4] - source_gains (array) (all_channels,) args[5] - sync_gains (array) (all_channels,)

pixel_numberint

The pixel index for the pixel map.

Returns:
channel_frame_datanumpy.ndarray (float)

The synced frame data for pixel_number of shape (n_frames,).

process()[source]

Process the source model.

Processes each pixel map separately. If ‘pixelmap.process’ is True in the configuration, each pixel map will be fully processed. Otherwise, the results are only accumulated.

Returns:
None
process_final()[source]

Perform the final processing steps for each pixel map.

Returns:
None
process_scan(scan)[source]

Process a scan.

Parameters:
scanScan
Returns:
None
reset_processing()[source]

Reset the source processing.

Reset the source processing for the full source model and all individual pixel maps.

Returns:
None
set_base()[source]

Set the base to the map (copy of).

Returns:
None
set_data_shape(shape)[source]

Set the shape of the map.

Parameters:
shapetuple (int)
Returns:
None
set_parallel(threads)[source]

Set the number of parallel operations for the pixel map.

Not applicable for the SkyDip model.

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

Remove the map source from frame data for all pixel maps.

In addition to source removal, samples are also flagged if the map is masked at that location.

For a given sample at frame i and channel j, frame data d_{i,j} will be decremented by dg where:

dg = fg * ( (gain(source) * map[index]) - (gain(sync) * base[index]) )

Here, fg is the frame gain and index is the index on the map of sample (i,j).

Any masked map value will result in matching samples being flagged.

Parameters:
framesFrames

The frames for which to remove the source gains.

pixelsChannels or ChannelGroup

The channels for which to remove the source gains.

frame_gainsnumpy.ndarray (float)

An array of frame gains of shape (n_frames,).

source_gainsnumpy.ndarray (float)

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

sync_gainsnumpy.ndarray (float)

an array of channel sync gains for all channels of shape (all_channels,). The sync gains should contain the prior source gain.

Returns:
None
write(path)[source]

Write the source to file.

Parameters:
pathstr

The directory in which to write the output products.

Returns:
None
write_fits(filename)[source]

Write the results to a FITS file.

Not implemented for the single PixelMap.

Parameters:
filenamestr
Returns:
None
write_pixel_data(path=None)[source]

Write the pixel data to file.

Parameters:
pathstr, optional

The directory in which to write the pixel data. The default is the reduction work path.

Returns:
None