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

744

745

746

747

748

749

750

751

752

753

754

755

756

757

758

759

760

761

762

763

764

765

766

767

768

769

770

771

772

773

774

775

776

777

778

779

780

781

782

783

784

785

786

787

788

789

790

791

792

793

794

795

796

797

798

799

800

801

802

803

804

805

806

807

808

809

810

811

812

813

814

815

816

817

818

819

820

821

822

823

824

825

826

827

828

829

830

831

832

833

834

835

836

837

838

839

840

841

842

843

844

845

846

847

848

849

850

851

852

853

854

855

856

857

858

859

860

861

862

863

864

865

866

867

868

869

870

871

872

873

874

875

876

877

878

879

880

881

882

883

884

885

886

887

888

889

890

891

892

893

894

895

896

897

898

899

900

901

902

903

904

905

906

907

908

909

910

911

912

913

914

915

916

917

918

919

920

921

922

923

924

925

926

927

928

929

930

931

932

933

934

935

936

937

938

939

940

941

942

943

944

945

946

947

948

949

950

951

952

953

954

955

956

957

958

959

960

961

962

963

964

965

966

967

968

969

970

971

972

973

974

975

976

977

978

979

980

981

982

983

984

985

986

987

988

989

990

991

992

993

994

995

996

997

998

999

1000

1001

1002

1003

1004

1005

1006

1007

1008

1009

1010

1011

1012

1013

1014

1015

1016

1017

1018

1019

1020

1021

1022

1023

1024

1025

1026

1027

1028

1029

1030

1031

1032

1033

1034

1035

1036

1037

1038

1039

1040

1041

1042

1043

1044

1045

1046

1047

1048

1049

1050

1051

1052

1053

1054

1055

1056

1057

1058

1059

1060

1061

1062

1063

1064

1065

1066

1067

1068

1069

1070

1071

1072

1073

1074

1075

1076

1077

1078

1079

1080

1081

1082

1083

1084

1085

1086

1087

1088

1089

1090

1091

1092

1093

1094

1095

1096

1097

1098

1099

1100

1101

1102

1103

1104

1105

1106

1107

1108

1109

1110

1111

1112

1113

1114

1115

1116

1117

1118

1119

1120

1121

1122

1123

1124

1125

1126

1127

1128

1129

1130

1131

1132

1133

1134

1135

1136

1137

1138

1139

1140

1141

1142

1143

1144

1145

1146

1147

1148

1149

1150

1151

1152

1153

1154

1155

1156

1157

1158

1159

1160

1161

1162

1163

1164

1165

1166

1167

1168

1169

1170

1171

1172

1173

1174

1175

1176

1177

1178

1179

1180

1181

1182

1183

1184

1185

1186

1187

1188

1189

1190

1191

1192

1193

1194

1195

1196

1197

1198

1199

1200

1201

1202

1203

1204

1205

1206

1207

1208

1209

1210

1211

1212

1213

1214

1215

1216

1217

1218

1219

1220

1221

1222

1223

1224

1225

1226

1227

1228

1229

1230

1231

1232

1233

1234

1235

1236

1237

1238

1239

1240

1241

1242

1243

1244

1245

1246

1247

1248

1249

1250

1251

1252

1253

1254

1255

1256

1257

1258

1259

1260

1261

1262

1263

1264

1265

1266

1267

1268

1269

1270

1271

1272

1273

1274

1275

1276

1277

1278

1279

1280

1281

1282

1283

1284

1285

1286

1287

1288

1289

1290

1291

1292

1293

1294

1295

1296

1297

1298

1299

1300

1301

1302

1303

1304

1305

1306

1307

1308

1309

1310

1311

1312

1313

1314

1315

1316

1317

1318

1319

1320

1321

1322

1323

1324

1325

1326

1327

1328

1329

1330

1331

1332

1333

1334

1335

1336

1337

1338

1339

1340

1341

1342

1343

1344

1345

1346

1347

1348

1349

1350

1351

1352

1353

1354

1355

1356

1357

1358

1359

1360

1361

1362

1363

1364

1365

1366

1367

1368

1369

1370

1371

1372

1373

1374

1375

1376

1377

1378

1379

1380

1381

1382

1383

1384

1385

1386

1387

1388

1389

1390

1391

1392

1393

1394

1395

1396

1397

1398

1399

1400

1401

1402

1403

1404

1405

1406

1407

1408

1409

1410

1411

1412

1413

1414

1415

1416

1417

1418

1419

1420

1421

1422

1423

1424

1425

1426

1427

1428

1429

1430

1431

1432

1433

1434

1435

1436

1437

1438

1439

1440

1441

1442

1443

1444

1445

1446

1447

1448

1449

1450

1451

1452

1453

1454

1455

1456

1457

1458

1459

1460

1461

1462

1463

1464

1465

1466

1467

1468

1469

1470

1471

1472

1473

1474

1475

1476

1477

1478

1479

1480

1481

1482

1483

1484

1485

1486

1487

1488

1489

1490

1491

1492

1493

1494

1495

1496

1497

1498

1499

1500

1501

1502

1503

1504

1505

1506

1507

1508

1509

1510

1511

1512

1513

1514

1515

1516

1517

1518

1519

1520

1521

1522

1523

1524

1525

1526

1527

1528

1529

1530

1531

1532

1533

1534

1535

1536

1537

1538

1539

1540

1541

1542

1543

1544

1545

1546

1547

1548

1549

1550

1551

1552

1553

1554

1555

1556

1557

1558

1559

1560

1561

1562

1563

1564

1565

1566

1567

1568

1569

1570

1571

1572

1573

1574

1575

1576

1577

1578

1579

1580

1581

1582

1583

1584

1585

1586

1587

1588

1589

1590

1591

1592

1593

1594

1595

1596

1597

1598

1599

1600

1601

1602

1603

1604

1605

1606

1607

1608

1609

1610

1611

1612

1613

1614

1615

1616

1617

1618

1619

1620

1621

1622

1623

1624

1625

1626

1627

1628

1629

1630

1631

1632

1633

1634

1635

1636

1637

1638

1639

1640

1641

1642

1643

1644

1645

1646

1647

1648

1649

1650

1651

1652

1653

1654

1655

1656

1657

1658

1659

1660

1661

1662

1663

1664

1665

1666

1667

1668

1669

1670

1671

1672

1673

1674

1675

1676

1677

1678

1679

1680

1681

1682

1683

1684

1685

1686

1687

1688

1689

1690

1691

1692

1693

1694

1695

1696

1697

1698

1699

1700

1701

1702

1703

1704

1705

1706

1707

1708

1709

1710

1711

1712

1713

1714

1715

1716

1717

1718

1719

1720

1721

1722

1723

1724

1725

1726

1727

1728

1729

1730

1731

1732

1733

1734

1735

1736

1737

1738

1739

1740

1741

1742

1743

1744

1745

1746

1747

1748

1749

1750

1751

1752

1753

1754

1755

1756

1757

1758

1759

1760

1761

1762

1763

1764

1765

1766

1767

1768

1769

1770

1771

1772

1773

1774

1775

1776

1777

1778

1779

1780

1781

1782

1783

1784

1785

1786

1787

1788

1789

1790

1791

1792

1793

1794

1795

1796

1797

1798

1799

1800

1801

1802

1803

1804

1805

1806

1807

1808

1809

1810

1811

1812

1813

1814

1815

1816

1817

1818

1819

1820

1821

1822

1823

1824

1825

1826

1827

1828

1829

1830

1831

1832

1833

1834

1835

1836

1837

1838

1839

1840

1841

1842

1843

1844

1845

1846

1847

1848

1849

1850

1851

1852

1853

1854

1855

1856

1857

1858

1859

1860

1861

1862

1863

1864

1865

1866

1867

1868

1869

1870

1871

1872

1873

1874

1875

1876

1877

1878

1879

1880

1881

1882

1883

1884

1885

1886

1887

1888

1889

1890

1891

1892

1893

1894

1895

1896

1897

1898

1899

1900

1901

1902

1903

1904

1905

1906

1907

1908

1909

1910

1911

1912

1913

1914

1915

1916

1917

1918

1919

1920

1921

1922

1923

1924

1925

1926

1927

1928

1929

1930

1931

1932

1933

1934

1935

1936

1937

1938

1939

1940

1941

1942

1943

1944

1945

1946

1947

1948

1949

1950

1951

1952

1953

1954

1955

1956

1957

1958

1959

1960

1961

1962

1963

1964

1965

1966

1967

1968

1969

1970

1971

1972

1973

1974

1975

1976

1977

1978

1979

1980

1981

1982

1983

1984

1985

1986

1987

1988

1989

1990

1991

1992

1993

1994

1995

1996

1997

1998

1999

2000

2001

2002

2003

2004

2005

2006

2007

2008

2009

2010

2011

2012

2013

2014

2015

2016

2017

2018

2019

2020

2021

2022

2023

2024

2025

2026

2027

2028

2029

2030

2031

2032

2033

2034

2035

2036

2037

2038

2039

2040

2041

2042

2043

2044

2045

2046

2047

2048

2049

2050

2051

2052

2053

2054

2055

2056

2057

2058

2059

2060

2061

2062

2063

2064

2065

2066

2067

2068

2069

2070

2071

2072

2073

2074

2075

2076

2077

2078

2079

2080

2081

2082

2083

2084

2085

2086

2087

2088

2089

2090

2091

2092

2093

2094

2095

2096

2097

2098

2099

2100

2101

2102

2103

2104

2105

2106

2107

2108

2109

2110

2111

2112

2113

2114

2115

2116

2117

2118

2119

2120

2121

2122

2123

2124

2125

2126

2127

2128

2129

2130

2131

2132

2133

2134

2135

2136

2137

2138

2139

2140

2141

2142

2143

2144

from __future__ import with_statement 

from builtins import zip 

from builtins import range 

import os 

import numpy as np 

import unittest 

import lsst.utils.tests 

from lsst.utils import getPackageDir 

 

from lsst.sims.utils import ObservationMetaData, radiansFromArcsec, arcsecFromRadians 

from lsst.sims.utils import haversine 

from lsst.obs.lsstSim import LsstSimMapper 

 

from lsst.sims.utils import pupilCoordsFromRaDec, observedFromICRS 

from lsst.sims.coordUtils import (chipNameFromRaDec, 

chipNameFromPupilCoords, 

_chipNameFromRaDec) 

 

from lsst.sims.coordUtils import (pixelCoordsFromPupilCoords, 

pixelCoordsFromRaDec, 

_pixelCoordsFromRaDec) 

 

from lsst.sims.coordUtils import (focalPlaneCoordsFromPupilCoords, 

focalPlaneCoordsFromRaDec, 

_focalPlaneCoordsFromRaDec) 

 

from lsst.sims.coordUtils import pupilCoordsFromPixelCoords 

from lsst.sims.coordUtils import raDecFromPixelCoords, _raDecFromPixelCoords 

from lsst.sims.coordUtils import getCornerPixels, _getCornerRaDec, getCornerRaDec 

 

from lsst.sims.coordUtils import pupilCoordsFromFocalPlaneCoords 

from lsst.sims.coordUtils import lsst_camera 

 

from lsst.afw.geom import Point2D 

from lsst.afw.cameraGeom import FIELD_ANGLE, FOCAL_PLANE 

 

def setup_module(module): 

lsst.utils.tests.init() 

 

 

class ChipNameTest(unittest.TestCase): 

 

@classmethod 

def setUpClass(cls): 

cls.camera = LsstSimMapper().camera 

 

@classmethod 

def tearDownClass(cls): 

del cls.camera 

 

def setUp(self): 

self.rng = np.random.RandomState(45532) 

 

def testRuns(self): 

""" 

Test that chipName runs, and that the various iterations of that method 

are all self-consistent 

""" 

nStars = 100 

ra0 = 45.0 

dec0 = -112.0 

rotSkyPos = 135.0 

mjd = 42350.0 

obs = ObservationMetaData(pointingRA=ra0, pointingDec=dec0, 

mjd=mjd, rotSkyPos=rotSkyPos) 

 

raList = (self.rng.random_sample(nStars)-0.5)*1000.0/3600.0 + ra0 

decList = (self.rng.random_sample(nStars)-0.5)*1000.0/3600.0 + dec0 

 

xpList, ypList = pupilCoordsFromRaDec(raList, decList, 

obs_metadata=obs, 

epoch=2000.0) 

 

names1 = chipNameFromRaDec(raList, decList, 

obs_metadata=obs, 

epoch=2000.0, 

camera=self.camera) 

 

names2 = _chipNameFromRaDec(np.radians(raList), np.radians(decList), 

obs_metadata=obs, 

epoch=2000.0, 

camera=self.camera) 

 

names3 = chipNameFromPupilCoords(xpList, ypList, camera=self.camera) 

 

np.testing.assert_array_equal(names1, names2) 

np.testing.assert_array_equal(names1, names3) 

 

isNone = 0 

isNotNone = 0 

for name in names1: 

if name is None: 

isNone += 1 

else: 

isNotNone += 1 

 

self.assertGreater(isNotNone, 0) 

 

def testExceptions(self): 

""" 

Test that exceptions are raised when they should be 

""" 

 

nStars = 10 

xpList = self.rng.random_sample(nStars)*0.1 

ypList = self.rng.random_sample(nStars)*0.1 

 

obs = ObservationMetaData(pointingRA=25.0, pointingDec=112.0, mjd=42351.0, 

rotSkyPos=35.0) 

 

# verify that an exception is raised if you do not pass in a camera 

with self.assertRaises(RuntimeError) as context: 

chipNameFromPupilCoords(xpList, ypList) 

self.assertEqual('No camera defined. Cannot run chipName.', 

context.exception.args[0]) 

 

with self.assertRaises(RuntimeError) as context: 

chipNameFromRaDec(xpList, ypList, obs_metadata=obs, epoch=2000.0) 

self.assertEqual('No camera defined. Cannot run chipName.', 

context.exception.args[0]) 

 

with self.assertRaises(RuntimeError) as context: 

_chipNameFromRaDec(xpList, ypList, obs_metadata=obs, epoch=2000.0) 

self.assertEqual('No camera defined. Cannot run chipName.', 

context.exception.args[0]) 

 

# verify that an exception is raised if you do not pass in a numpy array 

with self.assertRaises(RuntimeError) as context: 

chipNameFromPupilCoords(list(xpList), ypList) 

self.assertIn("The arg xPupil", context.exception.args[0]) 

 

with self.assertRaises(RuntimeError) as context: 

_chipNameFromRaDec(list(xpList), ypList, obs_metadata=obs, epoch=2000.0) 

self.assertIn("The arg ra", context.exception.args[0]) 

 

with self.assertRaises(RuntimeError) as context: 

chipNameFromPupilCoords(xpList, list(ypList)) 

self.assertIn("The input arguments:", context.exception.args[0]) 

self.assertIn("yPupil", context.exception.args[0]) 

 

with self.assertRaises(RuntimeError) as context: 

_chipNameFromRaDec(xpList, list(ypList), obs_metadata=obs, epoch=2000.0) 

self.assertIn("The input arguments:", context.exception.args[0]) 

self.assertIn("Dec", context.exception.args[0]) 

 

# do not need to run the above test on chipNameFromRaDec because 

# the conversion from degrees to radians that happens inside that 

# method automatically casts lists as numpy arrays 

 

# verify that an exception is raised if the two coordinate arrays contain 

# different numbers of elements 

xpDummy = self.rng.random_sample(nStars//2) 

 

with self.assertRaises(RuntimeError) as context: 

chipNameFromPupilCoords(xpDummy, ypList, camera=self.camera) 

 

self.assertEqual(context.exception.args[0], 

"The arrays input to chipNameFromPupilCoords all need " 

"to have the same length") 

 

with self.assertRaises(RuntimeError) as context: 

chipNameFromRaDec(xpDummy, ypList, obs_metadata=obs, epoch=2000.0, 

camera=self.camera) 

 

self.assertEqual(context.exception.args[0], 

"The arrays input to chipNameFromRaDec all need to have the same length") 

 

with self.assertRaises(RuntimeError) as context: 

_chipNameFromRaDec(xpDummy, ypList, obs_metadata=obs, epoch=2000.0, 

camera=self.camera) 

 

self.assertEqual(context.exception.args[0], 

"The arrays input to chipNameFromRaDec all need to have the same length") 

 

# verify that an exception is raised if you call chipNameFromRaDec 

# without an ObservationMetaData 

with self.assertRaises(RuntimeError) as context: 

chipNameFromRaDec(xpList, ypList, epoch=2000.0, camera=self.camera) 

 

self.assertEqual(context.exception.args[0], 

'You need to pass an ObservationMetaData into chipName') 

 

with self.assertRaises(RuntimeError) as context: 

_chipNameFromRaDec(xpList, ypList, epoch=2000.0, camera=self.camera) 

 

self.assertEqual(context.exception.args[0], 

'You need to pass an ObservationMetaData into chipName') 

 

# verify that an exception is raised if you call chipNameFromRaDec 

# with an ObservationMetaData that has no mjd 

obsDummy = ObservationMetaData(pointingRA=25.0, pointingDec=-112.0, 

rotSkyPos=112.0) 

 

with self.assertRaises(RuntimeError) as context: 

chipNameFromRaDec(xpList, ypList, epoch=2000.0, obs_metadata=obsDummy, 

camera=self.camera) 

 

self.assertEqual(context.exception.args[0], 

'You need to pass an ObservationMetaData with an mjd into chipName') 

 

with self.assertRaises(RuntimeError) as context: 

_chipNameFromRaDec(xpList, ypList, epoch=2000.0, obs_metadata=obsDummy, 

camera=self.camera) 

 

self.assertEqual(context.exception.args[0], 

'You need to pass an ObservationMetaData with an mjd into chipName') 

 

# verify that an exception is raised if you all chipNameFromRaDec 

# using an ObservationMetaData without a rotSkyPos 

obsDummy = ObservationMetaData(pointingRA=25.0, pointingDec=-112.0, 

mjd=52350.0) 

 

with self.assertRaises(RuntimeError) as context: 

chipNameFromRaDec(xpList, ypList, epoch=2000.0, obs_metadata=obsDummy, 

camera=self.camera) 

 

self.assertEqual(context.exception.args[0], 

'You need to pass an ObservationMetaData with a rotSkyPos into chipName') 

 

with self.assertRaises(RuntimeError) as context: 

_chipNameFromRaDec(xpList, ypList, epoch=2000.0, obs_metadata=obsDummy, 

camera=self.camera) 

 

self.assertEqual(context.exception.args[0], 

'You need to pass an ObservationMetaData with a rotSkyPos into chipName') 

 

def testNaNbecomesNone(self): 

""" 

Test that chipName maps NaNs and Nones in RA, Dec, and 

pupil coordinates to None as chip name 

""" 

nStars = 100 

ra0 = 45.0 

dec0 = -112.0 

rotSkyPos = 135.0 

mjd = 42350.0 

obs = ObservationMetaData(pointingRA=ra0, pointingDec=dec0, 

mjd=mjd, rotSkyPos=rotSkyPos) 

 

for badVal in [np.NaN, None]: 

 

raList = (self.rng.random_sample(nStars)-0.5)*5.0/3600.0 + ra0 

decList = (self.rng.random_sample(nStars)-0.5)*5.0/3600.0 + dec0 

 

raList[5] = badVal 

raList[10] = badVal 

decList[10] = badVal 

decList[25] = badVal 

 

xpList, ypList = pupilCoordsFromRaDec(raList, decList, 

obs_metadata=obs, 

epoch=2000.0) 

 

names1 = chipNameFromRaDec(raList, decList, obs_metadata=obs, epoch=2000.0, 

camera=self.camera) 

 

names2 = _chipNameFromRaDec(np.radians(raList), np.radians(decList), 

obs_metadata=obs, epoch=2000.0, camera=self.camera) 

 

names3 = chipNameFromPupilCoords(xpList, ypList, camera=self.camera) 

 

np.testing.assert_array_equal(names1, names2) 

np.testing.assert_array_equal(names1, names3) 

 

for ix in range(len(names1)): 

if ix != 5 and ix != 10 and ix != 25: 

self.assertEqual(names1[ix], 'R:2,2 S:1,1') 

self.assertEqual(names2[ix], 'R:2,2 S:1,1') 

self.assertEqual(names3[ix], 'R:2,2 S:1,1') 

else: 

self.assertIsNone(names1[ix], None) 

self.assertIsNone(names2[ix], None) 

self.assertIsNone(names3[ix], None) 

 

def testPassingFloats(self): 

""" 

Test that you can pass floats of RA, Dec into chipNameFromRaDec. 

 

Ditto for chipNameFromPupilCoords 

""" 

 

ra0 = 45.0 

dec0 = -112.0 

rotSkyPos = 135.0 

mjd = 42350.0 

obs = ObservationMetaData(pointingRA=ra0, pointingDec=dec0, 

mjd=mjd, rotSkyPos=rotSkyPos) 

 

nStars = 100 

raList = (self.rng.random_sample(nStars)-0.5)*500.0/3600.0 + ra0 

decList = (self.rng.random_sample(nStars)-0.5)*500.0/3600.0 + dec0 

 

chipNameList = chipNameFromRaDec(raList, decList, camera=self.camera, obs_metadata=obs) 

 

n_not_none = 0 

# now iterate over the list of RA, Dec to make sure that the same name comes back 

for ix, (rr, dd) in enumerate(zip(raList, decList)): 

test_name = chipNameFromRaDec(rr, dd, camera=self.camera, obs_metadata=obs) 

self.assertIsInstance(rr, np.float) 

self.assertIsInstance(dd, np.float) 

self.assertEqual(chipNameList[ix], test_name) 

if test_name is not None: 

try: 

self.assertIsInstance(test_name, str) 

except AssertionError: 

self.assertIsInstance(test_name, unicode) 

n_not_none += 1 

 

self.assertGreater(n_not_none, 50) 

 

# try it with pupil coordinates 

n_not_none = 0 

xpList, ypList = pupilCoordsFromRaDec(raList, decList, obs_metadata=obs) 

chipNameList = chipNameFromPupilCoords(xpList, ypList, camera=self.camera) 

for ix, (xp, yp) in enumerate(zip(xpList, ypList)): 

test_name = chipNameFromPupilCoords(xp, yp, camera=self.camera) 

self.assertIsInstance(xp, np.float) 

self.assertIsInstance(yp, np.float) 

self.assertEqual(chipNameList[ix], test_name) 

if test_name is not None: 

try: 

self.assertIsInstance(test_name, str) 

except AssertionError: 

self.assertIsInstance(test_name, unicode) 

n_not_none += 1 

 

self.assertGreater(n_not_none, 50) 

 

def test_one_by_one(self): 

""" 

Test that runing chipNameFromRaDec one at a time gives 

the same results as running in batch mode 

""" 

ra = 145.0 

dec = -25.0 

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

mjd=59580.0, rotSkyPos=113.0) 

rng = np.random.RandomState(100) 

theta = rng.random_sample(100)*2.0*np.pi 

rr = rng.random_sample(len(theta))*2.0 

ra_list = ra + rr*np.cos(theta) 

dec_list = dec + rr*np.sin(theta) 

name_control = chipNameFromRaDec(ra_list, dec_list, obs_metadata=obs, 

camera=self.camera) 

is_none = 0 

for ra, dec, name in zip(ra_list, dec_list, name_control): 

test_name = chipNameFromRaDec(ra, dec, obs_metadata=obs, 

camera=self.camera) 

self.assertEqual(test_name, name) 

if test_name is None: 

is_none += 1 

self.assertGreater(is_none, 0) 

self.assertLess(is_none, len(ra_list)) 

 

 

class PixelCoordTest(unittest.TestCase): 

 

longMessage = True 

 

@classmethod 

def setUpClass(cls): 

cls.camera = LsstSimMapper().camera 

 

@classmethod 

def tearDownClass(cls): 

del cls.camera 

 

def setUp(self): 

self.rng = np.random.RandomState(11324) 

 

def testConsistency(self): 

""" 

Test that all of the pixelCoord calculation methods agree with 

each other 

""" 

ra0 = 95.0 

dec0 = -33.0 

obs = ObservationMetaData(pointingRA=ra0, pointingDec=dec0, 

mjd=52350.0, rotSkyPos=27.0) 

 

nStars = 100 

raList = (self.rng.random_sample(nStars)-0.5)*1.5 + ra0 

decList = (self.rng.random_sample(nStars)-0.5)*1.5 + dec0 

 

xpList, ypList = pupilCoordsFromRaDec(raList, decList, obs_metadata=obs, epoch=2000.0) 

 

chipNameList = chipNameFromRaDec(raList, decList, obs_metadata=obs, epoch=2000.0, 

camera=self.camera) 

 

for includeDistortion in [True, False]: 

 

xx1, yy1 = pixelCoordsFromRaDec(raList, decList, obs_metadata=obs, epoch=2000.0, 

camera=self.camera, includeDistortion=includeDistortion) 

 

xx2, yy2 = _pixelCoordsFromRaDec(np.radians(raList), np.radians(decList), 

obs_metadata=obs, epoch=2000.0, 

camera=self.camera, includeDistortion=includeDistortion) 

 

xx3, yy3 = pixelCoordsFromPupilCoords(xpList, ypList, camera=self.camera, 

includeDistortion=includeDistortion) 

 

xx4, yy4 = pixelCoordsFromPupilCoords(xpList, ypList, chipName=chipNameList, 

camera=self.camera, 

includeDistortion=includeDistortion) 

 

xx5, yy5 = pixelCoordsFromRaDec(raList, decList, obs_metadata=obs, epoch=2000.0, 

camera=self.camera, includeDistortion=includeDistortion, 

chipName=chipNameList) 

 

xx6, yy6 = _pixelCoordsFromRaDec(np.radians(raList), np.radians(decList), 

obs_metadata=obs, epoch=2000.0, 

camera=self.camera, includeDistortion=includeDistortion, 

chipName=chipNameList) 

 

np.testing.assert_array_equal(xx1, xx2) 

np.testing.assert_array_equal(xx1, xx3) 

np.testing.assert_array_equal(xx1, xx4) 

np.testing.assert_array_equal(xx1, xx5) 

np.testing.assert_array_equal(xx1, xx6) 

 

np.testing.assert_array_equal(yy1, yy2) 

np.testing.assert_array_equal(yy1, yy3) 

np.testing.assert_array_equal(yy1, yy4) 

np.testing.assert_array_equal(yy1, yy5) 

np.testing.assert_array_equal(yy1, yy6) 

 

# make sure that objects which do not fall on a chip 

# get NaN pixel coords 

ctNaN = 0 

ctNotNaN = 0 

for x, y, name in zip(xx1, yy1, chipNameList): 

if name is None: 

np.testing.assert_equal(x, np.NaN) 

np.testing.assert_equal(y, np.NaN) 

ctNaN += 1 

else: 

self.assertFalse(np.isnan(x), msg='x is Nan; should not be') 

self.assertFalse(np.isnan(y), msg='y is Nan; should not be') 

ctNotNaN += 1 

 

self.assertGreater(ctNaN, 0) 

self.assertGreater(ctNotNaN, 0) 

 

# now test that passing in the points one at a time gives consistent results 

for ix in range(len(raList)): 

x_f, y_f = pixelCoordsFromRaDec(raList[ix], decList[ix], obs_metadata=obs, 

epoch=2000.0, camera=self.camera, 

includeDistortion=includeDistortion) 

self.assertIsInstance(x_f, np.float) 

self.assertIsInstance(y_f, np.float) 

if not np.isnan(x_f): 

self.assertEqual(x_f, xx1[ix]) 

self.assertEqual(y_f, yy1[ix]) 

else: 

np.testing.assert_equal(xx1[ix], np.NaN) 

np.testing.assert_equal(yy1[ix], np.NaN) 

 

x_f, y_f = pixelCoordsFromRaDec(raList[ix], decList[ix], obs_metadata=obs, 

epoch=2000.0, camera=self.camera, 

includeDistortion=includeDistortion, 

chipName=chipNameList[ix]) 

self.assertIsInstance(x_f, np.float) 

self.assertIsInstance(y_f, np.float) 

if not np.isnan(x_f): 

self.assertEqual(x_f, xx1[ix]) 

self.assertEqual(y_f, yy1[ix]) 

else: 

np.testing.assert_equal(xx1[ix], np.NaN) 

np.testing.assert_equal(yy1[ix], np.NaN) 

 

x_f, y_f = pixelCoordsFromRaDec(raList[ix], decList[ix], obs_metadata=obs, 

epoch=2000.0, camera=self.camera, 

includeDistortion=includeDistortion, 

chipName=[chipNameList[ix]]) 

self.assertIsInstance(x_f, np.float) 

self.assertIsInstance(y_f, np.float) 

if not np.isnan(x_f): 

self.assertEqual(x_f, xx1[ix]) 

self.assertEqual(y_f, yy1[ix]) 

else: 

np.testing.assert_equal(xx1[ix], np.NaN) 

np.testing.assert_equal(yy1[ix], np.NaN) 

 

def testSingleChipName(self): 

""" 

Test that pixelCoordsFromRaDec works when a list of RA, Dec are passed in, 

but only one chipName 

""" 

ra0 = 95.0 

dec0 = -33.0 

obs = ObservationMetaData(pointingRA=ra0, pointingDec=dec0, 

mjd=52350.0, rotSkyPos=27.0) 

 

nStars = 100 

raList = ra0 - (self.rng.random_sample(nStars)-0.5)*1.5 

decList = (self.rng.random_sample(nStars)-0.5)*1.5 + dec0 

 

xpList, ypList = pupilCoordsFromRaDec(raList, decList, obs_metadata=obs, epoch=2000.0) 

 

chipNameList = chipNameFromRaDec(raList, decList, obs_metadata=obs, epoch=2000.0, 

camera=self.camera) 

 

chosen_chip = 'R:2,1 S:1,1' 

valid_pts = np.where(chipNameList == chosen_chip)[0] 

self.assertGreater(len(valid_pts), 1, msg='list_of_chips: %s' % str(chipNameList[valid_pts])) 

xPixControl, yPixControl = pixelCoordsFromRaDec(raList[valid_pts], decList[valid_pts], 

obs_metadata=obs, 

includeDistortion=True, 

camera=self.camera) 

 

xPixTest, yPixTest = pixelCoordsFromRaDec(raList[valid_pts], decList[valid_pts], 

obs_metadata=obs, 

includeDistortion=True, 

camera=self.camera, 

chipName=chosen_chip) 

 

np.testing.assert_array_almost_equal(xPixControl, xPixTest, 12) 

np.testing.assert_array_almost_equal(yPixControl, yPixTest, 12) 

 

xPixTest, yPixTest = pixelCoordsFromRaDec(raList[valid_pts], decList[valid_pts], 

obs_metadata=obs, 

includeDistortion=True, 

camera=self.camera, 

chipName=[chosen_chip]) 

 

np.testing.assert_array_almost_equal(xPixControl, xPixTest, 12) 

np.testing.assert_array_almost_equal(yPixControl, yPixTest, 12) 

 

# test raDecFromPixelCoords 

raTest, decTest = raDecFromPixelCoords(xPixControl, yPixControl, chosen_chip, 

camera=self.camera, obs_metadata=obs, 

includeDistortion=True) 

 

distance = arcsecFromRadians(haversine(np.radians(raList[valid_pts]), 

np.radians(decList[valid_pts]), 

np.radians(raTest), np.radians(decTest))) 

 

self.assertLess(distance.max(), 0.004) # because of the imprecision in 

# _icrsFromObserved, this is the best we can do 

 

raTest, decTest = raDecFromPixelCoords(xPixControl, yPixControl, [chosen_chip], 

camera=self.camera, obs_metadata=obs, 

includeDistortion=True) 

 

distance = arcsecFromRadians(haversine(np.radians(raList[valid_pts]), 

np.radians(decList[valid_pts]), 

np.radians(raTest), np.radians(decTest))) 

 

self.assertLess(distance.max(), 0.004) 

 

def testExceptions(self): 

""" 

Test that pixelCoord calculation methods raise exceptions when 

they should 

""" 

nPoints = 100 

xpList = self.rng.random_sample(nPoints)*np.radians(1.0) 

ypList = self.rng.random_sample(nPoints)*np.radians(1.0) 

obs = ObservationMetaData(pointingRA=25.0, 

pointingDec=-36.0, 

rotSkyPos=122.0, 

mjd=41325.0) 

 

raList = self.rng.random_sample(nPoints)*1.0+25.0 

decList = self.rng.random_sample(nPoints)*1.0-36.0 

 

# check that an error is raised when you forget to 

# pass in a camera 

with self.assertRaises(RuntimeError) as context: 

pixelCoordsFromPupilCoords(xpList, ypList) 

 

self.assertEqual(context.exception.args[0], 

'Camera not specified. Cannot calculate pixel coordinates.') 

 

with self.assertRaises(RuntimeError) as context: 

pixelCoordsFromRaDec(raList, decList, obs_metadata=obs, 

epoch=2000.0) 

 

self.assertEqual(context.exception.args[0], 

'Camera not specified. Cannot calculate pixel coordinates.') 

 

with self.assertRaises(RuntimeError) as context: 

_pixelCoordsFromRaDec(np.radians(raList), 

np.radians(decList), 

obs_metadata=obs, 

epoch=2000.0) 

 

self.assertEqual(context.exception.args[0], 

'Camera not specified. Cannot calculate pixel coordinates.') 

 

# test that an exception is raised when you pass in something 

# that is not a numpy array 

with self.assertRaises(RuntimeError) as context: 

pixelCoordsFromPupilCoords(list(xpList), ypList, 

camera=self.camera) 

 

self.assertIn("The arg xPupil", context.exception.args[0]) 

 

with self.assertRaises(RuntimeError) as context: 

pixelCoordsFromPupilCoords(xpList, list(ypList), 

camera=self.camera) 

 

self.assertIn("The input arguments:", context.exception.args[0]) 

self.assertIn("yPupil", context.exception.args[0]) 

 

with self.assertRaises(RuntimeError) as context: 

_pixelCoordsFromRaDec(list(np.radians(raList)), 

np.radians(decList), 

obs_metadata=obs, 

epoch=2000.0, 

camera=self.camera) 

 

self.assertIn("The arg ra", context.exception.args[0]) 

 

with self.assertRaises(RuntimeError) as context: 

_pixelCoordsFromRaDec(np.radians(raList), 

list(np.radians(decList)), 

obs_metadata=obs, 

epoch=2000.0, 

camera=self.camera) 

 

self.assertIn("The input arguments:", context.exception.args[0]) 

self.assertIn("dec", context.exception.args[0]) 

 

# do not need to run the above test on pixelCoordsFromRaDec, 

# because the conversion from degrees to radians that happens 

# inside that method automatically casts lists as numpy arrays 

 

# test that an exception is raised if you pass in mis-matched 

# input arrays 

with self.assertRaises(RuntimeError) as context: 

pixelCoordsFromPupilCoords(xpList, ypList[0:10], 

camera=self.camera) 

 

self.assertEqual(context.exception.args[0], 

"The arrays input to pixelCoordsFromPupilCoords " 

"all need to have the same length") 

 

with self.assertRaises(RuntimeError) as context: 

pixelCoordsFromRaDec(raList, decList[0:10], 

obs_metadata=obs, 

epoch=2000.0, 

camera=self.camera) 

 

self.assertEqual(context.exception.args[0], 

"The arrays input to pixelCoordsFromRaDec all need " 

"to have the same length") 

 

with self.assertRaises(RuntimeError) as context: 

_pixelCoordsFromRaDec(np.radians(raList), 

np.radians(decList[0:10]), 

obs_metadata=obs, 

epoch=2000.0, 

camera=self.camera) 

 

self.assertEqual(context.exception.args[0], 

"The arrays input to pixelCoordsFromRaDec all need " 

"to have the same length") 

 

# test that an error is raised if you pass an incorrect 

# number of chipNames to pixelCoordsFromPupilCoords 

with self.assertRaises(RuntimeError) as context: 

pixelCoordsFromPupilCoords(xpList, ypList, chipName=['R:2,2 S:1,1']*10, 

camera=self.camera) 

 

self.assertIn("You passed 10 chipNames", context.exception.args[0]) 

 

with self.assertRaises(RuntimeError) as context: 

pixelCoordsFromRaDec(raList, decList, chipName=['R:2,2 S:1,1']*10, 

camera=self.camera, 

obs_metadata=obs, 

epoch=2000.0) 

 

self.assertIn("You passed 10 chipNames", context.exception.args[0]) 

 

with self.assertRaises(RuntimeError) as context: 

_pixelCoordsFromRaDec(np.radians(raList), 

np.radians(decList), 

chipName=['R:2,2 S:1,1']*10, 

camera=self.camera, 

obs_metadata=obs, 

epoch=2000.0) 

 

self.assertIn("You passed 10 chipNames", context.exception.args[0]) 

 

# test that an exception is raised if you call one of the 

# pixelCoordsFromRaDec methods without an ObservationMetaData 

with self.assertRaises(RuntimeError) as context: 

pixelCoordsFromRaDec(raList, decList, 

camera=self.camera, epoch=2000.0) 

 

self.assertEqual(context.exception.args[0], 

'You need to pass an ObservationMetaData into ' 

'pixelCoordsFromRaDec') 

 

with self.assertRaises(RuntimeError) as context: 

_pixelCoordsFromRaDec(raList, decList, 

camera=self.camera, epoch=2000.0) 

 

self.assertEqual(context.exception.args[0], 

'You need to pass an ObservationMetaData into ' 

'pixelCoordsFromRaDec') 

 

# test that an exception is raised if you try to use an 

# ObservationMetaData without an mjd 

obsDummy = ObservationMetaData(pointingRA=25.0, 

pointingDec=-36.0, 

rotSkyPos=112.0) 

 

with self.assertRaises(RuntimeError) as context: 

pixelCoordsFromRaDec(raList, decList, 

camera=self.camera, 

epoch=2000.0, 

obs_metadata=obsDummy) 

 

self.assertEqual(context.exception.args[0], 

'You need to pass an ObservationMetaData ' 

'with an mjd into pixelCoordsFromRaDec') 

 

with self.assertRaises(RuntimeError) as context: 

_pixelCoordsFromRaDec(raList, decList, 

camera=self.camera, 

epoch=2000.0, 

obs_metadata=obsDummy) 

 

self.assertEqual(context.exception.args[0], 

'You need to pass an ObservationMetaData ' 

'with an mjd into pixelCoordsFromRaDec') 

 

# test that an exception is raised if you try to use an 

# ObservationMetaData without a rotSkyPos 

obsDummy = ObservationMetaData(pointingRA=25.0, 

pointingDec=-36.0, 

mjd=53000.0) 

 

with self.assertRaises(RuntimeError) as context: 

pixelCoordsFromRaDec(raList, decList, 

camera=self.camera, 

epoch=2000.0, 

obs_metadata=obsDummy) 

 

self.assertEqual(context.exception.args[0], 

'You need to pass an ObservationMetaData ' 

'with a rotSkyPos into pixelCoordsFromRaDec') 

 

obsDummy = ObservationMetaData(pointingRA=25.0, 

pointingDec=-36.0, 

mjd=53000.0) 

with self.assertRaises(RuntimeError) as context: 

_pixelCoordsFromRaDec(raList, decList, 

camera=self.camera, 

epoch=2000.0, 

obs_metadata=obsDummy) 

 

self.assertEqual(context.exception.args[0], 

'You need to pass an ObservationMetaData ' 

'with a rotSkyPos into pixelCoordsFromRaDec') 

 

@unittest.skip("The test camera has changed") 

def testResults(self): 

""" 

Test that the results of the pixelCoords methods make sense. Note that the test 

camera has a platescale of 0.02 arcsec per pixel (2.0 arcsec per mm encoded in 

CameraForUnitTests.py and 10 microns per pixel encoded in cameraData/focalplanelayout.txt). 

We will use that to set the control values for our unit test. 

 

Note: This unit test will fail if the test camera ever changes. 

 

Note: Because we have already tested the self-consistency of 

pixelCoordsFromPupilCoords and pixelCoordsFromRaDec, we will 

only be testing pixelCoordsFromPupilCoords here, because it 

is easier. 

""" 

 

arcsecPerPixel = 0.02 

arcsecPerMicron = 0.002 

 

# list a bunch of detector centers in radians 

x22 = 0.0 

y22 = 0.0 

 

x32 = radiansFromArcsec(40000.0 * arcsecPerMicron) 

y32 = 0.0 

 

x40 = radiansFromArcsec(80000.0 * arcsecPerMicron) 

y40 = radiansFromArcsec(-80000.0 * arcsecPerMicron) 

 

# assemble a bunch of displacements in pixels 

dxPixList = [] 

dyPixList = [] 

for xx in np.arange(-1999.0, 1999.0, 500.0): 

for yy in np.arange(-1999.0, 1999.0, 500.0): 

dxPixList.append(xx) 

dyPixList.append(yy) 

 

dxPixList = np.array(dxPixList) 

dyPixList = np.array(dyPixList) 

 

# convert to raidans 

dxPupList = radiansFromArcsec(dxPixList*arcsecPerPixel) 

dyPupList = radiansFromArcsec(dyPixList*arcsecPerPixel) 

 

# assemble a bunch of test pupil coordinate pairs 

xPupList = x22 + dxPupList 

yPupList = y22 + dyPupList 

xPupList = np.append(xPupList, x32 + dxPupList) 

yPupList = np.append(yPupList, y32 + dyPupList) 

xPupList = np.append(xPupList, x40 + dxPupList) 

yPupList = np.append(yPupList, y40 + dyPupList) 

 

# this is what the chipNames ought to be for these points 

chipNameControl = np.array(['Det22'] * len(dxPupList)) 

chipNameControl = np.append(chipNameControl, ['Det32'] * len(dxPupList)) 

chipNameControl = np.append(chipNameControl, ['Det40'] * len(dxPupList)) 

 

chipNameTest = chipNameFromPupilCoords(xPupList, yPupList, camera=self.camera) 

 

# verify that the test points fall on the expected chips 

np.testing.assert_array_equal(chipNameControl, chipNameTest) 

 

# Note, the somewhat backwards way in which we go from dxPixList to 

# xPixControl is due to the fact that pixel coordinates are actually 

# aligned so that the x-axis is along the read-out direction, which 

# makes positive x in pixel coordinates correspond to positive y 

# in pupil coordinates 

xPixControl = 1999.5 + dyPixList 

yPixControl = 1999.5 - dxPixList 

xPixControl = np.append(xPixControl, 1999.5 + dyPixList) 

yPixControl = np.append(yPixControl, 1999.5 - dxPixList) 

xPixControl = np.append(xPixControl, 1999.5 + dyPixList) 

yPixControl = np.append(yPixControl, 1999.5 - dxPixList) 

 

# verify that the pixel coordinates are as expected to within 0.01 pixel 

xPixTest, yPixTest = pixelCoordsFromPupilCoords(xPupList, yPupList, camera=self.camera, 

includeDistortion=False) 

 

np.testing.assert_array_almost_equal(xPixTest, xPixControl, 2) 

np.testing.assert_array_almost_equal(yPixTest, yPixControl, 2) 

 

# now test that we get the same results when we pass the pupil coords in 

# one at a time 

for ix in range(len(xPupList)): 

xpx_f, ypx_f = pixelCoordsFromPupilCoords(xPupList[ix], yPupList[ix], 

camera=self.camera, 

includeDistortion=False) 

self.assertIsInstance(xpx_f, np.float) 

self.assertIsInstance(ypx_f, np.float) 

self.assertAlmostEqual(xpx_f, xPixTest[ix], 12) 

self.assertAlmostEqual(ypx_f, yPixTest[ix], 12) 

 

def testOffChipResults(self): 

""" 

Test that the results of the pixelCoords methods make sense in the case 

that you specify a chip name that is not necessarily the chip on which 

the object actually fell. 

 

Note that the test camera has a platescale of 0.02 arcsec per pixel 

(2.0 arcsec per mm encoded in CameraForUnitTests.py and 10 microns per 

pixel encoded in cameraData/focalplanelayout.txt). We will use that to 

set the control values for our unit test. 

 

Note: This unit test will fail if the test camera ever changes. 

 

Note: Because we have already tested the self-consistency of 

pixelCoordsFromPupilCoords and pixelCoordsFromRaDec, we will 

only be testing pixelCoordsFromPupilCoords here, because it 

is easier. 

""" 

 

arcsecPerPixel = 0.2 

arcsecPerMicron = 0.02 

 

# list a bunch of detector centers in radians 

x22 = 0.0 

y22 = 0.0 

 

x32 = 0.008 

y32 = 0.0 

 

x40 = 0.0 

y40 = -0.012 

 

# assemble a bunch of displacements in pixels 

dxPixList = [] 

dyPixList = [] 

for xx in np.arange(-1000.0, 1000.0, 250.0): 

for yy in np.arange(-1000.0, 1000.0, 250.0): 

dxPixList.append(xx) 

dyPixList.append(yy) 

 

dxPixList = np.array(dxPixList) 

dyPixList = np.array(dyPixList) 

 

# convert to radians 

dxPupList = radiansFromArcsec(dxPixList*arcsecPerPixel) 

dyPupList = radiansFromArcsec(dyPixList*arcsecPerPixel) 

 

# assemble a bunch of test pupil coordinate pairs 

xPupList = x22 + dxPupList 

yPupList = y22 + dyPupList 

xPupList = np.append(xPupList, x32 + dxPupList) 

yPupList = np.append(yPupList, y32 + dyPupList) 

xPupList = np.append(xPupList, x40 + dxPupList) 

yPupList = np.append(yPupList, y40 + dyPupList) 

 

# this is what the chipNames ought to be for these points 

chipNameControl = np.array(['R:2,2 S:1,1'] * len(dxPupList)) 

chipNameControl = np.append(chipNameControl, ['R:3,2 S:0,1'] * len(dxPupList)) 

chipNameControl = np.append(chipNameControl, ['R:2,1 S:1,1'] * len(dxPupList)) 

 

chipNameTest = chipNameFromPupilCoords(xPupList, yPupList, camera=self.camera) 

print(np.unique(chipNameTest)) 

 

# verify that the test points fall on the expected chips 

np.testing.assert_array_equal(chipNameControl, chipNameTest) 

 

 

"""Something about the new camera doesn't match, so this doesn't quite work. 

Commenting this section out for now - scale wrong maybe? Or bigger camera (and 

thus the pixels don't match because pixels within ccd vs. focal plane?)? 

 

# Note, the somewhat backwards way in which we go from dxPupList to 

# xPixControl is due to the fact that pixel coordinates are actually 

# aligned so that the x-axis is along the read-out direction, which 

# makes positive x in pixel coordinates correspond to positive y 

# in pupil coordinates 

xPixControl = 1000 + arcsecFromRadians(yPupList - y40)/arcsecPerPixel 

yPixControl = 1000 - arcsecFromRadians(xPupList - x40)/arcsecPerPixel 

 

# verify that the pixel coordinates are as expected to within 0.01 pixel 

inputChipNames = ['R:2,2 S:1,1'] * len(xPupList) 

xPixTest, yPixTest = pixelCoordsFromPupilCoords(xPupList, yPupList, camera=self.camera, 

includeDistortion=False, 

chipName=inputChipNames) 

 

np.testing.assert_array_almost_equal(xPixTest, xPixControl, 2) 

np.testing.assert_array_almost_equal(yPixTest, yPixControl, 2) 

 

# now test that we get the same results when we pass the pupil coords in 

# one at a time 

for ix in range(len(xPupList)): 

xpx_f, ypx_f = pixelCoordsFromPupilCoords(xPupList[ix], yPupList[ix], 

camera=self.camera, 

includeDistortion=False, 

chipName=inputChipNames[ix]) 

self.assertIsInstance(xpx_f, np.float) 

self.assertIsInstance(ypx_f, np.float) 

self.assertAlmostEqual(xpx_f, xPixTest[ix], 12) 

self.assertAlmostEqual(ypx_f, yPixTest[ix], 12) 

 

# We will now use this opportunity to test that pupilCoordsFromPixelCoords 

# and pixelCoordsFromPupilCoords work when we pass in a list of pixel 

# coords, but only one chip name 

xPix_one, yPix_one = pixelCoordsFromPupilCoords(xPupList, yPupList, 

camera=self.camera, 

includeDistortion=False, 

chipName='R:2,1 S:1,1') 

 

np.testing.assert_array_almost_equal(xPix_one, xPixTest, 12) 

np.testing.assert_array_almost_equal(yPix_one, yPixTest, 12) 

 

xPix_one, yPix_one = pixelCoordsFromPupilCoords(xPupList, yPupList, 

camera=self.camera, 

includeDistortion=False, 

chipName='R:2,1 S:1,1') 

 

np.testing.assert_array_almost_equal(xPix_one, xPixTest, 12) 

np.testing.assert_array_almost_equal(yPix_one, yPixTest, 12) 

 

xPupTest, yPupTest = pupilCoordsFromPixelCoords(xPixTest, yPixTest, 'R:2,1 S:1,1', 

camera=self.camera, 

includeDistortion=False) 

 

np.testing.assert_array_almost_equal(xPupTest, xPupList, 12) 

np.testing.assert_array_almost_equal(yPupTest, yPupList, 12) 

 

xPupTest, yPupTest = pupilCoordsFromPixelCoords(xPixTest, yPixTest, ['Det40'], 

camera=self.camera, 

includeDistortion=False) 

 

np.testing.assert_array_almost_equal(xPupTest, xPupList, 12) 

np.testing.assert_array_almost_equal(yPupTest, yPupList, 12) 

""" 

 

def testNaN(self): 

""" 

Verify that NaNs and Nones input to pixelCoordinate calculation methods result 

in NaNs coming out 

""" 

ra0 = 25.0 

dec0 = -35.0 

obs = ObservationMetaData(pointingRA=ra0, pointingDec=dec0, 

rotSkyPos=42.0, mjd=42356.0) 

 

raList = self.rng.random_sample(100)*100.0/3600.0 + ra0 

decList = self.rng.random_sample(100)*100.0/3600.0 + dec0 

chipNameList = chipNameFromRaDec(raList, decList, obs_metadata=obs, epoch=2000.0, 

camera=self.camera) 

 

# make sure that all of the test points actually fall on chips 

for name in chipNameList: 

self.assertIsNotNone(name) 

 

xPupList, yPupList = pupilCoordsFromRaDec(raList, decList, obs_metadata=obs, epoch=2000.0) 

 

# make sure that none of the test points already result in NaN pixel coordinates 

xPixList, yPixList = pixelCoordsFromRaDec(raList, decList, obs_metadata=obs, 

epoch=2000.0, camera=self.camera) 

 

for xx, yy in zip(xPixList, yPixList): 

self.assertFalse(np.isnan(xx), msg='xx is NaN; should not be') 

self.assertFalse(np.isnan(yy), msg='yy is NaN; should not be') 

self.assertIsNotNone(xx, None) 

self.assertIsNotNone(yy, None) 

 

for badVal in [np.NaN, None]: 

raList[5] = badVal 

decList[7] = badVal 

raList[9] = badVal 

decList[9] = badVal 

 

xPixList, yPixList = pixelCoordsFromRaDec(raList, decList, obs_metadata=obs, 

epoch=2000.0, camera=self.camera) 

 

for ix, (xx, yy) in enumerate(zip(xPixList, yPixList)): 

if ix in [5, 7, 9]: 

np.testing.assert_equal(xx, np.NaN) 

np.testing.assert_equal(yy, np.NaN) 

else: 

self.assertFalse(np.isnan(xx), msg='xx is NaN; should not be') 

self.assertFalse(np.isnan(yy), msg='yy is NaN; should not be') 

self.assertIsNotNone(xx) 

self.assertIsNotNone(yy) 

 

xPixList, yPixList = _pixelCoordsFromRaDec(np.radians(raList), np.radians(decList), 

obs_metadata=obs, epoch=2000.0, camera=self.camera) 

 

for ix, (xx, yy) in enumerate(zip(xPixList, yPixList)): 

if ix in [5, 7, 9]: 

np.testing.assert_equal(xx, np.NaN) 

np.testing.assert_equal(yy, np.NaN) 

else: 

self.assertFalse(np.isnan(xx), msg='xx is NaN; should not be') 

self.assertFalse(np.isnan(yy), msg='yy is NaN; should not be') 

self.assertIsNotNone(xx) 

self.assertIsNotNone(yy) 

 

xPupList[5] = badVal 

yPupList[7] = badVal 

xPupList[9] = badVal 

yPupList[9] = badVal 

xPixList, yPixList = pixelCoordsFromPupilCoords(xPupList, yPupList, camera=self.camera) 

for ix, (xx, yy) in enumerate(zip(xPixList, yPixList)): 

 

# verify the same result if we had passed in pupil coords one-at-a-time 

xpx_f, ypx_f = pixelCoordsFromPupilCoords(xPupList[ix], yPupList[ix], camera=self.camera) 

self.assertIsInstance(xpx_f, np.float) 

self.assertIsInstance(ypx_f, np.float) 

 

if ix in [5, 7, 9]: 

np.testing.assert_equal(xx, np.NaN) 

np.testing.assert_equal(yy, np.NaN) 

np.testing.assert_equal(xpx_f, np.NaN) 

np.testing.assert_equal(ypx_f, np.NaN) 

else: 

self.assertFalse(np.isnan(xx), msg='xx is NaN; should not be') 

self.assertFalse(np.isnan(yy), msg='yy is NaN; should not be') 

self.assertIsNotNone(xx) 

self.assertIsNotNone(yy) 

self.assertAlmostEqual(xx, xpx_f, 12) 

self.assertAlmostEqual(yy, ypx_f, 12) 

 

def testDistortion(self): 

""" 

Make sure that the results from pixelCoordsFromPupilCoords are different 

if includeDistortion is True as compared to if includeDistortion is False 

 

Note: This test passes because the test camera has a pincushion distortion. 

If we take that away, the test will no longer pass. 

""" 

xp = radiansFromArcsec((self.rng.random_sample(100)-0.5)*500.0) 

yp = radiansFromArcsec((self.rng.random_sample(100)-0.5)*500.0) 

 

xu, yu = pixelCoordsFromPupilCoords(xp, yp, camera=self.camera, includeDistortion=False) 

xd, yd = pixelCoordsFromPupilCoords(xp, yp, camera=self.camera, includeDistortion=True) 

 

# just verify that the distorted versus undistorted coordinates vary in the 

# 4th decimal place 

self.assertRaises(AssertionError, 

np.testing.assert_array_almost_equal, xu, xd, 4) 

 

self.assertRaises(AssertionError, 

np.testing.assert_array_almost_equal, yu, yd, 4) 

 

# make sure that distortions are also present when we pass pupil coordinates in 

# one-at-a-time 

for ix in range(len(xp)): 

x_f, y_f = pixelCoordsFromPupilCoords(xp[ix], yp[ix], camera=self.camera, 

includeDistortion=True) 

 

self.assertAlmostEqual(xd[ix], x_f, 12) 

self.assertAlmostEqual(yd[ix], y_f, 12) 

self.assertIsInstance(x_f, np.float) 

self.assertIsInstance(y_f, np.float) 

 

 

class FocalPlaneCoordTest(unittest.TestCase): 

 

@classmethod 

def setUpClass(cls): 

cls.camera = LsstSimMapper().camera 

 

@classmethod 

def tearDownClass(cls): 

del cls.camera 

 

def setUp(self): 

self.rng = np.random.RandomState(8374522) 

 

def testConsistency(self): 

""" 

Test that all of the focalPlaneCoord calculation methods 

return self-consistent answers. 

""" 

 

ra0 = 34.1 

dec0 = -23.0 

obs = ObservationMetaData(pointingRA=ra0, pointingDec=dec0, 

mjd=43257.0, rotSkyPos = 127.0) 

 

raCenter, decCenter = observedFromICRS(np.array([ra0]), 

np.array([dec0]), 

obs_metadata=obs, 

epoch=2000.0) 

 

nStars = 100 

raList = self.rng.random_sample(nStars)*1000.0/3600.0 + raCenter[0] 

decList = self.rng.random_sample(nStars)*1000.0/3600.0 + decCenter[0] 

 

xPupList, yPupList = pupilCoordsFromRaDec(raList, decList, 

obs_metadata=obs, 

epoch=2000.0) 

 

xf1, yf1 = focalPlaneCoordsFromRaDec(raList, decList, 

obs_metadata=obs, 

epoch=2000.0, camera=self.camera) 

 

xf2, yf2 = _focalPlaneCoordsFromRaDec(np.radians(raList), 

np.radians(decList), 

obs_metadata=obs, 

epoch=2000.0, camera=self.camera) 

 

xf3, yf3 = focalPlaneCoordsFromPupilCoords(xPupList, yPupList, 

camera=self.camera) 

 

np.testing.assert_array_equal(xf1, xf2) 

np.testing.assert_array_equal(xf1, xf3) 

np.testing.assert_array_equal(yf1, yf2) 

np.testing.assert_array_equal(yf1, yf3) 

 

for x, y in zip(xf1, yf1): 

self.assertFalse(np.isnan(x), msg='x is NaN; should not be') 

self.assertIsNotNone(x) 

self.assertFalse(np.isnan(y), msg='y is NaN; should not be') 

self.assertIsNotNone(y) 

 

# now test that focalPlaneCoordsFromRaDec and 

# focalPlaneCoordsFromPupilCoords give the same results 

# when you pass the inputs in one-by-one 

for ix in range(len(xf1)): 

x_f, y_f = focalPlaneCoordsFromRaDec(raList[ix], decList[ix], 

camera=self.camera, 

obs_metadata=obs, epoch=2000.0) 

self.assertIsInstance(x_f, float) 

self.assertIsInstance(y_f, float) 

self.assertEqual(x_f, xf1[ix]) 

self.assertEqual(y_f, yf1[ix]) 

 

x_f, y_f = focalPlaneCoordsFromPupilCoords(xPupList[ix], yPupList[ix], 

camera=self.camera) 

self.assertIsInstance(x_f, float) 

self.assertIsInstance(y_f, float) 

self.assertEqual(x_f, xf1[ix]) 

self.assertEqual(y_f, yf1[ix]) 

 

def testExceptions(self): 

""" 

Test that the focalPlaneCoord methods raise the exceptions 

(with the correct messages) when they should. 

""" 

 

ra0 = 34.0 

dec0 = -19.0 

obs = ObservationMetaData(pointingRA=ra0, pointingDec=dec0, 

rotSkyPos=61.0, mjd=52349.0) 

 

nStars = 10 

raList = (self.rng.random_sample(nStars)-0.5) + ra0 

decList = (self.rng.random_sample(nStars)-0.5) + dec0 

xPupList, yPupList = pupilCoordsFromRaDec(raList, decList, 

obs_metadata=obs, 

epoch=2000.0) 

 

# verify that an error is raised when you forget to pass 

# in a camera 

with self.assertRaises(RuntimeError) as context: 

xf, yf = focalPlaneCoordsFromPupilCoords(xPupList, yPupList) 

self.assertEqual(context.exception.args[0], 

"You cannot calculate focal plane coordinates " 

"without specifying a camera") 

 

with self.assertRaises(RuntimeError) as context: 

xf, yf = focalPlaneCoordsFromRaDec(raList, decList, 

obs_metadata=obs, 

epoch=2000.0) 

 

self.assertEqual(context.exception.args[0], 

"You cannot calculate focal plane coordinates " 

"without specifying a camera") 

 

with self.assertRaises(RuntimeError) as context: 

xf, yf = _focalPlaneCoordsFromRaDec(raList, decList, 

obs_metadata=obs, 

epoch=2000.0) 

 

self.assertEqual(context.exception.args[0], 

"You cannot calculate focal plane coordinates " 

"without specifying a camera") 

 

# test that an error is raised when you pass in something that 

# is not a numpy array 

with self.assertRaises(RuntimeError) as context: 

xf, yf = focalPlaneCoordsFromPupilCoords(list(xPupList), yPupList, 

camera=self.camera) 

self.assertIn("The arg xPupil", context.exception.args[0]) 

 

with self.assertRaises(RuntimeError) as context: 

xf, yf = focalPlaneCoordsFromPupilCoords(xPupList, list(yPupList), 

camera=self.camera) 

self.assertIn("The input arguments:", context.exception.args[0]) 

self.assertIn("yPupil", context.exception.args[0]) 

 

with self.assertRaises(RuntimeError) as context: 

xf, yf = _focalPlaneCoordsFromRaDec(list(raList), decList, 

obs_metadata=obs, 

epoch=2000.0, 

camera=self.camera) 

self.assertIn("The arg ra", context.exception.args[0]) 

 

with self.assertRaises(RuntimeError) as context: 

xf, yf = _focalPlaneCoordsFromRaDec(raList, list(decList), 

obs_metadata=obs, 

epoch=2000.0, 

camera=self.camera) 

self.assertIn("The input arguments:", context.exception.args[0]) 

self.assertIn("dec", context.exception.args[0]) 

 

# we do not have to run the test above on focalPlaneCoordsFromRaDec 

# because the conversion to radians automatically casts lists into 

# numpy arrays 

 

# test that an error is raised if you pass in mismatched numbers 

# of x and y coordinates 

with self.assertRaises(RuntimeError) as context: 

xf, yf = focalPlaneCoordsFromPupilCoords(xPupList, yPupList[0:4], 

camera=self.camera) 

self.assertEqual(context.exception.args[0], 

"The arrays input to focalPlaneCoordsFromPupilCoords " 

"all need to have the same length") 

 

with self.assertRaises(RuntimeError) as context: 

xf, yf = focalPlaneCoordsFromRaDec(raList, decList[0:4], 

obs_metadata=obs, 

epoch=2000.0, 

camera=self.camera) 

self.assertEqual(context.exception.args[0], 

"The arrays input to focalPlaneCoordsFromRaDec " 

"all need to have the same length") 

 

with self.assertRaises(RuntimeError) as context: 

xf, yf = _focalPlaneCoordsFromRaDec(raList, decList[0:4], 

obs_metadata=obs, 

epoch=2000.0, 

camera=self.camera) 

self.assertEqual(context.exception.args[0], 

"The arrays input to focalPlaneCoordsFromRaDec " 

"all need to have the same length") 

 

# test that an error is raised if you call 

# focalPlaneCoordsFromRaDec without an ObservationMetaData 

with self.assertRaises(RuntimeError) as context: 

xf, yf = focalPlaneCoordsFromRaDec(raList, decList, 

epoch=2000.0, 

camera=self.camera) 

 

self.assertEqual(context.exception.args[0], 

"You have to specify an ObservationMetaData to run " 

"focalPlaneCoordsFromRaDec") 

 

with self.assertRaises(RuntimeError) as context: 

xf, yf = _focalPlaneCoordsFromRaDec(raList, decList, 

epoch=2000.0, 

camera=self.camera) 

self.assertEqual(context.exception.args[0], 

"You have to specify an ObservationMetaData to run " 

"focalPlaneCoordsFromRaDec") 

 

# test that an error is raised if you pass an ObservationMetaData 

# without an mjd into focalPlaneCoordsFromRaDec 

obsDummy = ObservationMetaData(pointingRA=ra0, pointingDec=dec0, 

rotSkyPos=112.0) 

with self.assertRaises(RuntimeError) as context: 

xf, yf = focalPlaneCoordsFromRaDec(raList, decList, 

obs_metadata=obsDummy, 

epoch=2000.0, 

camera=self.camera) 

self.assertEqual(context.exception.args[0], 

"You need to pass an ObservationMetaData with an " 

"mjd into focalPlaneCoordsFromRaDec") 

 

with self.assertRaises(RuntimeError) as context: 

xf, yf = _focalPlaneCoordsFromRaDec(raList, decList, 

obs_metadata=obsDummy, 

epoch=2000.0, 

camera=self.camera) 

 

self.assertEqual(context.exception.args[0], 

"You need to pass an ObservationMetaData with an " 

"mjd into focalPlaneCoordsFromRaDec") 

 

# test that an error is raised if you pass an ObservationMetaData 

# without a rotSkyPos into focalPlaneCoordsFromRaDec 

obsDummy = ObservationMetaData(pointingRA=ra0, pointingDec=dec0, 

mjd=42356.0) 

with self.assertRaises(RuntimeError) as context: 

xf, yf = focalPlaneCoordsFromRaDec(raList, decList, 

obs_metadata=obsDummy, 

epoch=2000.0, 

camera=self.camera) 

 

self.assertEqual(context.exception.args[0], 

"You need to pass an ObservationMetaData with a " 

"rotSkyPos into focalPlaneCoordsFromRaDec") 

 

with self.assertRaises(RuntimeError) as context: 

xf, yf = _focalPlaneCoordsFromRaDec(raList, decList, 

obs_metadata=obsDummy, 

epoch=2000.0, 

camera=self.camera) 

self.assertEqual(context.exception.args[0], 

"You need to pass an ObservationMetaData with a " 

"rotSkyPos into focalPlaneCoordsFromRaDec") 

 

@unittest.skip("The test camera has changed") 

def testResults(self): 

""" 

Test that the focalPlaneCoords methods give sensible results. 

 

Note: since we have already tested the self-consistency of 

focalPlaneCoordsFromPupilCoords and focalPlaneCoordsFromRaDec, 

we will only test focalPlaneCoordsFromPupilCoords here, since it 

is easier. 

 

Note that the test camera has a platescale of 0.02 arcsec per pixel 

(2.0 arcsec per mm encoded in CameraForUnitTests.py and 10 microns 

per pixel encoded in cameraData/focalplanelayout.txt). We will use 

that to set the control values for our unit test. 

 

Note: This unit test will fail if the test camera ever changes. 

""" 

 

arcsecPerPixel = 0.02 

arcsecPerMicron = 0.002 

mmPerArcsec = 0.5 

 

# list a bunch of detector centers in radians 

x22 = 0.0 

y22 = 0.0 

 

x32 = radiansFromArcsec(40000.0 * arcsecPerMicron) 

y32 = 0.0 

 

x40 = radiansFromArcsec(80000.0 * arcsecPerMicron) 

y40 = radiansFromArcsec(-80000.0 * arcsecPerMicron) 

 

# assemble a bunch of displacements in pixels 

dxPixList = [] 

dyPixList = [] 

for xx in np.arange(-1999.0, 1999.0, 500.0): 

for yy in np.arange(-1999.0, 1999.0, 500.0): 

dxPixList.append(xx) 

dyPixList.append(yy) 

 

dxPixList = np.array(dxPixList) 

dyPixList = np.array(dyPixList) 

 

# convert to raidans 

dxPupList = radiansFromArcsec(dxPixList*arcsecPerPixel) 

dyPupList = radiansFromArcsec(dyPixList*arcsecPerPixel) 

 

# assemble a bunch of test pupil coordinate pairs 

xPupList = x22 + dxPupList 

yPupList = y22 + dyPupList 

xPupList = np.append(xPupList, x32 + dxPupList) 

yPupList = np.append(yPupList, y32 + dyPupList) 

xPupList = np.append(xPupList, x40 + dxPupList) 

yPupList = np.append(yPupList, y40 + dyPupList) 

 

# this is what the chipNames ought to be for these points 

chipNameControl = np.array(['Det22'] * len(dxPupList)) 

chipNameControl = np.append(chipNameControl, ['Det32'] * len(dxPupList)) 

chipNameControl = np.append(chipNameControl, ['Det40'] * len(dxPupList)) 

 

chipNameTest = chipNameFromPupilCoords(xPupList, yPupList, camera=self.camera) 

 

# verify that the test points fall on the expected chips 

np.testing.assert_array_equal(chipNameControl, chipNameTest) 

 

# convert into millimeters on the focal plane 

xFocalControl = arcsecFromRadians(xPupList)*mmPerArcsec 

yFocalControl = arcsecFromRadians(yPupList)*mmPerArcsec 

 

xFocalTest, yFocalTest = focalPlaneCoordsFromPupilCoords(xPupList, yPupList, camera=self.camera) 

 

np.testing.assert_array_almost_equal(xFocalTest, xFocalControl, 3) 

np.testing.assert_array_almost_equal(yFocalTest, yFocalControl, 3) 

 

def test_pupilCoordsFromFocalPlaneCoords(self): 

""" 

Test that pupilCoordsFromFocalPlaneCoords inverts 

focalPlaneCoordsFromPupilCoords 

""" 

rng = np.random.RandomState(88123) 

n_pts = 20 

x_pup = rng.random_sample(n_pts)*0.05-0.025 

y_pup = rng.random_sample(n_pts)*0.05-0.025 

 

x_f, y_f = focalPlaneCoordsFromPupilCoords(x_pup, y_pup, 

camera=lsst_camera()) 

 

x_p_test, y_p_test = pupilCoordsFromFocalPlaneCoords(x_f, y_f, 

camera=lsst_camera()) 

 

np.testing.assert_array_almost_equal(arcsecFromRadians(x_pup), 

arcsecFromRadians(x_p_test), 

decimal=6) 

 

np.testing.assert_array_almost_equal(arcsecFromRadians(y_pup), 

arcsecFromRadians(y_p_test), 

decimal=6) 

 

# test that it works on scalars, too 

for ii in range(len(x_pup)): 

(x_p_test, 

y_p_test) = pupilCoordsFromFocalPlaneCoords(x_f[ii], y_f[ii], 

camera=lsst_camera()) 

 

self.assertAlmostEqual(arcsecFromRadians(x_pup[ii]), 

arcsecFromRadians(x_p_test), 

6) 

 

self.assertAlmostEqual(arcsecFromRadians(y_pup[ii]), 

arcsecFromRadians(y_p_test), 

6) 

 

del lsst_camera._lsst_camera 

 

def test_pupilCoordsFromFocalPlaneCoordsNaNs(self): 

""" 

Test that pupilCoordsFromFocalPlaneCoords handles NaNs correctly 

""" 

xp, yp = pupilCoordsFromFocalPlaneCoords(1.0, 2.0, camera=lsst_camera()) 

self.assertFalse(np.isnan(xp)) 

self.assertFalse(np.isnan(yp)) 

xp, yp = pupilCoordsFromFocalPlaneCoords(np.NaN, 2.0, camera=lsst_camera()) 

self.assertTrue(np.isnan(xp)) 

self.assertTrue(np.isnan(yp)) 

xp, yp = pupilCoordsFromFocalPlaneCoords(1.0, np.NaN, camera=lsst_camera()) 

self.assertTrue(np.isnan(xp)) 

self.assertTrue(np.isnan(yp)) 

 

x = np.array([1,2,3,4]) 

y = np.array([5,6,7,8]) 

xp, yp = pupilCoordsFromFocalPlaneCoords(x, y, camera=lsst_camera()) 

for xx, yy in zip(xp, yp): 

self.assertFalse(np.isnan(xx)) 

self.assertFalse(np.isnan(yy)) 

 

x = np.array([np.NaN,2,3,4]) 

y = np.array([5,np.NaN,7,8]) 

xp, yp = pupilCoordsFromFocalPlaneCoords(x, y, camera=lsst_camera()) 

self.assertTrue(np.isnan(xp[0])) 

self.assertTrue(np.isnan(yp[0])) 

self.assertTrue(np.isnan(xp[1])) 

self.assertTrue(np.isnan(yp[1])) 

for ii in range(2,4): 

self.assertFalse(np.isnan(xp[ii])) 

self.assertFalse(np.isnan(yp[ii])) 

 

del lsst_camera._lsst_camera 

 

 

class ConversionFromPixelTest(unittest.TestCase): 

 

@classmethod 

def setUpClass(cls): 

cls.camera = LsstSimMapper().camera 

 

@classmethod 

def tearDownClass(cls): 

del cls.camera 

 

def setUp(self): 

self.rng = np.random.RandomState(543) 

 

def testPupCoordsException(self): 

""" 

Test that pupilCoordsFromPixelCoords raises an exception when you 

call it without a camera 

""" 

nStars = 100 

xPupList = radiansFromArcsec((self.rng.random_sample(nStars)-0.5)*320.0) 

yPupList = radiansFromArcsec((self.rng.random_sample(nStars)-0.5)*320.0) 

chipNameList = chipNameFromPupilCoords(xPupList, yPupList, camera=self.camera) 

xPix, yPix = pixelCoordsFromPupilCoords(xPupList, yPupList, camera=self.camera) 

with self.assertRaises(RuntimeError) as context: 

xPupTest, yPupTest = pupilCoordsFromPixelCoords(xPix, yPix, chipNameList) 

self.assertEqual(context.exception.args[0], 

"You cannot call pupilCoordsFromPixelCoords without specifying " 

"a camera") 

 

def testPupCoordsResults(self): 

""" 

Test that the results from pupilCoordsFromPixelCoords are consistent 

with the results from pixelCoordsFromPupilCoords 

""" 

 

nStars = 100 

xPupList = radiansFromArcsec((self.rng.random_sample(nStars)-0.5)*320.0) 

yPupList = radiansFromArcsec((self.rng.random_sample(nStars)-0.5)*320.0) 

chipNameList = chipNameFromPupilCoords(xPupList, yPupList, camera=self.camera) 

for includeDistortion in [True, False]: 

xPix, yPix = pixelCoordsFromPupilCoords(xPupList, yPupList, camera=self.camera, 

includeDistortion=includeDistortion) 

xPupTest, yPupTest = pupilCoordsFromPixelCoords(xPix, yPix, chipNameList, camera=self.camera, 

includeDistortion=includeDistortion) 

 

dx = arcsecFromRadians(xPupTest-xPupList) 

np.testing.assert_array_almost_equal(dx, np.zeros(len(dx)), 9) 

dy = arcsecFromRadians(yPupTest-yPupList) 

np.testing.assert_array_almost_equal(dy, np.zeros(len(dy)), 9) 

 

ctNaN = 0 

for x, y in zip(xPupTest, yPupTest): 

if np.isnan(x) or np.isnan(y): 

ctNaN += 1 

self.assertLess(ctNaN, len(xPupTest)/10) 

 

# test passing in pixel coordinates one at a time 

for ix in range(len(xPupList)): 

xp_f, yp_f = pupilCoordsFromPixelCoords(xPix[ix], yPix[ix], chipNameList[ix], 

camera=self.camera, 

includeDistortion=includeDistortion) 

 

self.assertIsInstance(xp_f, np.float) 

self.assertIsInstance(yp_f, np.float) 

self.assertAlmostEqual(xp_f, xPupTest[ix], 12) 

self.assertAlmostEqual(yp_f, yPupTest[ix], 12) 

 

def testPupCoordsNaN(self): 

""" 

Test that points which do not have a chip return NaN for pupilCoordsFromPixelCoords 

""" 

nStars = 10 

xPupList = radiansFromArcsec((self.rng.random_sample(nStars)-0.5)*320.0) 

yPupList = radiansFromArcsec((self.rng.random_sample(nStars)-0.5)*320.0) 

chipNameList = chipNameFromPupilCoords(xPupList, yPupList, camera=self.camera) 

chipNameList[5] = None 

xPix, yPix = pixelCoordsFromPupilCoords(xPupList, yPupList, camera=self.camera) 

xPupTest, yPupTest = pupilCoordsFromPixelCoords(xPix, yPix, chipNameList, camera=self.camera) 

np.testing.assert_equal(xPupTest[5], np.NaN) 

np.testing.assert_equal(yPupTest[5], np.NaN) 

 

def testRaDecExceptions(self): 

""" 

Test that raDecFromPupilCoords raises exceptions when it is supposed to 

""" 

nStars = 20 

ra0 = 45.0 

dec0 = -19.0 

obs = ObservationMetaData(pointingRA=ra0, pointingDec=dec0, 

mjd=43525.0, rotSkyPos=145.0) 

 

xPixList = self.rng.random_sample(nStars)*4000.0 

yPixList = self.rng.random_sample(nStars)*4000.0 

 

chipDexList = self.rng.randint(0, len(self.camera), nStars) 

camera_detector_keys = list([det.getName() for det in self.camera]) 

self.assertGreater(len(camera_detector_keys), 0) 

chipNameList = [self.camera[camera_detector_keys[ii]].getName() for ii in chipDexList] 

 

# test that an error is raised if you do not pass in a camera 

with self.assertRaises(RuntimeError) as context: 

ra, dec = raDecFromPixelCoords(xPixList, yPixList, chipNameList, 

obs_metadata=obs, epoch=2000.0) 

self.assertEqual(context.exception.args[0], 

"You cannot call raDecFromPixelCoords without specifying a camera") 

 

with self.assertRaises(RuntimeError) as context: 

ra, dec = _raDecFromPixelCoords(xPixList, yPixList, chipNameList, 

obs_metadata=obs, epoch=2000.0) 

self.assertEqual(context.exception.args[0], 

"You cannot call raDecFromPixelCoords without specifying a camera") 

 

# test that an error is raised if you do not pass in an ObservationMetaData 

with self.assertRaises(RuntimeError) as context: 

ra, dec = raDecFromPixelCoords(xPixList, yPixList, chipNameList, 

epoch=2000.0, camera=self.camera) 

self.assertEqual(context.exception.args[0], 

"You cannot call raDecFromPixelCoords without an ObservationMetaData") 

 

# test that an error is raised if you do not pass in an ObservationMetaData 

with self.assertRaises(RuntimeError) as context: 

ra, dec = _raDecFromPixelCoords(xPixList, yPixList, chipNameList, 

epoch=2000.0, camera=self.camera) 

self.assertEqual(context.exception.args[0], 

"You cannot call raDecFromPixelCoords without an ObservationMetaData") 

 

# test that an error is raised if you pass in an ObservationMetaData 

# without an mjd 

obsDummy = ObservationMetaData(pointingRA=ra0, pointingDec=dec0, rotSkyPos=95.0) 

with self.assertRaises(RuntimeError) as context: 

ra, dec = raDecFromPixelCoords(xPixList, yPixList, chipNameList, 

obs_metadata=obsDummy, 

epoch=2000.0, camera=self.camera) 

self.assertEqual(context.exception.args[0], 

"The ObservationMetaData in raDecFromPixelCoords must have an mjd") 

 

with self.assertRaises(RuntimeError) as context: 

ra, dec = _raDecFromPixelCoords(xPixList, yPixList, chipNameList, 

obs_metadata=obsDummy, 

epoch=2000.0, camera=self.camera) 

self.assertEqual(context.exception.args[0], 

"The ObservationMetaData in raDecFromPixelCoords must have an mjd") 

 

# test that an error is raised if you pass in an ObservationMetaData 

# without a rotSkyPos 

obsDummy = ObservationMetaData(pointingRA=ra0, pointingDec=dec0, mjd=43243.0) 

with self.assertRaises(RuntimeError) as context: 

ra, dec = raDecFromPixelCoords(xPixList, yPixList, chipNameList, 

obs_metadata=obsDummy, 

epoch=2000.0, camera=self.camera) 

self.assertEqual(context.exception.args[0], 

"The ObservationMetaData in raDecFromPixelCoords must have a rotSkyPos") 

 

with self.assertRaises(RuntimeError) as context: 

ra, dec = _raDecFromPixelCoords(xPixList, yPixList, chipNameList, 

obs_metadata=obsDummy, 

epoch=2000.0, camera=self.camera) 

self.assertEqual(context.exception.args[0], 

"The ObservationMetaData in raDecFromPixelCoords must have a rotSkyPos") 

 

# test that an error is raised if you pass in lists of pixel coordinates, 

# rather than numpy arrays 

with self.assertRaises(RuntimeError) as context: 

ra, dec = raDecFromPixelCoords(list(xPixList), yPixList, 

chipNameList, obs_metadata=obs, 

epoch=2000.0, camera=self.camera) 

self.assertIn("The arg xPix", context.exception.args[0]) 

 

with self.assertRaises(RuntimeError) as context: 

ra, dec = raDecFromPixelCoords(xPixList, list(yPixList), 

chipNameList, obs_metadata=obs, 

epoch=2000.0, camera=self.camera) 

self.assertIn("The input arguments:", context.exception.args[0]) 

self.assertIn("yPix", context.exception.args[0]) 

 

with self.assertRaises(RuntimeError) as context: 

ra, dec = _raDecFromPixelCoords(list(xPixList), yPixList, 

chipNameList, obs_metadata=obs, 

epoch=2000.0, camera=self.camera) 

self.assertIn("The arg xPix", context.exception.args[0]) 

 

with self.assertRaises(RuntimeError) as context: 

ra, dec = _raDecFromPixelCoords(xPixList, list(yPixList), 

chipNameList, obs_metadata=obs, 

epoch=2000.0, camera=self.camera) 

self.assertIn("The input arguments:", context.exception.args[0]) 

self.assertIn("yPix", context.exception.args[0]) 

 

# test that an error is raised if you pass in mismatched lists of 

# xPix and yPix 

with self.assertRaises(RuntimeError) as context: 

ra, dec = raDecFromPixelCoords(xPixList, yPixList[0:13], chipNameList, 

obs_metadata=obs, epoch=2000.0, camera=self.camera) 

self.assertEqual(context.exception.args[0], 

"The arrays input to raDecFromPixelCoords all need to have the same length") 

 

with self.assertRaises(RuntimeError) as context: 

ra, dec = _raDecFromPixelCoords(xPixList, yPixList[0:13], chipNameList, 

obs_metadata=obs, epoch=2000.0, camera=self.camera) 

self.assertEqual(context.exception.args[0], 

"The arrays input to raDecFromPixelCoords all need to have the same length") 

 

# test that an error is raised if you do not pass in the same number of chipNames 

# as pixel coordinates 

with self.assertRaises(RuntimeError) as context: 

ra, dec = raDecFromPixelCoords(xPixList, yPixList, ['R:2,2 S:1,1']*22, 

obs_metadata=obs, epoch=2000.0, camera=self.camera) 

self.assertIn("22 chipNames", context.exception.args[0]) 

 

with self.assertRaises(RuntimeError) as context: 

ra, dec = _raDecFromPixelCoords(xPixList, yPixList, ['R:2,2 S:1,1']*22, 

obs_metadata=obs, epoch=2000.0, camera=self.camera) 

self.assertIn("22 chipNames", context.exception.args[0]) 

 

def testResults(self): 

""" 

Test that raDecFromPixelCoords results are consistent with 

pixelCoordsFromRaDec 

""" 

nStars = 200 

ra0 = 45.0 

dec0 = -19.0 

obs = ObservationMetaData(pointingRA=ra0, pointingDec=dec0, 

mjd=43525.0, rotSkyPos=145.0) 

 

xPixList = self.rng.random_sample(nStars)*3000.0 + 100 

yPixList = self.rng.random_sample(nStars)*3000.0 + 100 

 

#chipDexList = self.rng.randint(0, len(self.camera), nStars) 

chipDexList = self.rng.randint(0, 1, nStars) 

camera_detector_keys = list([det.getName() for det in self.camera]) 

self.assertGreater(len(camera_detector_keys), 0) 

chipNameList = [self.camera[camera_detector_keys[ii]].getName() for ii in chipDexList] 

 

for includeDistortion in [True, False]: 

 

raDeg, decDeg = raDecFromPixelCoords(xPixList, yPixList, chipNameList, obs_metadata=obs, 

epoch=2000.0, camera=self.camera, 

includeDistortion=includeDistortion) 

 

raRad, decRad = _raDecFromPixelCoords(xPixList, yPixList, chipNameList, obs_metadata=obs, 

epoch=2000.0, camera=self.camera, 

includeDistortion=includeDistortion) 

 

# first, make sure that the radians and degrees methods agree with each other 

dRa = arcsecFromRadians(raRad-np.radians(raDeg)) 

np.testing.assert_array_almost_equal(dRa, np.zeros(len(raRad)), 9) 

dDec = arcsecFromRadians(decRad-np.radians(decDeg)) 

np.testing.assert_array_almost_equal(dDec, np.zeros(len(decRad)), 9) 

 

# now make sure that the results from raDecFromPixelCoords are consistent 

# with the results from pixelCoordsFromRaDec by taking the ra and dec 

# arrays found above and feeding them back into pixelCoordsFromRaDec 

# and seeing if we get the same results 

xPixTest, yPixTest = pixelCoordsFromRaDec(raDeg, decDeg, obs_metadata=obs, 

epoch=2000.0, camera=self.camera, 

includeDistortion=includeDistortion) 

 

distance = np.sqrt(np.power(xPixTest-xPixList, 2) + np.power(yPixTest-yPixList, 2)) 

idx = np.where(np.isnan(distance)) 

self.assertLess(distance.max(), 0.2) # because of the imprecision in _icrsFromObserved, 

# this is the best we can get; note that, in our test 

# camera, each pixel is 10 microns in size and the 

# plate scale is 2 arcsec per mm, so 0.2 pixels is 

# 0.004 arcsec 

 

# test passing the pixel coordinates in one at a time 

for ix in range(len(xPixList)): 

ra_f, dec_f = raDecFromPixelCoords(xPixList[ix], yPixList[ix], 

chipNameList[ix], obs_metadata=obs, 

epoch=2000.0, camera=self.camera, 

includeDistortion=includeDistortion) 

self.assertIsInstance(ra_f, np.float) 

self.assertIsInstance(dec_f, np.float) 

self.assertAlmostEqual(ra_f, raDeg[ix], 12) 

self.assertAlmostEqual(dec_f, decDeg[ix], 12) 

 

def testResultsOffChip(self): 

""" 

Test that raDecFromPixelCoords results are consistent with 

pixelCoordsFromRaDec with chip names are specified 

 

Note: this is the same test as in testResults, except that 

we are going to intentionally make the pixel coordinate lists 

fall outside the boundaries of the chips defined in chipNameList 

""" 

nStars = 200 

ra0 = 45.0 

dec0 = -19.0 

obs = ObservationMetaData(pointingRA=ra0, pointingDec=dec0, 

mjd=43525.0, rotSkyPos=145.0) 

 

xPixList = self.rng.random_sample(nStars)*4000.0 + 4000.0 

yPixList = self.rng.random_sample(nStars)*4000.0 + 4000.0 

 

chipDexList = self.rng.randint(0, len(self.camera), nStars) 

camera_detector_keys = list([det.getName() for det in self.camera]) 

self.assertGreater(len(camera_detector_keys), 0) 

chipNameList = [self.camera[camera_detector_keys[ii]].getName() for ii in chipDexList] 

 

for includeDistortion in [True, False]: 

 

raDeg, decDeg = raDecFromPixelCoords(xPixList, yPixList, chipNameList, obs_metadata=obs, 

epoch=2000.0, camera=self.camera, 

includeDistortion=includeDistortion) 

 

raRad, decRad = _raDecFromPixelCoords(xPixList, yPixList, chipNameList, obs_metadata=obs, 

epoch=2000.0, camera=self.camera, 

includeDistortion=includeDistortion) 

 

# first, make sure that the radians and degrees methods agree with each other 

dRa = arcsecFromRadians(raRad-np.radians(raDeg)) 

np.testing.assert_array_almost_equal(dRa, np.zeros(len(raRad)), 9) 

dDec = arcsecFromRadians(decRad-np.radians(decDeg)) 

np.testing.assert_array_almost_equal(dDec, np.zeros(len(decRad)), 9) 

 

# now make sure that the results from raDecFromPixelCoords are consistent 

# with the results from pixelCoordsFromRaDec by taking the ra and dec 

# arrays found above and feeding them back into pixelCoordsFromRaDec 

# and seeing if we get the same results 

xPixTest, yPixTest = pixelCoordsFromRaDec(raDeg, decDeg, chipName=chipNameList, 

obs_metadata=obs, 

epoch=2000.0, 

camera=self.camera, 

includeDistortion=includeDistortion) 

 

distance = np.sqrt(np.power(xPixTest-xPixList, 2) + np.power(yPixTest-yPixList, 2)) 

self.assertLess(distance.max(), 0.2) # because of the imprecision in _icrsFromObserved, 

# this is the best we can get; note that, in our 

# test camera, each pixel is 10 microns in size and 

# the plate scale is 2 arcsec per mm, so 0.2 pixels is 

# 0.004 arcsec 

 

def testDistortion(self): 

""" 

Make sure that the results from pupilCoordsFromPixelCoords are different 

if includeDistortion is True as compared to if includeDistortion is False 

 

Note: This test passes because the test camera has a pincushion distortion. 

If we take that away, the test will no longer pass. 

""" 

nStars = 200 

xPixList = self.rng.random_sample(nStars)*4000.0 + 4000.0 

yPixList = self.rng.random_sample(nStars)*4000.0 + 4000.0 

 

chipDexList = self.rng.randint(0, len(self.camera), nStars) 

camera_detector_keys = list([det.getName() for det in self.camera]) 

self.assertGreater(len(camera_detector_keys), 0) 

chipNameList = [self.camera[camera_detector_keys[ii]].getName() for ii in chipDexList] 

 

xu, yu = pupilCoordsFromPixelCoords(xPixList, yPixList, chipNameList, camera=self.camera, 

includeDistortion=False) 

 

xd, yd = pupilCoordsFromPixelCoords(xPixList, yPixList, chipNameList, camera=self.camera, 

includeDistortion=True) 

 

# just verify that the distorted versus undistorted coordinates vary in the 4th decimal 

self.assertRaises(AssertionError, 

np.testing.assert_array_almost_equal, 

arcsecFromRadians(xu), 

arcsecFromRadians(xd), 

4) 

 

self.assertRaises(AssertionError, 

np.testing.assert_array_almost_equal, 

arcsecFromRadians(yu), 

arcsecFromRadians(yd), 

4) 

 

 

class CornerTest(unittest.TestCase): 

 

@classmethod 

def setUpClass(cls): 

cls.camera = LsstSimMapper().camera 

 

@classmethod 

def tearDownClass(cls): 

del cls.camera 

 

def testCornerPixels(self): 

""" 

Test the method to get the pixel coordinates of the corner 

of a detector 

""" 

det_name = self.camera[12].getName() 

corners = getCornerPixels(det_name, self.camera) 

# [(0, 0), (0, 3999), (4071, 0), (4071, 3999)] 

self.assertEqual(corners[0][0], 0) 

self.assertEqual(corners[0][1], 0) 

self.assertEqual(corners[1][0], 0) 

self.assertEqual(corners[1][1], 3999) 

self.assertEqual(corners[2][0], 4071) 

self.assertEqual(corners[2][1], 0) 

self.assertEqual(corners[3][0], 4071) 

self.assertEqual(corners[3][1], 3999) 

self.assertEqual(len(corners), 4) 

for row in corners: 

self.assertEqual(len(row), 2) 

 

def testCornerRaDec_radians(self): 

""" 

Test that the method to return the Ra, Dec values of the corner 

of a chip (in radians) works by validating its results against 

known pixel corner values and the _raDecFromPixelCoords method, 

which is tested separately. 

""" 

obs = ObservationMetaData(pointingRA=23.0, pointingDec=-65.0, 

rotSkyPos=52.1, mjd=59582.3) 

 

det_name = self.camera[12].getName() 

cornerTest = _getCornerRaDec(det_name, self.camera, obs) 

 

ra_control, dec_control = _raDecFromPixelCoords(np.array([0, 0, 4071, 4071]), 

np.array([0, 3999, 0, 3999]), 

[det_name]*4, 

camera=self.camera, 

obs_metadata=obs, 

epoch=2000.0, includeDistortion=True) 

 

# Loop over the control values and the corner values, using 

# haversine() method to find the angular distance between the 

# test and control values. Assert that they are within 

# 0.01 milli-arcsecond of each other 

for rr1, dd1, cc in zip(ra_control, dec_control, cornerTest): 

dd = haversine(rr1, dd1, cc[0], cc[1]) 

self.assertLess(arcsecFromRadians(dd), 0.00001) 

 

def testCornerRaDec_degrees(self): 

""" 

Test that method to get corner RA, Dec in degrees is consistent 

with method to get corner RA, Dec in radians 

""" 

 

obs = ObservationMetaData(pointingRA=31.0, pointingDec=-45.0, 

rotSkyPos=46.2, mjd=59583.4) 

 

det_name = self.camera[1101].getName() 

 

cornerRad = _getCornerRaDec(det_name, self.camera, obs) 

cornerDeg = getCornerRaDec(det_name, self.camera, obs) 

for cc1, cc2 in zip(cornerRad, cornerDeg): 

dd = haversine(cc1[0], cc1[1], np.radians(cc2[0]), np.radians(cc2[1])) 

self.assertLess(arcsecFromRadians(dd), 0.000001) 

 

 

class MotionTestCase(unittest.TestCase): 

""" 

This class will contain test methods to verify that the camera utils 

work when proper motion, parallax, and radial velocity are not None. 

""" 

 

@classmethod 

def setUpClass(cls): 

cls.camera = LsstSimMapper().camera 

 

@classmethod 

def tearDownClass(cls): 

del cls.camera 

 

def set_data(self, seed): 

""" 

Accept a seed integer. Return an ObservationMetaData 

and numpy arrays of RA, Dec (in degrees), 

pm_ra, pm_dec, parallax (in arcsec) and v_rad (in km/s) 

centered on that bore site. 

""" 

rng = np.random.RandomState(seed) 

n_obj = 100 

ra = 23.1 

dec = -15.6 

rotSkyPos = 23.56 

mjd = 59723.2 

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

rotSkyPos=rotSkyPos, mjd=mjd) 

# Distribute objects out to rr degrees from ra/dec 

rr = rng.random_sample(n_obj)*2 

theta = rng.random_sample(n_obj)*2.0*np.pi 

ra_list = ra + rr*np.cos(theta) 

dec_list = dec + rr*np.sin(theta) 

pm_ra = rng.random_sample(n_obj)*20.0 - 10.0 

pm_dec = rng.random_sample(n_obj)*20.0 - 10.0 

parallax = rng.random_sample(n_obj)*1.0 - 0.5 

v_rad = rng.random_sample(n_obj)*600.0 - 300.0 

return obs, ra_list, dec_list, pm_ra, pm_dec, parallax, v_rad 

 

def test_chip_name(self): 

""" 

Test that chipNameFromRaDec with non-zero proper motion etc. 

agrees with chipNameFromPupilCoords when pupilCoords are 

calculated with the same proper motion, etc. 

""" 

(obs, ra_list, dec_list, 

pm_ra_list, pm_dec_list, 

parallax_list, v_rad_list) = self.set_data(8231) 

 

for is_none in ('pm_ra', 'pm_dec', 'parallax', 'v_rad'): 

pm_ra = pm_ra_list 

pm_dec = pm_dec_list 

parallax = parallax_list 

v_rad = v_rad_list 

 

if is_none == 'pm_ra': 

pm_ra = None 

elif is_none == 'pm_dec': 

pm_dec = None 

elif is_none == 'parallax': 

parallax = None 

elif is_none == 'v_rad': 

v_rad = None 

 

xp, yp = pupilCoordsFromRaDec(ra_list, dec_list, 

pm_ra=pm_ra, pm_dec=pm_dec, 

parallax=parallax, v_rad=v_rad, 

obs_metadata=obs) 

 

name_control = chipNameFromPupilCoords(xp, yp, camera=self.camera) 

 

name_test = chipNameFromRaDec(ra_list, dec_list, 

pm_ra=pm_ra, pm_dec=pm_dec, 

parallax=parallax, v_rad=v_rad, 

obs_metadata=obs, camera=self.camera) 

 

name_radians = _chipNameFromRaDec(np.radians(ra_list), np.radians(dec_list), 

pm_ra=radiansFromArcsec(pm_ra), 

pm_dec=radiansFromArcsec(pm_dec), 

parallax=radiansFromArcsec(parallax), v_rad=v_rad, 

obs_metadata=obs, camera=self.camera) 

 

np.testing.assert_array_equal(name_control, name_test) 

np.testing.assert_array_equal(name_control, name_radians) 

self.assertGreater(len(np.unique(name_control.astype(str))), 4) 

self.assertLess(len(np.where(np.equal(name_control, None))[0]), 2*len(name_control)/3) 

 

def test_pixel_coords(self): 

""" 

Test that pixelCoordsFromRaDec with non-zero proper motion etc. 

agrees with pixelCoordsFromPupilCoords when pupilCoords are 

calculated with the same proper motion, etc. 

""" 

(obs, ra_list, dec_list, 

pm_ra_list, pm_dec_list, 

parallax_list, v_rad_list) = self.set_data(72) 

 

for is_none in ('pm_ra', 'pm_dec', 'parallax', 'v_rad'): 

pm_ra = pm_ra_list 

pm_dec = pm_dec_list 

parallax = parallax_list 

v_rad = v_rad_list 

 

if is_none == 'pm_ra': 

pm_ra = None 

elif is_none == 'pm_dec': 

pm_dec = None 

elif is_none == 'parallax': 

parallax = None 

elif is_none == 'v_rad': 

v_rad = None 

 

xp, yp = pupilCoordsFromRaDec(ra_list, dec_list, 

pm_ra=pm_ra, pm_dec=pm_dec, 

parallax=parallax, v_rad=v_rad, 

obs_metadata=obs) 

 

xpx_control, ypx_control = pixelCoordsFromPupilCoords(xp, yp, camera=self.camera) 

 

xpx_test, ypx_test = pixelCoordsFromRaDec(ra_list, dec_list, 

pm_ra=pm_ra, pm_dec=pm_dec, 

parallax=parallax, v_rad=v_rad, 

obs_metadata=obs, camera=self.camera) 

 

xpx_radians, ypx_radians = _pixelCoordsFromRaDec(np.radians(ra_list), np.radians(dec_list), 

pm_ra=radiansFromArcsec(pm_ra), 

pm_dec=radiansFromArcsec(pm_dec), 

parallax=radiansFromArcsec(parallax), 

v_rad=v_rad, 

obs_metadata=obs, camera=self.camera) 

 

np.testing.assert_array_equal(xpx_control, xpx_test) 

np.testing.assert_array_equal(ypx_control, ypx_test) 

np.testing.assert_array_equal(xpx_control, xpx_radians) 

np.testing.assert_array_equal(ypx_control, ypx_radians) 

self.assertLess(len(np.where(np.isnan(xpx_control))[0]), 2*len(xpx_control)/3) 

 

def test_focal_plane_coords(self): 

""" 

Test that focalPlaneCoordsFromRaDec with non-zero proper motion etc. 

agrees with focalPlaneCoordsFromPupilCoords when pupilCoords are 

calculated with the same proper motion, etc. 

""" 

(obs, ra_list, dec_list, 

pm_ra_list, pm_dec_list, 

parallax_list, v_rad_list) = self.set_data(72) 

 

for is_none in ('pm_ra', 'pm_dec', 'parallax', 'v_rad'): 

pm_ra = pm_ra_list 

pm_dec = pm_dec_list 

parallax = parallax_list 

v_rad = v_rad_list 

 

if is_none == 'pm_ra': 

pm_ra = None 

elif is_none == 'pm_dec': 

pm_dec = None 

elif is_none == 'parallax': 

parallax = None 

elif is_none == 'v_rad': 

v_rad = None 

 

xp, yp = pupilCoordsFromRaDec(ra_list, dec_list, 

pm_ra=pm_ra, pm_dec=pm_dec, 

parallax=parallax, v_rad=v_rad, 

obs_metadata=obs) 

 

xf_control, yf_control = focalPlaneCoordsFromPupilCoords(xp, yp, camera=self.camera) 

 

xf_test, yf_test = focalPlaneCoordsFromRaDec(ra_list, dec_list, 

pm_ra=pm_ra, pm_dec=pm_dec, 

parallax=parallax, v_rad=v_rad, 

obs_metadata=obs, camera=self.camera) 

 

xf_radians, yf_radians = _focalPlaneCoordsFromRaDec(np.radians(ra_list), np.radians(dec_list), 

pm_ra=radiansFromArcsec(pm_ra), 

pm_dec=radiansFromArcsec(pm_dec), 

parallax=radiansFromArcsec(parallax), 

v_rad=v_rad, obs_metadata=obs, 

camera=self.camera) 

 

np.testing.assert_array_equal(xf_control, xf_test) 

np.testing.assert_array_equal(yf_control, yf_test) 

np.testing.assert_array_equal(xf_control, xf_radians) 

np.testing.assert_array_equal(yf_control, yf_radians) 

self.assertEqual(len(np.where(np.isnan(xf_control))[0]), 0) 

self.assertEqual(len(np.where(np.isnan(yf_control))[0]), 0) 

 

 

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

pass 

 

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

lsst.utils.tests.init() 

unittest.main()