Package scm_electron_microscopes
+Classes
+-
+
+class ZeissSEM +(filename) +
+-
++
Class with convenience functions for the Zeiss EVO and Gemini SEMs. By +default does not load the image into memory.
+Parameters
+-
+
filename
:str
+- filename of the image to load. The file extension may be but is not +required to be included. +
Returns
+-
+
ZeissSEM class instance
+- +
Methods
+-
+
+def export_metadata(self, filename=None) +
+-
++
save text file with metadata
+Parameters
+-
+
filename
:str
, optional
+- filename to store. The default is the image name with
+
'_metadata.txt'
appended.
+
+ +def export_with_scalebar(self, filename=None, **kwargs) +
+-
++
saves an exported image of the SEM image with a scalebar in one of the +four corners, where barsize is the scalebar size in data units (e.g. +nm) and scale the overall size of the scalebar and text with respect to +the width of the image.
+Parameters
+-
+
filename
:string
orNone
, optional
+- Filename + extension to use for the export file. The default is the +filename sans extension of the original SEM file, with +'_exported.png' appended. +
preprocess
:callable
, optional
+- callable to pre-process the image before any other processing is +done, useful for e.g. smoothing. Must take and return a +numpy.ndarray containing the image data as only arguments, and must +not change e.g. the pixel size or the scale bar may be incorrectly +sized. The default is None. +
crop
:tuple
orNone
, optional
+-
+
range describing a area of the original image (before rescaling the +resolution) to crop out for the export image. Can have two forms:
+-
+
-
+
+((xmin,ymin),(xmax,ymax))
, with the integer pixel indices of +the top left and bottom right corners respectively.
+ -
+
+(xmin,ymin,w,h)
with the integer indices of the top left corner +and the width and heigth of the cropped image in pixels (prior to +optional rescaling usingresolution
). When this format is used, +it is possible to set the width and height in pixels (default) or +in data units via thecrop_unit
parameter.
+
The default is
+None
which takes the entire image.
+ -
+
crop_unit
:'pixels'
or'data'
, optional
+- sets the unit in which the width and height in
crop
are +specified when using the (x,y,w,h) format, with'pixels'
to give +the size in pixels or'data'
to specify the size in the physical +unit used for the scalebar (after optional unit conversion via the +convert
parameter). Note that the position of the top left corner +is given in pixels. The((xmin,ymin),(xmax,ymax))
format must be +always given in pixels, andcrop_unit
is ignored ifcrop
is +given in this format. The default is'pixels'
.
+ resolution
:int
, optional
+- the resolution along the x-axis (i.e. image width in pixels) to use
+for the exported image. The default is
None
, which uses the size +of the original image (after optional cropping usingcrop
).
+ draw_bar
:boolean
, optional
+- whether to draw a scalebar on the image, such that this function
+may be used just to crop and rescale. The default is
True
.
+ barsize
:float
orNone
, optional
+- size (in data units matching the original scale bar, e.g. nm) of
+the scale bar to use. The default
None
, wich takes the desired +length for the current scale and round this to the nearest option +from a list of "nice" values.
+ scale
:float
, optional
+- factor to change the size of the scalebar+text with respect to the
+width of the image. Scale is chosen such, that at
scale=1
the +font size of the scale bar text is approximately 10 pt when +the image is printed at half the width of the text in a typical A4 +paper document (e.g. two images side-by-side). The default is 1.
+ loc
:int, one
of[
0,
1,
2,
3]
, optional
+- Location of the scalebar on the image, where
0
,1
,2
and3
+refer to the top left, top right, bottom left and bottom right +respectively. The default is2
, which is the bottom left corner.
+ convert
:one
ofstr, one
of[
'fm',
'pm',
'Å'or
A,
'nm',
'µm'or
'um',
'mm',
'cm',
'dm',
'm']
+- Unit that will be used for the scale bar, the value will be
+automatically converted if this unit differs from the pixel size
+unit. The default is
None
, which uses the unit of the scalebar on +the original image.
+ font
:str
, optional
+- filename of an installed TrueType font ('.ttf' file) to use for the
+text on the scalebar. The default is
'arialbd.ttf'
.
+ fontsize
:int
, optional
+- base font size to use for the scale bar text. The default is 16.
+Note that this size will be re-scaled according to
resolution
and +scale
.
+ fontbaseline
:int
, optional
+- vertical offset for the baseline of the scale bar text from the top +of the scale bar, in printer points. The default is 10. +
fontpad
:int
, optional
+- minimum size in printer points of the space/padding between the +text and the bar and surrounding box. The default is 10. +
barthickness
:int
, optional
+- thickness in printer points of the scale bar itself. The default is +16. +
barpad
:int
, optional
+- size in printer points of the padding between the scale bar and the +surrounding box. The default is 10. +
box
:bool
, optional
+- Whether to put a semitransparent box around the scalebar and text
+to enhance contrast. The default is
True
.
+ boxalpha
:float
, optional
+- value between 0 and 1 for the opacity (inverse of transparency) of
+the box behind the scalebar and text when
box=True
. The default +is0.8
.
+ invert
:bool
, optional
+- If
True
, a white scalebar and text on a black box are used. The +default isFalse
which gives black text on a white background.
+ boxpad
:int
, optional
+- size of the space/padding around the box (with respect to the sides +of the image) in printer points. The default is 10. +
store_settings
:bool
, optional
+- when
True
, a .txt file is saved along with the image containing +all settings passed to this function. The default is False
+
+ +def get_image(self) +
+-
++
loads the image data
+Returns
+-
+
PIL.Image instance
+- +
+ +def get_metadata(self) +
+-
++
extracts embedded metadata from the image file
+ +def get_pixelsize(self) +
+-
++
gets the physical size of a pixel from the metadata
+Returns
+-
+
pixelsize
:float
+- physical size of the pixels in x and y +
unit
:str
+- physical unit corresponding to the pixelsize. +
+ +def print_metadata(self) +
+-
++
print formatted output of metadata
+
+ +class helios +(filename) +
+-
++
Set of convenience functions for the Helios SEM.
+Parameters
+-
+
filename
:string
+- name of the file to load. Can but is not required to include .tif +as extension. +
Returns
+-
+
helios class instance
+- +
Methods
+-
+
+def export_metadata(self, filename=None) +
+-
++
save text file with metadata
+Parameters
+-
+
filename
:str
, optional
+- filename to store. The default is the image name with
+
'_metadata.txt'
appended.
+
+ +def export_with_scalebar(self, filename=None, **kwargs) +
+-
++
saves an exported image of the SEM image with a scalebar in one of the +four corners, where barsize is the scalebar size in data units (e.g. +nm) and scale the overall size of the scalebar and text with respect to +the width of the image.
+Parameters
+-
+
filename
:string
orNone
, optional
+- Filename + extension to use for the export file. The default is the +filename sans extension of the original SEM file, with +'_exported.png' appended. +
preprocess
:callable
, optional
+- callable to pre-process the image before any other processing is +done, useful for e.g. smoothing. Must take and return a +numpy.ndarray containing the image data as only arguments, and must +not change e.g. the pixel size or the scale bar may be incorrectly +sized. The default is None. +
crop
:tuple
orNone
, optional
+-
+
range describing a area of the original image (before rescaling the +resolution) to crop out for the export image. Can have two forms:
+-
+
-
+
+((xmin,ymin),(xmax,ymax))
, with the integer pixel indices of +the top left and bottom right corners respectively.
+ -
+
+(xmin,ymin,w,h)
with the integer indices of the top left corner +and the width and heigth of the cropped image in pixels (prior to +optional rescaling usingresolution
). When this format is used, +it is possible to set the width and height in pixels (default) or +in data units via thecrop_unit
parameter.
+
The default is
+None
which takes the entire image.
+ -
+
crop_unit
:'pixels'
or'data'
, optional
+- sets the unit in which the width and height in
crop
are +specified when using the (x,y,w,h) format, with'pixels'
to give +the size in pixels or'data'
to specify the size in the physical +unit used for the scalebar (after optional unit conversion via the +convert
parameter). Note that the position of the top left corner +is given in pixels. The((xmin,ymin),(xmax,ymax))
format must be +always given in pixels, andcrop_unit
is ignored ifcrop
is +given in this format. The default is'pixels'
.
+ resolution
:int
, optional
+- the resolution along the x-axis (i.e. image width in pixels) to use
+for the exported image. The default is
None
, which uses the size +of the original image (after optional cropping usingcrop
).
+ draw_bar
:boolean
, optional
+- whether to draw a scalebar on the image, such that this function
+may be used just to strip the original bar and crop. The default is
+
True
.
+ barsize
:float
orNone
, optional
+- size (in data units matching the original scale bar, e.g. nm) of
+the scale bar to use. The default
None
, wich takes the desired +length for the current scale and round this to the nearest option +from a list of "nice" values.
+ scale
:float
, optional
+- factor to change the size of the scalebar+text with respect to the
+width of the image. Scale is chosen such, that at
scale=1
the +font size of the scale bar text is approximately 10 pt when +the image is printed at half the width of the text in a typical A4 +paper document (e.g. two images side-by-side). The default is 1.
+ loc
:int, one
of[
0,
1,
2,
3]
, optional
+- Location of the scalebar on the image, where
0
,1
,2
and3
+refer to the top left, top right, bottom left and bottom right +respectively. The default is2
, which is the bottom left corner.
+ convert
:str, one
of[
'fm',
'pm',
'Å'or
A,
'nm',
'µm'or
'um',
'mm',
'cm',
'dm',
'm']
+- Unit that will be used for the scale bar, the value will be
+automatically converted if this unit differs from the pixel size
+unit. The default is
None
, which uses the unit of the scalebar on +the original image.
+ font
:str
, optional
+- filename of an installed TrueType font ('.ttf' file) to use for the
+text on the scalebar. The default is
'arialbd.ttf'
.
+ fontsize
:int
, optional
+- base font size to use for the scale bar text. The default is 16.
+Note that this size will be re-scaled according to
resolution
and +scale
.
+ fontbaseline
:int
, optional
+- vertical offset for the baseline of the scale bar text from the top +of the scale bar, in printer points. The default is 10. +
fontpad
:int
, optional
+- minimum size in printer points of the space/padding between the +text and the bar and surrounding box. The default is 10. +
barthickness
:int
, optional
+- thickness in printer points of the scale bar itself. The default is +16. +
barpad
:int
, optional
+- size in printer points of the padding between the scale bar and the +surrounding box. The default is 10. +
box
:bool
, optional
+- Whether to put a semitransparent box around the scalebar and text
+to enhance contrast. The default is
True
.
+ boxalpha
:float
, optional
+- value between 0 and 1 for the opacity (inverse of transparency) of
+the box behind the scalebar and text when
box=True
. The default +is0.8
.
+ invert
:bool
, optional
+- If
True
, a white scalebar and text on a black box are used. The +default isFalse
which gives black text on a white background.
+ boxpad
:int
, optional
+- size of the space/padding around the box (with respect to the sides +of the image) in printer points. The default is 10. +
store_settings
:bool
, optional
+- when
True
, a .txt file is saved along with the image containing +all settings passed to this function. The default is False
+
+ +def get_image(self) +
+-
++
load the image and split into image and databar
+Returns
+-
+
numpy.array
+- array of pixel values in the image (not including the data bar) +
+ +def get_metadata(self) +
+-
++
Load the metadata footer from Helios SEM files and return xml tree +object which can be indexed for extraction of useful parameters. Does +not require loading whole file into memory. Attempts first to find xml +formatted data, if this is not found it looks for 'human' formatted +metadata.
+Returns
+-
+
xml.etree.ElementTree root object
+- xml root object of the metadata. Can be printed using it as
+argument to print_metadata, or indexed with
+
xml_root.find('<element name>')
.
+
+ +def get_pixelsize(self) +
+-
++
gets the pixel size from the metadata and calculates the unit
+Returns
+-
+
pixelsize
:tuple
offloat
+- the pixelsize in calibrated (physical) units in (x,y) +
unit
:string
+- the physical unit of the pixel size +
+ +def print_metadata(self) +
+-
++
print formatted output of metadata
+
+ +class phenom +(filename) +
+-
++
Set of convenience functions for the phenom SEM microscopes.
+Parameters
+-
+
filename
:str
+- filename of the image to load +
Returns
+-
+
phenom class instance
+- +
Methods
+-
+
+def export_metadata(self, filename=None) +
+-
++
save text file with metadata
+Parameters
+-
+
filename
:str
, optional
+- filename to store. The default is the image name with
+
'_metadata.txt'
appended.
+
+ +def export_with_scalebar(self, filename=None, **kwargs) +
+-
++
saves an exported image of the SEM image with a scalebar in one of the +four corners, where barsize is the scalebar size in data units (e.g. +nm) and scale the overall size of the scalebar and text with respect to +the width of the image.
+Parameters
+-
+
filename
:string
orNone
, optional
+- Filename + extension to use for the export file. The default is the +filename sans extension of the original SEM file, with +'_exported.png' appended. +
preprocess
:callable
, optional
+- callable to pre-process the image before any other processing is +done, useful for e.g. smoothing. Must take and return a +numpy.ndarray containing the image data as only arguments, and must +not change e.g. the pixel size or the scale bar may be incorrectly +sized. The default is None. +
crop
:tuple
orNone
, optional
+-
+
range describing a area of the original image (before rescaling the +resolution) to crop out for the export image. Can have two forms:
+-
+
-
+
+((xmin,ymin),(xmax,ymax))
, with the integer pixel indices of +the top left and bottom right corners respectively.
+ -
+
+(xmin,ymin,w,h)
with the integer indices of the top left corner +and the width and heigth of the cropped image in pixels (prior to +optional rescaling usingresolution
). When this format is used, +it is possible to set the width and height in pixels (default) or +in data units via thecrop_unit
parameter.
+
The default is
+None
which takes the entire image.
+ -
+
crop_unit
:'pixels'
or'data'
, optional
+- sets the unit in which the width and height in
crop
are +specified when using the (x,y,w,h) format, with'pixels'
to give +the size in pixels or'data'
to specify the size in the physical +unit used for the scalebar (after optional unit conversion via the +convert
parameter). Note that the position of the top left corner +is given in pixels. The((xmin,ymin),(xmax,ymax))
format must be +always given in pixels, andcrop_unit
is ignored ifcrop
is +given in this format. The default is'pixels'
.
+ resolution
:int
, optional
+- the resolution along the x-axis (i.e. image width in pixels) to use
+for the exported image. The default is
None
, which uses the size +of the original image (after optional cropping usingcrop
).
+ draw_bar
:boolean
, optional
+- whether to draw a scalebar on the image, such that this function
+may be used just to strip the original bar and crop. The default is
+
True
.
+ barsize
:float
orNone
, optional
+- size (in data units matching the original scale bar, e.g. nm) of
+the scale bar to use. The default
None
, wich takes the desired +length for the current scale and round this to the nearest option +from a list of "nice" values.
+ scale
:float
, optional
+- factor to change the size of the scalebar+text with respect to the
+width of the image. Scale is chosen such, that at
scale=1
the +font size of the scale bar text is approximately 10 pt when +the image is printed at half the width of the text in a typical A4 +paper document (e.g. two images side-by-side). The default is 1.
+ loc
:int, one
of[
0,
1,
2,
3]
, optional
+- Location of the scalebar on the image, where
0
,1
,2
and3
+refer to the top left, top right, bottom left and bottom right +respectively. The default is2
, which is the bottom left corner.
+ convert
:str, one
of[
'fm',
'pm',
'Å'or
A,
'nm',
'µm'or
'um',
'mm',
'cm',
'dm',
'm']
+- Unit that will be used for the scale bar, the value will be
+automatically converted if this unit differs from the pixel size
+unit. The default is
None
, which uses the unit of the scalebar on +the original image.
+ font
:str
, optional
+- filename of an installed TrueType font ('.ttf' file) to use for the
+text on the scalebar. The default is
'arialbd.ttf'
.
+ fontsize
:int
, optional
+- base font size to use for the scale bar text. The default is 16.
+Note that this size will be re-scaled according to
resolution
and +scale
.
+ fontbaseline
:int
, optional
+- vertical offset for the baseline of the scale bar text from the top +of the scale bar, in printer points. The default is 10. +
fontpad
:int
, optional
+- minimum size in printer points of the space/padding between the +text and the bar and surrounding box. The default is 10. +
barthickness
:int
, optional
+- thickness in printer points of the scale bar itself. The default is +16. +
barpad
:int
, optional
+- size in printer points of the padding between the scale bar and the +surrounding box. The default is 10. +
box
:bool
, optional
+- Whether to put a semitransparent box around the scalebar and text
+to enhance contrast. The default is
True
.
+ boxalpha
:float
, optional
+- value between 0 and 1 for the opacity (inverse of transparency) of
+the box behind the scalebar and text when
box=True
. The default +is0.8
.
+ invert
:bool
, optional
+- If
True
, a white scalebar and text on a black box are used. The +default isFalse
which gives black text on a white background.
+ boxpad
:int
, optional
+- size of the space/padding around the box (with respect to the sides +of the image) in printer points. The default is 10. +
store_settings
:bool
, optional
+- when
True
, a .txt file is saved along with the image containing +all settings passed to this function. The default is False
+
+ +def get_image(self) +
+-
++
load the image and split into image and databar
+ +def get_metadata(self) +
+-
++
Load the metadata footer from Helios SEM files and return xml tree +object which can be indexed for extraction of useful parameters. Does +not require loading whole file into memory. Attempts first to find xml +formatted data, if this is not found it looks for 'human' formatted +metadata.
+Returns
+-
+
xml.etree.ElementTree object
+- xml root object of the metadata. Can be printed using it as
+argument to print_metadata, or indexed with
+xml_root.find('
')
+
+ +def get_pixelsize(self) +
+-
++
gets the pixel size from the metadata and calculates the unit
+Returns
+-
+
pixelsize
:(y,x) tuple
offloat
+- physical size of the pixels +
unit
:str
+- physical unit corresponding to the pixelsize. +
+ +def print_metadata(self) +
+-
++
print formatted output of metadata
+
+ +class sis +(filename) +
+-
++
Set of convenience functions for electron microscopy images of the now +defunct tecnai 10 microscope which operated the Olympus Soft Imaging System +software (analySIS) which exported to .tif. Initializing the class takes a +string containing the filename as only argument, and by default loads in +the image.
+Parameters
+-
+
filename
:string
+- name of the file to load. Can but is not required to include .tif +as extension. +
Methods
+-
+
+def export_with_scalebar(self, filename=None, **kwargs) +
+-
++
saves an exported image of the TEM image with a scalebar in one of the +four corners, where barsize is the scalebar size in data units (e.g. +nm) and scale the overall size of the scalebar and text with respect to +the width of the image.
+Parameters
+-
+
filename
:string
orNone
, optional
+- Filename + extension to use for the export file. The default is the +filename sans extension of the original TEM file, with +'_exported.png' appended. +
preprocess
:callable
, optional
+- callable to pre-process the image before any other processing is +done, useful for e.g. smoothing. Must take and return a +numpy.ndarray containing the image data as only arguments, and must +not change e.g. the pixel size or the scale bar may be incorrectly +sized. The default is None. +
crop
:tuple
orNone
, optional
+-
+
range describing a area of the original image (before rescaling the +resolution) to crop out for the export image. Can have two forms:
+-
+
-
+
+((xmin,ymin),(xmax,ymax))
, with the integer pixel indices of +the top left and bottom right corners respectively.
+ -
+
+(xmin,ymin,w,h)
with the integer indices of the top left corner +and the width and heigth of the cropped image in pixels (prior to +optional rescaling usingresolution
). When this format is used, +it is possible to set the width and height in pixels (default) or +in data units via thecrop_unit
parameter.
+
The default is
+None
which takes the entire image.
+ -
+
crop_unit
:'pixels'
or'data'
, optional
+- sets the unit in which the width and height in
crop
are +specified when using the (x,y,w,h) format, with'pixels'
to give +the size in pixels or'data'
to specify the size in the physical +unit used for the scalebar (after optional unit conversion via the +convert
parameter). Note that the position of the top left corner +is given in pixels. The((xmin,ymin),(xmax,ymax))
format must be +always given in pixels, andcrop_unit
is ignored ifcrop
is +given in this format. The default is'pixels'
.
+ intensity_range
:tuple
orNone
or'automatic'
+- tuple of
(lower,upper)
ranges for the (original) pixel values to +scale the brightness/contrast in the image to, or'automatic'
to +autoscale the intensity to the 0.01th and 99.99th percentile of the +input image, or None for the min and max value in the original +image. The default isNone
.
+ resolution
:int
, optional
+- the resolution along the x-axis (i.e. image width in pixels) to use
+for the exported image. The default is
None
, which uses the size +of the original image (after optional cropping usingcrop
).
+ draw_bar
:boolean
, optional
+- whether to draw a scalebar on the image, such that this function
+may be used just to strip the original bar and crop. The default is
+
True
.
+ barsize
:float
orNone
, optional
+- size (in data units matching the original scale bar, e.g. nm) of
+the scale bar to use. The default
None
, wich takes the desired +length for the current scale and round this to the nearest option +from a list of "nice" values.
+ scale
:float
, optional
+- factor to change the size of the scalebar+text with respect to the
+width of the image. Scale is chosen such, that at
scale=1
the +font size of the scale bar text is approximately 10 pt when +the image is printed at half the width of the text in a typical A4 +paper document (e.g. two images side-by-side). The default is 1.
+ loc
:int, one
of[
0,
1,
2,
3]
, optional
+- Location of the scalebar on the image, where
0
,1
,2
and3
+refer to the top left, top right, bottom left and bottom right +respectively. The default is2
, which is the bottom left corner.
+ convert
:str, one
of[
'fm',
'pm',
'Å'or
A,
'nm',
'µm'or
'um',
'mm',
'cm',
'dm',
'm']
+- Unit that will be used for the scale bar, the value will be
+automatically converted if this unit differs from the pixel size
+unit. The default is
None
, which uses the unit of the scalebar on +the original image.
+ font
:str
, optional
+- filename of an installed TrueType font ('.ttf' file) to use for the
+text on the scalebar. The default is
'arialbd.ttf'
.
+ fontsize
:int
, optional
+- base font size to use for the scale bar text. The default is 16.
+Note that this size will be re-scaled according to
resolution
and +scale
.
+ fontbaseline
:int
, optional
+- vertical offset for the baseline of the scale bar text from the top +of the scale bar, in printer points. The default is 10. +
fontpad
:int
, optional
+- minimum size in printer points of the space/padding between the +text and the bar and surrounding box. The default is 10. +
barthickness
:int
, optional
+- thickness in printer points of the scale bar itself. The default is +16. +
barpad
:int
, optional
+- size in printer points of the padding between the scale bar and the +surrounding box. The default is 10. +
box
:bool
, optional
+- Whether to put a semitransparent box around the scalebar and text
+to enhance contrast. The default is
True
.
+ boxalpha
:float
, optional
+- value between 0 and 1 for the opacity (inverse of transparency) of
+the box behind the scalebar and text when
box=True
. The default +is0.8
.
+ invert
:bool
, optional
+- If
True
, a white scalebar and text on a black box are used. The +default isFalse
which gives black text on a white background.
+ boxpad
:int
, optional
+- size of the space/padding around the box (with respect to the sides +of the image) in printer points. The default is 10. +
store_settings
:bool
, optional
+- when
True
, a .txt file is saved along with the image containing +all settings passed to this function. The default is False
+
+ +def get_metadata(self) +
+-
++
Loads metadata from the file.
+NOT IMPLEMENTED
+ +def get_pixelsize(self, convert=None) +
+-
++
Gets the physical size represented by the pixels from the image +metadata
+Parameters
+-
+
convert
:one
of['m', 'mm', 'um', 'µm', 'nm', 'pm', None]
, optional
+- physical unit to use for the pixel size. The default is None, which +chooses one of the above automatically based on the value. +
Returns
+-
+
pixelsize
:float
+- the physical size of a pixel in the given unit +
unit
:str
+- physical unit of the pixel size +
+
+ +class talos +(*args, **kwargs) +
+-
++++
Deprecated
+The tecnai and Talos classes have been renamed to the
+tia
class to +avoid confusion between data aquired using the older TIA and newer +Velox software from version 3.0.0 onwards. The old names are available +for backwards compatibility and should behave identically, but their +use is discouraged.Class of functions for TEM images from the Talos microscopes operated with +the TIA software
+See Also
+Ancestors
+-
+
- scm_electron_microscopes.tem.tia +
+ +class tecnai +(*args, **kwargs) +
+-
++++
Deprecated
+The tecnai and Talos classes have been renamed to the
+tia
class to +avoid confusion between data aquired using the older TIA and newer +Velox software from version 3.0.0 onwards. The old names are available +for backwards compatibility and should behave identically, but their +use is discouraged.Class of functions for TEM images from the tecnai microscopes operated with +the TIA software
+See Also
+Ancestors
+-
+
- scm_electron_microscopes.tem.tia +
+ +class tia +(filename) +
+-
++
Set of convenience functions for electron microscopy images of the tecnai +12, 20, 20feg and Talos microscopes when using the TIA software and +exporting the images as .tif files from TIA. Initializing the class takes a +string containing the filename as only argument, and by default loads in +the image.
+Parameters
+-
+
filename
:string
+- name of the file to load. Can but is not required to include .tif +as extension. +
Attributes
+-
+
filename
:string
+- name of the image file +
image
:np.ndarray
+- array of pixel values of the image with the optional data/scale bar +cropped off +
scalebar
:numpy.ndarray
+- if present, the array of pixel values of the original data/scale bar +
shape
:tuple
+- shape in (y,x) pixels of the image array +
dtype
:numpy.dtype
+- data type of the pixel values, generally
unint8
oruint16
+ PIL_image
:PIL.Image
+- python imaging library Image object of the image file +
Returns
+tia
class instanceSubclasses
+-
+
- scm_electron_microscopes.tem.talos +
- scm_electron_microscopes.tem.tecnai +
Methods
+-
+
+def export_metadata(self, filename=None) +
+-
++
save text file with metadata
+Parameters
+-
+
filename
:str
, optional
+- filename to store. The default is the image name with
+
'_metadata.txt'
appended.
+
+ +def export_with_scalebar(self, filename=None, **kwargs) +
+-
++
saves an exported image of the TEM image with a scalebar in one of the +four corners, where barsize is the scalebar size in data units (e.g. +nm) and scale the overall size of the scalebar and text with respect to +the width of the image.
+Parameters
+-
+
filename
:string
orNone
, optional
+- Filename + extension to use for the export file. The default is the +filename sans extension of the original TEM file, with +'_exported.png' appended. +
preprocess
:callable
, optional
+- callable to pre-process the image before any other processing is +done, useful for e.g. smoothing. Must take and return a +numpy.ndarray containing the image data as only arguments, and must +not change e.g. the pixel size or the scale bar may be incorrectly +sized. The default is None. +
crop
:tuple
orNone
, optional
+-
+
range describing a area of the original image (before rescaling the +resolution) to crop out for the export image. Can have two forms:
+-
+
-
+
+((xmin,ymin),(xmax,ymax))
, with the integer pixel indices of +the top left and bottom right corners respectively.
+ -
+
+(xmin,ymin,w,h)
with the integer indices of the top left corner +and the width and heigth of the cropped image in pixels (prior to +optional rescaling usingresolution
). When this format is used, +it is possible to set the width and height in pixels (default) or +in data units via thecrop_unit
parameter.
+
The default is
+None
which takes the entire image.
+ -
+
crop_unit
:'pixels'
or'data'
, optional
+- sets the unit in which the width and height in
crop
are +specified when using the (x,y,w,h) format, with'pixels'
to give +the size in pixels or'data'
to specify the size in the physical +unit used for the scalebar (after optional unit conversion via the +convert
parameter). Note that the position of the top left corner +is given in pixels. The((xmin,ymin),(xmax,ymax))
format must be +always given in pixels, andcrop_unit
is ignored ifcrop
is +given in this format. The default is'pixels'
.
+ intensity_range
:tuple
orNone
or'automatic'
, optional
+- tuple of
(lower,upper)
ranges for the (original) pixel values to +scale the brightness/contrast in the image to, or'automatic'
to +autoscale the intensity to the 0.01th and 99.99th percentile of the +input image, or None for the min and max value in the original +image. The default isNone
.
+ resolution
:int
, optional
+- the resolution along the x-axis (i.e. image width in pixels) to use
+for the exported image. The default is
None
, which uses the size +of the original image (after optional cropping usingcrop
).
+ draw_bar
:boolean
, optional
+- whether to draw a scalebar on the image, such that this function
+may be used just to strip the original bar and crop. The default is
+
True
.
+ barsize
:float
orNone
, optional
+- size (in data units matching the original scale bar, e.g. nm) of
+the scale bar to use. The default
None
, wich takes the desired +length for the current scale and round this to the nearest option +from a list of "nice" values.
+ scale
:float
, optional
+- factor to change the size of the scalebar+text with respect to the
+width of the image. Scale is chosen such, that at
scale=1
the +font size of the scale bar text is approximately 10 pt when +the image is printed at half the width of the text in a typical A4 +paper document (e.g. two images side-by-side). The default is 1.
+ loc
:int, one
of[
0,
1,
2,
3]
, optional
+- Location of the scalebar on the image, where
0
,1
,2
and3
+refer to the top left, top right, bottom left and bottom right +respectively. The default is2
, which is the bottom left corner.
+ convert
:str, one
of[
'fm',
'pm',
'Å'or
A,
'nm',
'µm'or
'um',
'mm',
'cm',
'dm',
'm']
+- Unit that will be used for the scale bar, the value will be
+automatically converted if this unit differs from the pixel size
+unit. The default is
None
, which uses the unit of the scalebar on +the original image.
+ font
:str
, optional
+- filename of an installed TrueType font ('.ttf' file) to use for the
+text on the scalebar. The default is
'arialbd.ttf'
.
+ fontsize
:int
, optional
+- base font size to use for the scale bar text. The default is 16.
+Note that this size will be re-scaled according to
resolution
and +scale
.
+ fontbaseline
:int
, optional
+- vertical offset for the baseline of the scale bar text from the top +of the scale bar, in printer points. The default is 10. +
fontpad
:int
, optional
+- minimum size in printer points of the space/padding between the +text and the bar and surrounding box. The default is 10. +
barthickness
:int
, optional
+- thickness in printer points of the scale bar itself. The default is +16. +
barpad
:int
, optional
+- size in printer points of the padding between the scale bar and the +surrounding box. The default is 10. +
box
:bool
, optional
+- Whether to put a semitransparent box around the scalebar and text
+to enhance contrast. The default is
True
.
+ boxalpha
:float
, optional
+- value between 0 and 1 for the opacity (inverse of transparency) of
+the box behind the scalebar and text when
box=True
. The default +is0.8
.
+ invert
:bool
, optional
+- If
True
, a white scalebar and text on a black box are used. The +default isFalse
which gives black text on a white background.
+ boxpad
:int
, optional
+- size of the space/padding around the box (with respect to the sides +of the image) in printer points. The default is 10. +
store_settings
:bool
, optional
+- when
True
, a .txt file is saved along with the image containing +all settings passed to this function. The default is False
+
+ +def get_metadata(self, asdict=False) +
+-
++
loads xml metadata from .tif file and returns xml tree object or dict
+Parameters
+-
+
asdict
:bool
, optional
+- whether to export as a dictionary. When False, an
+
xml.etree.ElementTree
is returned. The default is False.
+
Returns
+-
+
dictionary
orxml root object
+- dictionary or xml root object of the metadata. Can be indexed with
+xml_root.find('
')
+
+ +def get_pixelsize(self, convert=None) +
+-
++
Gets the physical size represented by the pixels from the image +metadata
+Parameters
+-
+
convert
:str, one
of[
fm,
pm,
Å,'A',
nm,
um,
µm,
mm,
cm,
dm,
m]
, optional
+- physical unit to use for the pixel size. The default is None, which +chooses one of the above automatically based on the value. +
Returns
+-
+
pixelsize
:float
+- the physical size of a pixel in the given unit +
unit
:str
+- physical unit of the pixel size +
+ +def get_pixelsize_legacy(self, debug=False, use_legacy_measurement=False) +
+-
++++
Deprecated
+This function has been deprecated and may give slightly inaccurate +result (only accurate to the nearest whole pixel), use +
+tia.get_pixelsize()
for more accurate and faster calibration. +Included for cases where results using the previous calibration +method must be reproduced or compared with.Reads the scalebar from images of the Tecnai or Talos +TEM microscopes +using text recognition via pytesseract or with manual input when +pytesseract is not installed
+Parameters
+-
+
debug
:bool
, optional
+- enable debug mode which prints extra information and figures to +troubleshoot any issues with calibration. The default is False. +
use_legacy_measurement
:bool
, optional
+- if
True
, use the (incorrect) left-side to left-side distance of +the vertical lines of the scale bar (i.e. equal to the +centre-to-centre distance of the vertical parts of the line). This +was long thought to be the correct way to interpret the scale bar +and is available for backwards compatability with older data +(analysis). The default isFalse
, which uses the outermost white +pixels of the scale bar, i.e. from the leftmost row of white pixels +of the left vertical part to the rightmost row of the right +vertical part.
+
Returns
+-
+
pixelsize
:float
+- the pixelsize in calibrated (physical) units +
unit
:string
+- the physical unit of the pixelsize +
+ +def print_metadata(self) +
+-
++
prints formatted output of the file's metadata
+
+ +class util +
+-
++
utility functions
Methods
+-
+
+def image_histogram(image, binsize=1, log=True) +
+-
++
plot histogram of the image grey values
+Parameters
+-
+
image
:numpy.array-like
+- the image to calculate the intensity histogram for. +
binsize
:float-like
, optional
+- width (in intensity units) of the bins to use. The default is 1. +
log
:bool
, optional
+- Whether to plot the histogram y axis on a log scale. The default is +True. +
+ +def print_metadata(xml_root) +
+-
++
print xml attributes/tags of phenom data to inspect elements.
+Parameters
+-
+
xml_root
:xml root object
+- Takes output of get_metadata() and prints formatted metadata to the +terminal +
+
+ +class velox +(filename=None, quiet=False) +
+-
++
Class for importing the .emd file format used natively by the Velox +software used on the Talos microscopes.
+Note that one .emd file may contain multiple images / videos, (e.g. when +recording with multiple detectors simultaneously), and most functions are +available through the
+velox_image
subclass accessible through the +get_image
function.Parameters
+-
+
filename
:str
orint
+- The filename to load, extension optional. Alternatively an integer may +be given to load the nth file in the current working directory. The +default is to load the first file. +
quiet
:bool
+- whether to print a list of images contained in the file when the class +is initialized. The default is False. +
Returns
+
+velox
class instance-
+
init class instance, open file container
+- +
Methods
+-
+
+def get_dataset(self, dataset) +
+-
++
Returns velox_image class instance containing all data and metadata +for a particular image in the file.
+Parameters
+-
+
image
:str
orint
+- the image to return the data for, given as the name/tag (when str)
+or as its integer index in the file, i.e.
velox.get_image(0)
+returns the data container for the first image.
+
Returns
+velox_dataset
orvelox_image
class instance
+ +def print_file_struct(self) +
+-
++
prints a formatted overview of the structure of the .emd file +container, useful for accessing additional data manually
+
+ +class velox_edx +(parent, im) +
+-
++
subclass for emd files with edx data
Ancestors
+-
+
- scm_electron_microscopes.tem.velox_dataset +
Methods
+-
+
+def get_image(self, energy_ranges=None, frame_range=None, binning=1) +
+-
++
returns edx/eds image where the pixel value is the total number of +photon counts within the specified energy range(s) and frame range.
+Parameters
+-
+
energy_ranges
:list
oftuples
, optional
+- List of (min,max) energy range(s) specifying which photons to +count, given in keV. The default is None which takes all photon +counts. +
frame_range
:tuple
, optional
+- Tuple of (min,max) for the frame indices to sum the counts for. The +default is None which sums all frames. +
Returns
+-
+
2D numpy.array
+- +
+ +def get_spectrum(self) +
+-
++
get overall spectral data for the edx dataset
+Returns
+-
+
energies
:numpy.array
+- energies in keV +
counts
:numpy.array
+- number of photon counts per energy +
+
+ +class velox_image +(parent, im) +
+-
++
Subclass of the
+velox_dataset
class for individual images (or image +series) in an .emd file, such as when simultaneously recording HAADF-STEM +and BF-STEM. Not indended to be called directly, rather to be initialized +trough theget_image
method of thevelox
+class.Parameters
+-
+
filename
:str
+- the .emd file to take the image from +
im
:str
orint
+- name / tag or integer index of the image to initialize +
Ancestors
+-
+
- scm_electron_microscopes.tem.velox_dataset +
Methods
+-
+
+def export_tiff(self, filename_prefix=None, frame_range=None, **kwargs) +
+-
++
stores the image data to a tiff file with metadata stored in the image +description for futher processing or viewing in other software.
+Parameters
+-
+
filename_prefix
:str
+- filename to use for saved file without file extension +
frame_range
:int
ortuple
ofint
+- int specifying which frame, or tuple of (start,stop) ints +specifying which frames, to save in the tiff file. The default is +all frames in the dataset +
kwargs
:dict
+- any further keyword arguments will be passed on to
+
tifffile.imsave
.
+
Returns
+None.
+ +def export_with_scalebar(self, frame=0, filename=None, **kwargs) +
+-
++
saves an exported image of the TEM image with a scalebar in one of the +four corners, where barsize is the scalebar size in data units (e.g. +nm) and scale the overall size of the scalebar and text with respect to +the width of the image.
+Parameters
+-
+
filename
:string
orNone
, optional
+- Filename + extension to use for the export file. The default is the +filename sans extension of the original TEM file, with +'_exported.png' appended. +
frame
:int
+- the frame to export, see
get_frame()
. The default is 0.
+ preprocess
:callable
, optional
+- callable to pre-process the image before any other processing is +done, useful for e.g. smoothing. Must take and return a +numpy.ndarray containing the image data as only arguments, and must +not change e.g. the pixel size or the scale bar may be incorrectly +sized. The default is None. +
crop
:tuple
orNone
, optional
+-
+
range describing a area of the original image (before rescaling the +resolution) to crop out for the export image. Can have two forms:
+-
+
-
+
+((xmin,ymin),(xmax,ymax))
, with the integer pixel indices of +the top left and bottom right corners respectively.
+ -
+
+(xmin,ymin,w,h)
with the integer indices of the top left corner +and the width and heigth of the cropped image in pixels (prior to +optional rescaling usingresolution
). When this format is used, +it is possible to set the width and height in pixels (default) or +in data units via thecrop_unit
parameter.
+
The default is
+None
which takes the entire image.
+ -
+
crop_unit
:'pixels'
or'data'
, optional
+- sets the unit in which the width and height in
crop
are +specified when using the (x,y,w,h) format, with'pixels'
to give +the size in pixels or'data'
to specify the size in the physical +unit used for the scalebar (after optional unit conversion via the +convert
parameter). Note that the position of the top left corner +is given in pixels. The((xmin,ymin),(xmax,ymax))
format must be +always given in pixels, andcrop_unit
is ignored ifcrop
is +given in this format. The default is'pixels'
.
+ intensity_range
:tuple
orNone
or'automatic'
+- tuple of
(lower,upper)
ranges for the (original) pixel values to +scale the brightness/contrast in the image to, or'automatic'
to +autoscale the intensity to the 0.01th and 99.99th percentile of the +input image, or None for the min and max value in the original +image. The default isNone
.
+ resolution
:int
, optional
+- the resolution along the x-axis (i.e. image width in pixels) to use
+for the exported image. The default is
None
, which uses the size +of the original image (after optional cropping usingcrop
).
+ draw_bar
:boolean
, optional
+- whether to draw a scalebar on the image, such that this function
+may be used just to strip the original bar and crop. The default is
+
True
.
+ barsize
:float
orNone
, optional
+- size (in data units matching the original scale bar, e.g. nm) of
+the scale bar to use. The default
None
, wich takes the desired +length for the current scale and round this to the nearest option +from a list of "nice" values.
+ scale
:float
, optional
+- factor to change the size of the scalebar+text with respect to the
+width of the image. Scale is chosen such, that at
scale=1
the +font size of the scale bar text is approximately 10 pt when +the image is printed at half the width of the text in a typical A4 +paper document (e.g. two images side-by-side). The default is 1.
+ loc
:int, one
of[
0,
1,
2,
3]
, optional
+- Location of the scalebar on the image, where
0
,1
,2
and3
+refer to the top left, top right, bottom left and bottom right +respectively. The default is2
, which is the bottom left corner.
+ convert
:str, one
of[
'fm',
'pm',
'Å'or
A,
'nm',
'µm'or
'um',
'mm',
'cm',
'dm',
'm']
, optional
+- Unit that will be used for the scale bar, the value will be
+automatically converted if this unit differs from the pixel size
+unit. The default is
None
, which uses the unit of the scalebar on +the original image.
+ font
:str
, optional
+- filename of an installed TrueType font ('.ttf' file) to use for the
+text on the scalebar. The default is
'arialbd.ttf'
.
+ fontsize
:int
, optional
+- base font size to use for the scale bar text. The default is 16.
+Note that this size will be re-scaled according to
resolution
and +scale
.
+ fontbaseline
:int
, optional
+- vertical offset for the baseline of the scale bar text from the top +of the scale bar, in printer points. The default is 10. +
fontpad
:int
, optional
+- minimum size in printer points of the space/padding between the +text and the bar and surrounding box. The default is 10. +
barthickness
:int
, optional
+- thickness in printer points of the scale bar itself. The default is +16. +
barpad
:int
, optional
+- size in printer points of the padding between the scale bar and the +surrounding box. The default is 10. +
box
:bool
, optional
+- Whether to put a semitransparent box around the scalebar and text
+to enhance contrast. The default is
True
.
+ boxalpha
:float
, optional
+- value between 0 and 1 for the opacity (inverse of transparency) of
+the box behind the scalebar and text when
box=True
. The default +is0.8
.
+ invert
:bool
, optional
+- If
True
, a white scalebar and text on a black box are used. The +default isFalse
which gives black text on a white background.
+ boxpad
:int
, optional
+- size of the space/padding around the box (with respect to the sides +of the image) in printer points. The default is 10. +
store_settings
:bool
, optional
+- when
True
, a .txt file is saved along with the image containing +all settings passed to this function. The default is False
+
+ +def get_data(self) +
+-
++
Loads and returns the full image data as numpy array
+Returns
+-
+
numpy.ndarray
ofpixel value
+- +
s
+- +
+ +def get_frame(self, i) +
+-
++
returns specific image / video frame from the dataset
+Parameters
+-
+
i
:int
+- the index of the frame to load +
Returns
+-
+
numpy.array
ofpixel values
+- +
+ +def get_frametime(self) +
+-
++
Returns the time in seconds it takes to scan one frame
+Returns
+-
+
float
+- +
+ +def get_pixelsize(self, convert=None) +
+-
++
returns the pixel size from the metadata, rescaled to an appropriate +unit for convenience
+Parameters
+-
+
convert
:one
of['pm', 'nm', 'µm', 'um', 'mm', 'm']
+- physical data unit to convert the pixel size to, the default is +None which chooses a unit based on the magnitude. +
Returns
+-
+
pixelsize
:tuple
offloat
+- (y,x) pixel sizes +
unit
:str
+- physical unit of the pixel size +
+
+ +class xl30sfeg +(filename) +
+-
++
Set of convenience functions for the xl30sfeg SEM microscope.
+Parameters
+-
+
filename
:str
+- filename of the image to load +
Returns
+-
+
xl30sfeg class instance
+- +
Methods
+-
+
+def export_with_scalebar(self, filename=None, **kwargs) +
+-
++
saves an exported image of the SEM image with a scalebar in one of the +four corners, where barsize is the scalebar size in data units (e.g. +nm) and scale the overall size of the scalebar and text with respect to +the width of the image.
+Parameters
+-
+
filename
:string
orNone
, optional
+- Filename + extension to use for the export file. The default is the +filename sans extension of the original SEM file, with +'_exported.png' appended. +
preprocess
:callable
, optional
+- callable to pre-process the image before any other processing is +done, useful for e.g. smoothing. Must take and return a +numpy.ndarray containing the image data as only arguments, and must +not change e.g. the pixel size or the scale bar may be incorrectly +sized. The default is None. +
crop
:tuple
orNone
, optional
+-
+
range describing a area of the original image (before rescaling the +resolution) to crop out for the export image. Can have two forms:
+-
+
-
+
+((xmin,ymin),(xmax,ymax))
, with the integer pixel indices of +the top left and bottom right corners respectively.
+ -
+
+(xmin,ymin,w,h)
with the integer indices of the top left corner +and the width and heigth of the cropped image in pixels (prior to +optional rescaling usingresolution
). When this format is used, +it is possible to set the width and height in pixels (default) or +in data units via thecrop_unit
parameter.
+
The default is
+None
which takes the entire image.
+ -
+
crop_unit
:'pixels'
or'data'
, optional
+- sets the unit in which the width and height in
crop
are +specified when using the (x,y,w,h) format, with'pixels'
to give +the size in pixels or'data'
to specify the size in the physical +unit used for the scalebar (after optional unit conversion via the +convert
parameter). Note that the position of the top left corner +is given in pixels. The((xmin,ymin),(xmax,ymax))
format must be +always given in pixels, andcrop_unit
is ignored ifcrop
is +given in this format. The default is'pixels'
.
+ resolution
:int
, optional
+- the resolution along the x-axis (i.e. image width in pixels) to use
+for the exported image. The default is
None
, which uses the size +of the original image (after optional cropping usingcrop
).
+ draw_bar
:boolean
, optional
+- whether to draw a scalebar on the image, such that this function
+may be used just to strip the original bar and crop. The default is
+
True
.
+ barsize
:float
orNone
, optional
+- size (in data units matching the original scale bar, e.g. nm) of
+the scale bar to use. The default
None
, wich takes the desired +length for the current scale and round this to the nearest option +from a list of "nice" values.
+ scale
:float
, optional
+- factor to change the size of the scalebar+text with respect to the
+width of the image. Scale is chosen such, that at
scale=1
the +font size of the scale bar text is approximately 10 pt when +the image is printed at half the width of the text in a typical A4 +paper document (e.g. two images side-by-side). The default is 1.
+ loc
:int, one
of[
0,
1,
2,
3]
, optional
+- Location of the scalebar on the image, where
0
,1
,2
and3
+refer to the top left, top right, bottom left and bottom right +respectively. The default is2
, which is the bottom left corner.
+ convert
:str, [
'fm',
'pm',
'Å'or
A,
'nm',
'µm'or
'um',
'mm',
'cm',
'dm',
'm']
+- Unit that will be used for the scale bar, the value will be
+automatically converted if this unit differs from the pixel size
+unit. The default is
None
, which uses the unit of the scalebar on +the original image.
+ font
:str
, optional
+- filename of an installed TrueType font ('.ttf' file) to use for the
+text on the scalebar. The default is
'arialbd.ttf'
.
+ fontsize
:int
, optional
+- base font size to use for the scale bar text. The default is 16.
+Note that this size will be re-scaled according to
resolution
and +scale
.
+ fontbaseline
:int
, optional
+- vertical offset for the baseline of the scale bar text from the top +of the scale bar, in printer points. The default is 10. +
fontpad
:int
, optional
+- minimum size in printer points of the space/padding between the +text and the bar and surrounding box. The default is 10. +
barthickness
:int
, optional
+- thickness in printer points of the scale bar itself. The default is +16. +
barpad
:int
, optional
+- size in printer points of the padding between the scale bar and the +surrounding box. The default is 10. +
box
:bool
, optional
+- Whether to put a semitransparent box around the scalebar and text
+to enhance contrast. The default is
True
.
+ boxalpha
:float
, optional
+- value between 0 and 1 for the opacity (inverse of transparency) of
+the box behind the scalebar and text when
box=True
. The default +is0.8
.
+ invert
:bool
, optional
+- If
True
, a white scalebar and text on a black box are used. The +default isFalse
which gives black text on a white background.
+ boxpad
:int
, optional
+- size of the space/padding around the box (with respect to the sides +of the image) in printer points. The default is 10. +
store_settings
:bool
, optional
+- when
True
, a .txt file is saved along with the image containing +all settings passed to this function. The default is False
+
+ +def get_image(self) +
+-
++
load the image and (if present) scalebar
+ +def get_metadata(self) +
+-
++
Load the metadata footer from XL30SFEG SEM files and return xml +tree object which can be indexed for extraction of useful parameters. +Does not require loading whole file into memory. Searches for 'human' +formatted metadata.
+Returns
+-
+
xml_root
:xml.etree.ElementTree object
+- xml root object of the metadata. Can be printed using it as
+argument to print_metadata, or indexed with
+xml_root.find('
')
+
+ +def get_pixelsize(self) +
+-
++
gets the pixel size from the metadata and calculates the unit
+Returns
+-
+
pixelsize
:float
+- physical size of the pixels in x and y +
unit
:str
+- physical unit corresponding to the pixelsize. +
+ +def print_metadata(self) +
+-
++
print formatted output of metadata
+
+