def test_nm_from_2t_zero(self):
     # boundary condition: 0
     result = get_nm_from_2t(0)
     self.assertIsNotNone(result)
     self.assertAlmostEquals(result, 1e+16)
     result = get_nm_from_2t(0, zero_for_inf=True)
     self.assertIsNotNone(result)
     self.assertAlmostEquals(result, 0)
Exemple #2
0
 def test_nm_from_2t_zero(self):
     # boundary condition: 0
     result = get_nm_from_2t(0)
     self.assertIsNotNone(result)
     self.assertAlmostEquals(result, 1e+16)
     result = get_nm_from_2t(0, zero_for_inf=True)
     self.assertIsNotNone(result)
     self.assertAlmostEquals(result, 0)
Exemple #3
0
def set_nm_ticks(axis, wavelength, xmin, xmax):
    """
        Sets the tick positions and labels for a nanometer x-axes using
        the given lower & upper limits and the wavelength
    """

    np_nm2a = np.vectorize(partial(get_2t_from_nm, wavelength=wavelength))

    def get_tick_labels(a, b):
        def in_close(value, arr):
            for val in arr:
                if np.isclose(value, val):
                    return True
            return False

        return ["%g" % val if in_close(val, b) else "" for val in a]

    minor_ticks_nm, major_ticks_nm, label_ticks_nm = _get_ticks()

    dmax = min(get_nm_from_2t(xmin, wavelength),
               100)  #limit this so we don't get an "infinite" scale
    dmin = get_nm_from_2t(xmax, wavelength)

    # Extract the part we need:
    selector = (minor_ticks_nm >= dmin) & (minor_ticks_nm <= dmax)
    minor_ticks_pos = np_nm2a(minor_ticks_nm[selector])
    selector = (major_ticks_nm >= dmin) & (major_ticks_nm <= dmax)
    major_ticks_pos = np_nm2a(major_ticks_nm[selector])

    major_ticks_labels = get_tick_labels(major_ticks_nm[selector],
                                         label_ticks_nm)

    # Set the ticks
    helper = axis.get_helper()

    helper.axis.minor.locator = FixedLocator(minor_ticks_pos)
    helper.axis.minor.formatter = FixedFormatter([""] * len(minor_ticks_pos))

    helper.axis.major.locator = FixedLocator(major_ticks_pos)
    helper.axis.major.formatter = FixedFormatter(major_ticks_labels)

    pass  #end of func
Exemple #4
0
def set_nm_ticks(axis, wavelength, xmin, xmax):
    """
        Sets the tick positions and labels for a nanometer x-axes using
        the given lower & upper limits and the wavelength
    """

    np_nm2a = np.vectorize(partial(get_2t_from_nm, wavelength=wavelength))

    def get_tick_labels(a, b):
        def in_close(value, arr):
            for val in arr:
                if np.isclose(value, val):
                    return True
            return False
        return [ "%g" % val if in_close(val, b) else "" for val in a ]

    minor_ticks_nm, major_ticks_nm, label_ticks_nm = _get_ticks()

    dmax = min(get_nm_from_2t(xmin, wavelength), 100) #limit this so we don't get an "infinite" scale
    dmin = get_nm_from_2t(xmax, wavelength)

    # Extract the part we need:
    selector = (minor_ticks_nm >= dmin) & (minor_ticks_nm <= dmax)
    minor_ticks_pos = np_nm2a(minor_ticks_nm[selector])
    selector = (major_ticks_nm >= dmin) & (major_ticks_nm <= dmax)
    major_ticks_pos = np_nm2a(major_ticks_nm[selector])

    major_ticks_labels = get_tick_labels(major_ticks_nm[selector], label_ticks_nm)

    # Set the ticks
    helper = axis.get_helper()

    helper.axis.minor.locator = FixedLocator(minor_ticks_pos)
    helper.axis.minor.formatter = FixedFormatter([""] * len(minor_ticks_pos))

    helper.axis.major.locator = FixedLocator(major_ticks_pos)
    helper.axis.major.formatter = FixedFormatter(major_ticks_labels)

    pass #end of func
Exemple #5
0
 def test_nm_from_2t_negative(self):
     # boundary condition: negative
     result = get_nm_from_2t(-12.351779659)
     self.assertIsNotNone(result)
     self.assertAlmostEquals(result, -0.716)
Exemple #6
0
 def get_nm_from_2t(self, twotheta):
     """Converts a 2-theta position to a nanometer value"""
     return get_nm_from_2t(twotheta,
                           wavelength=self.wavelength,
                           zero_for_inf=True)
Exemple #7
0
 def get_nm_from_2t(self, twotheta):
     """Converts a 2-theta position to a nanometer value"""
     return get_nm_from_2t(
         twotheta,
         wavelength=self.wavelength, zero_for_inf=True
     )
 def test_nm_from_2t_negative(self):
     # boundary condition: negative
     result = get_nm_from_2t(-12.351779659)
     self.assertIsNotNone(result)
     self.assertAlmostEquals(result, -0.716)