def UpdateMagnification(self): # Total magnification mag = self._mpp_screen / self._microscope_view.mpp.value label = u"Mag: × %s" % units.readable_str( units.round_significant(mag, 3)) # Gather all different image mpp values mpps = set() for im, stream in self._microscope_view.stream_tree.getImages(): try: if hasattr(stream, 'mpp'): # im is a tuple of tuple of tiles mpps.add(stream.mpp.min) else: md = im.metadata mpps.add(md[model.MD_PIXEL_SIZE][0]) except KeyError: pass # If there's only one mpp value (i.e. there's only one image, or they # all have the same mpp value), indicate the digital zoom. if len(mpps) == 1: mpp_im = mpps.pop() # mag_im = self._mpp_screen / mpp_im # as if 1 im.px == 1 sc.px mag_dig = mpp_im / self._microscope_view.mpp.value label += u" (Digital: × %s)" % units.readable_str( units.round_significant(mag_dig, 2)) if self.bottom_legend: self.bottom_legend.set_mag_label(label)
def UpdateHFWLabel(self): """ Physical width of the display""" if not self._microscope_view: return hfw = self._microscope_view.mpp.value * self.GetClientSize()[0] hfw = units.round_significant(hfw, 4) label = u"HFW: %s" % units.readable_str(hfw, "m", sig=3) self.bottom_legend.set_hfw_label(label)
def UpdateMagnification(self): # Total magnification mag = self._mpp_screen / self._microscope_view.mpp.value label = u"Mag: × %s" % units.readable_str(units.round_significant(mag, 3)) # Gather all different image mpp values mpps = set() for im in self._microscope_view.stream_tree.getImages(): try: mpps.add(im.metadata[model.MD_PIXEL_SIZE][0]) except KeyError: pass # If there's only one mpp value (i.e. there's only one image, or they # all have the same mpp value), indicate the digital zoom. if len(mpps) == 1: mpp_im = mpps.pop() # mag_im = self._mpp_screen / mpp_im # as if 1 im.px == 1 sc.px mag_dig = mpp_im / self._microscope_view.mpp.value label += u" (Digital: × %s)" % units.readable_str(units.round_significant(mag_dig, 2)) self.bottom_legend.set_mag_label(label)
def test_to_string_pretty(self): values = [ 0.000000041003, 0.0051, 0.014, 0.39, 0.230234543545, ] for sig in [2, 4, 6]: # (None, 0, 1, 2, 4, 8): for v in values: self.assertEqual(units.round_significant(v, sig), float(units.to_string_pretty(v, sig, "s")))
def test_round_significant(self): # (input) (expected output) values = [((1, 1), 1), ((-1.234, 1), -1), ((-1234, 1), -1000), ((1600, 1), 2000), ((-1600, 1), -2000), ((0.0001236, 3), 0.000124), ((0, 5), 0), ((4.375479375074184e-6, 3), 4.38e-6), ] for (i, eo) in values: o = units.round_significant(*i) self.assertEquals(o, eo, u"%f to %d figures = %f should be %f" % (i[0], i[1], o, eo))
def test_to_string_pretty(self): values = [ 0.000000041003, 0.0051, 0.014, 0.39, 0.230234543545, ] for sig in [2, 4, 6]: # (None, 0, 1, 2, 4, 8): for v in values: self.assertEqual( units.round_significant(v, sig), float(units.to_string_pretty(v, sig, "s")) )
def UpdateMagnification(self): # TODO: shall we use the real density of the screen? # We could use real density but how much important is it? mppScreen = 0.00025 # 0.25 mm/px label = u"Mag: " # three possibilities: # * no image => total mag (using current mpp) # * all images have same mpp => mag instrument * mag digital # * >1 mpp => total mag # get all the mpps mpps = set() for im in self._microscope_view.stream_tree.getImages(): try: mpps.add(im.metadata[model.MD_PIXEL_SIZE][0]) except KeyError: pass if len(mpps) == 1: # two magnifications im_mpp = mpps.pop() magIm = mppScreen / im_mpp # as if 1 im.px == 1 sc.px if magIm >= 1: label += u"×" + units.readable_str( units.round_significant(magIm, 3)) else: label += u"÷" + units.readable_str( units.round_significant(1.0 / magIm, 3)) magDig = im_mpp / self._microscope_view.mpp.value if magDig >= 1: label += u" ×" + units.readable_str( units.round_significant(magDig, 3)) else: label += u" ÷" + units.readable_str( units.round_significant(1.0 / magDig, 3)) else: # one magnification mag = mppScreen / self._microscope_view.mpp.value if mag >= 1: label += u"×" + units.readable_str( units.round_significant(mag, 3)) else: label += u"÷" + units.readable_str( units.round_significant(1.0 / mag, 3)) self.legend.set_mag_label(label)
def UpdateMagnification(self): # TODO: shall we use the real density of the screen? # We could use real density but how much important is it? mppScreen = 0.00025 # 0.25 mm/px label = u"Mag: " # three possibilities: # * no image => total mag (using current mpp) # * all images have same mpp => mag instrument * mag digital # * >1 mpp => total mag # get all the mpps mpps = set() for im in self._microscope_view.stream_tree.getImages(): try: mpps.add(im.metadata[model.MD_PIXEL_SIZE][0]) except KeyError: pass if len(mpps) == 1: # two magnifications im_mpp = mpps.pop() magIm = mppScreen / im_mpp # as if 1 im.px == 1 sc.px if magIm >= 1: label += u"×" + units.readable_str(units.round_significant(magIm, 3)) else: label += u"÷" + units.readable_str(units.round_significant(1.0 / magIm, 3)) magDig = im_mpp / self._microscope_view.mpp.value if magDig >= 1: label += u" ×" + units.readable_str(units.round_significant(magDig, 3)) else: label += u" ÷" + units.readable_str(units.round_significant(1.0 / magDig, 3)) else: # one magnification mag = mppScreen / self._microscope_view.mpp.value if mag >= 1: label += u"×" + units.readable_str(units.round_significant(mag, 3)) else: label += u"÷" + units.readable_str(units.round_significant(1.0 / mag, 3)) self.legend.set_mag_label(label)