Example #1
0
 def test_plotting3(self):
     self.fig = plt.figure()
     self.fig.canvas.set_window_title('Figure Title')
     ax = self.fig.add_subplot(111)
     ax.plot(self.x, self.y, label='data')
     truth = dcs.TruthPlotter(self.x, None, lo=self.y, hi=self.y + 0.03)
     truth.plot_truth(ax)
Example #2
0
 def test_nominal(self):
     truth = dcs.TruthPlotter(self.x,
                              self.y + 0.01,
                              lo=self.y,
                              hi=self.y + 0.03)
     np.testing.assert_array_almost_equal(self.y + 0.01, truth.data)
     np.testing.assert_array_almost_equal(self.y, truth.data_lo)
     np.testing.assert_array_almost_equal(self.y + 0.03, truth.data_hi)
Example #3
0
 def setUp(self):
     self.time = np.arange(0, 10, 0.1)
     self.data = np.sin(self.time)
     self.label = 'Sin'
     self.type_ = 'population'
     self.opts = dcs.Opts()
     self.opts.names = ['Name 1']
     self.truth = dcs.TruthPlotter(self.time, np.cos(self.time))
     self.data_matrix = np.column_stack((self.data, self.truth.data))
     self.second_y_scale = 1000000
     self.fig = None
Example #4
0
 def test_pprint(self):
     truth = dcs.TruthPlotter(self.x,
                              self.y + 0.01,
                              lo=self.y,
                              hi=self.y + 0.03)
     with dcs.capture_output() as out:
         truth.pprint()
     lines = out.getvalue().strip().split('\n')
     out.close()
     self.assertEqual(lines[0], 'TruthPlotter')
     self.assertTrue(lines[1].startswith(' time    = ['))
     self.assertEqual(lines[-1], ' name    = Observed')
Example #5
0
 def test_bad_type(self):
     self.fig = plt.figure()
     self.fig.canvas.set_window_title('Figure Title')
     ax = self.fig.add_subplot(111)
     ax.plot(self.x, self.y, label='data')
     truth = dcs.TruthPlotter(self.x,
                              self.y + 0.01,
                              lo=self.y,
                              hi=self.y + 0.03,
                              type_='bad type')
     with self.assertRaises(ValueError):
         truth.plot_truth(ax)
Example #6
0
 def test_matrix2(self):
     truth = dcs.TruthPlotter(self.x, self.data)
     np.testing.assert_array_almost_equal(self.y + 0.01, truth.data)
     np.testing.assert_array_almost_equal(self.y, truth.data_lo)
     np.testing.assert_array_almost_equal(self.y + 0.03, truth.data_hi)
Example #7
0
 def test_matrix1(self):
     truth = dcs.TruthPlotter(self.x, self.data[:, np.array([1])])
     np.testing.assert_array_almost_equal(self.y + 0.01, truth.data)
     self.assertTrue(truth.data_lo is None)
     self.assertTrue(truth.data_hi is None)

#%% Script
if __name__ == '__main__':
    # Constants
    rerun = True
    make_plots = True
    time = np.arange(251)

    # Parameters
    sim_params = SimParams(time, magnitude=3.5, frequency=12, phase=180)

    # Truth data
    truth_time = np.arange(-10, 201)
    truth_data = truth(truth_time)
    truth = dcs.TruthPlotter(truth_time, truth_data)

    # Logger
    dcs.Logger().set_level(10)

    # BPE Settings
    opti_opts = dcs.OptiOpts()
    opti_opts.model_func = sim_model
    opti_opts.model_args = {'sim_params': sim_params}
    opti_opts.cost_func = cost_wrapper
    opti_opts.cost_args = {
        'results_time': time,
        'truth_time': truth_time,
        'truth_data': truth_data
    }
    opti_opts.get_param_func = get_parameter