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

596

597

598

599

600

601

602

603

604

605

606

607

608

609

610

611

612

613

614

615

616

617

618

619

620

621

622

623

624

625

626

627

628

629

630

631

632

633

634

635

636

637

638

639

640

641

642

643

644

645

646

647

648

649

650

651

652

653

654

655

656

657

658

659

660

661

662

663

664

665

666

667

668

669

670

671

672

673

674

675

676

677

678

679

680

681

682

683

684

685

686

687

688

689

690

691

692

693

694

695

696

697

698

699

700

701

702

703

704

705

706

707

708

709

710

711

712

713

714

715

716

717

718

719

720

721

722

723

724

725

726

727

728

729

730

731

732

733

734

735

736

737

738

739

740

741

742

743

import unittest 

import os 

import numpy as np 

import tempfile 

import palpy 

 

import lsst.utils.tests 

from lsst.utils import getPackageDir 

 

from lsst.sims.catalogs.db import fileDBObject 

from lsst.sims.utils import _angularSeparation 

from lsst.sims.utils import angularSeparation 

from lsst.sims.utils import arcsecFromRadians 

from lsst.sims.catalogs.definitions import InstanceCatalog 

from lsst.sims.catUtils.utils import makePhoSimTestDB 

from lsst.sims.catUtils.utils import testStarsDBObj, testGalaxyDiskDBObj 

from lsst.sims.catUtils.mixins import PhoSimAstrometryBase 

from lsst.sims.catUtils.mixins import PhoSimAstrometryStars 

from lsst.sims.catUtils.mixins import PhoSimAstrometryGalaxies 

 

from lsst.sims.utils import _observedFromICRS 

from lsst.sims.utils import _observedFromAppGeo 

 

from lsst.sims.utils import observedFromICRS 

from lsst.sims.utils import observedFromAppGeo 

 

from lsst.sims.utils import Site, ObservationMetaData 

from lsst.sims.utils import distanceToSun 

from lsst.sims.utils import raDecFromAltAz 

from lsst.sims.utils import pupilCoordsFromRaDec 

from lsst.sims.coordUtils import focalPlaneCoordsFromPupilCoords 

from lsst.sims.coordUtils import lsst_camera 

 

from lsst.sims.utils.CodeUtilities import sims_clean_up 

from lsst.sims.utils.CodeUtilities import _validate_inputs 

 

from lsst.sims.catUtils.exampleCatalogDefinitions import PhoSimCatalogPoint 

from lsst.sims.catUtils.exampleCatalogDefinitions import DefaultPhoSimHeaderMap 

 

from lsst.sims.utils import angularSeparation 

from lsst.sims.utils import _angularSeparation,arcsecFromRadians 

 

from lsst.sims.coordUtils import clean_up_lsst_camera 

 

ROOT = os.path.abspath(os.path.dirname(__file__)) 

 

 

def setup_module(module): 

lsst.utils.tests.init() 

 

 

def _naivePupilCoordsFromObserved(ra_obs, dec_obs, ra0, dec0, rotSkyPos): 

""" 

Convert Observed RA, Dec into pupil coordinates 

 

Parameters 

---------- 

ra_obs is the observed RA in radians 

 

dec_obs is the observed Dec in radians 

 

obs_metadata is an ObservationMetaData characterizing the telescope location and pointing 

 

epoch is the epoch of the mean RA and Dec in julian years (default=2000.0) 

 

includeRefraction is a boolean controlling the application of refraction. 

 

Returns 

-------- 

A numpy array whose first row is the x coordinate on the pupil in 

radians and whose second row is the y coordinate in radians 

""" 

 

are_arrays = _validate_inputs([ra_obs, dec_obs], ['ra_obs', 'dec_obs'], 

"pupilCoordsFromObserved") 

 

theta = -1.0*rotSkyPos 

 

ra_pointing = ra0 

dec_pointing = dec0 

 

# palpy.ds2tp performs the gnomonic projection on ra_in and dec_in 

# with a tangent point at (pointingRA, pointingDec) 

# 

if not are_arrays: 

try: 

x, y = palpy.ds2tp(ra_obs, dec_obs, ra_pointing, dec_pointing) 

except: 

x = np.NaN 

y = np.NaN 

else: 

try: 

x, y = palpy.ds2tpVector(ra_obs, dec_obs, ra_pointing, dec_pointing) 

except: 

# apparently, one of your ra/dec values was improper; we will have to do this 

# element-wise, putting NaN in the place of the bad values 

x = [] 

y = [] 

for rr, dd in zip(ra_obs, dec_obs): 

try: 

xx, yy = palpy.ds2tp(rr, dd, ra_pointing, dec_pointing) 

except: 

xx = np.NaN 

yy = np.NaN 

x.append(xx) 

y.append(yy) 

x = np.array(x) 

y = np.array(y) 

 

# rotate the result by rotskypos (rotskypos being "the angle of the sky relative to 

# camera coordinates" according to phoSim documentation) to account for 

# the rotation of the focal plane about the telescope pointing 

 

x_out = x*np.cos(theta) - y*np.sin(theta) 

y_out = x*np.sin(theta) + y*np.cos(theta) 

 

return np.array([x_out, y_out]) 

 

 

class StarTestCatalog(PhoSimAstrometryStars, InstanceCatalog): 

column_outputs = ['raICRS', 'decICRS', 'raPhoSim', 'decPhoSim', 

'raJ2000', 'decJ2000', 

'properMotionRa','properMotionDec', 'parallax', 

'radialVelocity'] 

 

transformations = {'raICRS': np.degrees, 'decICRS': np.degrees, 

'raPhoSim': np.degrees, 'decPhoSim': np.degrees} 

 

default_formats = {'f': '%.12g'} 

 

delimiter = ' ' 

 

 

class GalaxyTestCatalog(PhoSimAstrometryGalaxies, InstanceCatalog): 

column_outputs = ['raICRS', 'decICRS', 'raPhoSim', 'decPhoSim'] 

transformations = {'raICRS': np.degrees, 'decICRS': np.degrees, 

'raPhoSim': np.degrees, 'decPhoSim': np.degrees} 

 

override_formats = {'raICRS': '%.12g', 'decICRS': '%.12g', 

'raPhoSim': '%.12g', 'decPhoSim': '%.12g'} 

 

delimiter = ' ' 

 

 

class PhoSimAstrometryTestCase(unittest.TestCase): 

 

@classmethod 

def setUpClass(cls): 

cls.db_name = tempfile.mktemp(dir=ROOT, prefix='PhoSimAstDB', suffix='.db') 

cls.obs = makePhoSimTestDB(filename=cls.db_name, 

size=1000) 

 

@classmethod 

def tearDownClass(cls): 

sims_clean_up() 

if os.path.exists(cls.db_name): 

os.unlink(cls.db_name) 

 

clean_up_lsst_camera() 

 

def test_stellar_astrometry_radians(self): 

""" 

Test that we can go from raPhoSim, decPhoSim to ICRS coordinates 

in the case of stars (in radians) 

""" 

db = testStarsDBObj(driver='sqlite', database=self.db_name) 

cat = StarTestCatalog(db, obs_metadata=self.obs) 

with lsst.utils.tests.getTempFilePath('.txt') as cat_name: 

cat.write_catalog(cat_name) 

dtype = np.dtype([('raICRS', float), ('decICRS', float), 

('raPhoSim', float), ('decPhoSim', float), 

('raJ2000', float), ('decJ2000', float), 

('pmRA', float), ('pmDec', float), 

('parallax', float), ('vRad', float)]) 

data = np.genfromtxt(cat_name, dtype=dtype) 

self.assertGreater(len(data), 100) 

ra_pho_rad = np.radians(data['raPhoSim']) 

dec_pho_rad = np.radians(data['decPhoSim']) 

 

# verify that, when transforming back to ICRS, we are within 

# 10^-3 arcsec 

ra_icrs, dec_icrs = PhoSimAstrometryBase._icrsFromPhoSim(ra_pho_rad, 

dec_pho_rad, 

self.obs) 

dist = _angularSeparation(np.radians(data['raICRS']), 

np.radians(data['decICRS']), 

ra_icrs, dec_icrs) 

 

dist = arcsecFromRadians(dist) 

self.assertLess(dist.max(), 0.001) 

 

# verify that the distance between raPhoSim, decPhoSim and 

# raICRS, decICRS is greater than the distance between 

# the original raICRS, decICRS and the newly-calculated 

# raICRS, decICRS 

dist_bad = _angularSeparation(ra_pho_rad, dec_pho_rad, 

np.radians(data['raICRS']), 

np.radians(data['decICRS'])) 

 

dist_bad = arcsecFromRadians(dist_bad) 

self.assertGreater(dist_bad.min(), dist.max()) 

 

del db 

 

def test_stellar_astrometry_degrees(self): 

""" 

Test that we can go from raPhoSim, decPhoSim to ICRS coordinates 

in the case of stars (in degrees) 

""" 

db = testStarsDBObj(driver='sqlite', database=self.db_name) 

cat = StarTestCatalog(db, obs_metadata=self.obs) 

with lsst.utils.tests.getTempFilePath('.txt') as cat_name: 

cat.write_catalog(cat_name) 

dtype = np.dtype([('raICRS', float), ('decICRS', float), 

('raPhoSim', float), ('decPhoSim', float), 

('raJ2000', float), ('decJ2000', float), 

('pmRA', float), ('pmDec', float), 

('parallax', float), ('vRad', float)]) 

data = np.genfromtxt(cat_name, dtype=dtype) 

self.assertGreater(len(data), 100) 

 

# verify that, when transforming back to ICRS, we are within 

# 10^-3 arcsec 

ra_icrs, dec_icrs = PhoSimAstrometryBase.icrsFromPhoSim(data['raPhoSim'], 

data['decPhoSim'], 

self.obs) 

dist = angularSeparation(data['raICRS'], data['decICRS'], 

ra_icrs, dec_icrs) 

 

dist = 3600.0*dist 

self.assertLess(dist.max(), 0.001) 

 

# verify that the distance between raPhoSim, decPhoSim and 

# raICRS, decICRS is greater than the distance between 

# the original raICRS, decICRS and the newly-calculated 

# raICRS, decICRS 

dist_bad = angularSeparation(data['raPhoSim'], data['decPhoSim'], 

data['raICRS'], data['decICRS']) 

 

dist_bad = 3600.0*dist_bad 

self.assertGreater(dist_bad.min(), dist.max()) 

 

del db 

 

def test_stellar_observed_radians(self): 

""" 

Test ability to go all the way to observed RA, Dec 

from PhoSim (this is necessary for the ImSim software 

that DESC is working on) 

""" 

db = testStarsDBObj(driver='sqlite', database=self.db_name) 

cat = StarTestCatalog(db, obs_metadata=self.obs) 

with lsst.utils.tests.getTempFilePath('.txt') as cat_name: 

cat.write_catalog(cat_name) 

dtype = np.dtype([('raICRS', float), ('decICRS', float), 

('raPhoSim', float), ('decPhoSim', float), 

('raJ2000', float), ('decJ2000', float), 

('pmRA', float), ('pmDec', float), 

('parallax', float), ('vRad', float)]) 

data = np.genfromtxt(cat_name, dtype=dtype) 

self.assertGreater(len(data), 100) 

 

(ra_obs, 

dec_obs) = _observedFromICRS(data['raJ2000'], 

data['decJ2000'], 

obs_metadata=self.obs, 

pm_ra=data['pmRA'], 

pm_dec=data['pmDec'], 

parallax=data['parallax'], 

v_rad=data['vRad'], 

includeRefraction=True, 

epoch=2000.0) 

 

(ra_appGeo, 

dec_appGeo) = PhoSimAstrometryBase._appGeoFromPhoSim(np.radians(data['raPhoSim']), 

np.radians(data['decPhoSim']), 

self.obs) 

 

(ra_obs_2, 

dec_obs_2) = _observedFromAppGeo(ra_appGeo, dec_appGeo, 

obs_metadata=self.obs, 

includeRefraction=True) 

 

dd = arcsecFromRadians(_angularSeparation(ra_obs, dec_obs, ra_obs_2, dec_obs_2)) 

self.assertLess(dd.max(), 1.0e-5) 

 

def test_stellar_observed_degrees(self): 

""" 

Test ability to go all the way to observed RA, Dec 

from PhoSim (this is necessary for the ImSim software 

that DESC is working on) 

""" 

db = testStarsDBObj(driver='sqlite', database=self.db_name) 

cat = StarTestCatalog(db, obs_metadata=self.obs) 

with lsst.utils.tests.getTempFilePath('.txt') as cat_name: 

cat.write_catalog(cat_name) 

dtype = np.dtype([('raICRS', float), ('decICRS', float), 

('raPhoSim', float), ('decPhoSim', float), 

('raJ2000', float), ('decJ2000', float), 

('pmRA', float), ('pmDec', float), 

('parallax', float), ('vRad', float)]) 

data = np.genfromtxt(cat_name, dtype=dtype) 

self.assertGreater(len(data), 100) 

 

(ra_obs, 

dec_obs) = observedFromICRS(np.degrees(data['raJ2000']), 

np.degrees(data['decJ2000']), 

obs_metadata=self.obs, 

pm_ra=arcsecFromRadians(data['pmRA']), 

pm_dec=arcsecFromRadians(data['pmDec']), 

parallax=arcsecFromRadians(data['parallax']), 

v_rad=data['vRad'], 

includeRefraction=True, 

epoch=2000.0) 

 

(ra_appGeo, 

dec_appGeo) = PhoSimAstrometryBase.appGeoFromPhoSim(data['raPhoSim'], 

data['decPhoSim'], 

self.obs) 

 

(ra_obs_2, 

dec_obs_2) = observedFromAppGeo(ra_appGeo, dec_appGeo, 

obs_metadata=self.obs, 

includeRefraction=True) 

 

dd = 3600.0*angularSeparation(ra_obs, dec_obs, ra_obs_2, dec_obs_2) 

self.assertLess(dd.max(), 1.0e-5) 

 

def test_galaxy_astrometry_radians(self): 

""" 

Test that we can go from raPhoSim, decPhoSim to ICRS coordinates 

in the case of galaxies (in radians) 

""" 

db = testGalaxyDiskDBObj(driver='sqlite', database=self.db_name) 

cat = GalaxyTestCatalog(db, obs_metadata=self.obs) 

with lsst.utils.tests.getTempFilePath('.txt') as cat_name: 

cat.write_catalog(cat_name) 

dtype = np.dtype([('raICRS', float), ('decICRS', float), 

('raPhoSim', float), ('decPhoSim', float)]) 

data = np.genfromtxt(cat_name, dtype=dtype) 

self.assertGreater(len(data), 100) 

ra_pho_rad = np.radians(data['raPhoSim']) 

dec_pho_rad = np.radians(data['decPhoSim']) 

 

# verify that, when transforming back to ICRS, we are within 

# 10^-3 arcsec 

ra_icrs, dec_icrs = PhoSimAstrometryBase._icrsFromPhoSim(ra_pho_rad, 

dec_pho_rad, 

self.obs) 

dist = _angularSeparation(np.radians(data['raICRS']), 

np.radians(data['decICRS']), 

ra_icrs, dec_icrs) 

 

dist = arcsecFromRadians(dist) 

self.assertLess(dist.max(), 0.001) 

 

# verify that the distance between raPhoSim, decPhoSim and 

# raICRS, decICRS is greater than the distance between 

# the original raICRS, decICRS and the newly-calculated 

# raICRS, decICRS 

dist_bad = _angularSeparation(ra_pho_rad, dec_pho_rad, 

np.radians(data['raICRS']), 

np.radians(data['decICRS'])) 

 

dist_bad = arcsecFromRadians(dist_bad) 

self.assertGreater(dist_bad.min(), dist.max()) 

 

del db 

 

def test_galaxy_astrometry_degrees(self): 

""" 

Test that we can go from raPhoSim, decPhoSim to ICRS coordinates 

in the case of galaxies (in degrees) 

""" 

db = testGalaxyDiskDBObj(driver='sqlite', database=self.db_name) 

cat = GalaxyTestCatalog(db, obs_metadata=self.obs) 

with lsst.utils.tests.getTempFilePath('.txt') as cat_name: 

cat.write_catalog(cat_name) 

dtype = np.dtype([('raICRS', float), ('decICRS', float), 

('raPhoSim', float), ('decPhoSim', float)]) 

data = np.genfromtxt(cat_name, dtype=dtype) 

self.assertGreater(len(data), 100) 

 

# verify that, when transforming back to ICRS, we are within 

# 10^-3 arcsec 

ra_icrs, dec_icrs = PhoSimAstrometryBase.icrsFromPhoSim(data['raPhoSim'], 

data['decPhoSim'], 

self.obs) 

dist = angularSeparation(data['raICRS'], data['decICRS'], 

ra_icrs, dec_icrs) 

 

dist = 3600.0*dist 

self.assertLess(dist.max(), 0.001) 

 

# verify that the distance between raPhoSim, decPhoSim and 

# raICRS, decICRS is greater than the distance between 

# the original raICRS, decICRS and the newly-calculated 

# raICRS, decICRS 

dist_bad = angularSeparation(data['raPhoSim'], data['decPhoSim'], 

data['raICRS'], data['decICRS']) 

 

dist_bad = 3600.0*dist_bad 

self.assertGreater(dist_bad.min(), dist.max()) 

 

del db 

 

def test_naive_focal_plane_position(self): 

""" 

Test deprecession of PhoSim coordinates by comparing 

the focal plane position predicted by CatSim from ICRS 

with the focal plane position predicted by CatSim from deprecessed 

coordinates. 

""" 

 

phosim_mixin = PhoSimAstrometryBase() 

 

mjd = 59587.2 

 

# create site with no atmosphere so that we can avoid 

# refraction 

site = Site(name="LSST", pressure=0.0, humidity=0.0) 

 

obs = ObservationMetaData(mjd=mjd, site=site) 

ra, dec = raDecFromAltAz(31.0, 112.0, obs) 

 

d_sun = distanceToSun(ra, dec, obs.mjd) 

self.assertGreater(d_sun, 45.0) 

 

obs = ObservationMetaData(pointingRA=ra, pointingDec=dec, 

rotSkyPos=27.3, mjd=mjd, 

site=site) 

ra_icrs = np.arange(obs.pointingRA-2.0, obs.pointingRA+2.0, 0.05) 

dec_icrs = np.arange(obs.pointingDec-2.0, obs.pointingDec+2.0, 0.05) 

 

coord_grid = np.meshgrid(ra_icrs, dec_icrs) 

ra_icrs = coord_grid[0].flatten() 

dec_icrs = coord_grid[1].flatten() 

 

(xpup_icrs, 

ypup_icrs) = pupilCoordsFromRaDec(ra_icrs, dec_icrs, 

obs_metadata=obs, 

epoch=2000.0, 

includeRefraction=False) 

 

(x_focal_icrs, 

y_focal_icrs) = focalPlaneCoordsFromPupilCoords(xpup_icrs, 

ypup_icrs, 

camera=lsst_camera()) 

 

ra_obs, dec_obs = observedFromICRS(ra_icrs, dec_icrs, obs_metadata=obs, 

epoch=2000.0, 

includeRefraction=False) 

 

ra_obs_rad = np.radians(ra_obs) 

dec_obs_rad = np.radians(dec_obs) 

 

(ra_deprecessed_rad, 

dec_deprecessed_rad) = phosim_mixin._dePrecess(ra_obs_rad, 

dec_obs_rad, obs) 

 

(xpup_deprecessed, 

ypup_deprecessed) = _naivePupilCoordsFromObserved(ra_deprecessed_rad, 

dec_deprecessed_rad, 

obs._pointingRA, 

obs._pointingDec, 

obs._rotSkyPos) 

 

(x_focal_deprecessed, 

y_focal_deprecessed) = focalPlaneCoordsFromPupilCoords(xpup_deprecessed, 

ypup_deprecessed, 

camera=lsst_camera()) 

 

dd = np.sqrt((x_focal_icrs-x_focal_deprecessed)**2 

+(y_focal_icrs-y_focal_deprecessed)**2) 

 

self.assertLess(dd.max(), 1.0e-8) 

 

def test_against_catalog(self): 

""" 

Compare deprecession results to a catalog that was validated 

with PhoSim. 

""" 

obs = ObservationMetaData(pointingRA=53.00913847303155535, 

pointingDec=-27.43894880881512321, 

rotSkyPos=256.75075318193080420, 

mjd=59580.13955500000156462, 

site=Site(name="LSST", pressure=0.0, 

humidity=0.0)) 

 

dtype = np.dtype([('id', int), ('ra', float), ('dec', float), 

('ra_deprecessed', float), ('dec_deprecessed', float), 

('x_dm', float), ('y_dm', float), 

('x_focal', float), ('y_focal', float), 

('x_cam', float), ('y_cam', float)]) 

 

data = np.genfromtxt(os.path.join(getPackageDir('sims_catUtils'), 

'tests', 'testData', 

'pixel_prediction_catalog.txt'), 

dtype=dtype) 

 

ra_obs, dec_obs = observedFromICRS(data['ra'], data['dec'], 

obs_metadata=obs, 

includeRefraction=False, 

epoch=2000.0) 

 

phosim_mixin = PhoSimAstrometryBase() 

ra_dep, dec_dep = phosim_mixin._dePrecess(np.radians(ra_obs), 

np.radians(dec_obs), 

obs) 

 

dd = 3600.0*angularSeparation(data['ra_deprecessed'], data['dec_deprecessed'], 

np.degrees(ra_dep), np.degrees(dec_dep)) 

self.assertLess(dd.max(), 1.0e-5) 

 

def test_InstanceCatalog_against_catalog(self): 

""" 

Test that we can reproduce the validated data using the 

InstanceCatalog framework 

""" 

 

obs = ObservationMetaData(pointingRA=53.00913847303155535, 

pointingDec=-27.43894880881512321, 

rotSkyPos=256.75075318193080420, 

mjd=59580.13955500000156462, 

bandpassName='r', 

site=Site(name="LSST", pressure=0.0, 

humidity=0.0)) 

 

data_dir = os.path.join(getPackageDir('sims_catUtils'),'tests', 

'testData') 

 

dtype = np.dtype([('id', int), ('ra', float), ('dec', float), 

('ra_deprecessed', float), ('dec_deprecessed', float), 

('x_dm', float), ('y_dm', float), 

('x_focal', float), ('y_focal', float), 

('x_cam', float), ('y_cam', float)]) 

 

data = np.genfromtxt(os.path.join(data_dir, 

'pixel_prediction_catalog.txt'), 

dtype=dtype) 

 

data_txt_file = tempfile.mktemp(dir=data_dir, 

prefix='ic_validation_cat', 

suffix='.txt') 

 

cat_dtype = np.dtype([('id', int), 

('raJ2000', float), ('decJ2000', float)]) 

 

with open(data_txt_file, 'w') as out_file: 

out_file.write('# a header\n') 

for ii, rr, dd in zip(data['id'], 

np.radians(data['ra']), 

np.radians(data['dec'])): 

 

out_file.write('%d %.17f %.17f\n' % (ii, rr, dd)) 

 

db = fileDBObject(data_txt_file, idColKey='id', dtype=cat_dtype, 

delimiter=' ') 

 

class DeprecessionTestCatalog(PhoSimCatalogPoint): 

def get_uniqueId(self): 

return self.column_by_name('id') 

 

def get_properMotionRa(self): 

return np.zeros(len(self.column_by_name('raJ2000'))) 

 

def get_properMotionDec(self): 

return np.zeros(len(self.column_by_name('raJ2000'))) 

 

def get_radialVelocity(self): 

return np.zeros(len(self.column_by_name('raJ2000'))) 

 

def get_parallax(self): 

return np.zeros(len(self.column_by_name('raJ2000'))) 

 

def get_galacticAv(self): 

return np.zeros(len(self.column_by_name('raJ2000'))) 

 

def get_galacticRv(self): 

return 3.1*np.ones(len(self.column_by_name('raJ2000'))) 

 

def get_sedFilepath(self): 

return np.array(['sed_flat.txt.gz']*len(self.column_by_name('raJ2000'))) 

 

def get_phoSimMagNorm(self): 

return np.ones(len(self.column_by_name('raJ2000'))) 

 

cat = DeprecessionTestCatalog(db, obs_metadata=obs) 

cat.phoSimHeaderMap = DefaultPhoSimHeaderMap 

 

id_list = [] 

ra_dep_list = [] 

dec_dep_list= [] 

 

phosim_cat_name = tempfile.mktemp(dir=data_dir, 

prefix='phosim_dep', 

suffix='.txt') 

 

cat.write_catalog(phosim_cat_name) 

with open(phosim_cat_name, 'r') as input_file: 

for line in input_file: 

params = line.strip().split() 

if len(params) < 3: 

continue 

id_list.append(int(params[1])) 

ra_dep_list.append(float(params[2])) 

dec_dep_list.append(float(params[3])) 

 

id_list = np.array(id_list) 

np.testing.assert_array_equal(id_list, data['id']) 

ra_dep_list = np.array(ra_dep_list) 

dec_dep_list = np.array(dec_dep_list) 

 

dd = 3600.0*angularSeparation(data['ra_deprecessed'], data['dec_deprecessed'], 

ra_dep_list, dec_dep_list) 

 

self.assertLess(dd.max(), 1.0e-5) 

 

if os.path.exists(data_txt_file): 

os.unlink(data_txt_file) 

 

if os.path.exists(phosim_cat_name): 

os.unlink(phosim_cat_name) 

 

def test_InstanceCatalog_against_catalog_chunks(self): 

""" 

Test that we can reproduce the validated data using the 

InstanceCatalog framework when the catalog must be written 

in multiple chunks 

""" 

 

obs = ObservationMetaData(pointingRA=53.00913847303155535, 

pointingDec=-27.43894880881512321, 

rotSkyPos=256.75075318193080420, 

mjd=59580.13955500000156462, 

bandpassName='r', 

site=Site(name="LSST", pressure=0.0, 

humidity=0.0)) 

 

data_dir = os.path.join(getPackageDir('sims_catUtils'),'tests', 

'testData') 

 

dtype = np.dtype([('id', int), ('ra', float), ('dec', float), 

('ra_deprecessed', float), ('dec_deprecessed', float), 

('x_dm', float), ('y_dm', float), 

('x_focal', float), ('y_focal', float), 

('x_cam', float), ('y_cam', float)]) 

 

data = np.genfromtxt(os.path.join(data_dir, 

'pixel_prediction_catalog.txt'), 

dtype=dtype) 

 

data_txt_file = tempfile.mktemp(dir=data_dir, 

prefix='ic_validation_cat', 

suffix='.txt') 

 

cat_dtype = np.dtype([('id', int), 

('raJ2000', float), ('decJ2000', float)]) 

 

with open(data_txt_file, 'w') as out_file: 

out_file.write('# a header\n') 

for ii, rr, dd in zip(data['id'], 

np.radians(data['ra']), 

np.radians(data['dec'])): 

 

out_file.write('%d %.17f %.17f\n' % (ii, rr, dd)) 

 

db = fileDBObject(data_txt_file, idColKey='id', dtype=cat_dtype, 

delimiter=' ') 

 

class DeprecessionTestCatalog_chunks(PhoSimCatalogPoint): 

def get_uniqueId(self): 

return self.column_by_name('id') 

 

def get_properMotionRa(self): 

return np.zeros(len(self.column_by_name('raJ2000'))) 

 

def get_properMotionDec(self): 

return np.zeros(len(self.column_by_name('raJ2000'))) 

 

def get_radialVelocity(self): 

return np.zeros(len(self.column_by_name('raJ2000'))) 

 

def get_parallax(self): 

return np.zeros(len(self.column_by_name('raJ2000'))) 

 

def get_galacticAv(self): 

return np.zeros(len(self.column_by_name('raJ2000'))) 

 

def get_galacticRv(self): 

return 3.1*np.ones(len(self.column_by_name('raJ2000'))) 

 

def get_sedFilepath(self): 

return np.array(['sed_flat.txt.gz']*len(self.column_by_name('raJ2000'))) 

 

def get_phoSimMagNorm(self): 

return np.ones(len(self.column_by_name('raJ2000'))) 

 

cat = DeprecessionTestCatalog_chunks(db, obs_metadata=obs) 

cat.phoSimHeaderMap = DefaultPhoSimHeaderMap 

 

id_list = [] 

ra_dep_list = [] 

dec_dep_list= [] 

 

phosim_cat_name = tempfile.mktemp(dir=data_dir, 

prefix='phosim_dep', 

suffix='.txt') 

 

cat.write_catalog(phosim_cat_name, chunk_size=10) 

with open(phosim_cat_name, 'r') as input_file: 

for line in input_file: 

params = line.strip().split() 

if len(params) < 3: 

continue 

id_list.append(int(params[1])) 

ra_dep_list.append(float(params[2])) 

dec_dep_list.append(float(params[3])) 

 

id_list = np.array(id_list) 

np.testing.assert_array_equal(id_list, data['id']) 

ra_dep_list = np.array(ra_dep_list) 

dec_dep_list = np.array(dec_dep_list) 

 

dd = 3600.0*angularSeparation(data['ra_deprecessed'], data['dec_deprecessed'], 

ra_dep_list, dec_dep_list) 

 

self.assertLess(dd.max(), 1.0e-5) 

 

if os.path.exists(data_txt_file): 

os.unlink(data_txt_file) 

 

if os.path.exists(phosim_cat_name): 

os.unlink(phosim_cat_name) 

 

 

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

pass 

 

 

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

lsst.utils.tests.init() 

unittest.main()