astrowisp.utils.explore_prf module
Class Inheritance Diagram

Create some plots helpful for picking PSF grid.
- class astrowisp.utils.explore_prf.AlglibSpline(prf_data, resolution, penalty, domain)[source]
Bases:
object
Wrap alglib based splines so they can be evaluated on scipy arrays.
- __init__(prf_data, resolution, penalty, domain)[source]
Fit the spline on the given data.
- Parameters:
prf_data – The return value of get_prf_data().
resolution (int, int) – The grid resolution to use when building the spline.
penalty (float) – The nonlinearity penalty when fitting the spline.
domain (float, float, float, float) – The area (xmin, xmax, ymin, ymax) over which the spline will be derived.
- Returns:
None
- astrowisp.utils.explore_prf.extract_pixel_data(cmdline_args, image_slices, sources=None)[source]
Get the pixel level data from the input image required for the plot.
- Parameters:
cmdline_args – The parsed command line arguments.
image_slices – How to split the image when plotting (the return value of get_image_slices()).
sources (scipy.array or None) – If not None, it should be an array with equivalent structure to get_source_info(). If None, get_source_info() is used to initialize it.
- Returns:
A list of the PRF data (see return of get_prf_data()) for each image slice each entry contains the data and a plot label.
- Return type:
List
- astrowisp.utils.explore_prf.find_pixel_offsets(sources, prf_range, image_resolution, crowding_distance, plot=False)[source]
Return the positions of pixels within prf range relative to source centers.
- Parameters:
sources – The return value of get_source_info().
prf_range – See –prf-range command line argument.
image_resolution (int, int) – The x and y resolution of the image under investigation.
crowding_distance (float) – The minimum distance between a source and its closest neighbor to still consider the source isolated.
plot (bool) – If True, show plots of the offsets and norm images.
- Returns:
x_off: The field giving the offset of the pixel center from the source position in the x direction
y_off: The field giving the offset of the pixel center from the source position in the y direction
norm: The normalization to use for the pixel response.
Pixels that are not within range of any PSF or that are within more than one PSF’s range have nan entries.
- Return type:
2-D field array
- astrowisp.utils.explore_prf.fit_spline(prf_data, domain, cmdline_args)[source]
Return the best-fit spline to the PRF per the command line config.
- astrowisp.utils.explore_prf.get_image_slices(splits, inner_only)[source]
Return [(x-slice, y-slice, x_index, y_index), …] per –split-image arg.
- Parameters:
splits – The parsed image splits directly from the command line.
inner_only (bool) – If True, slices in contact with the outer border of the image are discarded.
- Returns:
Array slices directly useable to index the image implementing the splitting specified on the command line.
- Return type:
[(x-slice, y-slice, x_index, y_index), …]
- astrowisp.utils.explore_prf.get_plot_tasks(cmdline_args)[source]
Generator for all the plots that must be created.
- Parameters:
cmdline_args – The parse command line configuration.
- Yields:
dict – The parsed PRF slice directly taken from the command line to plot
- [(str on None), …]: List of the filenames to save the plot if each
slice is saved separately. Appropriate length of Nones otherwise.
- str or None: The filanem to save a combined plot of all pieces of the
image together or None if individual images are saved separately.
- astrowisp.utils.explore_prf.get_prf_data(pixel_values, pixel_stddev, pixel_offsets, error_threshold=0.1)[source]
Return the PRF measurements for (a subset of) the image.
- Parameters:
pixel_values (2-D float array) – The calibrated pixel responses from the image to include in the plot.
pixel_stddev (2-D float array) – The estimated standard deviation of pixel_values.
pixel_offsets – The slice of the return value of find_pixel_offsets() corresponding to pixel_values.
error_threshold (float) – See –error-threshold command line argument
- Returns:
The x-offsets of the points at which PRF measurements are available.
The y-offsets of the points at which PRF measurements are available.
The measured normalized PRF at the available offsets
estimated errors of the PRF measurements.
- Return type:
(2-D float array, 2-D float array, 2-D float array, 2-D float array)
- astrowisp.utils.explore_prf.get_source_info(*, pixel_array, stddev_array, mask_array, source_positions, aperture, bg_radii)[source]
Return field array containing source positions, fluxes and backgrounds.
- Parameters:
pixel_array (2-D array like) – The measured values of the image pixels.
stddev_array (2-D array like) – The estimated variance of the image pixels.
mask_array (2-D array like) – Quality flags for the image pixels.
source_positions – The return value from get_source_positions().
aperture – The size of the aperture to use for measuring the flux.
bg_radii ((float, float)) – The inner and outer radius to use for the background annulus.
- Returns:
All relevant source information in the following fields:
x: The x coordinates of the sources.
y: The y coordinates of the sources.
flux: The measured fluxes of the sources.
flux_err: Estimated error of the flux.
bg: The measured backgrounds of the sources.
bg_err: Estimated error of the background.
bg_npix: The number of pixels used in determining the background.
- Return type:
(scipy field array)
- astrowisp.utils.explore_prf.get_source_positions(catalogue_fname, trans_fname, image_resolution)[source]
Return [(x, y), …] positions of the sources in the image.
- Parameters:
catalogue_fname (str) – The filename of a catalogue query containing all sources in the image (could contain more).
trans_fname (str) – The filename of the grtrans file for transforming tan-projected (xi, eta) to image positions.
image_resolution ((x_res, y_res)) – The resolution of the input image. Used to determine which sources project outside the image.
- Returns:
A list of the (x, y) positions of the sources in the image.
- Return type:
- astrowisp.utils.explore_prf.get_trans_fname(frame_fname, trans_pattern)[source]
Return the filename of the trans file corresponding to a given frame.
- astrowisp.utils.explore_prf.list_plot_filenames(cmdline_args)[source]
List the filenames of all the plots that will be generated.
- astrowisp.utils.explore_prf.pad_prf_data(prf_data, cmdline_args)[source]
Return PRF data zero-padded for fitting and the spline fit domain.
- astrowisp.utils.explore_prf.parse_command_line(parser=None, assume_sources=False, add_config_file=True, add_frame_arg=True)[source]
Return the command line arguments as attributes of an object.
- Parameters:
parser (ArgumentParser) – If not None, should be a valid command line parser to which further arguments are addded by this method.
- Returns:
See ArgumentParser.parse_args().
- astrowisp.utils.explore_prf.plot_3d_prf(cmdline_args, meshgrid_x, meshgrid_y, prf_slice_splines)[source]
Plot a 3D slice of the PRF.
- Parameters:
cmdline_args – The parse command line configuration.
meshgrid_x – The meshgrid generated for evaluating the PRF made from the grid points of the star_shape_grid
meshgrid_y – The meshgrid generated for evaluating the PRF made from the grid points of the star_shape_grid
prf_slice_splines – The evaluated PRF at the meshgrid points extracted from slice_splines
- Returns:
None
- astrowisp.utils.explore_prf.plot_entire_prf(cmdline_args, image_slices, grid_x, grid_y, sources=None)[source]
Plots the entire PRF on a 3d axes and displays it to the user.
- Parameters:
cmdline_args – The parsed command line arguments.
image_slices – How to split the image when plotting (the return value of get_image_slices())
grid_x – The PSF x-grid, pulled from star_shape_grid
grid_y – The PSF y-grid, pulled from star_shape_grid
sources (scipy.array or None) – If not None, it should be an array with equivalent structure to get_source_info(). If None, get_source_info() is used to initialize it.
- Returns:
None
- astrowisp.utils.explore_prf.plot_prf_slice(prf_data, spline, *, label, x_offset=None, y_offset=None, thickness=0.1, error_scale=0.1, points_color='k', marker_size=2, **binning)[source]
Plot a slice of the PRF.
- Parameters:
prf_data – The return value of get_prf_data().
x_offset/y_offset (float) – Plot a slice of constant x or y (determined by the argument name) offset from the source center.
thickness (float) – Points with x or y within thickness of the specified offset are included in the plot.
error_scale (float) – See –error-scale command line argument.
error_threshold (float) – See –error-threshold command line argument.
- Returns:
None
- astrowisp.utils.explore_prf.show_plots(slice_prf_data, slice_splines, cmdline_args, append=False)[source]
Generate the plots and display them to the user.
- Parameters:
slice_prf_data (iterable) – List of the result of either get_prf_data() or pad_prf_data() for each image slice.
slice_splines (iterable) – List of best-fit splines to the data for each image slice. Must support evaluation using arrays of x & y positions.
cmdline_args – The parsed command line arguments.
- Returns
None