Beispiel #1
0
    def test_single_epoch_weak_transient(self):
        """
        A weak (barely detected in blind extraction) transient appears at
        field centre in one image, then disappears entirely.

        Because it is a weak extraction, it will not be immediately marked
        as transient, but it will get flagged up after forced-fitting due to
        the variability search.
        """
        im_params = self.im_params

        transient_src = db_subs.MockSource(
            template_extractedsource=db_subs.example_extractedsource_tuple(
                ra=im_params[0]['centre_ra'],
                dec=im_params[0]['centre_decl'],
            ),
            lightcurve={
                im_params[2]['taustart_ts']: self.barely_detectable_flux
            })

        for img_pars in im_params[:3]:
            image, _, forced_fits = insert_image_and_simulated_sources(
                self.dataset, img_pars, [transient_src],
                self.new_source_sigma_margin)
            self.assertEqual(forced_fits, [])
            newsources = get_newsources_for_dataset(self.dataset.id)
            self.assertEqual(len(newsources), 0)
            transients = get_sources_filtered_by_final_variability(
                dataset_id=self.dataset.id, **self.search_params)
            # No variability yet
            self.assertEqual(len(transients), 0)

        # Now, the final, empty image:
        image, blind_extractions, forced_fits = insert_image_and_simulated_sources(
            self.dataset, im_params[3], [transient_src],
            self.new_source_sigma_margin)
        self.assertEqual(len(blind_extractions), 0)
        self.assertEqual(len(forced_fits), 1)

        # No changes to newsource table
        newsources = get_newsources_for_dataset(self.dataset.id)
        self.assertEqual(len(newsources), 0)

        # But it now has high variability
        transients = get_sources_filtered_by_final_variability(
            dataset_id=self.dataset.id, **self.search_params)
        self.assertEqual(len(transients), 1)
        transient_properties = transients[0]

        # Check that the bands for the images are the same as the transient's band
        freq_bands = frequency_bands(self.dataset._id)
        self.assertEqual(len(freq_bands), 1)
        self.assertEqual(freq_bands[0], transient_properties['band'])

        # Sanity check that the runcat is correctly matched
        runcats = runcat_entries(self.dataset._id)
        self.assertEqual(len(runcats), 1)
        self.assertEqual(runcats[0]['runcat'],
                         transient_properties['runcat_id'])
Beispiel #2
0
    def test_single_epoch_weak_transient(self):
        """
        A weak (barely detected in blind extraction) transient appears at
        field centre in one image, then disappears entirely.

        Because it is a weak extraction, it will not be immediately marked
        as transient, but it will get flagged up after forced-fitting due to
        the variability search.
        """
        im_params = self.im_params

        transient_src = db_subs.MockSource(
             template_extractedsource=db_subs.example_extractedsource_tuple(
                 ra=im_params[0]['centre_ra'],
                 dec=im_params[0]['centre_decl'],
             ),
             lightcurve={im_params[2]['taustart_ts'] :
                             self.barely_detectable_flux}
        )

        for img_pars in im_params[:3]:
            image, _, forced_fits = insert_image_and_simulated_sources(
                self.dataset, img_pars, [transient_src],
                self.new_source_sigma_margin)
            self.assertEqual(forced_fits, [])
            newsources = get_newsources_for_dataset(self.dataset.id)
            self.assertEqual(len(newsources), 0)
            transients = get_sources_filtered_by_final_variability(
                dataset_id=self.dataset.id, **self.search_params)
            # No variability yet
            self.assertEqual(len(transients), 0)

        # Now, the final, empty image:
        image, blind_extractions, forced_fits = insert_image_and_simulated_sources(
                self.dataset, im_params[3], [transient_src],
                self.new_source_sigma_margin)
        self.assertEqual(len(blind_extractions), 0)
        self.assertEqual(len(forced_fits), 1)

        # No changes to newsource table
        newsources = get_newsources_for_dataset(self.dataset.id)
        self.assertEqual(len(newsources), 0)

        # But it now has high variability
        transients = get_sources_filtered_by_final_variability(
            dataset_id=self.dataset.id, **self.search_params)
        self.assertEqual(len(transients), 1)
        transient_properties = transients[0]

        # Check that the bands for the images are the same as the transient's band
        freq_bands = frequency_bands(self.dataset._id)
        self.assertEqual(len(freq_bands), 1)
        self.assertEqual(freq_bands[0], transient_properties['band'])

        # Sanity check that the runcat is correctly matched
        runcats = runcat_entries(self.dataset._id)
        self.assertEqual(len(runcats), 1)
        self.assertEqual(runcats[0]['runcat'], transient_properties['runcat_id'])
Beispiel #3
0
    def test_single_epoch_bright_transient(self):
        """A bright transient appears at field centre in one image."""
        im_params = self.im_params
        transient_src = db_subs.MockSource(
            template_extractedsource=db_subs.example_extractedsource_tuple(
                ra=im_params[0]['centre_ra'],
                dec=im_params[0]['centre_decl'],
            ),
            lightcurve={
                im_params[2]['taustart_ts']: self.reliably_detectable_flux
            })

        for img_pars in im_params[:3]:
            image, _, forced_fits = insert_image_and_simulated_sources(
                self.dataset, img_pars, [transient_src],
                self.new_source_sigma_margin)
            self.assertEqual(len(forced_fits), 0)

        # Check the number of detected transients
        transients = get_newsources_for_dataset(self.dataset.id)
        self.assertEqual(len(transients), 1)
        newsrc_properties = transients[0]
        # Check that the bands for the images are the same as the transient's band
        freq_bands = frequency_bands(self.dataset._id)
        self.assertEqual(len(freq_bands), 1)
        self.assertEqual(freq_bands[0], newsrc_properties['band'])

        # Sanity check that the runcat is correctly matched
        runcats = runcat_entries(self.dataset._id)
        self.assertEqual(len(runcats), 1)
        self.assertEqual(runcats[0]['runcat'], newsrc_properties['runcat_id'])

        # Since it is a single-epoch source, variability indices default to 0:
        self.assertEqual(newsrc_properties['v_int'], 0)
        self.assertEqual(newsrc_properties['eta_int'], 0)

        # Bright 'new-source' / single-epoch transient; should have high sigmas:
        self.assertTrue(newsrc_properties['low_thresh_sigma'] >
                        self.new_source_sigma_margin)
        self.assertEqual(newsrc_properties['low_thresh_sigma'],
                         newsrc_properties['high_thresh_sigma'])

        # Check the correct trigger xtrsrc was identified:
        self.assertEqual(newsrc_properties['taustart_ts'],
                         transient_src.lightcurve.keys()[0])

        # Ok, now add the last image and check that we get a correct forced-fit
        # request:
        image, _, forced_fits = insert_image_and_simulated_sources(
            self.dataset, im_params[3], [transient_src],
            self.new_source_sigma_margin)
        self.assertEqual(len(forced_fits), 1)

        transients = get_sources_filtered_by_final_variability(
            dataset_id=self.dataset.id, **self.search_params)

        self.assertEqual(len(transients), 1)
        transient_properties = transients[0]

        # And now we should have a non-zero variability value
        self.assertNotAlmostEqual(transient_properties['v_int'], 0)
        self.assertNotAlmostEqual(transient_properties['eta_int'], 0)
Beispiel #4
0
    def test_multi_epoch_source_flare_and_fade(self):
        """
        A steady source (i.e. detected in first image) flares up,
        then fades and finally disappears.
        """
        im_params = self.im_params
        transient_src = db_subs.MockSource(
            template_extractedsource=db_subs.example_extractedsource_tuple(
                ra=im_params[0]['centre_ra'],
                dec=im_params[0]['centre_decl'],
            ),
            lightcurve={
                im_params[0]['taustart_ts']: self.barely_detectable_flux,
                im_params[1]['taustart_ts']: 2 * self.barely_detectable_flux,
                im_params[2]['taustart_ts']: self.barely_detectable_flux,
            })

        inserted_sources = []

        for img_pars in im_params[:2]:
            image, blind_xtr, forced_fits = insert_image_and_simulated_sources(
                self.dataset, img_pars, [transient_src],
                self.new_source_sigma_margin)
            self.assertEqual(len(forced_fits), 0)
            inserted_sources.extend(blind_xtr)
            #This should always be 0:
            newsources = get_newsources_for_dataset(self.dataset.id)
            self.assertEqual(len(newsources), 0)

        transients = get_sources_filtered_by_final_variability(
            dataset_id=self.dataset.id, **self.search_params)
        #We've seen a flare:
        self.assertEqual(len(transients), 1)
        transient_properties = transients[0]
        # Check that the bands for the images are the same as the transient's band
        freq_bands = frequency_bands(self.dataset._id)
        self.assertEqual(len(freq_bands), 1)
        self.assertEqual(freq_bands[0], transient_properties['band'])

        #Sanity check that the runcat is correctly matched
        runcats = runcat_entries(self.dataset._id)
        self.assertEqual(len(runcats), 1)
        self.assertEqual(runcats[0]['runcat'],
                         transient_properties['runcat_id'])

        #Check we have sensible variability indices
        # print "\n",transient_properties
        metrics = db_subs.lightcurve_metrics(inserted_sources)
        # print "\nAfter two images:"
        for metric_name in 'v_int', 'eta_int':
            # print metric_name, transient_properties[metric_name]
            self.assertAlmostEqual(transient_properties[metric_name],
                                   metrics[-1][metric_name])

        #Add 3rd image (another blind detection), check everything is sane
        image, blind_xtr, forced_fits = insert_image_and_simulated_sources(
            self.dataset, im_params[2], [transient_src],
            self.new_source_sigma_margin)
        self.assertEqual(len(forced_fits), 0)
        inserted_sources.extend(blind_xtr)

        self.assertEqual(len(get_newsources_for_dataset(self.dataset.id)), 0)

        # Ok, now add the last image and check that we get a correct forced-fit
        # request:
        image, blind_xtr, forced_fits = insert_image_and_simulated_sources(
            self.dataset, im_params[3], [transient_src],
            self.new_source_sigma_margin)
        self.assertEqual(len(blind_xtr), 0)
        self.assertEqual(len(forced_fits), 1)
        inserted_sources.extend(forced_fits)

        self.assertEqual(len(get_newsources_for_dataset(self.dataset.id)), 0)

        transients = get_sources_filtered_by_final_variability(
            dataset_id=self.dataset.id, **self.search_params)

        # Variability indices should take non-detections into account
        self.assertEqual(len(transients), 1)
        transient_properties = transients[0]
        metrics = db_subs.lightcurve_metrics(inserted_sources)
        # print "\nAfter four images:"
        for metric_name in 'v_int', 'eta_int':
            # print metric_name, transient_properties[metric_name]
            self.assertAlmostEqual(transient_properties[metric_name],
                                   metrics[-1][metric_name])
Beispiel #5
0
    def test_multi_epoch_source_flare_and_fade(self):
        """
        A steady source (i.e. detected in first image) flares up,
        then fades and finally disappears.
        """
        im_params = self.im_params
        transient_src = db_subs.MockSource(
             template_extractedsource=db_subs.example_extractedsource_tuple(
                 ra=im_params[0]['centre_ra'],
                 dec=im_params[0]['centre_decl'],
             ),
             lightcurve={
                 im_params[0]['taustart_ts'] : self.barely_detectable_flux,
                 im_params[1]['taustart_ts'] : 2*self.barely_detectable_flux,
                 im_params[2]['taustart_ts'] : self.barely_detectable_flux,
             }
        )

        inserted_sources = []

        for img_pars in im_params[:2]:
            image, blind_xtr,forced_fits = insert_image_and_simulated_sources(
                self.dataset,img_pars,[transient_src],
                self.new_source_sigma_margin)
            self.assertEqual(len(forced_fits), 0)
            inserted_sources.extend(blind_xtr)
            #This should always be 0:
            newsources = get_newsources_for_dataset(self.dataset.id)
            self.assertEqual(len(newsources), 0)


        transients = get_sources_filtered_by_final_variability(dataset_id=self.dataset.id,
                                          **self.search_params)
        #We've seen a flare:
        self.assertEqual(len(transients), 1)
        transient_properties = transients[0]
        # Check that the bands for the images are the same as the transient's band
        freq_bands = frequency_bands(self.dataset._id)
        self.assertEqual(len(freq_bands), 1)
        self.assertEqual(freq_bands[0], transient_properties['band'])

        #Sanity check that the runcat is correctly matched
        runcats = runcat_entries(self.dataset._id)
        self.assertEqual(len(runcats), 1)
        self.assertEqual(runcats[0]['runcat'], transient_properties['runcat_id'])



        #Check we have sensible variability indices
        # print "\n",transient_properties
        metrics = db_subs.lightcurve_metrics(inserted_sources)
        # print "\nAfter two images:"
        for metric_name in 'v_int', 'eta_int':
            # print metric_name, transient_properties[metric_name]
            self.assertAlmostEqual(transient_properties[metric_name],
                             metrics[-1][metric_name])


        #Add 3rd image (another blind detection), check everything is sane
        image, blind_xtr,forced_fits = insert_image_and_simulated_sources(
            self.dataset,im_params[2],[transient_src],
            self.new_source_sigma_margin)
        self.assertEqual(len(forced_fits), 0)
        inserted_sources.extend(blind_xtr)

        self.assertEqual(len(get_newsources_for_dataset(self.dataset.id)),0)

        # Ok, now add the last image and check that we get a correct forced-fit
        # request:
        image, blind_xtr,forced_fits = insert_image_and_simulated_sources(
                self.dataset,im_params[3],[transient_src],
                self.new_source_sigma_margin)
        self.assertEqual(len(blind_xtr),0)
        self.assertEqual(len(forced_fits),1)
        inserted_sources.extend(forced_fits)

        self.assertEqual(len(get_newsources_for_dataset(self.dataset.id)),0)

        transients = get_sources_filtered_by_final_variability(dataset_id=self.dataset.id,
                                          **self.search_params)

        # Variability indices should take non-detections into account
        self.assertEqual(len(transients), 1)
        transient_properties = transients[0]
        metrics = db_subs.lightcurve_metrics(inserted_sources)
        # print "\nAfter four images:"
        for metric_name in 'v_int', 'eta_int':
            # print metric_name, transient_properties[metric_name]
            self.assertAlmostEqual(transient_properties[metric_name],
                             metrics[-1][metric_name])
Beispiel #6
0
    def test_single_epoch_bright_transient(self):
        """A bright transient appears at field centre in one image."""
        im_params = self.im_params
        transient_src = db_subs.MockSource(
             template_extractedsource=db_subs.example_extractedsource_tuple(
                 ra=im_params[0]['centre_ra'],
                 dec=im_params[0]['centre_decl'],
             ),
             lightcurve={im_params[2]['taustart_ts'] :
                             self.reliably_detectable_flux}
        )

        for img_pars in im_params[:3]:
            image, _,forced_fits = insert_image_and_simulated_sources(
                self.dataset,img_pars,[transient_src],
                self.new_source_sigma_margin)
            self.assertEqual(len(forced_fits), 0)

        # Check the number of detected transients
        transients = get_newsources_for_dataset(self.dataset.id)
        self.assertEqual(len(transients), 1)
        newsrc_properties = transients[0]
        # Check that the bands for the images are the same as the transient's band
        freq_bands = frequency_bands(self.dataset._id)
        self.assertEqual(len(freq_bands), 1)
        self.assertEqual(freq_bands[0], newsrc_properties['band'])

        # Sanity check that the runcat is correctly matched
        runcats = runcat_entries(self.dataset._id)
        self.assertEqual(len(runcats), 1)
        self.assertEqual(runcats[0]['runcat'], newsrc_properties['runcat_id'])

        # Since it is a single-epoch source, variability indices default to 0:
        self.assertEqual(newsrc_properties['v_int'],0)
        self.assertEqual(newsrc_properties['eta_int'],0)

        # Bright 'new-source' / single-epoch transient; should have high sigmas:
        self.assertTrue(
            newsrc_properties['low_thresh_sigma']> self.new_source_sigma_margin)
        self.assertEqual(newsrc_properties['low_thresh_sigma'],
                         newsrc_properties['high_thresh_sigma'])

        # Check the correct trigger xtrsrc was identified:
        self.assertEqual(newsrc_properties['taustart_ts'],
                         transient_src.lightcurve.keys()[0])

        # Ok, now add the last image and check that we get a correct forced-fit
        # request:
        image, _,forced_fits = insert_image_and_simulated_sources(
                self.dataset,im_params[3],[transient_src],
                self.new_source_sigma_margin)
        self.assertEqual(len(forced_fits),1)


        transients = get_sources_filtered_by_final_variability(
            dataset_id=self.dataset.id,**self.search_params)

        self.assertEqual(len(transients), 1)
        transient_properties = transients[0]

        # And now we should have a non-zero variability value
        self.assertNotAlmostEqual(transient_properties['v_int'], 0)
        self.assertNotAlmostEqual(transient_properties['eta_int'], 0)