def test_create2(self): dataset1 = DataSet(data={'description': 'dataset with images'}, database=self.database) self.assertEqual(dataset1.images, set()) image_data = db_subs.example_dbimage_data_dict() image1 = Image(dataset=dataset1, data=image_data) image2 = Image(dataset=dataset1, data=image_data) extractedsource_data = { 'ra': 123.123, 'decl': 23.23, 'ra_err': 21.1, 'decl_err': 21.09, 'ra_fit_err': 0.1, 'decl_fit_err': 0.1, 'uncertainty_ew': 0.1, 'uncertainty_ns': 0.1, 'zone': 1, 'x': 0.11, 'y': 0.22, 'z': 0.33, 'racosdecl': 0.44, 'det_sigma': 10.0, 'ew_sys_err': 20, 'ns_sys_err': 20, 'error_radius': 10.0 } source1 = ExtractedSource(image=image1, data=extractedsource_data) extractedsource_data['ra'] = 45.45 extractedsource_data['decl'] = 55.55 source2 = ExtractedSource(image=image1, data=extractedsource_data) self.assertEqual(len(image1.sources), 2) # Source #3 points to the same source as #2 source3 = ExtractedSource(id=source2.id, database=self.database) # Which means there are no extra sources for image1 self.assertEqual(len(image1.sources), 2) srcids = set([source.id for source in image1.sources]) # If, however, we create a new source with # an image reference in the constructor, we get a # 'deep' copy: source4 = ExtractedSource(image=image1, id=source2.id) # Now there's a new source for image1! self.assertEqual(len(image1.sources), 3) # But if we filter on the source ids, # we see there are really only two sources srcids = set([source.id for source in image1.sources]) self.assertEqual(set([source1.id, source2.id]), srcids) extractedsource_data['ra'] = 89.89 extractedsource_data['decl'] = 78.78 source5 = ExtractedSource(image=image2, data=extractedsource_data) self.assertEqual(len(image2.sources), 1) self.assertEqual(image2.sources.pop().id, source5.id)
def test_update(self): data = { 'freq_eff': 80e6, 'freq_bw': 1e6, 'taustart_ts': datetime.datetime(1999, 9, 9), 'url': '/path/to/image', 'tau_time': 0, 'beam_smaj_pix': float(2.7), 'beam_smin_pix': float(2.3), 'beam_pa_rad': float(1.7), 'deltax': float(-0.01111), 'deltay': float(0.01111), 'centre_ra': 0, 'centre_decl': 0, 'xtr_radius' : 3 } dataset1 = DataSet(data={'description': 'dataset with images'}, database=self.database) self.assertEqual(dataset1.images, set()) image1 = Image(dataset=dataset1, data=data) image2 = Image(dataset=dataset1, data=data) data = {'ra': 123.123, 'decl': 23.23, 'ra_err': 21.1, 'decl_err': 21.09, 'ra_fit_err': 0.1, 'decl_fit_err': 0.1, 'uncertainty_ew': 0.1, 'uncertainty_ns': 0.1, 'zone': 1, 'x': 0.11, 'y': 0.22, 'z': 0.33, 'racosdecl': 0.44, 'det_sigma': 11.1, 'ew_sys_err': 20, 'ns_sys_err': 20, 'error_radius': 10.0} source1 = ExtractedSource(image=image1, data=data) data['ra'] = 45.45 data['decl'] = 55.55 source2 = ExtractedSource(image=image1, data=data) self.assertEqual(len(image1.sources), 2) # Source #3 points to the same source as #2 source3 = ExtractedSource(id=source2.id, database=self.database) # Update source3 source3.update(decl=44.44) # But no change for #1 and #2 self.assertAlmostEqual(source1.decl, 23.23) self.assertAlmostEqual(source2.decl, 55.55) self.assertAlmostEqual(source3.decl, 44.44) source1.update() # nothing changes for #1 self.assertAlmostEqual(source1.decl, 23.23) self.assertAlmostEqual(source2.decl, 55.55) self.assertAlmostEqual(source3.decl, 44.44) # Now we make sure source #2 takes note of the change done through #3 source2.update() self.assertAlmostEqual(source1.decl, 23.23) self.assertAlmostEqual(source1.decl, 23.23) self.assertAlmostEqual(source2.decl, 44.44)
def test_create(self): dataset = DataSet(data={'description': 'dataset with images'}, database=self.database) # create 4 images, separated by one day each image = Image(dataset=dataset, data=db_subs.example_dbimage_data_dict()) extracted_source_data = dict(zone=13, ra=12.12, decl=13.13, ra_err=21.1, decl_err=21.09, ra_fit_err=1.12, decl_fit_err=1.23, uncertainty_ew=0.1, uncertainty_ns=0.1, ew_sys_err=20, ns_sys_err=20, error_radius=10.0, x=0.11, y=0.22, z=0.33, racosdecl=0.44, det_sigma=10.) src1 = ExtractedSource(data=extracted_source_data, image=image) src2 = ExtractedSource(data=extracted_source_data, image=image, database=self.database) self.assertNotEqual(src1.id, src2.id) extracted_source_data['image'] = image.id src3 = ExtractedSource(data=extracted_source_data, database=self.database) extracted_source_data['ra'] = 23.23 src4 = ExtractedSource(data=extracted_source_data, database=self.database, id=src1.id) self.assertEqual(src1.id, src4.id) self.assertAlmostEqual(src1.ra, src4.ra) del extracted_source_data['x'] self.assertRaisesRegexp(AttributeError, "missing required data key: x", ExtractedSource, data=extracted_source_data, database=self.database)
def test_update(self): image_data = db_subs.example_dbimage_data_dict() dataset1 = DataSet(data={'description': 'dataset with images'}, database=self.database) self.assertEqual(dataset1.images, set()) image1 = Image(dataset=dataset1, data=image_data) image2 = Image(dataset=dataset1, data=image_data) extractedsource_data = {'ra': 123.123, 'decl': 23.23, 'ra_err': 21.1, 'decl_err': 21.09, 'ra_fit_err': 0.1, 'decl_fit_err': 0.1, 'uncertainty_ew': 0.1, 'uncertainty_ns': 0.1, 'zone': 1, 'x': 0.11, 'y': 0.22, 'z': 0.33, 'racosdecl': 0.44, 'det_sigma': 11.1, 'ew_sys_err': 20, 'ns_sys_err': 20, 'error_radius': 10.0} source1 = ExtractedSource(image=image1, data=extractedsource_data) extractedsource_data['ra'] = 45.45 extractedsource_data['decl'] = 55.55 source2 = ExtractedSource(image=image1, data=extractedsource_data) self.assertEqual(len(image1.sources), 2) # Source #3 points to the same source as #2 source3 = ExtractedSource(id=source2.id, database=self.database) # Update source3 source3.update(decl=44.44) # But no change for #1 and #2 self.assertAlmostEqual(source1.decl, 23.23) self.assertAlmostEqual(source2.decl, 55.55) self.assertAlmostEqual(source3.decl, 44.44) source1.update() # nothing changes for #1 self.assertAlmostEqual(source1.decl, 23.23) self.assertAlmostEqual(source2.decl, 55.55) self.assertAlmostEqual(source3.decl, 44.44) # Now we make sure source #2 takes note of the change done through #3 source2.update() self.assertAlmostEqual(source1.decl, 23.23) self.assertAlmostEqual(source1.decl, 23.23) self.assertAlmostEqual(source2.decl, 44.44)
def test_update(self): image_data = db_subs.example_dbimage_data_dict() dataset1 = DataSet(data={'description': 'dataset with images'}, database=self.database) self.assertEqual(dataset1.images, set()) image1 = Image(dataset=dataset1, data=image_data) image2 = Image(dataset=dataset1, data=image_data) extractedsource_data = { 'ra': 123.123, 'decl': 23.23, 'ra_err': 21.1, 'decl_err': 21.09, 'ra_fit_err': 0.1, 'decl_fit_err': 0.1, 'uncertainty_ew': 0.1, 'uncertainty_ns': 0.1, 'zone': 1, 'x': 0.11, 'y': 0.22, 'z': 0.33, 'racosdecl': 0.44, 'det_sigma': 11.1, 'ew_sys_err': 20, 'ns_sys_err': 20, 'error_radius': 10.0 } source1 = ExtractedSource(image=image1, data=extractedsource_data) extractedsource_data['ra'] = 45.45 extractedsource_data['decl'] = 55.55 source2 = ExtractedSource(image=image1, data=extractedsource_data) self.assertEqual(len(image1.sources), 2) # Source #3 points to the same source as #2 source3 = ExtractedSource(id=source2.id, database=self.database) # Update source3 source3.update(decl=44.44) # But no change for #1 and #2 self.assertAlmostEqual(source1.decl, 23.23) self.assertAlmostEqual(source2.decl, 55.55) self.assertAlmostEqual(source3.decl, 44.44) source1.update() # nothing changes for #1 self.assertAlmostEqual(source1.decl, 23.23) self.assertAlmostEqual(source2.decl, 55.55) self.assertAlmostEqual(source3.decl, 44.44) # Now we make sure source #2 takes note of the change done through #3 source2.update() self.assertAlmostEqual(source1.decl, 23.23) self.assertAlmostEqual(source1.decl, 23.23) self.assertAlmostEqual(source2.decl, 44.44)