Browse Source

Merge pull request #144 from jimrybarski/143-find-pixel-size

143 find pixel size
zolfa-add_slices_loading
Jim Rybarski 9 years ago
parent
commit
77475bb3fc
6 changed files with 36 additions and 2 deletions
  1. +3
    -0
      functional_tests/FYLM141111001.py
  2. +6
    -0
      functional_tests/monocycle.py
  3. +3
    -0
      functional_tests/single.py
  4. +10
    -0
      nd2reader/main.py
  5. +12
    -1
      nd2reader/model/metadata.py
  6. +2
    -1
      nd2reader/parser/v3.py

+ 3
- 0
functional_tests/FYLM141111001.py View File

@ -39,6 +39,9 @@ class FYLM141111Tests(unittest.TestCase):
def test_z_levels(self):
self.assertTupleEqual(tuple(self.nd2.z_levels), (0, 1, 2))
def test_pixel_size(self):
self.assertGreater(self.nd2.pixel_microns, 0.0)
def test_image(self):
image = self.nd2[14]
self.assertEqual(image.field_of_view, 2)


+ 6
- 0
functional_tests/monocycle.py View File

@ -17,6 +17,9 @@ class Monocycle1Tests(unittest.TestCase):
def test_channels(self):
self.assertListEqual(self.nd2.channels, ['Cy3Narrow', 'TxRed-modified', 'FITC', 'DAPI'])
def test_pixel_size(self):
self.assertGreater(self.nd2.pixel_microns, 0.0)
def test_select(self):
manual_images = []
for _, image in zip(range(20), self.nd2):
@ -78,6 +81,9 @@ class Monocycle2Tests(unittest.TestCase):
def tearDown(self):
self.nd2.close()
def test_pixel_size(self):
self.assertGreater(self.nd2.pixel_microns, 0.0)
def test_select(self):
manual_images = []
for _, image in zip(range(20), self.nd2):


+ 3
- 0
functional_tests/single.py View File

@ -28,6 +28,9 @@ class SingleTests(unittest.TestCase):
def test_channels(self):
self.assertEqual(self.nd2.channels, ['Quad Band 2'])
def test_pixel_size(self):
self.assertGreater(self.nd2.pixel_microns, 0.0)
def test_actual_length(self):
count = 0
for image in self.nd2:


+ 10
- 0
nd2reader/main.py View File

@ -170,6 +170,16 @@ class Nd2(object):
"""
return self._metadata.date
@property
def pixel_microns(self):
"""
The width of a pixel in microns. Note that the user can override this in NIS Elements so it may not reflect reality.
:rtype: float
"""
return self._metadata.pixel_microns
def get_image(self, frame_number, field_of_view, channel_name, z_level):
"""
Attempts to return the image with the unique combination of given attributes. None will be returned if a match


+ 12
- 1
nd2reader/model/metadata.py View File

@ -3,7 +3,7 @@ import six
class Metadata(object):
""" A simple container for ND2 metadata. """
def __init__(self, height, width, channels, date, fields_of_view, frames, z_levels, total_images_per_channel):
def __init__(self, height, width, channels, date, fields_of_view, frames, z_levels, total_images_per_channel, pixel_microns):
self._height = height
self._width = width
self._channels = channels
@ -12,6 +12,7 @@ class Metadata(object):
self._frames = frames
self._z_levels = z_levels
self._total_images_per_channel = total_images_per_channel
self._pixel_microns = pixel_microns
@property
def height(self):
@ -97,6 +98,16 @@ class Metadata(object):
"""
return self._total_images_per_channel
@property
def pixel_microns(self):
"""
The width of a pixel in microns.
:rtype: float
"""
return self._pixel_microns
class CameraSettings(object):
""" Contains some basic information about a physical camera and its settings. """


+ 2
- 1
nd2reader/parser/v3.py View File

@ -174,7 +174,8 @@ class V3Parser(BaseParser):
z_levels = self._parse_z_levels(self.raw_metadata)
total_images_per_channel = self._parse_total_images_per_channel(self.raw_metadata)
channels = self._parse_channels(self.raw_metadata)
self.metadata = Metadata(height, width, channels, date, fields_of_view, frames, z_levels, total_images_per_channel)
pixel_microns = self.raw_metadata.image_calibration.get(six.b('SLxCalibration'), {}).get(six.b('dCalibration'))
self.metadata = Metadata(height, width, channels, date, fields_of_view, frames, z_levels, total_images_per_channel, pixel_microns)
def _parse_camera_settings(self):
"""


Loading…
Cancel
Save