Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

225

226

227

228

229

230

231

232

233

234

235

236

237

238

239

240

241

242

243

244

245

246

247

248

249

250

251

252

253

254

255

256

257

258

259

260

261

262

263

264

265

266

267

268

269

270

271

272

273

274

275

276

277

278

279

280

281

282

283

284

285

286

287

288

289

290

291

292

293

294

295

296

297

298

299

300

301

302

303

304

305

306

307

308

309

310

311

312

313

314

315

316

317

318

319

320

321

322

323

324

325

326

327

328

329

330

331

332

333

334

335

336

337

338

339

340

341

342

343

344

345

346

347

348

349

350

351

352

353

354

355

356

357

358

359

360

361

362

363

364

365

366

367

368

369

370

371

372

373

374

375

376

377

378

379

380

381

382

383

384

385

386

387

388

389

390

391

392

393

394

395

396

397

398

399

400

401

402

403

404

405

406

407

408

409

410

411

412

413

414

415

416

417

418

419

420

421

422

423

424

425

426

427

428

429

430

431

432

433

434

435

436

437

438

439

440

441

442

443

444

445

446

447

448

449

450

451

452

453

454

455

456

457

458

459

460

461

462

463

464

465

466

467

468

469

470

471

472

473

474

475

476

477

478

479

480

481

482

483

484

485

486

487

488

489

490

491

492

493

494

495

496

497

498

499

500

501

502

503

504

505

506

507

508

509

510

511

512

513

514

515

516

517

518

519

520

521

522

523

524

525

526

527

528

529

530

531

532

533

534

535

536

537

538

539

540

541

542

543

544

545

546

547

548

549

550

551

552

553

554

555

556

557

558

559

560

561

562

563

564

565

566

567

568

569

570

571

572

573

574

575

576

577

578

579

580

581

582

583

584

585

586

587

588

589

590

591

592

593

594

595

# This file is part of ap_association. 

# 

# Developed for the LSST Data Management System. 

# This product includes software developed by the LSST Project 

# (https://www.lsst.org). 

# See the COPYRIGHT file at the top-level directory of this distribution 

# for details of code ownership. 

# 

# This program is free software: you can redistribute it and/or modify 

# it under the terms of the GNU General Public License as published by 

# the Free Software Foundation, either version 3 of the License, or 

# (at your option) any later version. 

# 

# This program is distributed in the hope that it will be useful, 

# but WITHOUT ANY WARRANTY; without even the implied warranty of 

# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

# GNU General Public License for more details. 

# 

# You should have received a copy of the GNU General Public License 

# along with this program. If not, see <https://www.gnu.org/licenses/>. 

 

import numpy as np 

import os 

import tempfile 

import unittest 

 

from lsst.afw.cameraGeom.testUtils import DetectorWrapper 

import lsst.afw.geom as afwGeom 

import lsst.afw.image as afwImage 

import lsst.afw.image.utils as afwImageUtils 

import lsst.afw.table as afwTable 

import lsst.daf.base as dafBase 

from lsst.dax.ppdb import Ppdb, PpdbConfig 

import lsst.geom as geom 

from lsst.ap.association import \ 

AssociationTask, \ 

make_dia_source_schema, \ 

make_dia_object_schema 

from lsst.utils import getPackageDir 

import lsst.utils.tests 

 

 

def create_test_points(point_locs_deg, 

wcs=None, 

start_id=0, 

schema=None, 

scatter_arcsec=1.0, 

indexer_ids=None, 

associated_ids=None): 

"""Create dummy DIASources or DIAObjects for use in our tests. 

Parameters 

---------- 

point_locs_deg : array-like (N, 2) of `float`s 

Positions of the test points to create in RA, DEC. 

wcs : `lsst.afw.geom.SkyWcs` 

Wcs to convert RA/Dec to x/y if provided. 

start_id : `int` 

Unique id of the first object to create. The remaining sources are 

incremented by one from the first id. 

schema : `lsst.afw.table.Schema` 

Schema of the objects to create. Defaults to the DIASource schema. 

scatter_arcsec : `float` 

Scatter to add to the position of each DIASource. 

indexer_ids : `list` of `ints`s 

Id numbers of pixelization indexer to store. Must be the same length 

as the first dimension of point_locs_deg. 

associated_ids : `list` of `ints`s 

Id numbers of associated DIAObjects to store. Must be the same length 

as the first dimension of point_locs_deg. 

Returns 

------- 

test_points : `lsst.afw.table.SourceCatalog` 

Catalog of points to test. 

""" 

if schema is None: 

schema = make_dia_source_schema() 

sources = afwTable.SourceCatalog(schema) 

 

for src_idx, (ra, dec,) in enumerate(point_locs_deg): 

src = sources.addNew() 

src['id'] = src_idx + start_id 

coord = geom.SpherePoint(ra, dec, geom.degrees) 

if scatter_arcsec > 0.0: 

coord = coord.offset( 

np.random.rand() * 360 * geom.degrees, 

np.random.rand() * scatter_arcsec * geom.arcseconds) 

if indexer_ids is not None: 

src['pixelId'] = indexer_ids[src_idx] 

if associated_ids is not None: 

src['diaObjectId'] = associated_ids[src_idx] 

src.setCoord(coord) 

 

if wcs is not None: 

xyCentroid = wcs.skykToPixel(coord) 

src.set("x", xyCentroid.getX()) 

src.set("y", xyCentroid.getY()) 

 

return sources 

 

 

def _data_file_name(basename, module_name): 

"""Return path name of a data file. 

 

Parameters 

---------- 

basename : `str` 

Name of the file to add to the path string. 

module_name : `str` 

Name of lsst stack package environment variable. 

 

Returns 

------- 

data_file_path : `str` 

Full path of the file to load from the "data" directory in a given 

repository. 

""" 

return os.path.join(getPackageDir(module_name), "data", basename) 

 

 

class TestAssociationTask(unittest.TestCase): 

 

def setUp(self): 

"""Create a sqlite3 database with default tables and schemas. 

""" 

# CFHT Filters from the camera mapper. 

self.filter_names = ["u", "g", "r", "i", "z"] 

afwImageUtils.resetFilters() 

afwImageUtils.defineFilter('u', lambdaEff=374, alias="u.MP9301") 

afwImageUtils.defineFilter('g', lambdaEff=487, alias="g.MP9401") 

afwImageUtils.defineFilter('r', lambdaEff=628, alias="r.MP9601") 

afwImageUtils.defineFilter('i', lambdaEff=778, alias="i.MP9701") 

afwImageUtils.defineFilter('z', lambdaEff=1170, alias="z.MP9801") 

 

self.tmp_file, self.db_file = tempfile.mkstemp(dir=os.path.dirname(__file__)) 

 

self.dia_object_schema = make_dia_object_schema() 

 

self.ppdbConfig = PpdbConfig() 

self.ppdbConfig.db_url = "sqlite:///" + self.db_file 

self.ppdbConfig.isolation_level = "READ_UNCOMMITTED" 

self.ppdbConfig.dia_object_index = "baseline" 

self.ppdbConfig.dia_object_columns = [] 

self.ppdbConfig.schema_file = _data_file_name( 

"ppdb-schema.yaml", "dax_ppdb") 

self.ppdbConfig.column_map = _data_file_name( 

"ppdb-ap-pipe-afw-map.yaml", "ap_association") 

self.ppdbConfig.extra_schema_file = _data_file_name( 

"ppdb-ap-pipe-schema-extra.yaml", "ap_association") 

 

# metadata taken from CFHT data 

# v695856-e0/v695856-e0-c000-a00.sci_img.fits 

 

self.metadata = dafBase.PropertySet() 

 

self.metadata.set("SIMPLE", "T") 

self.metadata.set("BITPIX", -32) 

self.metadata.set("NAXIS", 2) 

self.metadata.set("NAXIS1", 1024) 

self.metadata.set("NAXIS2", 1153) 

self.metadata.set("RADECSYS", 'FK5') 

self.metadata.set("EQUINOX", 2000.) 

 

self.metadata.setDouble("CRVAL1", 215.604025685476) 

self.metadata.setDouble("CRVAL2", 53.1595451514076) 

self.metadata.setDouble("CRPIX1", 1109.99981456774) 

self.metadata.setDouble("CRPIX2", 560.018167811613) 

self.metadata.set("CTYPE1", 'RA---SIN') 

self.metadata.set("CTYPE2", 'DEC--SIN') 

 

self.metadata.setDouble("CD1_1", 5.10808596133527E-05) 

self.metadata.setDouble("CD1_2", 1.85579539217196E-07) 

self.metadata.setDouble("CD2_2", -5.10281493481982E-05) 

self.metadata.setDouble("CD2_1", -8.27440751733828E-07) 

 

self.wcs = afwGeom.makeSkyWcs(self.metadata) 

self.exposure = afwImage.makeExposure( 

afwImage.makeMaskedImageFromArrays(np.ones((1024, 1153))), 

self.wcs) 

detector = DetectorWrapper(id=23, bbox=self.exposure.getBBox()).detector 

visit = afwImage.VisitInfo( 

exposureId=1234, 

exposureTime=200., 

date=dafBase.DateTime("2014-05-13T17:00:00.000000000", 

dafBase.DateTime.Timescale.TAI)) 

self.exposure.setDetector(detector) 

self.exposure.getInfo().setVisitInfo(visit) 

self.exposure.setFilter(afwImage.Filter('g')) 

self.flux0 = 10000 

self.flux0_err = 100 

self.exposure.getCalib().setFluxMag0((self.flux0, self.flux0_err)) 

 

bbox = geom.Box2D(self.exposure.getBBox()) 

wcs = self.exposure.getWcs() 

 

ctr_coord = wcs.pixelToSky(bbox.getCenter()) 

max_radius = max( 

ctr_coord.separation(wcs.pixelToSky(pp)) 

for pp in bbox.getCorners()) 

 

assoc_task = AssociationTask() 

 

indexer_indices, on_boundry = assoc_task.indexer.getShardIds( 

ctr_coord, max_radius) 

# Index types must be cast to int to work with dax_ppdb. 

self.index_ranges = [[int(indexer_idx), int(indexer_idx) + 1] 

for indexer_idx in indexer_indices] 

 

def tearDown(self): 

"""Delete the database after we are done with it. 

""" 

del self.tmp_file 

os.remove(self.db_file) 

del self.db_file 

del self.metadata 

del self.wcs 

del self.exposure 

 

def test_run(self): 

"""Test the run method with a database that already exists and 

contains DIAObjects and Sources. 

""" 

dia_objects = self._run_association_and_retrieve_objects(True) 

not_updated_idx = 0 

updated_idx_start = 1 

new_idx_start = 5 

total_expected_dia_objects = 10 

self.assertEqual(len(dia_objects), total_expected_dia_objects) 

 

# Test to make sure the number of DIAObjects have been properly 

# associated within the db. 

for obj_idx, dia_object in enumerate(dia_objects): 

if obj_idx == not_updated_idx: 

# Test the DIAObject we expect to not be associated with any 

# new DIASources. 

self.assertEqual(dia_object['gPSFluxNdata'], 1) 

self.assertEqual(dia_object['rPSFluxNdata'], 1) 

self.assertEqual(dia_object['nDiaSources'], 2) 

self.assertEqual(dia_object.getId(), obj_idx) 

elif updated_idx_start <= obj_idx < new_idx_start: 

# Test that associating to the existing DIAObjects went 

# as planned and test that the IDs of the newly associated 

# DIASources is correct. 

self.assertEqual(dia_object['gPSFluxNdata'], 2) 

self.assertEqual(dia_object['rPSFluxNdata'], 1) 

self.assertEqual(dia_object['nDiaSources'], 3) 

self.assertEqual(dia_object.getId(), obj_idx) 

else: 

self.assertEqual(dia_object['gPSFluxNdata'], 1) 

self.assertEqual(dia_object['nDiaSources'], 1) 

self.assertEqual(dia_object.getId(), obj_idx + 4 + 5) 

 

def test_run_no_existing_objects(self): 

"""Test the run method with a completely empty database. 

""" 

dia_objects = self._run_association_and_retrieve_objects(False) 

total_expected_dia_objects = 9 

self.assertEqual(len(dia_objects), 

total_expected_dia_objects) 

for obj_idx, output_dia_object in enumerate(dia_objects): 

self.assertEqual(output_dia_object['gPSFluxNdata'], 1) 

self.assertEqual(output_dia_object.getId(), 

obj_idx + 10) 

self.assertEqual(output_dia_object.getId(), obj_idx + 10) 

 

def _make_ppdb(self): 

"""Create an empty ppdb database. 

 

Returns 

------- 

ppdb : `lsst.dax.ppdb.Ppdb` 

Initialized and empty ppdb. 

""" 

ppdb = Ppdb(config=self.ppdbConfig, 

afw_schemas=dict(DiaObject=make_dia_object_schema(), 

DiaSource=make_dia_source_schema())) 

ppdb.makeSchema() 

 

return ppdb 

 

def _run_association_and_retrieve_objects(self, create_objects=False): 

"""Convenience method for testing the Association run method. 

 

Parameters 

---------- 

create_objects : `bool` 

Boolean specifying if seed DIAObjects and DIASources should be 

inserted into the database before association. 

 

Return 

------ 

dia_objects : `lsst.afw.table.SourceCatalog` 

Final set of DIAObjects to be tested. 

""" 

if create_objects: 

self._store_dia_objects_and_sources() 

 

source_centers = [ 

[self.wcs.pixelToSky(idx, idx).getRa().asDegrees(), 

self.wcs.pixelToSky(idx, idx).getDec().asDegrees()] 

for idx in np.linspace(1, 1000, 10)[1:]] 

dia_sources = create_test_points( 

point_locs_deg=source_centers, 

start_id=10, 

scatter_arcsec=-1) 

for dia_source in dia_sources: 

self._set_source_values( 

dia_source=dia_source, 

flux=10000, 

fluxErr=100, 

filterName=self.exposure.getFilter().getName(), 

filterId=self.exposure.getFilter().getId(), 

ccdVisitId=self.exposure.getInfo().getVisitInfo().getExposureId(), 

midPointTai=self.exposure.getInfo().getVisitInfo().getDate().get(system=dafBase.DateTime.MJD)) 

 

assoc_task = AssociationTask() 

 

ppdb = self._make_ppdb() 

 

assoc_task.run(dia_sources, self.exposure, ppdb) 

 

dia_objects = assoc_task.retrieve_dia_objects(self.exposure, ppdb) 

return dia_objects 

 

def _set_source_values(self, dia_source, flux, fluxErr, filterName, 

filterId, ccdVisitId, midPointTai): 

"""Set fluxes and visit info for DiaSources. 

 

Parameters 

---------- 

dia_source : `lsst.afw.table.SourceRecord` 

SourceRecord object to edit. 

flux : `double` 

Flux of DiaSource 

fluxErr : `double` 

Flux error of DiaSource 

filterName : `string` 

Name of filter for flux. 

filterId : `int` 

Unique id of filter. 

ccdVisitId : `int` 

Integer id of this ccd/visit. 

midPointTai : `double` 

Time of observation 

""" 

dia_source['ccdVisitId'] = ccdVisitId 

dia_source["midPointTai"] = midPointTai 

dia_source["psFlux"] = flux / self.flux0 

dia_source["psFluxErr"] = \ 

np.sqrt((fluxErr / self.flux0) ** 2 + (flux * self.flux0_err / self.flux0 ** 2) ** 2) 

dia_source["apFlux"] = flux / self.flux0 

dia_source["apFluxErr"] = \ 

np.sqrt((fluxErr / self.flux0) ** 2 + (flux * self.flux0_err / self.flux0 ** 2) ** 2) 

dia_source["filterName"] = filterName 

dia_source["filterId"] = filterId 

dia_source["x"] = 0. 

dia_source["y"] = 0. 

 

def _store_dia_objects_and_sources(self): 

"""Method for storing a set of test DIAObjects and sources into 

the L1 database. 

""" 

 

# This should create a DB of 5 DIAObjects with 2 DIASources associated 

# to them. The DIASources are "observed" in g and r. 

 

# Create an empty database 

ppdb = self._make_ppdb() 

 

# Create DIObjects, give them fluxes, and store them 

n_objects = 5 

object_centers = np.array([ 

[self.wcs.pixelToSky(idx, idx).getRa().asDegrees(), 

self.wcs.pixelToSky(idx, idx).getDec().asDegrees()] 

for idx in np.linspace(1, 1000, 10)]) 

dia_objects = create_test_points( 

point_locs_deg=object_centers[:n_objects], 

start_id=0, 

schema=self.dia_object_schema, 

scatter_arcsec=-1,) 

# Set the DIAObject fluxes and number of associated sources. 

for dia_object in dia_objects: 

dia_object["nDiaSources"] = 2 

for filter_name in self.filter_names: 

dia_object["pixelId"] = 225823 

dia_object['%sPSFluxMean' % filter_name] = 1 

dia_object['%sPSFluxMeanErr' % filter_name] = 1 

dia_object['%sPSFluxSigma' % filter_name] = 1 

dia_object['%sPSFluxNdata' % filter_name] = 1 

 

dateTime = dafBase.DateTime("2014-05-13T16:00:00.000000000", 

dafBase.DateTime.Timescale.TAI) 

ppdb.storeDiaObjects(dia_objects, dateTime.toPython()) 

loaded_dia_objects = ppdb.getDiaObjects(self.index_ranges) 

 

self.assertTrue(loaded_dia_objects.schema == dia_objects.schema) 

 

# Create DIASources, update their ccdVisitId and fluxes, and store 

# them. 

dia_sources = create_test_points( 

point_locs_deg=np.concatenate( 

[object_centers[:n_objects], object_centers[:n_objects]]), 

start_id=0, 

scatter_arcsec=-1, 

associated_ids=[0, 1, 2, 3, 4, 

0, 1, 2, 3, 4]) 

for src_idx, dia_source in enumerate(dia_sources): 

if src_idx < n_objects: 

self._set_source_values( 

dia_source=dia_source, 

flux=10000, 

fluxErr=100, 

filterName='g', 

filterId=1, 

ccdVisitId=1232, 

midPointTai=dateTime.get(system=dafBase.DateTime.MJD)) 

else: 

self._set_source_values( 

dia_source=dia_source, 

flux=10000, 

fluxErr=100, 

filterName='r', 

filterId=2, 

ccdVisitId=1233, 

midPointTai=dateTime.get(system=dafBase.DateTime.MJD)) 

ppdb.storeDiaSources(dia_sources) 

 

def test_update_dia_objects(self): 

"""Test the update_dia_objects method. 

""" 

self._store_dia_objects_and_sources() 

# Create new DIAObjects 

n_sources = 5 

object_centers = np.array([ 

[self.wcs.pixelToSky(idx, idx).getRa().asDegrees(), 

self.wcs.pixelToSky(idx, idx).getDec().asDegrees()] 

for idx in np.linspace(1, 1000, 10)]) 

dia_sources = create_test_points( 

point_locs_deg=object_centers[:n_sources], 

start_id=10, 

scatter_arcsec=-1, 

associated_ids=[1, 2, 3, 4, 14]) 

 

for dia_source in dia_sources: 

self._set_source_values( 

dia_source=dia_source, 

flux=20000, 

fluxErr=100, 

filterName='g', 

filterId=1, 

ccdVisitId=self.exposure.getInfo().getVisitInfo().getExposureId(), 

midPointTai=self.exposure.getInfo().getVisitInfo().getDate().get(system=dafBase.DateTime.MJD)) 

 

# Store them in the DB containing pre-existing objects. 

ppdb = self._make_ppdb() 

# Load the Existing DIAObjects for use in the update method. 

loaded_dia_objects = ppdb.getDiaObjects(self.index_ranges) 

 

# Store the new DIASources with associations and an exposure. 

ppdb.storeDiaSources(dia_sources) 

 

# Create our task and update the stored DIAObjects. 

assoc_task = AssociationTask() 

assoc_task.update_dia_objects(loaded_dia_objects, 

[1, 2, 3, 4, 14], 

self.exposure, 

ppdb) 

 

# Retrieve the DIAObjects from the DB. 

output_dia_objects = ppdb.getDiaObjects(self.index_ranges) 

 

# Data and column names to test. 

test_dia_object_values = [ 

{'id': 0, 

'gPSFluxMean': 1., 'gPSFluxMeanErr': 1., 'gPSFluxSigma': 1., 

'rPSFluxMean': 1., 'rPSFluxMeanErr': 1., 'rPSFluxSigma': 1.}, 

{'id': 1, 

'gPSFluxMean': 1.2857141, 'gPSFluxMeanErr': 0.01195228, 'gPSFluxSigma': 0.70710678, 

'rPSFluxMean': 1., 'rPSFluxMeanErr': 1., 'rPSFluxSigma': 1.}, 

{'id': 2, 

'gPSFluxMean': 1.2857141, 'gPSFluxMeanErr': 0.01195228, 'gPSFluxSigma': 0.70710678, 

'rPSFluxMean': 1., 'rPSFluxMeanErr': 1., 'rPSFluxSigma': 1.}, 

{'id': 3, 

'gPSFluxMean': 1.2857141, 'gPSFluxMeanErr': 0.01195228, 'gPSFluxSigma': 0.70710678, 

'rPSFluxMean': 1., 'rPSFluxMeanErr': 1., 'rPSFluxSigma': 1.}, 

{'id': 4, 

'gPSFluxMean': 1.2857141, 'gPSFluxMeanErr': 0.01195228, 'gPSFluxSigma': 0.70710678, 

'rPSFluxMean': 1., 'rPSFluxMeanErr': 1., 'rPSFluxSigma': 1.}, 

{'id': 14, 

'gPSFluxMean': 2., 'gPSFluxMeanErr': np.nan, 'gPSFluxSigma': np.nan, 

'rPSFluxMean': np.nan, 'rPSFluxMeanErr': np.nan, 'rPSFluxSigma': np.nan} 

] 

 

# Test that the stored values are as expected. 

self.assertEqual(len(output_dia_objects), 6) 

for dia_object, values in zip(output_dia_objects, 

test_dia_object_values): 

for test_name in values.keys(): 

if np.isnan(values[test_name]): 

self.assertTrue(np.isnan(dia_object[test_name])) 

elif test_name == 'id' or test_name == 'nDiaSources': 

self.assertEqual(dia_object[test_name], 

values[test_name]) 

else: 

self.assertAlmostEqual(dia_object[test_name], 

values[test_name]) 

 

def test_associate_sources(self): 

"""Test the performance of the associate_sources method in 

AssociationTask. 

""" 

n_objects = 5 

dia_objects = create_test_points( 

point_locs_deg=[[0.04 * obj_idx, 0.04 * obj_idx] 

for obj_idx in range(n_objects)], 

start_id=0, 

schema=self.dia_object_schema, 

scatter_arcsec=-1,) 

 

n_sources = 5 

dia_sources = create_test_points( 

point_locs_deg=[ 

[0.04 * (src_idx + 1), 

0.04 * (src_idx + 1)] 

for src_idx in range(n_sources)], 

start_id=n_objects, 

scatter_arcsec=0.1) 

 

assoc_task = AssociationTask() 

assoc_result = assoc_task.associate_sources( 

dia_objects, dia_sources) 

 

for test_obj_id, expected_obj_id in zip(assoc_result, [1, 2, 3, 4, 9]): 

self.assertEqual(test_obj_id, expected_obj_id) 

 

def test_score_and_match(self): 

"""Test association between a set of sources and an existing 

DIAObjectCollection. 

 

This also tests that a DIASource that can't be associated within 

tolerance is appended to the DIAObjectCollection as a new 

DIAObject. 

""" 

 

assoc_task = AssociationTask() 

# Create a set of DIAObjects that contain only one DIASource 

n_objects = 5 

dia_objects = create_test_points( 

point_locs_deg=[[0.04 * obj_idx, 0.04 * obj_idx] 

for obj_idx in range(n_objects)], 

start_id=0, 

schema=self.dia_object_schema, 

scatter_arcsec=-1,) 

 

n_sources = 5 

dia_sources = create_test_points( 

point_locs_deg=[ 

[0.04 * (src_idx + 1), 

0.04 * (src_idx + 1)] 

for src_idx in range(n_sources)], 

start_id=n_objects, 

scatter_arcsec=-1) 

 

score_struct = assoc_task.score(dia_objects, 

dia_sources, 

1.0 * geom.arcseconds) 

self.assertFalse(np.isfinite(score_struct.scores[-1])) 

for src_idx in range(4): 

# Our scores should be extremely close to 0 but not exactly so due 

# to machine noise. 

self.assertAlmostEqual(score_struct.scores[src_idx], 0.0, 

places=16) 

 

# After matching each DIAObject should now contain 2 DIASources 

# except the last DIAObject in this collection which should be 

# newly created during the matching step and contain only one 

# DIASource. 

match_result = assoc_task.match(dia_objects, dia_sources, score_struct) 

updated_ids = match_result.associated_dia_object_ids 

self.assertEqual(len(updated_ids), 5) 

self.assertEqual(match_result.n_updated_dia_objects, 4) 

self.assertEqual(match_result.n_new_dia_objects, 1) 

self.assertEqual(match_result.n_unassociated_dia_objects, 1) 

 

 

class MemoryTester(lsst.utils.tests.MemoryTestCase): 

pass 

 

 

def setup_module(module): 

lsst.utils.tests.init() 

 

 

593 ↛ 594line 593 didn't jump to line 594, because the condition on line 593 was never trueif __name__ == "__main__": 

lsst.utils.tests.init() 

unittest.main()