solpolpy.util#

Functions#

combine_all_collection_masks(→ numpy.ndarray | None)

Combine all the masks in a given collection.

combine_masks(→ numpy.ndarray | None)

Combine masks.

calculate_pc_matrix() → numpy.ndarray)

Calculate a PC matrix given CROTA and CDELT.

convert_cd_matrix_to_pc_matrix(wcs)

extract_crota_from_wcs(→ astropy.units.deg)

Extract CROTA from a WCS.

indexed_offset(index, distortion, image_shape)

calculate_distortion(distortion, image_shape)

compute_distortion_shift(image_shape, wcs)

Calculate shift in pixels due to optical distortion

apply_distortion_shift(input_image, new_x, new_y, ...)

Apply shift in pixels due to optical distortion

make_empty_distortion_model(num_bins, image, ...)

Create an empty distortion table

collection_to_maps(collection)

Convert an NDCollection to a list of SunPy Map objects.

compute_lats(wcs, shape)

solnorth_from_wcs(input_wcs, shape[, precomputed_lats])

Compute the angle of solar north direction at each pixel using the solar WCS.

Module Contents#

solpolpy.util.combine_all_collection_masks(collection: ndcube.NDCollection) numpy.ndarray | None[source]#

Combine all the masks in a given collection.

solpolpy.util.combine_masks(*args) numpy.ndarray | None[source]#

Combine masks.

If any of the masks are None, the result is None. Otherwise, when combining any value that is masked in any of the input args, gets masked, i.e. it does a logical or.

solpolpy.util.calculate_pc_matrix(crota: float, cdelt: float, float) numpy.ndarray[source]#

Calculate a PC matrix given CROTA and CDELT.

Parameters:
  • crota (float) – rotation angle from the WCS

  • cdelt (float) – pixel size from the WCS

Returns:

PC matrix

Return type:

np.ndarray

solpolpy.util.convert_cd_matrix_to_pc_matrix(wcs)[source]#
solpolpy.util.extract_crota_from_wcs(wcs: astropy.wcs.WCS) astropy.units.deg[source]#

Extract CROTA from a WCS.

solpolpy.util.indexed_offset(index, distortion, image_shape)[source]#
solpolpy.util.calculate_distortion(distortion, image_shape)[source]#
solpolpy.util.compute_distortion_shift(image_shape, wcs: astropy.wcs.WCS)[source]#

Calculate shift in pixels due to optical distortion

Parameters:
  • image_shape (Tuple(int, int)) – shape of input image

  • wcs (WCS) – WCS from input object

Returns:

Tuple containing new x-coordinates, new y-coordinates, valid mask, original i-coordinates, and original j-coordinates.

Return type:

tuple (np.ndarray, np.ndarray, np.ndarray, np.ndarray, np.ndarray)

solpolpy.util.apply_distortion_shift(input_image, new_x, new_y, valid_mask, i_coords, j_coords)[source]#

Apply shift in pixels due to optical distortion

Parameters:
  • input_image (np.ndarray) – input image on which shift to be applied

  • new_x (np.ndarray) – The precomputed new x-coordinates after distortion.

  • new_y (np.ndarray) – The precomputed new y-coordinates after distortion.

  • valid_mask (np.ndarray) – Boolean mask indicating valid shifts within bounds.

  • i_coords (np.ndarray) – Original i-coordinates of pixels frpm input_image.

  • j_coords (np.ndarray) – Original j-coordinates of pixels from input_image.

Returns:

Image after applying the distortion shifts.

Return type:

np.ndarray

solpolpy.util.make_empty_distortion_model(num_bins: int, image: numpy.ndarray)[source]#

Create an empty distortion table

Parameters:
  • num_bins (int) – number of histogram bins in the distortion model, i.e. the size of the distortion model is (num_bins, num_bins)

  • image (np.ndarray) – image to create a distortion model for

Returns:

x and y distortion models

Return type:

(DistortionLookupTable, DistortionLookupTable)

solpolpy.util.collection_to_maps(collection)[source]#

Convert an NDCollection to a list of SunPy Map objects.

Parameters:#

ndcollectionNDCollection

The NDCollection containing data, metadata and wcs.

Returns:#

list of sunpy.map.Map

A list of SunPy Map objects created from the NDCollection.

solpolpy.util.compute_lats(wcs, shape)[source]#
solpolpy.util.solnorth_from_wcs(input_wcs, shape, precomputed_lats=None)[source]#

Compute the angle of solar north direction at each pixel using the solar WCS.

Parameters:
  • input_wcs (astropy.wcs.WCS) – WCS object with solar projection (e.g., Helioprojective).

  • shape (tuple) – Shape of the image as (nrows, ncols).

Returns:

angle_solar_north – Angle in degrees from +Y image axis to solar north at each pixel (measured counterclockwise).

Return type:

2D numpy.ndarray