You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

57 lines
1.8 KiB

8 years ago
8 years ago
  1. # Tutorial
  2. ### Installation
  3. The package is available on PyPi. Install it using:
  4. ```
  5. pip install nd2reader
  6. ```
  7. If you don't already have the packages `numpy`, `pims`, `six` and `xmltodict`, they will be installed automatically if you use the `setup.py` script.
  8. `nd2reader` is an order of magnitude faster in Python 3. I recommend using it unless you have no other choice. Python 2.7 and Python >= 3.4 are supported.
  9. ### Opening ND2s
  10. `nd2reader` follows the [pims](https://github.com/soft-matter/pims) framework. To open a file and show the first frame:
  11. ```python
  12. from nd2reader import ND2Reader
  13. import matplotlib.pyplot as plt
  14. with ND2Reader('my_directory/example.nd2') as images:
  15. plt.imshow(images[0])
  16. ```
  17. After opening the file, all `pims` features are supported. Please refer to the [pims documentation](http://soft-matter.github.io/pims/).
  18. ### ND2 metadata
  19. The ND2 file contains various metadata, such as acquisition information,
  20. regions of interest and custom user comments. Most of this metadata is parsed
  21. and available in dictionary form. For example:
  22. ```python
  23. from nd2reader import ND2Reader
  24. with ND2Reader('my_directory/example.nd2') as images:
  25. # width and height of the image
  26. print('%d x %d px' % (images.metadata['width'], images.metadata['height']))
  27. ```
  28. All metadata properties are:
  29. * `width`: the width of the image in pixels
  30. * `height`: the height of the image in pixels
  31. * `date`: the date the image was taken
  32. * `fields_of_view`: the fields of view in the image
  33. * `frames`: a list of all frame numbers
  34. * `z_levels`: the z levels in the image
  35. * `total_images_per_channel`: the number of images per color channel
  36. * `channels`: the color channels
  37. * `pixel_microns`: the amount of microns per pixel
  38. * `rois`: the regions of interest (ROIs) defined by the user
  39. * `experiment`: information about the nature and timings of the ND experiment