Пример #1
0
    def test_empty_wavelengths(self):
        spectrum = Spectrum(np.array([0.2, 0.3, 0.5]))
        assert_array_equal(spectrum.wavelengths, [0, 1, 2])

        spectrum = Spectrum(np.array([0.2, 0.3, 0.5]),
                            first_wavelength=5,
                            dispersion=2)
        assert_array_equal(spectrum.wavelengths, [5, 7, 9])
Пример #2
0
    def test_calibrate(self):
        spectrum = Spectrum(np.array([0.2, 0.3, 0.5]), np.array([3, 4, 5]))
        spectrum.calibrate(points=[{'x': 1, 'wavelength': 2}], dispersion=4)
        assert_array_equal(spectrum.wavelengths, [-2., 2., 6.])

        spectrum = Spectrum(np.array([0.2, 0.3, 0.5, 0.7]), np.array([3, 4,
                                                                      5]))
        spectrum.calibrate(points=[{
            'x': 1,
            'wavelength': 3.
        }, {
            'x': 2,
            'wavelength': 9.
        }])
        assert_array_almost_equal(spectrum.wavelengths, [-3., 3., 9., 15.])
Пример #3
0
 def execute_operation(self):
     max_wavelengths = lambda operands: np.arange(max([o[0].wavelengths[0] for o in operands]), min([o[0].wavelengths[-1] for o in operands]))
     datasets = lambda operands, wavelengths: [PlotsMath.__data(o[1], wavelengths) for o in operands]
     operands = [(self.operands_model.item(a).data(PlotsMath.FITS_SPECTRUM), self.operands_model.item(a).data(PlotsMath.F_X)) for a in np.arange(self.operands_model.rowCount())]
     
     
     def divide(operands):
         if len(operands) > 2:
             print("Division supports only 2 operands, truncating")
         wavelengths = max_wavelengths(operands[0:2])
         datas = datasets(operands[0:2], wavelengths)
         return (wavelengths, datas[0]/datas[1])
     
     def mean(operands):
         wavelengths = max_wavelengths(operands)
         mean_data = np.zeros(wavelengths.shape)
         for data in datasets(operands, wavelengths):
             mean_data += data
         return (wavelengths, mean_data/len(wavelengths))
     
     operations = { 0: divide, 1: mean }
     try:
         wavelengths, data = operations[self.ui.operation_type.currentIndex()](operands)
         self.spectrum = Spectrum(data, wavelengths)
         
         self.spectrum.normalize_to_max()
         self.undo.set_spectrum(self.spectrum)
         self.ui.spline_degrees.setValue(5)
         self.ui.spline_factor.setValue(0)
         self.ui.spline_factor_auto.setChecked(False)
         self.draw()
     except IndexError:
         QMessageBox.warning(None, "Error", "Datasets are not compatible. Maybe you need to calibrate better, or use a different reference file")
Пример #4
0
 def test_get_index_from_wavelength(self):
     spectrum = Spectrum(np.array([0.2, 0.3, 0.5, 0.7]),
                         np.array([3, 6, 9, 12]))
     self.assertEqual(1, spectrum.wavelength_index(6))
     self.assertEqual(0, spectrum.wavelength_index(5))
     self.assertEqual(0, spectrum.wavelength_index(3))
     self.assertEqual(2, spectrum.wavelength_index(9))
     self.assertEqual(3, spectrum.wavelength_index(12))
Пример #5
0
    def test_cut(self):
        spectrum = Spectrum(np.array([0.2, 0.3, 0.5, 0.7]),
                            np.array([3, 6, 9, 12]))
        spectrum.cut(start=1)
        assert_array_equal(spectrum.wavelengths, [6, 9, 12])
        assert_array_equal(spectrum.fluxes, [0.3, 0.5, 0.7])

        spectrum = Spectrum(np.array([0.2, 0.3, 0.5, 0.7]),
                            np.array([3, 6, 9, 12]))
        spectrum.cut(end=2)
        assert_array_equal(spectrum.wavelengths, [3, 6, 9])
        assert_array_equal(spectrum.fluxes, [0.2, 0.3, 0.5])

        spectrum = Spectrum(np.array([0.2, 0.3, 0.5, 0.7]),
                            np.array([3, 6, 9, 12]))
        spectrum.cut(start=1, end=2)
        assert_array_equal(spectrum.wavelengths, [6, 9])
        assert_array_equal(spectrum.fluxes, [0.3, 0.5])
Пример #6
0
    def test_calc_dispersion(self):
        spectrum = Spectrum(np.array([0.2, 0.3, 0.5]), np.array([0, 1, 2]))
        self.assertEqual(spectrum.dispersion(), 1)

        spectrum = Spectrum(np.array([0.2, 0.3, 0.5]), np.array([0, 2.5, 5]))
        self.assertEqual(spectrum.dispersion(), 2.5)