instamatic.formats
Functions
read_cbf(fname)
CBF reader not implemented.
Source code in src/instamatic/formats/__init__.py
119 120 121 |
|
read_hdf5(fname)
Simple function to read a hdf5 file written by Instamatic.
fname: str, path or filename to image which should be opened
Returns: image: np.ndarray, header: dict a tuple of the image as numpy array and dictionary with all the tem parameters and image attributes
Source code in src/instamatic/formats/__init__.py
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
|
read_image(fname)
Guess filetype by extension.
Source code in src/instamatic/formats/__init__.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
|
read_tiff(fname)
Simple function to read a tiff file.
fname: str, path or filename to image which should be opened
Returns: image: np.ndarray, header: dict a tuple of the image as numpy array and dictionary with all the tem parameters and image attributes
Source code in src/instamatic/formats/__init__.py
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
|
write_hdf5(fname, data, header=None)
Simple function to write data to hdf5 format using h5py.
fname: str, path or filename to which the image should be saved data: np.ndarray, numpy array containing image data (path="/data") header: dict, dictionary containing the metadata that should be saved key/value pairs are stored as attributes on the data
Source code in src/instamatic/formats/__init__.py
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
|
write_tiff(fname, data, header=None)
Simple function to write a tiff file.
fname: str, path or filename to which the image should be saved data: np.ndarray, numpy array containing image data header: dict, dictionary containing the metadata that should be saved key/value pairs are stored as yaml in the TIFF ImageDescription tag
Source code in src/instamatic/formats/__init__.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
|
Modules
adscimage
Functions
read_adsc(fname)
Read in the file.
Source code in src/instamatic/formats/adscimage.py
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 |
|
readheader(infile)
Read an adsc header.
Source code in src/instamatic/formats/adscimage.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
|
write_adsc(fname, data, header={})
Write adsc format.
Source code in src/instamatic/formats/adscimage.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
|
csvIO
Functions
read_csv(f)
Read a csv file into a pandas DataFrame.
Source code in src/instamatic/formats/csvIO.py
25 26 27 28 29 30 |
|
read_ycsv(f)
read file in ycsv format: https://blog.datacite.org/using-yaml- frontmatter-with-csv/
format:
$YAML_BLOCK
$YAML_BLOCK
$CSV_BLOCK
Source code in src/instamatic/formats/csvIO.py
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 |
|
results2df(results, sort=True)
Convert a list of IndexingResult objects to pandas DataFrame.
Source code in src/instamatic/formats/csvIO.py
8 9 10 11 12 13 14 15 |
|
write_csv(f, results)
Write a list of IndexingResult objects to a csv file.
Source code in src/instamatic/formats/csvIO.py
18 19 20 21 22 |
|
write_ycsv(f, data, metadata)
write file in ycsv format: https://blog.datacite.org/using-yaml- frontmatter-with-csv/
format:
$YAML_BLOCK
$YAML_BLOCK
$CSV_BLOCK
Source code in src/instamatic/formats/csvIO.py
80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
|
mrc
Read and write images in the MRC format.
.. todo:: define arachnid header and map to mrc
.. note::
This code is heavily modified version of the MRC parser/writer
found in the Scripps Appion program.
.. Created on Aug 9, 2012 .. codeauthor:: Robert Langlois rl2528@columbia.edu
Functions
array_from_header(header)
Convert header information to array parameters.
:Parameters:
header : header_dtype Header fields
:Returns:
header : dict File header dtype : dtype Data type shape : tuple Shape of the array order : str Order of the array offset : int Header offset swap : bool Swap byte order
Source code in src/instamatic/formats/mrc.py
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 |
|
cache_data()
Get keywords to be added as data cache.
:Returns:
extra : dict Keyword arguments
Source code in src/instamatic/formats/mrc.py
217 218 219 220 221 222 223 224 225 226 |
|
count_images(filename, no_strict_mrc=False)
Count the number of images in the file.
:Parameters:
filename : str or file object Filename or open stream for a file no_strict_mrc : bool Perform strict MRC header checking (recommended) - Only EPU MRC files and Yifan's frame alignment require this to be off.
:Returns:
out : int Number of images in the file
Source code in src/instamatic/formats/mrc.py
391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 |
|
create_header(shape, dtype, order='C', header=None)
Create a header for the MRC image format.
@todo support header parameters
:Parameters:
shape : tuple Shape of the array dtype : numpy.dtype Data type for NumPy ndarray header : dict Header values for image :Returns:
h : dtype Data type for NumPy ndarray describing the header
Source code in src/instamatic/formats/mrc.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 |
|
is_format_header(h)
Test if the given header has the proper format.
:Parameters:
h : array Header to test
:Returns:
val : bool Test if dtype matches format dtype
Source code in src/instamatic/formats/mrc.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 |
|
is_readable(filename, no_strict_mrc=False)
Test if the file read has a valid MRC header.
:Parameters:
filename : str or file object Filename or open stream for a file no_strict_mrc : bool Perform strict MRC header checking (recommended) - Only EPU MRC files and Yifan's frame alignment require this to be off.
:Returns:
out : bool True if the header conforms to MRC
Source code in src/instamatic/formats/mrc.py
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 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 |
|
is_writable(filename)
Test if the image extension of the given filename is understood as a writable format.
:Parameters:
filename : str Output filename to test
:Returns:
write : bool True if the format is recognized
Source code in src/instamatic/formats/mrc.py
598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 |
|
iter_images(filename, index=None, header=None, no_strict_mrc=False)
Read a set of SPIDER images.
:Parameters:
filename : str or file object Filename or open stream for a file index : int, optional Index of image to start, if None, start with the first image (Default: None) header : dict, optional Output dictionary to place header values no_strict_mrc : bool Perform strict MRC header checking (recommended) - Only EPU MRC files and Yifan's frame alignment require this to be off.
:Returns:
out : array Array with image information from the file
Source code in src/instamatic/formats/mrc.py
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 |
|
read_header(filename, index=None, no_strict_mrc=False, force_volume=False)
Read the MRC header.
:Parameters:
filename : str or file object Filename or open stream for a file index : int, ignored Index of image to get the header, if None, the stack header (Default: None) no_strict_mrc : bool Perform strict MRC header checking (recommended) - Only EPU MRC files and Yifan's frame alignment require this to be off. force_volume : bool Force image to be treated as a volume
:Returns:
header : dict Dictionary with header information
Source code in src/instamatic/formats/mrc.py
315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 |
|
read_image(filename, index=None, cache=None, no_strict_mrc=False, force_volume=False)
Read an image from the specified file in the MRC format.
:Parameters:
filename : str or file object
Filename or open stream for a file
index : int, optional
Index of image to get, if None, first image (Default: None)
no_strict_mrc : bool
Perform strict MRC header checking (recommended) - Only
EPU MRC files and Yifan's frame alignment require this
to be off.
force_volume : bool
For image to be read as a volume
:Returns:
out : array
Array with image information from the file
Source code in src/instamatic/formats/mrc.py
505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 |
|
read_mrc_header(filename, index=None, no_strict_mrc=False)
Read the MRC header.
:Parameters:
filename : str or file object Filename or open stream for a file index : int, ignored Index of image to get the header, if None, the stack header (Default: None) no_strict_mrc : bool Perform strict MRC header checking (recommended) - Only EPU MRC files and Yifan's frame alignment require this to be off.
:Returns:
out : array Array with header information in the file
Source code in src/instamatic/formats/mrc.py
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 |
|
reshape_data(out, h, index, count, force_volume=False)
Reshape the data to the proper dimensions.
:Parameters:
out : array Array with image information from the file h : array Header information index : int Index of image count : int Number of images in file
:Returns:
out : array Array with image information from the file
Source code in src/instamatic/formats/mrc.py
557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 |
|
valid_image(filename, no_strict_mrc=False)
Test if the image is valid.
:Parameters:
filename : str
Input filename to test
no_strict_mrc : bool
Perform strict MRC header checking (recommended) - Only
EPU MRC files and Yifan's frame alignment require this
to be off.
:Returns:
flag : bool
True if image is valid
Source code in src/instamatic/formats/mrc.py
477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 |
|
write_image(filename, img, index=None, header=None, inplace=False)
Write an image array to a file in the MRC format.
:Parameters:
filename : str Name of the output file img : array Image array index : int, optional Index to write image in the stack header : dict, optional Dictionary of header values inplace : bool Write new image to stack without removing the stack
Source code in src/instamatic/formats/mrc.py
619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 |
|
Modules
util
Defines a set of utility functions.
.. Created on Jul 18, 2013 .. codeauthor:: Robert Langlois rl2528@columbia.edu
Classes
InvalidHeaderException
Bases: Exception
Thrown when the image file has an invalid header.
Functions
close(filename, fd)
Close the file descriptor (if it was opened by caller)
filename : str Name of the file fd : File File descriptor
Source code in src/instamatic/formats/util.py
63 64 65 66 67 68 69 70 71 72 |
|
fromfile(fin, dtype, count, sep='')
Source code in src/instamatic/formats/util.py
24 25 26 27 28 29 |
|
read_image(f, header, dtype, dlen, shape, swap, order='C')
Read an image from a file using random file acess.
:Parameters:
f : stream Input file stream header : dict Header dtype : dtype Data type dlen : int Number of elements shape : tuple Shape of the array swap : bool Swap the byte order order : str Layout of a 2 or 3D array
:Returns:
out : ndarray Array of image data
Source code in src/instamatic/formats/util.py
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 |
|
uopen(filename, mode)
Open a stream to filename.
:Parameters:
filename : str Name of the file mode : str Mode to open file
:Returns:
fd : File File descriptor
Source code in src/instamatic/formats/util.py
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 |
|
update_header(dest, source, header_map, tag=None)
Map values from or to the format and the internal header.
:Parameters:
dest : array or dict Destination of the header values source : array or dict Source of the header values header_map : dict Map from destination to source tag : str Format specific attribute tag
:Returns:
dest : array or dict Destination of the header values
Source code in src/instamatic/formats/util.py
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 |
|
xdscbf
Functions
compByteOffset(data)
Compress a dataset into a string using the byte_offet algorithm.
:param data: ndarray :return: string/bytes with compressed data
test = np.array([0,1,2,127,0,1,2,128,0,1,2,32767,0,1,2,32768,0,1,2,2147483647,0,1,2,2147483648,0,1,2,128,129,130,32767,32768,128,129,130,32768,2147483647,2147483648])
Source code in src/instamatic/formats/xdscbf.py
20 21 22 23 24 25 26 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 |
|
write(fname, data, header={})
Write the file in CBF format.
:param str fname: name of the file
Source code in src/instamatic/formats/xdscbf.py
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 |
|