PySilCam¶
This is documentation, auto-generated by Sphinx, for the PySilCam python interface and analysis for the SINTEF SilCam.
You can find out more about the system and higher-level descriptions on the wiki, here.
The code repository can be found here.
Top-Level functions and entry points¶
-
pysilcam.__main__.
silcam
()¶ Main entry point function to acquire/process images from the SilCam.
Use this function in command line arguments according to the below documentation.
- Usage:
silcam acquire <configfile> <datapath> silcam process <configfile> <datapath> [–nbimages=<number of images>] [–nomultiproc] [–appendstats] silcam realtime <configfile> <datapath> [–discwrite] [–nomultiproc] [–appendstats] [–discread] silcam -h | –help silcam –version
- Parameters
Acquire images (acquire) –
Process images (process) –
Acquire images from the camera and process them in real time (realtime) –
- Options:
- --nbimages=<number of images>
Number of images to process.
- --discwrite
Write images to disc.
- --nomultiproc
Deactivate multiprocessing.
- --appendstats
Appends data to output STATS.h5 file. If not specified, the STATS.h5 file will be overwritten!
-h –help Show this screen. –version Show version. –discread emergency disc read version of realtime analysis, to be run seperately but at
the same time as silcam acquire
-
pysilcam.silcreport.
silcreport
()¶ Generate a report figure for a processed dataset from the SilCam.
You can access this function from the command line using the below documentation.
- Usage:
- silcam-report <configfile> <statsfile> [–type=<particle_type>]
[–dpi=<dpi>] [–monitor] [–filter-stats=<y1,x1,y2,x2>]
- Parameters
configfile – The config filename associated with the data
statsfile – The -STATS.h5 filename associated with the data
- Options:
- --type=<particle_type>
The particle type to summarise. Can be: ‘all’, ‘oil’, or ‘gas’
- --dpi=<dpi>
DPI resolution of figure (default is 600)
- --monitor
Enables continuous monitoring (requires display)
- –filter-stats=<y1,x1,y2,x2> Filters stats file to only include particle
from the specified coordinate rectangle. (y1,x1) are the lower-left corner, and (y2,x2) are the upper-right corner of the rectangle.
-h –help Show this screen.
Main processing functions¶
Processing and analysis is performed using the below functions.
-
pysilcam.__main__.
processImage
(nnmodel, class_labels, image, settings, logger, gui)¶ Proceses an image
- Parameters
nnmodel (tensorflow model object) – loaded using sccl.load_model()
class_labels (str) – loaded using sccl.load_model()
image (tuple) – tuple contianing (i, timestamp, imc) where i is an int referring to the image number timestamp is the image timestamp obtained from passing the filename imc is the background-corrected image obtained using the backgrounder generator
settings (PySilcamSettings) – Settings read from a .ini file
logger (logger object) – logger object created using configure_logger()
gui=None (Class object) – Queue used to pass information between process thread and GUI initialised in ProcThread within guicals.py
- Returns
stats dataframe containing particle statistics
- Return type
stats_all (DataFrame)
-
pysilcam.process.
statextract
(imc, settings, timestamp, nnmodel, class_labels)¶ extracts statistics of particles in imc (raw corrected image)
- Parameters
imc – background-corrected image
timestamp – timestamp of image collection
settings – PySilCam settings
nnmodel – loaded tensorflow model from silcam_classify
class_labels – lables of particle classes in tensorflow model
- Returns
(list of particle statistics for every particle, according to Partstats class) imbw : segmented image saturation : percentage saturation of image
- Return type
stats
-
pysilcam.process.
image2blackwhite_fast
(imc, greythresh)¶ converts corrected image (imc) to a binary image using greythresh as the threshold value (fixed scaling of greythresh is done inside)
- Parameters
imc – background-corrected image
greythresh – threshold multiplier (greythresh is multiplied by 50th percentile of the image histogram)
- Returns
segmented image (binary image)
- Return type
imbw
-
pysilcam.process.
image2blackwhite_accurate
(imc, greythresh)¶ converts corrected image (imc) to a binary image using greythresh as the threshold value (some auto-scaling of greythresh is done inside)
- Parameters
imc – background-corrected image
greythresh – threshold multiplier (greythresh is multiplied by 50th percentile of the image histogram)
- Returns
segmented image (binary image)
- Return type
imbw
-
pysilcam.process.
clean_bw
(imbw, min_area)¶ cleans up particles which are too small and particles touching the border
- Parameters
imbw – segmented image
min_area – minimum number of accepted pixels for a particle
- Returns
cleaned up segmented image
- Return type
imbw (DataFrame)
-
pysilcam.process.
measure_particles
(imbw, imc, settings, timestamp, nnmodel, class_labels)¶ Measures properties of particles
- Parameters
imbw (full-frame binary image) –
imc (full-frame corrected raw image) –
image_index (some sort of tag for location matching) –
- Returns
stats (list of particle statistics for every particle, according to Partstats class)
Classification functions¶
-
pysilcam.silcam_classify.
check_model
(model_path)¶ Raises errors if classification model is not found, or if it is not a valid file.
- Parameters
model_path (str) – path to particle-classifier e.g. ‘/mnt/ARRAY/classifier/model/particle_classifier.h5’ usually obtained from settings.NNClassify.model_path
-
pysilcam.silcam_classify.
get_class_labels
(model_path)¶ Read the header file that defines the catagories of particles in the model
- Parameters
model_path (str) – path to particle-classifier e.g. ‘/testdata/model_name/particle_classifier.h5’ usually obtained from settings.NNClassify.model_path
- Returns
labelled catagories which can be predicted
- Return type
class_labels (str)
-
pysilcam.silcam_classify.
load_model
(model_path)¶ Load the trained tensorflow keras model
- Parameters
model_path (str) – path to particle-classifier e.g. ‘/testdata/model_name/particle_classifier.h5’
- Returns
loaded tf.keras model from load_model()
- Return type
model (tf model object)
-
pysilcam.silcam_classify.
predict
(img, model)¶ Use tensorflow model to classify particles
- Parameters
img (uint8) – a particle ROI, corrected and treated with the silcam explode_contrast function
model (tf model object) – loaded tfl model from load_model()
- Returns
the probability of the roi belonging to each class
- Return type
prediction (array)
PySilCam contents¶
- pysilcam package
- Subpackages
- pysilcam.silcamgui package
- Submodules
- pysilcam.silcamgui.PathLengthCTRL module
- pysilcam.silcamgui.STATSTrimmer module
- pysilcam.silcamgui.ServerDLG module
- pysilcam.silcamgui.SilCam module
- pysilcam.silcamgui.SilCamController module
- pysilcam.silcamgui.configEditor module
- pysilcam.silcamgui.guicalcs module
- pysilcam.silcamgui.interactive_summary module
- pysilcam.silcamgui.liveviewer module
- pysilcam.silcamgui.silcamgui module
- Module contents
- Submodules
- pysilcam.tests package
- Submodules
- pysilcam.tests.synthesizer module
- pysilcam.tests.test_background module
- pysilcam.tests.test_config module
- pysilcam.tests.test_oilgas module
- pysilcam.tests.test_overwrite_stats module
- pysilcam.tests.test_process module
- pysilcam.tests.test_silcam-aquire module
- pysilcam.tests.test_standards module
- pysilcam.tests.test_stats_convert module
- pysilcam.tests.test_tracking module
- pysilcam.tests.test_z_classify module
- pysilcam.tests.test_z_speed module
- Module contents
- Submodules
- pysilcam.silcamgui package
- Submodules
- Module contents
- Subpackages