def test_values_error_for_missing_fit_result(self) -> None: """Test returned values are masked when no fit results are stored in the packet""" # Create a packet with no fit results. packet = create_mock_pipeline_packet(include_fit=False) with self.assertRaises(ValueError): packet.fitted_params_to_pandas()
def generic_setup(cls, vparams: List[str]) -> None: """Set up nodes for feeding/accumulating a mock fitting pipeline Args: vparams: Parameters to vary in the fit """ cls.packet = create_mock_pipeline_packet(include_fit=False) # Create a mock pipeline for fitting the packet's light-curve source = MockSource([cls.packet]) cls.node = FitLightCurves(SNModel('salt2-extended'), vparams=vparams, num_processes=0) cls.success_target = MockTarget() cls.failure_target = MockTarget() source.output.connect(cls.node.input) cls.node.success_output.connect(cls.success_target.input) cls.node.failure_output.connect(cls.failure_target.input) # Run the mock pipeline for mock_node in (source, cls.node, cls.success_target, cls.failure_target): mock_node.execute() sleep(2)
def setUpClass(cls) -> None: """Use the ``SimulationToDisk`` node to write data to disk""" cls.packets = [ create_mock_pipeline_packet(123), create_mock_pipeline_packet(456) ] cls.temp_dir = TemporaryDirectory() cls.temp_path = Path(cls.temp_dir.name) / 'tempfile.h5' node = WritePipelinePacket(cls.temp_path) node.debug = True moc_source = MockSource(cls.packets) moc_source.output.connect(node.input) moc_source.execute() node.execute()
def test_df_matches_packet_on_successful_fit(self) -> None: """Test the returned dataframe matches data from a picket with a successful fit result""" packet = create_mock_pipeline_packet() df_data = packet.packet_status_to_pandas().iloc[0] self.assertEqual(packet.snid, df_data['snid']) self.assertEqual(packet.message, df_data['message']) self.assertEqual(packet.fit_result.success, df_data['success'])
def test_df_matches_packet_on_missing_fit(self) -> None: """Test the returned dataframe matches data from a picket with a failed fit result""" packet = create_mock_pipeline_packet(include_fit=False) df_data = packet.packet_status_to_pandas().iloc[0] self.assertEqual(packet.snid, df_data['snid']) self.assertEqual(packet.message, df_data['message']) self.assertEqual(False, df_data['success'])
def test_simulation_routed_to_success_output(self) -> None: """Test successful simulations are sent to the ``success_output`` connector""" self.source.load_data.append( create_mock_pipeline_packet(include_lc=False)) self.run_nodes() self.assertTrue(self.success_target.accumulated_data) self.assertFalse(self.failure_target.accumulated_data)
def test_failure_routed_to_failure_output(self) -> None: """Test failed simulations are sent to the ``failure_output`` connector""" # Pick a crazy redshift so the simulation fails packet = create_mock_pipeline_packet(include_lc=False) packet.sim_params['z'] = 1000 self.source.load_data.append(packet) self.run_nodes() self.assertFalse(self.success_target.accumulated_data) self.assertTrue(self.failure_target.accumulated_data)
def test_simulation_includes_reference_catalog() -> None: """Test simulated light-curves are calibrated if a reference catalog is specified""" model = SNModel('salt2-extended') catalog = create_mock_variable_catalog('G2', 'M5', 'K2') packet = create_mock_pipeline_packet(include_lc=False) node_without_catalog = SimulateLightCurves(model, add_scatter=False) uncalibrated_lc = node_without_catalog.simulate_lc( packet.sim_params, packet.cadence) node_with_catalog = SimulateLightCurves(model, add_scatter=False, catalog=catalog) calibrated_lc = node_with_catalog.simulate_lc(packet.sim_params, packet.cadence) ra, dec = packet.sim_params['ra'], packet.sim_params['dec'] pd.testing.assert_frame_equal( catalog.calibrate_lc(uncalibrated_lc, ra, dec).to_pandas(), calibrated_lc.to_pandas())
def setUp(self) -> None: """Create a mock pipeline packet for testing""" self.packet = create_mock_pipeline_packet()