pwspy.dataTypes.RoiFile

class pwspy.dataTypes.RoiFile(name, number, roi, filePath, fileFormat, acquisition)[source]

Bases: object

This class represents a single Roi File used to save and load an ROI. Each Roi File is identified by a name and a number. The recommended file format is HDF2, in this format multiple rois of the same name but differing numbers can be saved in a single HDF file.

Parameters
  • name (str) – The name used to identify this ROI. Multiple ROIs can share the same name but must have unique numbers.

  • number (int) – The number used to identify this ROI. Each ROI with the same name must have a unique number.

  • roi (Roi) – The ROI object associated with this file.

  • filePath (str) – The path to the file that this object was loaded from.

  • fileFormat (FileFormats) – The format of the file that this object was loaded from.

  • acquisition (Acquisition) – The acquisition object that this ROI belongs to.

class FileFormats(value)[source]

Bases: enum.Enum

An enumerator of the different file formats that an ROI can be saved to.

delete()[source]

Delete the dataset associated with the Roi object.

static deleteRoi(directory, name, number, fformat=None)[source]

Delete the dataset associated with the Roi object specified by name and num.

Parameters
  • directory (str) – The path to the folder containing the Roi file.

  • name (str) – The name used to identify this ROI.

  • number (int) – The number used to identify this ROI.

  • fformat (Optional[FileFormats]) – The format of the file.

Raises

FileNotFoundError – If the file isn’t found.

classmethod fromHDF(directory, name, number, acquisition=None)[source]

Load an Roi from the newest ROI format of HDF file.

Parameters
  • directory (str) – The path to the directory containing the HDF file.

  • name (str) – The name used to identify this ROI.

  • number (int) – The number used to identify this ROI.

Raises

OSError – If the file was not found

Return type

RoiFile

Returns

A new instance of Roi loaded from file

Examples

myRoi = Roi.fromHDF(‘~/Desktop’, ‘nucleus’, 1)

classmethod fromHDF_legacy(directory, name, number, acquisition=None)[source]

Load an Roi from an HDF file. Uses the old HDF2 format.

Parameters
  • directory (str) – The path to the directory containing the HDF file.

  • name (str) – The name used to identify this ROI.

  • number (int) – The number used to identify this ROI.

Raises

OSError – If the file was not found

Return type

RoiFile

Returns

A new instance of Roi loaded from file

Examples

myRoi = Roi.fromHDF(‘~/Desktop’, ‘nucleus’, 1)

classmethod fromHDF_legacy_legacy(directory, name, number, acquisition=None)[source]

Load an Roi from an older version of the HDF file format which did not include the vertices parameter.

Parameters
  • directory (str) – The path to the directory containing the HDF file.

  • name (str) – The name used to identify this ROI.

  • number (int) – The number used to identify this ROI.

Raises

OSError – If the file was not found

Return type

RoiFile

Returns

A new instance of Roi loaded from file

classmethod fromMat(directory, name, number, acquisition=None)[source]

Load an Roi from a .mat file saved in matlab. This file format is not recommended as it does not include the vertices parameter which is useful for visually rendering and readjusting the Roi.

Parameters
  • directory (str) – The path to the directory containing the HDF file.

  • name (str) – The name used to identify this ROI.

  • number (int) – The number used to identify this ROI.

Return type

RoiFile

Returns

A new instance of Roi loaded from file

getRoi()[source]

Return the ROI object associated with this file.

Return type

Roi

Returns

The Roi object containing geometry information.

static getValidRoisInPath(path)[source]

Search the path for valid roiFile files and return the detected rois as a list of tuple where each tuple contains the name, number, and file format for the Roi.

Parameters

path (str) – The path to the folder containing the Roi files.

Returns

name: The detected Roi name number: The detected Roi number fformat: The file format of the file that the Roi is stored in

Return type

A list of tuples containing

classmethod loadAny(directory, name, number, acquisition=None)[source]

Attempt loading any of the known file formats.

Parameters
  • directory (str) – The path to the directory containing the HDF file.

  • name (str) – The name used to identify this ROI.

  • number (int) – The number used to identify this ROI.

Return type

RoiFile

Returns

A new instance of Roi loaded from file

classmethod toHDF(roi, name, number, directory, overwrite=False, acquisition=None)[source]

Save the Roi to an HDF file in the specified directory. The filename is automatically chosen based on the name parameter of the Roi. Multiple Roi’s with the same name will be saved into the same file if they have differing number parameters. If overwrite is true then any existing dataset will be replaced, otherwise an error will be raised.

Parameters
  • roi (Roi) – The ROI to save.

  • name (str) – The name name to save as. This will be part of the file name

  • number (int) – The ROI number to save as. Multiple ROIS of the same name can be saved to the same file but the numbers must be unique

  • directory (str) – The path of the folder to save the new HDF file to. The file will be named automatically based on the name attribute of the Roi

  • overwrite (Optional[bool]) – If True then if an Roi with the same number as this Roi is found it will be overwritten.

Return type

RoiFile

update(roi)[source]

Save a new roiFile to the existing file. :type roi: Roi :param roi: The updated ROI to save