Skip to content

instamatic.montage

Classes

InstamaticMontage

Bases: Montage

Functions

export(outfile='stitched.tiff')

Export the stitched image to a tiff file.

Parameters:

  • outfile (str, default: 'stitched.tiff' ) –

    Name of the image file.

Source code in src/instamatic/montage.py
57
58
59
60
61
62
63
64
65
66
def export(self, outfile: str = 'stitched.tiff') -> None:
    """Export the stitched image to a tiff file.

    Parameters
    ----------
    outfile : str
        Name of the image file.
    """
    from instamatic.formats import write_tiff
    write_tiff(outfile, self.stitched)
from_montage_yaml(filename='montage.yaml') classmethod

Load montage from a series of tiff files + montage.yaml

Source code in src/instamatic/montage.py
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
@classmethod
def from_montage_yaml(cls, filename: str = 'montage.yaml'):
    """Load montage from a series of tiff files + `montage.yaml`"""
    import yaml

    from instamatic.formats import read_tiff

    p = Path(filename)
    drc = p.parent

    d = yaml.safe_load(open(p))
    fns = (drc / fn for fn in d['filenames'])

    d['stagecoords'] = np.array(d['stagecoords'])
    d['stagematrix'] = np.array(d['stagematrix'])

    images = [read_tiff(fn)[0] for fn in fns]

    gridspec = {k: v for k, v in d.items() if k in ('gridshape', 'direction', 'zigzag', 'flip')}

    m = cls(images=images, gridspec=gridspec, **d)
    m.update_gridspec(flip=not d['flip'])  # BUG: Work-around for gridspec madness
    # Possibly related is that images are rotated 90 deg. in SerialEM mrc files

    return m
set_calibration(mode, magnification)

Set the calibration parameters for the montage map. Sets the pixelsize and stagematrix from the config files.

Parameters:

  • mode (str) –

    The TEM mode used, i.e. lowmag, mag1, samag

  • magnification (int) –

    The magnification used

Source code in src/instamatic/montage.py
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
def set_calibration(self, mode: str, magnification: int) -> None:
    """Set the calibration parameters for the montage map. Sets the
    pixelsize and stagematrix from the config files.

    Parameters
    ----------
    mode : str
        The TEM mode used, i.e. `lowmag`, `mag1`, `samag`
    magnification : int
        The magnification used
    """
    from instamatic import config

    pixelsize = config.calibration[mode]['pixelsize'][magnification]

    stagematrix = config.calibration[mode]['stagematrix'][magnification]
    stagematrix = np.array(stagematrix).reshape(2, 2)

    self.set_pixelsize(pixelsize)
    self.set_stagematrix(stagematrix)
    self.mode = mode
    self.magnification = magnification