openformat.mims package

openformat.mims.apply_mask(data, mask, replacement_values)

Replace all values in data by replacement_values where mask is True.

Parameters
  • data (np.ndarray) – data tensor with shape (n, p, w, h), where n is the number of frames, p is the number of detectors, w is the width, and h is the height

  • mask (np.ndarray) – binary mask of hot pixels with shape (n, w, h)

  • replacement_values (np.ndarray) – tensor of replacement values with the same shape as data, a list of the same length as non-zero elements in mask, or a scalar

openformat.mims.apply_translations(data, translations, padding=8)

Apply the sequence of translations to the data.

Parameters
  • data (np.ndarray) – data tensor with shape (n, p, w, h), where n is the number of frames, p is the number of detectors, w is the width, and h is the height

  • translations (np.ndarray) – sequence of translations that should be applied to align the images

Returns

translated – translated data tensor with shape (n, p, w + 2 * padding, h + 2 * padding)

Return type

np.ndarray

openformat.mims.infer_hot_pixels(data, num_outliers, kernel_size=3, outlier_factor=3, min_count=1, max_repeat_fraction=0.1, num_nonzero=None, return_filtered=False)

Identify hot pixels due to correlated noise.

Parameters
  • data (np.ndarray) – data tensor with shape (n, p, w, h), where n is the number of frames, p is the number of detectors, w is the width, and h is the height

  • num_outliers (int) – number of times a pixel needs to be labelled as an outlier in different detectors to be considered correlated noise

  • kernel_size (int) – size of the kernel used for median filtering

  • outlier_factor (float) – factor multiplying the median-filtered image to define the threshold that serves to flag a pixel as an outlier

  • min_count (float) – minimum count used to determine the threshold if the median-filtered image is smaller

  • max_repeat_fraction (float) – maximum fraction of frames in which a pixel is allowed to be a hot pixel. If a pixel is a hot pixel candidate in more than max_repeat_fraction of all frames, it is not considered a hot pixel.

  • num_nonzeros (int) – number of detectors in which a hot pixel candidate must be non-zero. Default is all detectors.

  • return_filtered (bool) – whether to return the median-filtered image

Returns

mask – binary mask of hot pixels with shape (n, w, h)

Return type

np.ndarray

openformat.mims.infer_translations(data, padding=8, method='sequential')

Infer translations between successive frames to increase sharpness of aggregated nanoSIMS images.

Parameters
  • data (np.ndarray) – data tensor for a single detector with shape (n, w, h), where n is the number of frames, w is the width, and h is the height

  • padding (int) – padding applied to the data tensor before computing correlations

  • method (str) – method used to align different frames. ‘sequential’ aggregates frames in order and aligns successive frames with the current best aggregate.

Returns

translations – sequence of translations that should be applied to align the images

Return type

np.ndarray

openformat.mims.load_mims(filename, byte_order='<', roll_data=True)

Load a multi-isotope imaging mass spectrometry (MIMS) file.

Note

This function returns a dictionary with keys listed in the Returns section.

Parameters
  • filename (str) – path to the MIMS file with .im extension

  • byte_order (str) – byte order of the encoded binary data

  • roll_data (bool) – whether to roll image data along the last two dimenions. Rolling the image fixes an issue with Cameca’s encoding of pixel positions.

Returns

  • def_analysis (Def_analysis) – information about the analysis performed. See [fmt] for details.

  • def_analysis_bis (Def_analysis_bis) – additional information about the analysis peformed. See [fmt] for details.

  • mask_im (Mask_im) – image acquisition information. See [fmt] for details.

  • tab_mass (list[Tab_mass]) – information about the detectors and masses. See [fmt] for details.

  • cal_cond (Cal_cond) – information about the conditions for data acquisition. See [fmt] for details.

  • poly_list (Poly_list) – header for element information. See [fmt] for details.

  • polyatomique (list[Polyatomique]) – sequence of element information containers. See [fmt] for details.

  • mask_nano (Mask_nano) – data acquisition information. See [fmt] for details.

  • tab_Bfield_nano (tab_Bfield_nano) – information about the magnetic field. See [fmt] for details.

  • anal_param_nano (Anal_param_nano) – parameters for the analysis. See [fmt] for details.

  • anal_param_nano_bis (Anal_param_nano_bis) – additional parameters for the analysis. See [fmt] for details.

  • _anal_param (bytes) – unparsed value

  • _setup_soft (bytes) – unparsed value

  • header_image (Header_image) – information regarding images. See [fmt] for details.

  • data (np.ndarray) – data tensor with shape (n, p, w, h), where n is the number of frames, p is the number of detectors, w is the width, and h is the height

References

fmt(1,2,3,4,5,6,7,8,9,10,11,12)

Alain Morgand. “Format File N50 V7”, https://www.dropbox.com/sh/gyss2uvv5ggu2vl/AACkLTMRfKjZj3PEt3H_PxY_a/manual?preview=Format+File+N50+V7.doc

openformat.mims.process_image_data(filename, alignment_detector, padding=8, load_mims_kwargs=None, remove_hot_pixels_kwargs=None, infer_translations_kwargs=None)

Process a raw .im file, remove hot pixels, and align the frames of each image. Returns a dictionary of cleaned aligned data and relevent information.

Note

This function returns a dictionary with keys listed in the Returns section.

Parameters
  • filename (str) – path to the MIMS file with .im extension

  • alignment_detector (str) – the element or element combination to use for frame alignment e.g. ‘12C 14N’ or ‘32Se’

  • padding (int) – number of border pixels to allow image shifts without data loss

  • load_mims_kwargs (dict, optional) – dictionary with keywords passed to the load_mims() call used to load the raw data

  • remove_hot_pixel_kwargs (dict, optional) – dictionary with keywords passed to the remove_hot_pixels() call used to remove hot pixels from the dataset

  • infer_translations_kwargs (dict, optional) – dictionary with keywords passed to the infer_translations() call used to calculate image alignment shifts

Returns

  • total_lookup (dict) – cleaned, aligned detector data keyed by detector name

  • detector_names (list) – sequence of detector names

  • cleaned (list) – sequence of detector data with hot pixels replaced by median-filtered pixels

  • translations (np.array) – sequence of horizontal and vertical translations to align different scans

  • aligned (list) – sequence of aligned detector data

  • image_shape (tuple) – width and height of the image in pixels

  • image_size (tuple) – width and height of the image in micrometers

  • pixel_size (float) – size of each pixel in micrometers

  • alignment_detector_index (int) – index of detector used for aligning different scans

  • se_detector_index (int) – index of the detector collecting secondary electron data

openformat.mims.remove_hot_pixels(data, num_outliers=3, kernel_size=3, outlier_factor=1.999, min_count=0.5, max_repeat_fraction=0.1, num_nonzero=None)

Remove hot pixels due to correlated noise.

Parameters
  • data (np.ndarray) – data tensor with shape (n, p, w, h), where n is the number of frames, p is the number of detectors, w is the width, and h is the height

  • num_outliers (int) – number of times a pixel needs to be labelled as an outlier in different detectors to be considered correlated noise

  • kernel_size (int) – size of the kernel used for median filtering

  • outlier_factor (float) – factor multiplying the median-filtered image to define the threshold that serves to flag a pixel as an outlier

  • min_count (float) – minimum count used to determine the threshold if the median-filtered image is smaller

  • max_repeat_fraction (float) – maximum fraction of frames in which a pixel is allowed to be a hot pixel. If a pixel is a hot pixel candidate in more than max_repeat_fraction of all frames, it is not considered a hot pixel.

  • num_nonzeros (int) – number of detectors in which a hot pixel candidate must be non-zero. Default is all detectors.

Returns

cleaned – cleaned data tensor with the same shape as data with hot pixels replaced by median-filtered pixels

Return type

np.ndarray

openformat.mims.structures module

This module contains structures to load MIMS data. See 1 for general information and 2 for a specific reference.

1

Utrecht University. “nanosims-wiki”, http://nanosims.geo.uu.nl/nanosims-wiki/

2

Alain Morgand. “Format File N50 V7”, https://www.dropbox.com/sh/gyss2uvv5ggu2vl/AACkLTMRfKjZj3PEt3H_PxY_a/manual?preview=Format+File+N50+V7.doc

class openformat.mims.structures.Anal_param_nano

Bases: openformat.util.Structure

It contains analytical parameters information.

validate()

Validate the structure.

class openformat.mims.structures.Anal_param_nano_bis

Bases: openformat.util.Structure

It contains new analytical parameters information.

validate()

Validate the structure.

class openformat.mims.structures.ApParamPreset

Bases: openformat.util.Structure

It contains Parameter for Preset information.

class openformat.mims.structures.ApPresetDef

Bases: openformat.util.Structure

It contains Preset definition.

class openformat.mims.structures.ApPresetLens

Bases: openformat.util.Structure

It contains Preset Lens definition.

validate()

Validate the structure.

class openformat.mims.structures.ApPresetSlit

Bases: openformat.util.Structure

It contains Preset Slit definition.

validate()

Validate the structure.

class openformat.mims.structures.Ap_primary_nano

Bases: openformat.util.Structure

It contains primary analytical parameters information.

class openformat.mims.structures.Ap_secondary_nano

Bases: openformat.util.Structure

It contains secondary analytical parameters information.

class openformat.mims.structures.AutoCal

Bases: openformat.util.Structure

It contains mass calibration information.

class openformat.mims.structures.Cal_cond

Bases: openformat.util.Structure

It contains acquired mass condition information.

class openformat.mims.structures.Champs_list

Bases: openformat.util.Structure

It contains Autocalibration field list information.

validate()

Validate the structure.

class openformat.mims.structures.Couple

Bases: openformat.util.Structure

It contains couple data information.

class openformat.mims.structures.Crater

Bases: openformat.util.Structure

It contains crater information.

class openformat.mims.structures.Def_analysis

Bases: openformat.util.Structure

It contains definition information.

class openformat.mims.structures.Def_analysis_bis

Bases: openformat.util.Structure

validate()

Validate the structure.

class openformat.mims.structures.Def_eps

Bases: openformat.util.Structure

It contains IMS EPS definition information.

class openformat.mims.structures.E0S_Nano

Bases: openformat.util.Structure

It contains the E0S Centering parameter information.

class openformat.mims.structures.Energy_Nano

Bases: openformat.util.Structure

It contains the Energy Centering parameter information.

class openformat.mims.structures.Header_image

Bases: openformat.util.Structure

It contains images information.

validate()

Validate the structure.

class openformat.mims.structures.HvCont

Bases: openformat.util.Structure

It contains Hv control information.

class openformat.mims.structures.Mask_dp

Bases: openformat.util.Structure

It contains isotop acquisition information.

class openformat.mims.structures.Mask_im

Bases: openformat.util.Structure

validate()

Validate the structure.

class openformat.mims.structures.Mask_ls

Bases: openformat.util.Structure

It contains linescan acquisition information.

class openformat.mims.structures.Mask_nano

Bases: openformat.util.Structure

It contains the acquisition definition information.

class openformat.mims.structures.Offset_list

Bases: openformat.util.Structure

It contains Hv control offset list information.

validate()

Validate the structure.

class openformat.mims.structures.PHD_Trolley_Nano

Bases: openformat.util.Structure

It contains the PHD Scan parameter information.

class openformat.mims.structures.Poly_list

Bases: openformat.util.Structure

It contains header of polyatomic informations.

validate()

Validate the structure.

class openformat.mims.structures.Polyatomique

Bases: openformat.util.Structure

It contains polyatomic information.

class openformat.mims.structures.Sec_Ion_Beam_Nano

Bases: openformat.util.Structure

It contains the Secondary Ion Beam Centering parameter information.

class openformat.mims.structures.SigRef

Bases: openformat.util.Structure

It contains reference signal information.

class openformat.mims.structures.SigRefExp

Bases: openformat.util.Structure

It contains expanded structure for SigRef information.

class openformat.mims.structures.SigRefMulti

Bases: openformat.util.Structure

It contains multi reference signal information.

class openformat.mims.structures.Tab_BField_nano

Bases: openformat.util.Structure

It contains the B field information.

class openformat.mims.structures.Tab_Trolley_nano

Bases: openformat.util.Structure

It contains the Trolley information.

class openformat.mims.structures.Tab_elts

Bases: openformat.util.Structure

It contains elements information.

class openformat.mims.structures.Tab_mass

Bases: openformat.util.Structure

It contains acquired mass information.