Exemplo n.º 1
0
 def setUp(self):
     self.figs = []
     self.logger = dcs.Logger(10)
     self.bpe_results = dcs.BpeResults()
     self.opts = dcs.Opts()
     self.plots = {'innovs': True, 'convergence': True, 'correlation': True, 'info_svd': True, \
     'covariance': True}
Exemplo n.º 2
0
 def test_pprint(self):
     opts = dcs.Opts()
     with dcs.capture_output() as out:
         opts.pprint(indent=2)
     lines = out.getvalue().strip().split('\n')
     out.close()
     self.assertEqual(lines[0], 'Opts')
     self.assertEqual(lines[1], '  case_name = ')
     self.assertEqual(lines[3], '  save_plot = False')
     self.assertEqual(lines[-1], '  names     = []')
Exemplo n.º 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
Exemplo n.º 4
0
 def setUp(self):
     self.time = np.arange(0, 5, 1. / 12) + 2000
     num_bins = 5
     self.data = np.random.rand(len(self.time), num_bins)
     mag = self.data.cumsum(axis=1)[:, -1]
     self.data = self.data / np.expand_dims(mag, axis=1)
     self.label = 'Plot bar testing'
     self.legend = ['Value 1', 'Value 2', 'Value 3', 'Value 4', 'Value 5']
     self.opts = dcs.Opts()
     self.opts.show_plot = False
     self.colormap = 'seismic'
     self.figs = []
Exemplo n.º 5
0
 def setUp(self):
     self.time = np.arange(0, 10, 0.1) + 2000
     num_channels = 5
     self.data = np.random.rand(len(self.time), num_channels)
     mag = self.data.cumsum(axis=1)[:, -1]
     self.data = 10 * self.data / np.expand_dims(mag, axis=1)
     self.label = 'Plot description'
     self.type_ = 'percentage'
     self.opts = dcs.Opts()
     self.opts.show_plot = False
     self.legend = ['Value 1', 'Value 2', 'Value 3', 'Value 4', 'Value 5']
     self.colormap = 'seismic'
     self.figs = []
     self.second_y_scale = 1000000
Exemplo n.º 6
0
 def setUp(self):
     self.fig = plt.figure()
     self.fig.canvas.set_window_title('Figure Title')
     ax = self.fig.add_subplot(111)
     x = np.arange(0, 10, 0.1)
     y = np.sin(x)
     ax.plot(x, y)
     ax.set_title('X vs Y')
     ax.set_xlabel('time [years]')
     ax.set_ylabel('value [radians]')
     self.opts = dcs.Opts()
     self.opts.case_name = 'Testing'
     self.opts.show_plot = True
     self.opts.save_plot = False
     self.opts.save_path = dcs.get_tests_dir()
Exemplo n.º 7
0
 def setUp(self):
     num = 10
     self.figs = []
     self.data = dcs.unit(np.random.rand(num, num), axis=0)
     self.labels = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']
     self.type_ = 'percentage'
     self.opts = dcs.Opts()
     self.opts.case_name = 'Testing Correlation'
     self.matrix_name = 'Not a Correlation Matrix'
     self.sym = self.data.copy()
     for j in range(num):
         for i in range(num):
             if i == j:
                 self.sym[i, j] = 1
             elif i > j:
                 self.sym[i, j] = self.data[j, i]
Exemplo n.º 8
0
 def test_plot2(self):
     opts = dcs.Opts()
     (inc_cost, inc_qaly, icer_out, order, icer_data, self.fig) = dcs.icer(self.cost, self.qaly, \
         make_plot=True, opts=opts, baseline=0)
     temp = self.inc_cost
     temp[0] = 0
     np.testing.assert_array_equal(inc_cost, temp,
                                   'Incremental cost mismatch.')
     temp = self.inc_qaly
     temp[0] = 0
     np.testing.assert_array_equal(inc_qaly, temp,
                                   'Incremental QALY mismatch.')
     temp = self.icer_out
     temp[0] = np.nan
     np.testing.assert_array_equal(icer_out, temp, 'ICER mismatch.')
     np.testing.assert_array_equal(order, self.order, 'Order mismatch.')
     self.assertTrue(isinstance(self.fig, plt.Figure))
Exemplo n.º 9
0
 def setUp(self):
     self.costs = np.array([1, 0.1, 0.05, 0.01])
     self.opts = dcs.Opts()
     self.opts.show_plot = False
     self.figs = []
Exemplo n.º 10
0
 def test_get_names_unsuccessful(self):
     opts = dcs.Opts()
     opts.names = ['Name 1', 'Name 2']
     name = opts.get_names(2)
     self.assertEqual(name, '')
Exemplo n.º 11
0
 def test_new_attr(self):
     opts = dcs.Opts()
     with self.assertRaises(AttributeError):
         opts.new_field_that_does_not_exist = 1
Exemplo n.º 12
0
 def test_calling(self):
     opts = dcs.Opts()
     for field in self.opts_fields:
         self.assertTrue(hasattr(opts, field))
Exemplo n.º 13
0
                      typical=100,
                      minstep=0.1))

    # Run code
    if rerun:
        (bpe_results, results) = dcs.run_bpe(opti_opts)
    else:
        bpe_results = dcs.BpeResults.load(
            os.path.join(opti_opts.output_folder, opti_opts.output_results))
        results = sim_model(
            sim_params)  # just re-run, nothing is actually saved by this model

    # Plot results
    if make_plots:
        # build opts
        opts = dcs.Opts()
        opts.case_name = 'Model Results'
        opts.save_path = dcs.get_output_dir()
        opts.save_plot = True

        # make model plots
        dcs.plot_time_history(time,
                              results,
                              description='Output vs. Time',
                              opts=opts,
                              truth=truth)

        # make BPE plots
        bpe_plots = {'innovs': True, 'convergence': False, 'correlation': True, 'info_svd': True, \
            'covariance': False}
        dcs.plot_bpe_results(bpe_results, opts, plots=bpe_plots)