micropolarray package

Subpackages

Submodules

micropolarray.cameras module

class micropolarray.cameras.Antarticor[source]

Bases: object

class micropolarray.cameras.Camera[source]

Bases: object

occulter_mask(overoccult: int = 0, rmax: int | None = None) array[source]

Returns an array of True inside the roi, False elsewhere. Useful for mean/std operations (where=occulter_mask).

Parameters:
  • overoccult (int, optional) – Pixels to overoccult. Defaults to 15.

  • rmax (int, optional) – Maximum r of the ROI. Defaults to image nearest border.

Returns:

Boolean roi array

Return type:

np.array

occulter_roi(data: array, fill: float = 0.0, overoccult: int = 0) array[source]

Returns the array in the polar ROI, else fill

Parameters:
  • data (np.array) – Input array

  • fill (float, optional) – Value for filling. Defaults to 0.0.

  • overoccult (int, optional) – Pixels to overoccult. Defaults to 0.

Returns:

Array if in ROI, fill elsewhere

Return type:

np.array

class micropolarray.cameras.Kasi[source]

Bases: Camera

class micropolarray.cameras.PolarCam[source]

Bases: Camera

micropolarray.image module

class micropolarray.image.Image(initializer: str | np.ndarray | Image, averageimages: bool = True)[source]

Bases: object

Basic image class. Can be initialized from a filename, a filenames list, a numpy array or another Image instance. If multiple filenames are provided, will perform the mean of them unless averageimages is False.

property data: ndarray
save_as_fits(filename: str, fixto: str[float, float] = None)[source]

Saves image as fits with current header

Parameters:
  • filename (str) – output filename

  • fixto (str[float, float], optional) – Set a maximum and minimum range for the data. Defaults to None.

Raises:

ValueError – filename does not end with “.fits”

save_as_raw(filename: str)[source]

Saves the image as a raw binary file

Parameters:

filename (str) – output filename

Raises:

ValueError – filename does not end with “.raw”

shift(y: int, x: int) Image[source]

Shifts image by y, x pixels and fills with 0 the remaining space. Positive numbers for up/right shift and negative for down/left shift.

Parameters:
  • y (int) – vertical shift in pix

  • x (int) – horizontal shift in pix

Returns:

shifted image copied from the original

Return type:

Image

show(cmap='Greys_r', vmin=None, vmax=None, **kwargs) tuple[source]

Shows the image data

Parameters:
  • cmap (str, optional) – figure colorbar. Defaults to “Greys_r”.

  • vmin (_type_, optional) – Minimum value to plot. Defaults to None.

  • vmax (_type_, optional) – Maximum value to plot. Defaults to None.

Returns:

fig, ax tuple as returned by matplotlib.pyplot.subplots

Return type:

tuple

show_histogram(split_pols=False, **kwargs) tuple[source]

Print the histogram of the flattened image data

Parameters:

**kwargs (int, optional) – arguments to pass to numpy.histogram(), like bins and range.

Returns:

fig, ax tuple as returned by matplotlib.pyplot.subplots

Return type:

tuple

micropolarray.micropol_image module

class micropolarray.micropol_image.MicropolImage(initializer: str | np.ndarray | list | MicropolImage, angle_dic: dict = None, dark: MicropolImage = None, flat: MicropolImage = None, averageimages: bool = True)[source]

Bases: Image

Micro-polarizer array image class. Can be initialized from a 2d array, a list of 1 or more file names (use the boolean keyword averageimages to select if sum or average is taken) or another MicropolImage. Dark and flat micropolarray images can also be provided to automatically correct the result.

property AoLP: PolParam
property DoLP: PolParam
property I: PolParam
property Q: PolParam
property U: PolParam
clean_hot_pixels(flagged_hot_pix_map: MicropolImage)[source]

Returns a copy of the image with gaussian smeared pixels where flagged_hot_pix_map == 1.

Parameters:

flagged_hot_pix_map (MicropolImage) – hot pixels map.

Returns:

copy of the original image, gaussian smeared where flagged_hot_pix_map == 1

Return type:

MicropolImage

congrid(newdim_y: int, newdim_x: int) MicropolImage[source]

Reshapes a MicropolImage into any new lenght and width. This is done separately for each pixel family.

Parameters:
  • newdim_y (int) – new height

  • newdim_x (int) – new width

Returns:

image with reshaped data.

Return type:

MicropolImage

correct_flat(flat: MicropolImage) MicropolImage[source]

Normalizes the flat and uses it to correStokes_vecct the image.

Parameters:

flat (MicropolImage) – flat image, does not need to be normalized.

Returns:

copy of input image corrected by flat

Return type:

MicropolImage

correct_ifov() MicropolImage[source]

Corrects differences in single pixels fields of view inside each superpixel

Returns:

image with data corrected for field of view differences

Return type:

MicropolImage

demodulate(demodulator: Demodulator, demosaicing: bool = False) MicropolImage[source]

Returns a MicropolImage with polarization parameters calculated from the demodulation tensor provided.

Parameters:
  • demodulator (Demodulator) – Demodulator object containing the demodulation tensor components (see processing.new_demodulation)

  • demosaicing (bool, optional) – wether to apply demosaicing to the image or not. Set it to False if demodulation matrices have half the dimension of the image. Defaults to True.

Raises:

ValueError – raised if image and demodulator do not have the same dimension, for example in case of different binning

Returns:

copy of the input imagreturn e with I, Q, U, pB, DoLP, AoLP calculated from the demodulation tensor.

Return type:

MicropolImage

demosaic(demosaic_mode='adjacent') MicropolImage[source]

Returns a demosaiced copy of the image with updated polarization parameters. Demoisacing is done IN PLACE and using the THEORETICAL MATRIX. If demodulation and demosaicing are required, please use demodulate(demosaic=True)

Parameters:

demosaic_mode (str, optional) – demosaicing mode (see processing.demosaic). Defaults to “adjacent”.

Returns:

demosaiced image

Return type:

MicropolImage

first_call = True
mask_occulter(y: int = 919, x: int = 941, r: int = 536, overoccult: int = 0) None[source]

Masks occulter for all image parameters

Parameters:
  • y (int, optional) – Occulter y position. Defaults to PolarCam().occulter_pos_last[0].

  • x (int, optional) – Occulter x position. Defaults to PolarCam().occulter_pos_last[1].

  • r (int, optional) – Occulter radius. Defaults to PolarCam().occulter_pos_last[2].

  • overoccult (int, optional) – Pixels to overoccult. Defaults to 0.

  • camera (_type_, optional) – Camera image type. Defaults to PolarCam().

Returns:

None

property pB: PolParam
property pol0: PolParam
property pol45: PolParam
property pol90: PolParam
property pol_45: PolParam
property polparam_list: list
rebin(binning: int) MicropolImage[source]

Rebins the micropolarizer array image, binned each binningxbinning. Sum bins by default.

Parameters:

binning (int) – binning to perform. A value of n will be translated in a nxn binning.

Raises:

ValueError – negative binning provided

Returns:

copy of the input image, rebinned.

Return type:

MicropolImage

rotate(angle: float) MicropolImage[source]

Rotates an image of angle degrees, counter-clockwise.

save_all_pol_params_as_fits(filename: str) None[source]

Saves the image and all polarization parameters as fits file with the same name

Parameters:

filename (str) – filename of the output image. Will be saved as filename_[I, Q, U, pB, AoLP, DoLP].fits

Raises:

ValueError – filename is not a valid .fits file

save_demosaiced_images_as_fits(filename: str, fixto: list[float, float] = None) None[source]

Saves the four demosaiced images as fits files

Parameters:
  • filename (str) – filename of the output image. The four images will be saved as filename_POLXX.fits

  • fixto (list[float, float], optional) – set the minimum and maximum value for the output images. Defaults to None.

Raises:

ValueError – an invalid file name is provided

save_param_as_fits(polparam: str, filename: str, fixto: list[float, float] = None) None[source]

Saves chosen polarization parameter as a fits file

Parameters:
  • polparam (str) – polarization parameter to save. Can be one among [I, Q, U, pB, AoLP, DoLP]

  • filename (str) – filename of the output image.

  • fixto (list[float, float], optional) – set the minimum and maximum value for the output images. Defaults to None.

Raises:

ValueError – filename is not a valid .fits file

save_single_pol_images(filename: str, fixto: list[float, float] = None) None[source]

Saves the four polarized images as fits files

Parameters:
  • filename (str) – filename of the output image. The four images will be saved as filename_POLXX.fits

  • fixto (list[float, float], optional) – set the minimum and maximum value for the output images. Defaults to None.

Raises:

ValueError – an invalid file name is provided

shift(y: int, x: int) MicropolImage[source]

Shifts image by y, x pixels and fills with 0 the remaining space. Positive numbers for up/right shift and negative for down/left shift. Image is split into polarizations, each one is shifted, then they are merged again.

Parameters:
  • y (int) – vertical shift in pix

  • x (int) – horizontal shift in pix

Returns:

shifted image copied from the original

Return type:

MicropolImage

show_demo_images(cmap='Greys_r', vmin=None, vmax=None, **kwargs)[source]

Plots the four demosaiced images.

Parameters:
  • cmap (str, optional) – colormap for the plot. Defaults to “Greys_r”.

  • **kwargs – arguments passed to matplotlib.pyplot.imshow.

Returns:

a (figure, axis) couple same as matplotlib.pyplot.subplots

Return type:

tuple

show_histogram(split_pols: bool = True, **kwargs)[source]

Print the histogram of the flattened image data

Parameters:
  • split_pols (bool, optional) – Whether to overplot histograms of same family pixels separately. Defaults to False.

  • **kwargs (int, optional) – arguments to pass to numpy.histogram(), like bins and range.

Returns:

fig, ax tuple as returned by matplotlib.pyplot.subplots

Return type:

tuple

show_pol_param(polparam: str, cmap='Greys_r', vmin=None, vmax=None, **kwargs)[source]

Plots a single polarization parameter given as input

Parameters:
  • polparam (str) – image PolParam containing the parameter to plot. Can be one among [I, Q, U, pB, AoLP, DoLP]

  • cmap (str, optional) – colormap for the plot. Defaults to “Greys_r”.

  • **kwargs – arguments passed to matplotlib.pyplot.imshow.

Returns:

a (figure, axis) couple same as matplotlib.pyplot.subplots

Return type:

tuple

show_pol_params(cmap='Greys_r', figsize=None, **kwargs) tuple[source]

Returns a tuple containing figure and axis of polarization parameters (3x2 subplots). User must call plt.show after this is called.

Parameters:

cmap (str, optional) – colormap string. Defaults to “Greys_r”.

Returns:

a (figure, axis) couple same as matplotlib.pyplot.subplots for the six polarization parameters

Return type:

tuple

show_single_pol_images(cmap='Greys_r', **kwargs)[source]

Plots the four polarizations images.

Parameters:
  • cmap (str, optional) – colormap for the plot. Defaults to “Greys_r”.

  • **kwargs – arguments passed to matplotlib.pyplot.imshow.

Returns:

a (figure, axis) couple same as matplotlib.pyplot.subplots

Return type:

tuple

show_with_pol_params(cmap='Greys_r') tuple[source]

Returns a tuple containing figure and axis of the plotted data, and figure and axis of polarization parameters (3x2 subplots). User must callplt.show after this is called.

Parameters:

cmap (str, optional) – colormap string. Defaults to “Greys_r”.

Returns:

a (figure, axis, figure, axis) couple same as matplotlib.pyplot.subplots for the image data and another for the six polarization parameters

Return type:

tuple

property single_pol_subimages
subtract_dark(dark: MicropolImage) MicropolImage[source]

Correctly subtracts the input dark image from the image

Parameters:

dark (MicropolImage) – dark to subtract

Returns:

copy of input image with dark subtracted

Return type:

MicropolImage

class micropolarray.micropol_image.PolParam(ID: str, data: ndarray, title: str, measure_unit: str, fix_data: bool = False)[source]

Bases: object

Auxiliary class for polarization parameters.

Members:

ID (str): parameter identifier data (np.array): parameter image as numpy 2D array title (str): brief title of the parameter, useful for plotting measure_unit (str): initial measure units of the parameter fix_data (bool): controls whether data has to be constrained to [0, 4096] interval (not implemented yet)

ID: str
data: ndarray
fix_data: bool = False
measure_unit: str
title: str
micropolarray.micropol_image.set_default_angles(angles_dic: dict)[source]

Sets the default micropolarizer orientations for images.

Parameters:

angles_dic (dict) – dictionary {value : pos} where value is the angle in degrees from -90 to 90 and pos is the pixel position in superpixel, from 0 to 3 (position [y, x], fast index x)

micropolarray.polarization_functions module

micropolarray.polarization_functions.AoLP(Stokes_vec_components)[source]

Angle of linear polarization in [rad]

micropolarray.polarization_functions.DoLP(Stokes_vec_components)[source]

Degree of linear polarization in [%]

micropolarray.polarization_functions.normalize2pi(angles_list)[source]

Normalizes the input angle list in the -90,90 range

Parameters:

angles_list (_type_) – list of input angles in degrees

Returns:

normalized angles

Return type:

_type_

micropolarray.polarization_functions.pB(Stokes_vec_components)[source]

Polarized brighness in [%]

micropolarray.utils module

micropolarray.utils.align_keywords_and_data(header, data, sun_center, platescale, binning=1)[source]

Fixes antarticor keywords and data to reflect each other.

Parameters:
  • header (dict) – fits file header

  • data (ndarray) – data as np array

  • platescale (float) – plate scale in arcsec/pixel

  • binning (int, optional) – binning applied to image. Defaults to 1 (no binning).

Returns:

new fixed header and data

Return type:

header, data

micropolarray.utils.fix_data(data: array, min, max)[source]
micropolarray.utils.get_Bsun_units(diffuser_I: float, texp_image: float = 1.0, texp_diffuser: float = 1.0) float[source]

Returns the conversion unit for expressing brightness in units of sun brightness. Usage is data [units of B_sun] = data[DN] * get_Bsun_units(mean_Bsun_brightness, texp_image, texp_diffuser)

Parameters:
  • mean_sun_brightness (float) – diffuser mean in DN.

  • texp_image (float, optional) – image exposure time. Defaults to 1.0.

  • texp_diffuser (float, optional) – diffuser exposure time. Defaults to 1.0.

Returns:

Bsun units conversion factor

Return type:

float

micropolarray.utils.get_malus_normalization(four_peaks_images, show_hist=False)[source]
micropolarray.utils.mean_minus_std(data: array, stds_n: int = 1) float[source]

Returns the value at the mean - standard deviation for the input data

Parameters:
  • data (np.array) – input data

  • stds_n (int, optional) – number of standard deviations. Defaults to 1.

Returns:

mean value - n*stdevs

Return type:

float

micropolarray.utils.mean_plus_std(data: array, stds_n: int = 1) float[source]

Returns the value at the mean + standard deviation for the input data

Parameters:
  • data (np.array) – input data

  • stds_n (int, optional) – number of standard deviations. Defaults to 1.

Returns:

mean value + n*stdevs

Return type:

float

micropolarray.utils.median_minus_std(data: array, stds_n: int = 1) float[source]

Returns the value at the median - median deviation for the input data

Parameters:
  • data (np.array) – input data

  • stds_n (int, optional) – number of standard deviations. Defaults to 1.

Returns:

median value - n*mediandevs

Return type:

float

micropolarray.utils.median_plus_std(data: array, stds_n: int = 1) float[source]

Returns the value at the median + median deviation for the input data

Parameters:
  • data (np.array) – input data

  • stds_n (int, optional) – number of standard deviations. Defaults to 1.

Returns:

median value + n*mediandevs

Return type:

float

micropolarray.utils.normalize2pi(angles_list)[source]

Returns the list of angles (in degrees) normalized between -90 and 90 degrees.

Parameters:

angles_list (list) – list of angles to normalize

Returns:

list of normalized angles

Return type:

list

micropolarray.utils.sigma_DN(pix_DN)[source]
micropolarray.utils.timer(func)[source]

Use this to time function execution

Parameters:

func (function) – function of which to measure execution time

Module contents