def test_intialisation_b(self): _ = SFH(time_axis / 1e9, sfh_type="b", parameters_dict={ 'T0': 1, 'constant': 1 })
class TestSFHCustom(object): def test_intialisation(self): _ = SFH(time_axis, sfh_type="custom", sfh_arr=sfr) def test_model_not_recognised(self): with pytest.raises(HokiTypeError): _ = SFH(time_axis, sfh_type="afs", sfh_arr=sfr) def test_input_sizes(self): with pytest.raises(HokiFormatError): _ = SFH(time_axis[1:], sfh_type="custom", sfh_arr=sfr) sfh = SFH(time_axis, sfh_type="custom", sfh_arr=sfr) def test_sfr_at(self): assert np.isclose( [self.sfh(i) for i in time_axis], sfr).all(),\ "Something is wrong with the stellar formation rate." def test_mass_per_bin(self): mass_per_bin = np.loadtxt( f"{data_path}/csp_test_data/mass_per_bin.txt") result = self.sfh.mass_per_bin(np.linspace(0, HOKI_NOW, 101), sample_rate=100) assert np.allclose(result, mass_per_bin),\ "The mass per bin is calculated incorrectly."
def test_type_check_history(self): csp = CSP() # define pyton callable def x(i): return i # define SFH object time_axis = np.linspace(0, 13e9, 1000) sfh = SFH(time_axis, "b", {"constant": 10, "T0": 5e9}) # Check Types with pytest.raises(HokiTypeError): csp._type_check_histories([10], [0]) with pytest.raises(HokiTypeError): csp._type_check_histories([10], 0) with pytest.raises(HokiTypeError): csp._type_check_histories([x, x], [x, 10]) # Check Format with pytest.raises(HokiFormatError): csp._type_check_histories([x], [x, x]) with pytest.raises(HokiFormatError): csp._type_check_histories([x, x], [x]) with pytest.raises(HokiFormatError): csp._type_check_histories([x], []) # Checking if the correct input does run assert csp._type_check_histories([x], [x]) == ([x], [x]) assert csp._type_check_histories([x, x], [x, x]) == ([x, x], [x, x]) assert csp._type_check_histories(x, x) == ([x], [x]) assert csp._type_check_histories([x], x) == ([x], [x]) assert csp._type_check_histories(sfh, x) == ([sfh], [x]) assert csp._type_check_histories([sfh], [x]) == ([sfh], [x])
class TestSFHParametric(object): def test_intialisation_c(self): _ = SFH(time_axis / 1e9, sfh_type="c", parameters_dict={'constant': 1}) def test_intialisation_b(self): _ = SFH(time_axis / 1e9, sfh_type="b", parameters_dict={ 'T0': 1, 'constant': 1 }) def test_intialisation_e(self): _ = SFH(time_axis / 1e9, sfh_type="e", parameters_dict={ 'tau': 1, 'T0': 1, 'constant': 1 }) def test_intialisation_de(self): _ = SFH(time_axis / 1e9, sfh_type="de", parameters_dict={ 'tau': 1, 'T0': 1, 'constant': 1 }) def test_intialisation_dpl(self): _ = SFH(time_axis / 1e9, sfh_type="dpl", parameters_dict={ 'tau': 1, 'alpha': 1, 'beta': 1, 'constant': 1 }) def test_intialisation_ln(self): _ = SFH(time_axis / 1e9, sfh_type="ln", parameters_dict={ 'tau': 1, 'T0': 1, 'constant': 1 }) sfh = SFH(time_axis, sfh_type="c", parameters_dict={'constant': 1}) def test_sfr_at(self): # this only works for constant sfr = 1 assert np.isclose([self.sfh(i) for i in time_axis], [1]*len(time_axis)).all(),\ "Something is wrong with the stellar formation rate." def test_mass_per_bin(self): assert np.isclose(self.sfh.mass_per_bin([2, 3, 6, 8]), [1., 3., 2.]).all(),\ "The mass per bin is calculated incorrectly."
def test_intialisation_dpl(self): _ = SFH(time_axis / 1e9, sfh_type="dpl", parameters_dict={ 'tau': 1, 'alpha': 1, 'beta': 1, 'constant': 1 })
def test_input_sizes(self): with pytest.raises(HokiFormatError): _ = SFH(time_axis[1:], sfh_type="custom", sfh_arr=sfr)
def test_model_not_recognised(self): with pytest.raises(HokiTypeError): _ = SFH(time_axis, sfh_type="afs", sfh_arr=sfr)
def test_intialisation(self): _ = SFH(time_axis, sfh_type="custom", sfh_arr=sfr)
def Z_fnc(x): return 0.00001 def vec_sfh(x): return np.zeros(len(x)) + 1 def vec_Z(x): return np.zeros(len(x)) + 0.00001 # define SFH object time_axis = np.linspace(0, HOKI_NOW, 1000) sfh = SFH(time_axis, "c", {"constant": 1}) class TestCSPEventRate(): data = model_output(f"{data_path}/supernova-bin-imf135_300.zem5.dat") # Check initalisation @patch("hoki.load.model_output") def test_init(self, mock_model_output): mock_model_output.return_value = self.data _ = er.CSPEventRate(f"{data_path}", "imf135_300") def test_input_functions_at_time(self): assert np.isclose( self.CSP.at_time([sfh_fnc], [Z_fnc], ["Ia"], 0,