PartSegCore.analysis.measurement_base

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

Bases: Enum

On which area type measurement should be calculated

pydantic model PartSegCore.analysis.measurement_base.Leaf[source]

Bases: BaseModel

Class for describe calculation of basic measurement

Show JSON schema
{
   "title": "Leaf",
   "description": "Class for describe calculation of basic measurement",
   "type": "object",
   "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"
      }
   },
   "$defs": {
      "AreaType": {
         "description": "On which area type measurement should be calculated",
         "enum": [
            1,
            2,
            3
         ],
         "title": "AreaType",
         "type": "integer"
      },
      "PerComponent": {
         "description": "How measurement should be calculated",
         "enum": [
            1,
            2,
            3,
            4
         ],
         "title": "PerComponent",
         "type": "integer"
      }
   },
   "additionalProperties": false,
   "required": [
      "name"
   ]
}

Config:
  • extra: str = forbid

Fields:
field area: Optional[AreaType] = None
field channel: Optional[Channel] = None
field name: str [Required]
field parameters: Any [Optional]
field per_component: Optional[PerComponent] = None
field power: float = 1.0
get_channel_num(measurement_dict)[source]

Get set with number of channels needed for calculate this measurement

Parameters:

measurement_dict (Dict[str, MeasurementMethodBase]) – dict with all measurementh method.

Return type:

Set[Channel]

Returns:

set of channels num

get_unit(ndim)[source]

Return unit of selected measurement reflecting dimensionality.

Parameters:

ndim (int) – data dimensionality

Return type:

Symbol

is_per_component()[source]

If measurement return list of result or single value.

Return type:

bool

need_mask()[source]

If this measurement need mast for proper calculation.

Return type:

bool

pretty_print(measurement_dict)[source]

Pretty print for presentation in user interface.

Parameters:

measurement_dict (Dict[str, MeasurementMethodBase]) – dict with additional information used for more detailed description

Return type:

str

Returns:

string with indentation

replace_(**kwargs)
Return type:

Leaf

pydantic model PartSegCore.analysis.measurement_base.MeasurementEntry[source]

Bases: BaseModel

Describe single measurement in measurement set

Show JSON schema
{
   "title": "MeasurementEntry",
   "description": "Describe single measurement in measurement set",
   "type": "object",
   "properties": {
      "name": {
         "title": "Name",
         "type": "string"
      },
      "calculation_tree": {
         "anyOf": [
            {
               "$ref": "#/$defs/Node"
            },
            {
               "$ref": "#/$defs/Leaf"
            }
         ],
         "title": "Calculation Tree"
      }
   },
   "$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"
      },
      "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"
      }
   },
   "additionalProperties": false,
   "required": [
      "name",
      "calculation_tree"
   ]
}

Config:
  • extra: str = forbid

Fields:
field calculation_tree: Union[Node, Leaf] [Required]
field name: str [Required]
get_channel_num(measurement_dict)[source]
Return type:

Set[Channel]

get_unit(unit, ndim)[source]
Return type:

str

class PartSegCore.analysis.measurement_base.MeasurementMethodBase[source]

Bases: AlgorithmDescribeBase, ABC

This is base class For all measurement calculation classes based on text_info[0] the measurement name will be generated, based_on text_info[1] the description is generated

static area_type(area)[source]

Map chosen area type to proper area type. Allow to correct Area type.

static calculate_property(channel, roi, mask, voxel_size, result_scalar, roi_alternative, roi_annotation, **kwargs)[source]

Main function for calculating measurement

Parameters:
  • channel (ndarray) – main channel selected for measurement

  • channel_{i} – for channel requested using get_fields() AlgorithmProperty("channel", "Channel", 0, value_type=Channel)

  • area_array – array representing current area returned by area_type()

  • roi (ndarray) – array representing roi

  • mask (ndarray) – array representing mask (upper level roi)

  • voxel_size (Tuple[Union[float, int], ...]) – size of single voxel in meters

  • result_scalar (float) – scalar to get proper units in result

  • roi_alternative (Dict[str, ndarray]) – dict with alternative roi representation (for plugin specific mapping)

  • roi_annotation (Dict[int, Any]) – dict with roi annotations (for plugin specific mapping)

List incomplete.

classmethod get_description()[source]

Measurement long description

Return type:

str

classmethod get_name()[source]

Name of measurement

Return type:

str

classmethod get_starting_leaf()[source]

This leaf is put on default list

Return type:

Leaf

classmethod get_units(ndim)[source]

Return units for measurement. They are shown to user

Return type:

symbols

classmethod is_component()[source]

Return information if Need information about components

Return type:

bool

classmethod need_channel()[source]

if need image data

pydantic model PartSegCore.analysis.measurement_base.Node[source]

Bases: BaseModel

Class for describe operation between two measurements

Show JSON schema
{
   "$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"
      },
      "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"
      }
   },
   "allOf": [
      {
         "$ref": "#/$defs/Node"
      }
   ]
}

Config:
  • extra: str = forbid

Fields:
field left: Union[Node, Leaf] [Required]
field op: str [Required]

Operation to perform between left and right child. Currently only division (/) supported

field right: Union[Node, Leaf] [Required]
get_channel_num(measurement_dict)[source]
Return type:

Set[Channel]

get_unit(ndim)[source]
Return type:

Symbol

is_per_component()[source]
Return type:

bool

need_mask()[source]
pretty_print(measurement_dict)[source]
Return type:

str

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

Bases: Enum

How measurement should be calculated

PartSegCore.analysis.measurement_base.has_mask_components(component_and_mask_info)[source]

Check if any measurement will return value per mask component

Return type:

bool

PartSegCore.analysis.measurement_base.has_roi_components(component_and_mask_info)[source]

Check if any measurement will return value per ROI component

Return type:

bool