napari_ndev.measure
#
Functions for measuring properties of labels.
Measure properties of labels in images using sci-kit image's regionprops. It includes utilities for handling label and intensity images, extracting information from ID strings, renaming intensity columns, and mapping treatment dictionaries to DataFrame ID columns.
Functions:
-
measure_regionprops : Measure properties of labels with sci-kit image regionprops.
– -
group_and_agg_measurements : Count and aggregate measurements by grouping IDs from measurement results.
–
_convert_to_list
#
_convert_to_list(arg)
Convert any non-list arguments to lists.
Parameters:
Returns:
-
list or None
–The converted list or None if the input was None.
Source code in src/napari_ndev/measure.py
224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
|
_extract_info_from_id_string
#
_extract_info_from_id_string(id_string, id_regex)
Extract information from an id string using a regex dictionary.
Parameters:
-
id_string
#str
) –The ID string to extract information from.
-
id_regex
#dict
) –A dictionary where keys are the information to extract and values are the regex patterns to use for extraction.
Returns:
-
dict
–A dictionary containing the extracted information.
Examples:
>>> id_string = "P14-A6__2024-07-16 25x 18HIC ncoa4 FT dapi obl 01"
>>> id_regex = {'well': '-(\w+)__', 'HIC': r'(\d{1,3})HIC', 'exp': r'obl (\d{2,3})'}
>>> _extract_info_from_id_string(id_string, id_regex)
{'well': 'A6', 'HIC': '18', 'exp': '01'}
Source code in src/napari_ndev/measure.py
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 |
|
_generate_measure_dict
#
_generate_measure_dict(
label_images, label_names=None, intensity_images=None, intensity_names=None
)
Generate a dictionary of label and intensity images with their names.
Parameters:
-
label_images
#list of ArrayLike or ArrayLike
) –The label images.
-
label_names
#list of str or str or None
, default:None
) –The names of the label images.
-
intensity_images
#list of ArrayLike or ArrayLike or None
, default:None
) –The intensity images.
-
intensity_names
#list of str or str or None
, default:None
) –The names of the intensity images.
Returns:
-
dict
–A dictionary containing label and intensity images with their names.
Source code in src/napari_ndev/measure.py
246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 |
|
_map_tx_dict_to_df_id_col
#
_map_tx_dict_to_df_id_col(
tx=None, tx_n_well=None, tx_leading_zeroes=False, df=None, id_column=None
)
Map a dictionary of treatments to a DataFrame's id_column.
This should work on either a complete dataset, or as part of an iterative.
Parameters:
-
tx
#dict or None
, default:None
) –The dictionary of treatments.
-
tx_n_well
#int or None
, default:None
) –The number of wells in the plate.
-
tx_leading_zeroes
#bool
, default:False
) –Whether to use leading zeroes in the plate map. Default is False.
-
df
#DataFrame
, default:None
) –The DataFrame to map treatments to.
-
id_column
#str or None
, default:None
) –The column in the DataFrame that contains the IDs.
Returns:
-
DataFrame
–The DataFrame with treatments mapped to the id_column.
Source code in src/napari_ndev/measure.py
361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 |
|
_rename_intensity_columns
#
_rename_intensity_columns(df, intensity_names)
Rename columns in the DataFrame to include the intensity names.
The intensity names are appended to the end of the column name based on the index of the intensity_names list.
Parameters:
-
df
#DataFrame
) –The DataFrame with measurement properties.
-
intensity_names
#list of str
) –The list of intensity names.
Returns:
-
DataFrame
–The DataFrame with renamed columns.
Source code in src/napari_ndev/measure.py
328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 |
|
group_and_agg_measurements
#
group_and_agg_measurements(
df, grouping_cols="id", count_col="label", agg_cols=None, agg_funcs="mean"
)
Count and aggregate measurements by grouping IDs from measurement results.
Parameters:
-
df
#DataFrame
) –The DataFrame with measurement properties, usually from measure_regionprops.
-
grouping_cols
#str or list of str
, default:'id'
) –The columns to group by. By default, just the image ID.
-
count_col
#str
, default:'label'
) –The column to count. By default, just the 'label' column.
-
agg_cols
#list of str or None
, default:None
) –The columns to aggregate. By default, None.
-
agg_funcs
#str or list of str
, default:'mean'
) –The aggregating functions. By default, just the mean.
Returns:
-
DataFrame
–The DataFrame with grouped and aggregated measurements.
Source code in src/napari_ndev/measure.py
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 |
|
measure_regionprops
#
measure_regionprops(
label_images,
label_names=None,
intensity_images=None,
intensity_names=None,
properties=None,
scale=(1, 1),
id_string=None,
id_regex_dict=None,
tx_id=None,
tx_dict=None,
tx_n_well=None,
tx_leading_zeroes=False,
save_data_path=None,
)
Measure properties of labels with sci-kit image regionprops.
Optionally give a list of intensity_images to measure intensity properties of labels (i.e. 'intensity_mean', 'intensity_min', 'intensity_max', 'intensity_std'). If no label or intensity names are given, the names are automatically generated as a string of the input variable name. Choose from a list of properties to measure: [ "label", "area", "area_convex", "bbox", "centroid", "eccentricity", "extent", "feret_diameter_max", "intensity_max", "intensity_mean", "intensity_min", "intensity_std", "num_pixels", "orientation", "perimeter", "solidity", ].
Parameters:
-
label_images
#list of ArrayLike or ArrayLike
) –The label images.
-
label_names
#list of str or str or None
, default:None
) –The names of the label images.
-
intensity_images
#list of ArrayLike or ArrayLike or None
, default:None
) –The intensity images.
-
intensity_names
#list of str or str or None
, default:None
) –The names of the intensity images.
-
properties
#list of str or None
, default:None
) –The properties to measure.
-
scale
#tuple of float
, default:(1, 1)
) –The scale for the measurements.
-
id_string
#str or None
, default:None
) –The ID string.
-
id_regex_dict
#dict or None
, default:None
) –The regex dictionary for extracting information from the ID string.
-
tx_id
#str or None
, default:None
) –The treatment ID.
-
tx_dict
#dict or None
, default:None
) –The treatment dictionary.
-
tx_n_well
#int or None
, default:None
) –The number of wells in the plate.
-
tx_leading_zeroes
#bool
, default:False
) –Whether to use leading zeroes in the plate map.
-
save_data_path
#PathLike or None
, default:None
) –The path to save the data.
Returns:
-
DataFrame
–The DataFrame with measured properties.
Source code in src/napari_ndev/measure.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 |
|