示例#1
0
def test_add():
    chargeres = ChargeResolutionCalculator()
    true_charge = np.arange(100)
    measured_charge = np.arange(100)
    chargeres.add(0, true_charge, measured_charge)
    assert len(chargeres._df_list) == 1
    assert chargeres._df_list[0].index.size == 100
    def setup(self):
        self.log_format = "%(levelname)s: %(message)s [%(name)s.%(funcName)s]"

        self.eventsource = EventSource(parent=self)

        self.calibrator = CameraCalibrator(parent=self,
                                           subarray=self.eventsource.subarray)
        self.calculator = ChargeResolutionCalculator()
示例#3
0
def test_memory_limit():
    chargeres = ChargeResolutionCalculator()
    chargeres._max_bytes = 1
    true_charge = np.arange(100)
    measured_charge = np.arange(100)
    chargeres.add(0, true_charge, measured_charge)
    assert len(chargeres._df_list) == 0
    chargeres.add(0, true_charge, measured_charge)
    assert len(chargeres._df_list) == 0
示例#4
0
def test_bin_dataframe():
    chargeres = ChargeResolutionCalculator()
    true_charge = np.arange(100)
    measured_charge = np.arange(100)
    chargeres.add(0, true_charge, measured_charge)
    chargeres.add(0, true_charge, measured_charge)
    df_p, df_c = chargeres.finish()

    df = bin_dataframe(df_p, 20)
    assert "bin" in df.columns
    assert np.unique(df["bin"]).size <= 20
示例#5
0
def test_amalgamate():
    chargeres = ChargeResolutionCalculator()
    true_charge = np.arange(100)
    measured_charge = np.arange(100)
    chargeres.add(0, true_charge, measured_charge)
    chargeres.add(0, true_charge, measured_charge)
    chargeres.add(1, true_charge, measured_charge)
    assert len(chargeres._df_list) == 3
    chargeres._amalgamate()
    assert len(chargeres._df_list) == 0
    assert chargeres._df.index.size == 200
    def setup(self):
        self.log_format = "%(levelname)s: %(message)s [%(name)s.%(funcName)s]"

        self.eventsource = self.add_component(SimTelEventSource(parent=self))

        extractor = self.add_component(
            ImageExtractor.from_name(self.extractor_product, parent=self))

        self.calibrator = self.add_component(
            CameraCalibrator(parent=self, image_extractor=extractor))
        self.calculator = ChargeResolutionCalculator()
    def setup(self):
        self.log_format = "%(levelname)s: %(message)s [%(name)s.%(funcName)s]"

        self.eventsource = SimTelEventSource(parent=self)

        extractor = ImageExtractor.from_name(self.extractor_product,
                                             parent=self)

        self.dl0 = CameraDL0Reducer(parent=self)

        self.dl1 = CameraDL1Calibrator(extractor=extractor, parent=self)

        self.calculator = ChargeResolutionCalculator()
示例#8
0
def create_temp_cr_file(directory):
    chargeres = ChargeResolutionCalculator()
    true_charge = np.arange(100)
    measured_charge = np.arange(100)
    chargeres.add(0, true_charge, measured_charge)
    chargeres.add(0, true_charge, measured_charge)
    df_p, df_c = chargeres.finish()

    output_path = os.path.join(str(directory), "cr.h5")
    with pd.HDFStore(output_path, "w") as store:
        store["charge_resolution_pixel"] = df_p
        store["charge_resolution_camera"] = df_c
    return output_path
示例#9
0
def test_result():
    chargeres = ChargeResolutionCalculator(mc_true=False)
    measured = np.array([3.5, 2.7])
    true = 3
    n = measured.size
    sum_ = np.sum(np.power(measured - true, 2))

    chargeres.add(0, true, measured)
    df_p, df_c = chargeres.finish()
    assert (df_p['charge_resolution'].values[0] == chargeres.rmse(
        true, sum_, n))
    assert (df_p['charge_resolution_abs'].values[0] == chargeres.rmse_abs(
        sum_, n))
示例#10
0
def test_finish():
    chargeres = ChargeResolutionCalculator()
    true_charge = np.arange(100)
    measured_charge = np.arange(100)
    chargeres.add(0, true_charge, measured_charge)
    chargeres.add(0, true_charge, measured_charge)
    df_p, df_c = chargeres.finish()
    assert np.array_equal(df_p['charge_resolution'].values,
                          df_c['charge_resolution'].values)
    chargeres.add(1, true_charge, measured_charge)
    df_p, df_c = chargeres.finish()
    assert not np.array_equal(df_p['charge_resolution'].values,
                              df_c['charge_resolution'].values)
示例#11
0
def test_result_mc_true():
    chargeres = ChargeResolutionCalculator()
    measured = np.array([3.5, 2.7])
    true = 3
    n = measured.size
    sum_ = np.sum((measured - true)**2)

    chargeres.add(0, true, measured)
    df_p, df_c = chargeres.finish()
    assert df_p["charge_resolution"].values[0] == chargeres.charge_res(
        true, sum_, n)
    assert df_p["charge_resolution_abs"].values[0] == chargeres.charge_res_abs(
        true, sum_, n)
示例#12
0
def test_result():
    charge_res = ChargeResolutionCalculator(mc_true=False)
    measured = np.array([3.5, 2.7])
    true = 3
    n = measured.size
    sum_ = np.sum((measured - true)**2)

    charge_res.add(0, true, measured)
    df_p, df_c = charge_res.finish()
    resolution = df_p["charge_resolution"].values[0]
    assert resolution == charge_res.rmse(true, sum_, n)
    resolution_abs = df_p["charge_resolution_abs"].values[0]
    assert resolution_abs == charge_res.rmse_abs(sum_, n)
    def setup(self):
        self.log_format = "%(levelname)s: %(message)s [%(name)s.%(funcName)s]"
        kwargs = dict(config=self.config, parent=self)

        self.eventsource = SimTelEventSource(**kwargs)

        extractor = ChargeExtractor.from_name(self.extractor_product, **kwargs)

        self.r1 = HESSIOR1Calibrator(**kwargs)

        self.dl0 = CameraDL0Reducer(**kwargs)

        self.dl1 = CameraDL1Calibrator(extractor=extractor, **kwargs)

        self.calculator = ChargeResolutionCalculator()
示例#14
0
def test_calculation():
    chargeres = ChargeResolutionCalculator()
    measured = np.array([3.5, 2.7])
    true = 3
    n = measured.size

    sum_ = np.sum(np.power(measured - true, 2))
    assert_almost_equal(sum_, 0.34, 3)
    assert_almost_equal(chargeres.rmse_abs(sum_, n), 0.412, 3)
    assert_almost_equal(chargeres.rmse(true, sum_, n), 0.137, 3)
    assert_almost_equal(chargeres.charge_res_abs(true, sum_, n), 1.780, 3)
    assert_almost_equal(chargeres.charge_res(true, sum_, n), 0.593, 3)

    assert chargeres.rmse_abs(sum_, n) == chargeres.rmse(true, sum_, n) * true
    assert (chargeres.charge_res_abs(
        true, sum_, n) == chargeres.charge_res(true, sum_, n) * true)