PartSegCore.analysis.calculation_plan

class PartSegCore.analysis.calculation_plan.BaseCalculation(base_prefix, result_prefix, measurement_file_path, sheet_name, calculation_plan, voxel_size, overwrite_voxel_size=False)[source]

Bases: object

Base description of calculation needed for single file

Variables:
  • ~.base_prefix (str) – path prefix which should be used to calculate relative path of processed files

  • ~.result_prefix (str) – path prefix for saving structure

  • ~.measurement_file_path (str) – path to file in which result of measurement should be saved

  • ~.sheet_name (str) – name of sheet in excel file

  • ~.calculation_plan (CalculationPlan) – plan of calculation

  • uuid (str) – ~.uuid of whole calculation

  • ~.voxel_size – default voxel size (for files which do not contains this information in metadata

class PartSegCore.analysis.calculation_plan.Calculation(file_list, base_prefix, result_prefix, measurement_file_path, sheet_name, calculation_plan, voxel_size, overwrite_voxel_size=False)[source]

Bases: BaseCalculation

Description of whole calculation. Extended with list of all files to proceed

Variables:
  • ~.base_prefix (str) – path prefix which should be used to calculate relative path of processed files

  • ~.result_prefix (str) – path prefix for saving structure

  • ~.measurement_file_path (str) – path to file in which result of measurement should be saved

  • ~.sheet_name (str) – name of sheet in excel file

  • ~.calculation_plan (CalculationPlan) – plan of calculation

  • uuid (str) – ~.uuid of whole calculation

  • ~.voxel_size – default voxel size (for files which do not contains this information in metadata

  • ~.file_list (List[str]) – list of files to be proceed

get_base_calculation()[source]

Extract py:class:BaseCalculation from instance.

Return type:

BaseCalculation

class PartSegCore.analysis.calculation_plan.CalculationPlan(tree=None, name='')[source]

Bases: object

Clean description Calculation plan.

static get_el_name(el)[source]
Parameters:

el – Plan element

Returns:

str

get_list_file_mask()[source]
Returns:

list[MaskMapper]

get_mask_names(node=None)[source]
Parameters:

node (CalculationTree) –

Returns:

set[str]

get_measurements(node=None)[source]

Get all measurement Calculation below given node

Parameters:

node (Optional[CalculationTree]) – Node for start, if absent then start from plan root

Return type:

List[MeasurementCalculate]

Returns:

list of measurements

get_node(search_pos=None, parent=False)[source]
Parameters:

search_pos (Optional[List[int]]) –

Return type:

CalculationTree

Returns:

CalculationTree

class PartSegCore.analysis.calculation_plan.CalculationTree(operation, children)[source]

Bases: object

Structure for describe calculation structure

class PartSegCore.analysis.calculation_plan.FileCalculation(file_path, calculation)[source]

Bases: object

Description of single file calculation

property base_prefix

path prefix which should be used to calculate relative path of processed files

property calculation_plan

plan of calculation

property overwrite_voxel_size

overwrite voxel size

property result_prefix

path prefix for saving structure

property uuid

uuid of whole calculation

property voxel_size

default voxel size (for files which do not contains this information in metadata

pydantic model PartSegCore.analysis.calculation_plan.MaskBase[source]

Bases: BaseModel

Base class for mask in calculation plan.

Variables:

~.name (str) – name of mask

Show JSON schema
{
   "title": "MaskBase",
   "description": "Base class for mask in calculation plan.\n\n:ivar str ~.name: name of mask",
   "type": "object",
   "properties": {
      "name": {
         "title": "Name",
         "type": "string"
      }
   },
   "additionalProperties": false,
   "required": [
      "name"
   ]
}

Config:
  • extra: str = forbid

Fields:
field name: str [Required]
model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

pydantic model PartSegCore.analysis.calculation_plan.MaskCreate[source]

Bases: MaskBase

Description of mask creation in calculation plan.

Variables:

Show JSON schema
{
   "title": "MaskCreate",
   "description": "Description of mask creation in calculation plan.\n\n:ivar str ~.name: name of mask\n:ivar str ~.mask_property: instance of :py:class:`.MaskProperty`",
   "type": "object",
   "properties": {
      "name": {
         "title": "Name",
         "type": "string"
      },
      "mask_property": {
         "$ref": "#/$defs/MaskProperty"
      }
   },
   "$defs": {
      "MaskProperty": {
         "additionalProperties": false,
         "description": "Description of creation mask from segmentation\n\n:ivar RadiusType ~.dilate: Select dilation mode.\n:ivar int ~.dilate_radius: Radius of dilation calculate with respect of image spacing.\n:ivar RadiusType ~.fill_holes: Select if fill holes and if it should be done in 2d or 3d.\n:ivar int ~.max_holes_size: Maximum holes size if positive. Otherwise fill all holes.\n:ivar bool ~.save_components: If mask should save components of segmentation or set to 1.\n:ivar bool ~.clip_to_mask: If resulted should be clipped to previous mask (if exist).\n    Useful for positive dilate radius\n:ivar bool ~.reversed_mask: If mask should be reversed (region which are not part of segmentation)",
         "properties": {
            "dilate": {
               "$ref": "#/$defs/RadiusType"
            },
            "dilate_radius": {
               "title": "Dilate Radius",
               "type": "integer"
            },
            "fill_holes": {
               "$ref": "#/$defs/RadiusType"
            },
            "max_holes_size": {
               "title": "Max Holes Size",
               "type": "integer"
            },
            "save_components": {
               "title": "Save Components",
               "type": "boolean"
            },
            "clip_to_mask": {
               "title": "Clip To Mask",
               "type": "boolean"
            },
            "reversed_mask": {
               "default": false,
               "title": "Reversed Mask",
               "type": "boolean"
            }
         },
         "required": [
            "dilate",
            "dilate_radius",
            "fill_holes",
            "max_holes_size",
            "save_components",
            "clip_to_mask"
         ],
         "title": "MaskProperty",
         "type": "object"
      },
      "RadiusType": {
         "description": "If operation should be performed and if on each layer separately on globally",
         "enum": [
            0,
            1,
            2
         ],
         "title": "RadiusType",
         "type": "integer"
      }
   },
   "additionalProperties": false,
   "required": [
      "name",
      "mask_property"
   ]
}

Config:
  • extra: str = forbid

Fields:
field mask_property: MaskProperty [Required]
model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

pydantic model PartSegCore.analysis.calculation_plan.MaskFile[source]

Bases: MaskMapper

Show JSON schema
{
   "title": "MaskFile",
   "type": "object",
   "properties": {
      "name": {
         "title": "Name",
         "type": "string"
      },
      "path_to_file": {
         "title": "Path To File",
         "type": "string"
      },
      "name_dict": {
         "anyOf": [
            {
               "type": "object"
            },
            {
               "type": "null"
            }
         ],
         "default": null,
         "title": "Name Dict"
      }
   },
   "additionalProperties": false,
   "required": [
      "name",
      "path_to_file"
   ]
}

Config:
  • extra: str = forbid

Fields:
field name_dict: Optional[dict] = None
field path_to_file: str [Required]
get_mask_path(file_path)[source]

Calculate mask path based od file_path

Parameters:

file_path (str) – path to proceeded file

Return type:

str

get_parameters()[source]

Parameters for serialize

is_ready()[source]

Check if this mask mapper can be used

Return type:

bool

parse_map(sep=';')[source]
set_map_path(value)[source]
model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

pydantic model PartSegCore.analysis.calculation_plan.MaskIntersection[source]

Bases: MaskBase

Description of AND operation on mask

Variables:
  • ~.name (str) – name of mask

  • ~.mask1 (str) – first mask name

  • ~.mask2 (str) – second mask name

Show JSON schema
{
   "title": "MaskIntersection",
   "description": "Description of AND operation on mask\n\n:ivar str ~.name: name of mask\n:ivar str ~.mask1: first mask name\n:ivar str ~.mask2: second mask name",
   "type": "object",
   "properties": {
      "name": {
         "title": "Name",
         "type": "string"
      },
      "mask1": {
         "title": "Mask1",
         "type": "string"
      },
      "mask2": {
         "title": "Mask2",
         "type": "string"
      }
   },
   "additionalProperties": false,
   "required": [
      "name",
      "mask1",
      "mask2"
   ]
}

Config:
  • extra: str = forbid

Fields:
field mask1: str [Required]
field mask2: str [Required]
model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

pydantic model PartSegCore.analysis.calculation_plan.MaskMapper[source]

Bases: BaseModel

Base class for obtaining mask from computer disc

Variables:

~.name – mask name

Show JSON schema
{
   "title": "MaskMapper",
   "description": "Base class for obtaining mask from computer disc\n\n:ivar ~.name: mask name",
   "type": "object",
   "properties": {
      "name": {
         "title": "Name",
         "type": "string"
      }
   },
   "additionalProperties": false,
   "required": [
      "name"
   ]
}

Config:
  • extra: str = forbid

Fields:
field name: str [Required]
abstract get_mask_path(file_path)[source]

Calculate mask path based od file_path

Parameters:

file_path (str) – path to proceeded file

Return type:

str

abstract get_parameters()[source]

Parameters for serialize

static is_ready()[source]

Check if this mask mapper can be used

Return type:

bool

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

pydantic model PartSegCore.analysis.calculation_plan.MaskSub[source]

Bases: MaskMapper

Description of mask form file obtained by substitution

Variables:
  • ~.name (str) – mask name

  • ~.base (str) – string to be searched

  • ~.repr (str) – string to be put instead of base

Show JSON schema
{
   "title": "MaskSub",
   "description": "Description of mask form file obtained by substitution\n\n:ivar str ~.name: mask name\n:ivar str ~.base: string to be searched\n:ivar str ~.repr: string to be put instead of ``base``",
   "type": "object",
   "properties": {
      "name": {
         "title": "Name",
         "type": "string"
      },
      "base": {
         "title": "Base",
         "type": "string"
      },
      "rep": {
         "title": "Rep",
         "type": "string"
      }
   },
   "additionalProperties": false,
   "required": [
      "name",
      "base",
      "rep"
   ]
}

Config:
  • extra: str = forbid

Fields:
field base: str [Required]
field rep: str [Required]
get_mask_path(file_path)[source]

Calculate mask path based od file_path

Parameters:

file_path (str) – path to proceeded file

Return type:

str

get_parameters()[source]

Parameters for serialize

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

pydantic model PartSegCore.analysis.calculation_plan.MaskSuffix[source]

Bases: MaskMapper

Description of mask form file obtained by adding suffix to image file path

Variables:
  • ~.name (str) – mask name

  • ~.suffix (str) – mask file path suffix

Show JSON schema
{
   "title": "MaskSuffix",
   "description": "Description of mask form file obtained by adding suffix to image file path\n\n:ivar str ~.name: mask name\n:ivar str ~.suffix: mask file path suffix",
   "type": "object",
   "properties": {
      "name": {
         "title": "Name",
         "type": "string"
      },
      "suffix": {
         "title": "Suffix",
         "type": "string"
      }
   },
   "additionalProperties": false,
   "required": [
      "name",
      "suffix"
   ]
}

Config:
  • extra: str = forbid

Fields:
field suffix: str [Required]
get_mask_path(file_path)[source]

Calculate mask path based od file_path

Parameters:

file_path (str) – path to proceeded file

Return type:

str

get_parameters()[source]

Parameters for serialize

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

pydantic model PartSegCore.analysis.calculation_plan.MaskSum[source]

Bases: MaskBase

Description of OR operation on mask

Variables:
  • ~.name (str) – name of mask

  • ~.mask1 (str) – first mask name

  • ~.mask2 (str) – second mask name

Show JSON schema
{
   "title": "MaskSum",
   "description": "Description of OR operation on mask\n\n:ivar str ~.name: name of mask\n:ivar str ~.mask1: first mask name\n:ivar str ~.mask2: second mask name",
   "type": "object",
   "properties": {
      "name": {
         "title": "Name",
         "type": "string"
      },
      "mask1": {
         "title": "Mask1",
         "type": "string"
      },
      "mask2": {
         "title": "Mask2",
         "type": "string"
      }
   },
   "additionalProperties": false,
   "required": [
      "name",
      "mask1",
      "mask2"
   ]
}

Config:
  • extra: str = forbid

Fields:
field mask1: str [Required]
field mask2: str [Required]
model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

pydantic model PartSegCore.analysis.calculation_plan.MaskUse[source]

Bases: MaskBase

Reuse of already defined mask Will be deprecated in short time

Show JSON schema
{
   "title": "MaskUse",
   "description": "Reuse of already defined mask\nWill be deprecated in short time",
   "type": "object",
   "properties": {
      "name": {
         "title": "Name",
         "type": "string"
      }
   },
   "additionalProperties": false,
   "required": [
      "name"
   ]
}

Config:
  • extra: str = forbid

Fields:

model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

pydantic model PartSegCore.analysis.calculation_plan.MeasurementCalculate[source]

Bases: BaseModel

Measurement calculation description

Variables:
  • ~.channel (int) – on which channel measurements should be calculated

  • ~.units (Units) – Type of units in which results of measurements should be represented

  • ~.statistic_profile (MeasurementProfile) – description of measurements

  • name_prefix (str) – prefix of column names

Show JSON schema
{
   "title": "MeasurementCalculate",
   "description": "Measurement calculation description\n\n:ivar int ~.channel: on which channel measurements should be calculated\n:ivar Units ~.units: Type of units in which results of measurements should be represented\n:ivar MeasurementProfile ~.statistic_profile: description of measurements\n:ivar str name_prefix: prefix of column names",
   "type": "object",
   "properties": {
      "channel": {
         "title": "Channel",
         "type": "integer"
      },
      "units": {
         "$ref": "#/$defs/Units"
      },
      "measurement_profile": {
         "$ref": "#/$defs/MeasurementProfile"
      },
      "name_prefix": {
         "title": "Name Prefix",
         "type": "string"
      }
   },
   "$defs": {
      "AreaType": {
         "description": "On which area type measurement should be calculated",
         "enum": [
            1,
            2,
            3
         ],
         "title": "AreaType",
         "type": "integer"
      },
      "Leaf": {
         "additionalProperties": false,
         "description": "Class for describe calculation of basic measurement",
         "properties": {
            "name": {
               "title": "Name",
               "type": "string"
            },
            "parameters": {
               "title": "Parameters"
            },
            "power": {
               "default": 1.0,
               "title": "Power",
               "type": "number"
            },
            "area": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/AreaType"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null
            },
            "per_component": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/PerComponent"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null
            },
            "channel": {
               "anyOf": [
                  {
                     "properties": {
                        "value": {
                           "anyOf": [
                              {
                                 "type": "string"
                              },
                              {
                                 "type": "integer"
                              }
                           ],
                           "title": "value"
                        }
                     },
                     "title": "Channel",
                     "type": "object"
                  },
                  {
                     "type": "null"
                  }
               ],
               "default": null,
               "title": "Channel"
            }
         },
         "required": [
            "name"
         ],
         "title": "Leaf",
         "type": "object"
      },
      "MeasurementEntry": {
         "additionalProperties": false,
         "description": "Describe single measurement in measurement set",
         "properties": {
            "name": {
               "title": "Name",
               "type": "string"
            },
            "calculation_tree": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/Node"
                  },
                  {
                     "$ref": "#/$defs/Leaf"
                  }
               ],
               "title": "Calculation Tree"
            }
         },
         "required": [
            "name",
            "calculation_tree"
         ],
         "title": "MeasurementEntry",
         "type": "object"
      },
      "MeasurementProfile": {
         "additionalProperties": false,
         "properties": {
            "name": {
               "title": "Name",
               "type": "string"
            },
            "chosen_fields": {
               "items": {
                  "$ref": "#/$defs/MeasurementEntry"
               },
               "title": "Chosen Fields",
               "type": "array"
            },
            "name_prefix": {
               "default": "",
               "title": "Name Prefix",
               "type": "string"
            }
         },
         "required": [
            "name",
            "chosen_fields"
         ],
         "title": "MeasurementProfile",
         "type": "object"
      },
      "Node": {
         "additionalProperties": false,
         "description": "Class for describe operation between two measurements",
         "properties": {
            "left": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/Node"
                  },
                  {
                     "$ref": "#/$defs/Leaf"
                  }
               ],
               "title": "Left"
            },
            "op": {
               "description": "Operation to perform between left and right child. Currently only division (`/`) supported",
               "title": "Op",
               "type": "string"
            },
            "right": {
               "anyOf": [
                  {
                     "$ref": "#/$defs/Node"
                  },
                  {
                     "$ref": "#/$defs/Leaf"
                  }
               ],
               "title": "Right"
            }
         },
         "required": [
            "left",
            "op",
            "right"
         ],
         "title": "Node",
         "type": "object"
      },
      "PerComponent": {
         "description": "How measurement should be calculated",
         "enum": [
            1,
            2,
            3,
            4
         ],
         "title": "PerComponent",
         "type": "integer"
      },
      "Units": {
         "enum": [
            0,
            1,
            2,
            3
         ],
         "title": "Units",
         "type": "integer"
      }
   },
   "additionalProperties": false,
   "required": [
      "channel",
      "units",
      "measurement_profile",
      "name_prefix"
   ]
}

Config:
  • extra: str = forbid

Fields:
field channel: int [Required]
field measurement_profile: MeasurementProfile [Required]
field name_prefix: str [Required]
field units: Units [Required]
model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

property name

name of used MeasurementProfile

class PartSegCore.analysis.calculation_plan.NodeType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Type of node in calculation

file_mask = 7

mask load

mask = 2

mask creation

measurement = 3

measurement calculation

none = 6

other, like description

root = 4

root of calculation

save = 5

save operation

segment = 1

segmentation

class PartSegCore.analysis.calculation_plan.Operations(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Global operations

class PartSegCore.analysis.calculation_plan.PlanChanges(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

History elements

add_node = 1
remove_node = 2
replace_node = 3
class PartSegCore.analysis.calculation_plan.RootType(value, names=None, *, module=None, qualname=None, type=None, start=1, boundary=None)[source]

Bases: Enum

Defines root type which changes of data available on begin of calculation

Image = 0

raw image

Mask_project = 2

Project from mask segmentation. It contains multiple elements.

Project = 1

PartSeg project with defined segmentation

pydantic model PartSegCore.analysis.calculation_plan.Save[source]

Bases: BaseModel

Save operation description

Variables:
  • ~.suffix (str) – suffix for saved file

  • ~.directory (str) – name of subdirectory to save

  • ~.algorithm (str) – name of save method

  • ~.short_name (str) – short name of save method

  • ~.values (dict) – parameters specific for save method

Show JSON schema
{
   "title": "Save",
   "description": "Save operation description\n\n:ivar str ~.suffix: suffix for saved file\n:ivar str ~.directory: name of subdirectory to save\n:ivar str ~.algorithm: name of save method\n:ivar str ~.short_name: short name of save method\n:ivar dict ~.values: parameters specific for save method",
   "type": "object",
   "properties": {
      "suffix": {
         "title": "Suffix",
         "type": "string"
      },
      "directory": {
         "title": "Directory",
         "type": "string"
      },
      "algorithm": {
         "title": "Algorithm",
         "type": "string"
      },
      "short_name": {
         "title": "Short Name",
         "type": "string"
      },
      "values": {
         "title": "Values",
         "type": "object"
      }
   },
   "additionalProperties": false,
   "required": [
      "suffix",
      "directory",
      "algorithm",
      "short_name",
      "values"
   ]
}

Config:
  • extra: str = forbid

Fields:
field algorithm: str [Required]
field directory: str [Required]
field short_name: str [Required]
field suffix: str [Required]
field values: dict [Required]
model_computed_fields: ClassVar[dict[str, ComputedFieldInfo]] = {}

A dictionary of computed field names and their corresponding ComputedFieldInfo objects.

PartSegCore.analysis.calculation_plan.get_save_path(op, calculation)[source]

Calculate save path base on proceeded file path and save operation parameters. It assume that save algorithm is registered in PartSegCore.analysis.save_functions.save_dict

Parameters:
  • op (Save) – operation to do

  • calculation (FileCalculation) – information about calculation

Return type:

str

Returns:

save path