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

""" 

This module provides wrappers for afwCameraGeom camera objects. 

This is necessary because of a 90-degree rotation between how 

the LSST Data Management software team defines coordinate 

axes on the focal plane and how the LSST Camera team defines 

coorindate axes on the focal plane. Specifically 

 

Camera +y = DM +x 

Camera +x = DM -y 

 

Because we want ImSim images to have the same WCS conventions 

as PhoSim e-images, we need to apply this rotation to the 

mappings between RA, Dec and pixel coordinates. We may not 

wish to do that for arbitrary cameras, so we will give 

users the ability to apply a no-op wrapper to their cameras. 

 

The class LSSTCameraWrapper applies this transformation. 

In cases where users do not wish to apply any transformation 

to their pixel coordinate system, the class GalSimCameraWrapper 

provides the same API as LSSTCamerWrapper, but treats the 

software-based pixel coordinates as truth. 

 

In order to implement your own camera wrapper, create a python 

class that inherits from GalSimCameraWrapper. This class will 

need: 

 

- a property self.camera that is an afwCamerGeom camera object 

 

- a method getBBox() that returns the bounding box in pixel space 

of a detector, given that detector's name 

 

- a method getCenterPixel() that returns the central pixel of a 

detector, given that detector's name 

 

- a method getCenterPupil() that returns the pupil coordinates 

(or field angle) in radians of the center of a detector given 

that detector's name 

 

- a method getCornerPupilList that returns the pupil coordinates 

(or field angles) in radians of the corners of a detector given 

that detector's name 

 

- a method getTanPixelBounds() that returns the minimum and maximum 

x and y pixel values of a detector, ignoring radial distortions, 

given that detector's name 

 

- wrappers to the corresponding methods in lsst.sims.coordUtils that 

use the self.camera property and apply the necessary transformations 

to pixel space coordinates: 

pixelCoordsFromPupilCoords() 

pupilCoordsFromPixelCoords() 

pixelCoordsFromRaDec() 

_pixelCoordsFromRaDec() 

raDecFromPixelCoords() 

_raDecFromPixelCoords() 

""" 

 

import numpy as np 

from lsst.afw.cameraGeom import FOCAL_PLANE, PIXELS, TAN_PIXELS 

from lsst.afw.cameraGeom import FIELD_ANGLE 

import lsst.geom as LsstGeom 

import lsst.sims.coordUtils as coordUtils 

import lsst.sims.utils as simsUtils 

 

__all__ = ["GalSimCameraWrapper", "LSSTCameraWrapper"] 

 

class GalSimCameraWrapper(object): 

""" 

This is a no-op camera wrapper. 

""" 

 

def __init__(self, camera): 

""" 

Parameters 

---------- 

camera is an instantiation of an afwCameraGeom camera 

""" 

self._camera = camera 

 

@property 

def camera(self): 

return self._camera 

 

@property 

def focal_to_field(self): 

""" 

Transformation to go from FOCAL_PLANE to FIELD_ANGLE 

""" 

if not hasattr(self, '_focal_to_field'): 

self._focal_to_field = self.camera.getTransformMap().getTransform(FOCAL_PLANE, FIELD_ANGLE) 

return self._focal_to_field 

 

def getBBox(self, detector_name): 

""" 

Return the bounding box for the detector named by detector_name 

""" 

return self._camera[detector_name].getBBox() 

 

def getCenterPixel(self, detector_name): 

""" 

Return the central pixel for the detector named by detector_name 

""" 

if not hasattr(self, '_center_pixel_cache'): 

self._center_pixel_cache = {} 

 

if detector_name not in self._center_pixel_cache: 

centerPoint = self._camera[detector_name].getCenter(FOCAL_PLANE) 

centerPixel = self._camera[detector_name].getTransform(FOCAL_PLANE, PIXELS).applyForward(centerPoint) 

self._center_pixel_cache[detector_name] = centerPixel 

 

return self._center_pixel_cache[detector_name] 

 

def getCenterPupil(self, detector_name): 

""" 

Return the pupil coordinates of the center of the named detector 

as an LsstGeom.Point2D 

""" 

if not hasattr(self, '_center_pupil_cache'): 

self._center_pupil_cache = {} 

 

if detector_name not in self._center_pupil_cache: 

dd = self._camera[detector_name] 

centerPoint = dd.getCenter(FOCAL_PLANE) 

pupilPoint = self.focal_to_field.applyForward(centerPoint) 

self._center_pupil_cache[detector_name] = pupilPoint 

 

return self._center_pupil_cache[detector_name] 

 

def getCornerPupilList(self, detector_name): 

""" 

Return a list of the pupil coordinates of the corners of the named 

detector as a list of LsstGeom.Point2D objects 

""" 

if not hasattr(self, '_corner_pupil_cache'): 

self._corner_pupil_cache = {} 

 

if detector_name not in self._corner_pupil_cache: 

dd = self._camera[detector_name] 

cornerPointList = dd.getCorners(FOCAL_PLANE) 

pupil_point_list = self.focal_to_field.applyForward(cornerPointList) 

self._corner_pupil_cache[detector_name] = pupil_point_list 

 

return self._corner_pupil_cache[detector_name] 

 

def getTanPixelBounds(self, detector_name): 

""" 

Return the min and max pixel values of a detector, assuming 

all radial distortions are set to zero (i.e. using the afwCameraGeom 

TAN_PIXELS coordinate system) 

 

Parameters 

---------- 

detector_name is a string denoting the name of the detector 

 

Returns 

------- 

xmin, xmax, ymin, ymax pixel values 

""" 

if not hasattr(self, '_tan_pixel_bounds_cache'): 

self._tan_pixel_bounds_cache = {} 

 

if detector_name not in self._tan_pixel_bounds_cache: 

afwDetector = self._camera[detector_name] 

focal_to_tan_pix = afwDetector.getTransform(FOCAL_PLANE, TAN_PIXELS) 

xPixMin = None 

xPixMax = None 

yPixMin = None 

yPixMax = None 

cornerPointList = focal_to_tan_pix.applyForward(afwDetector.getCorners(FOCAL_PLANE)) 

for cornerPoint in cornerPointList: 

xx = cornerPoint.getX() 

yy = cornerPoint.getY() 

if xPixMin is None or xx < xPixMin: 

xPixMin = xx 

if xPixMax is None or xx > xPixMax: 

xPixMax = xx 

if yPixMin is None or yy < yPixMin: 

yPixMin = yy 

if yPixMax is None or yy > yPixMax: 

yPixMax = yy 

 

self._tan_pixel_bounds_cache[detector_name] = (xPixMin, xPixMax, yPixMin, yPixMax) 

 

return self._tan_pixel_bounds_cache[detector_name] 

 

def pixelCoordsFromPupilCoords(self, xPupil, yPupil, chipName, obs_metadata, 

includeDistortion=True): 

""" 

Get the pixel positions (or nan if not on a chip) for objects based 

on their pupil coordinates. 

 

Parameters 

--------- 

xPupil is the x pupil coordinates in radians. Can be either a float 

or a numpy array. 

 

yPupil is the y pupil coordinates in radians. Can be either a float 

or a numpy array. 

 

chipName designates the names of the chips on which the pixel 

coordinates will be reckoned. Can be either single value, an array, or None. 

If an array, there must be as many chipNames as there are (RA, Dec) pairs. 

If a single value, all of the pixel coordinates will be reckoned on the same 

chip. If None, this method will calculate which chip each(RA, Dec) pair actually 

falls on, and return pixel coordinates for each (RA, Dec) pair on the appropriate 

chip. 

 

obs_metadata is an ObservationMetaData characterizing the telescope 

pointing. 

 

includeDistortion is a boolean. If True (default), then this method will 

return the true pixel coordinates with optical distortion included. If False, this 

method will return TAN_PIXEL coordinates, which are the pixel coordinates with 

estimated optical distortion removed. See the documentation in afw.cameraGeom for more 

details. 

 

Returns 

------- 

a 2-D numpy array in which the first row is the x pixel coordinate 

and the second row is the y pixel coordinate 

""" 

if obs_metadata is None: 

raise RuntimeError("Must pass obs_metdata to " 

"cameraWrapper.pixelCoordsFromPupilCoords") 

 

return coordUtils.pixelCoordsFromPupilCoords(xPupil, yPupil, chipName=chipName, 

camera=self._camera, 

includeDistortion=includeDistortion) 

 

def pupilCoordsFromPixelCoords(self, xPix, yPix, chipName, obs_metadata, 

includeDistortion=True): 

 

""" 

Convert pixel coordinates into pupil coordinates 

 

Parameters 

---------- 

xPix is the x pixel coordinate of the point. 

Can be either a float or a numpy array. 

 

yPix is the y pixel coordinate of the point. 

Can be either a float or a numpy array. 

 

chipName is the name of the chip(s) on which the pixel coordinates 

are defined. This can be a list (in which case there should be one chip name 

for each (xPix, yPix) coordinate pair), or a single value (in which case, all 

of the (xPix, yPix) points will be reckoned on that chip). 

 

obs_metadata is an ObservationMetaData characterizing the telescope 

pointing. 

 

includeDistortion is a boolean. If True (default), then this method will 

expect the true pixel coordinates with optical distortion included. If False, this 

method will expect TAN_PIXEL coordinates, which are the pixel coordinates with 

estimated optical distortion removed. See the documentation in afw.cameraGeom for more 

details. 

 

Returns 

------- 

a 2-D numpy array in which the first row is the x pupil coordinate 

and the second row is the y pupil coordinate (both in radians) 

""" 

 

return coordUtils.pupilCoordsFromPixelCoords(xPix, yPix, chipName, 

camera=self._camera, 

includeDistortion=includeDistortion) 

 

def _raDecFromPixelCoords(self, xPix, yPix, chipName, obs_metadata, 

epoch=2000.0, includeDistortion=True): 

""" 

Convert pixel coordinates into RA, Dec 

 

Parameters 

---------- 

xPix is the x pixel coordinate. It can be either 

a float or a numpy array. 

 

yPix is the y pixel coordinate. It can be either 

a float or a numpy array. 

 

chipName is the name of the chip(s) on which the pixel coordinates 

are defined. This can be a list (in which case there should be one chip name 

for each (xPix, yPix) coordinate pair), or a single value (in which case, all 

of the (xPix, yPix) points will be reckoned on that chip). 

 

obs_metadata is an ObservationMetaData defining the pointing 

 

epoch is the mean epoch in years of the celestial coordinate system. 

Default is 2000. 

 

includeDistortion is a boolean. If True (default), then this method will 

expect the true pixel coordinates with optical distortion included. If False, this 

method will expect TAN_PIXEL coordinates, which are the pixel coordinates with 

estimated optical distortion removed. See the documentation in afw.cameraGeom for more 

details. 

 

Returns 

------- 

a 2-D numpy array in which the first row is the RA coordinate 

and the second row is the Dec coordinate (both in radians; in the 

International Celestial Reference System) 

 

WARNING: This method does not account for apparent motion due to parallax. 

This method is only useful for mapping positions on a theoretical focal plane 

to positions on the celestial sphere. 

""" 

 

return coordUtils._raDecFromPixelCoords(xPix, yPix, chipName, 

camera=self._camera, 

obs_metadata=obs_metadata, 

epoch=epoch, 

includeDistortion=includeDistortion) 

 

def raDecFromPixelCoords(self, xPix, yPix, chipName, obs_metadata, 

epoch=2000.0, includeDistortion=True): 

 

""" 

Convert pixel coordinates into RA, Dec 

 

Parameters 

---------- 

xPix is the x pixel coordinate. It can be either 

a float or a numpy array. 

 

yPix is the y pixel coordinate. It can be either 

a float or a numpy array. 

 

chipName is the name of the chip(s) on which the pixel coordinates 

are defined. This can be a list (in which case there should be one chip name 

for each (xPix, yPix) coordinate pair), or a single value (in which case, all 

of the (xPix, yPix) points will be reckoned on that chip). 

 

obs_metadata is an ObservationMetaData defining the pointing 

 

epoch is the mean epoch in years of the celestial coordinate system. 

Default is 2000. 

 

includeDistortion is a boolean. If True (default), then this method will 

expect the true pixel coordinates with optical distortion included. If False, this 

method will expect TAN_PIXEL coordinates, which are the pixel coordinates with 

estimated optical distortion removed. See the documentation in afw.cameraGeom for more 

details. 

 

Returns 

------- 

a 2-D numpy array in which the first row is the RA coordinate 

and the second row is the Dec coordinate (both in degrees; in the 

International Celestial Reference System) 

 

WARNING: This method does not account for apparent motion due to parallax. 

This method is only useful for mapping positions on a theoretical focal plane 

to positions on the celestial sphere. 

""" 

 

return coordUtils.raDecFromPixelCoords(xPix, yPix, chipName, 

camera=self._camera, 

obs_metadata=obs_metadata, 

epoch=2000.0, includeDistortion=True) 

 

def _pixelCoordsFromRaDec(self, ra, dec, pm_ra=None, pm_dec=None, 

parallax=None, v_rad=None, 

obs_metadata=None, 

chipName=None, 

epoch=2000.0, includeDistortion=True): 

""" 

Get the pixel positions (or nan if not on a chip) for objects based 

on their RA, and Dec (in radians) 

 

Parameters 

---------- 

ra is in radians in the International Celestial Reference System. 

Can be either a float or a numpy array. 

 

dec is in radians in the International Celestial Reference System. 

Can be either a float or a numpy array. 

 

pm_ra is proper motion in RA multiplied by cos(Dec) (radians/yr) 

Can be a numpy array or a number or None (default=None). 

 

pm_dec is proper motion in dec (radians/yr) 

Can be a numpy array or a number or None (default=None). 

 

parallax is parallax in radians 

Can be a numpy array or a number or None (default=None). 

 

v_rad is radial velocity (km/s) 

Can be a numpy array or a number or None (default=None). 

 

obs_metadata is an ObservationMetaData characterizing the telescope 

pointing. 

 

epoch is the epoch in Julian years of the equinox against which 

RA is measured. Default is 2000. 

 

chipName designates the names of the chips on which the pixel 

coordinates will be reckoned. Can be either single value, an array, or None. 

If an array, there must be as many chipNames as there are (RA, Dec) pairs. 

If a single value, all of the pixel coordinates will be reckoned on the same 

chip. If None, this method will calculate which chip each(RA, Dec) pair actually 

falls on, and return pixel coordinates for each (RA, Dec) pair on the appropriate 

chip. Default is None. 

 

includeDistortion is a boolean. If True (default), then this method will 

return the true pixel coordinates with optical distortion included. If False, this 

method will return TAN_PIXEL coordinates, which are the pixel coordinates with 

estimated optical distortion removed. See the documentation in afw.cameraGeom for more 

details. 

 

Returns 

------- 

a 2-D numpy array in which the first row is the x pixel coordinate 

and the second row is the y pixel coordinate 

""" 

 

return coordUtils._pixelCoordsFromRaDec(ra, dec, pm_ra=pm_ra, pm_dec=pm_dec, 

parallax=parallax, v_rad=v_rad, 

obs_metadata=obs_metadata, 

chipName=chipName, camera=self._camera, 

epoch=epoch, includeDistortion=includeDistortion) 

 

def pixelCoordsFromRaDec(self, ra, dec, pm_ra=None, pm_dec=None, parallax=None, v_rad=None, 

obs_metadata=None, 

chipName=None, camera=None, 

epoch=2000.0, includeDistortion=True): 

""" 

Get the pixel positions (or nan if not on a chip) for objects based 

on their RA, and Dec (in degrees) 

 

Parameters 

---------- 

ra is in degrees in the International Celestial Reference System. 

Can be either a float or a numpy array. 

 

dec is in degrees in the International Celestial Reference System. 

Can be either a float or a numpy array. 

 

pm_ra is proper motion in RA multiplied by cos(Dec) (arcsec/yr) 

Can be a numpy array or a number or None (default=None). 

 

pm_dec is proper motion in dec (arcsec/yr) 

Can be a numpy array or a number or None (default=None). 

 

parallax is parallax in arcsec 

Can be a numpy array or a number or None (default=None). 

 

v_rad is radial velocity (km/s) 

Can be a numpy array or a number or None (default=None). 

 

obs_metadata is an ObservationMetaData characterizing the telescope 

pointing. 

 

epoch is the epoch in Julian years of the equinox against which 

RA is measured. Default is 2000. 

 

chipName designates the names of the chips on which the pixel 

coordinates will be reckoned. Can be either single value, an array, or None. 

If an array, there must be as many chipNames as there are (RA, Dec) pairs. 

If a single value, all of the pixel coordinates will be reckoned on the same 

chip. If None, this method will calculate which chip each(RA, Dec) pair actually 

falls on, and return pixel coordinates for each (RA, Dec) pair on the appropriate 

chip. Default is None. 

 

includeDistortion is a boolean. If True (default), then this method will 

return the true pixel coordinates with optical distortion included. If False, this 

method will return TAN_PIXEL coordinates, which are the pixel coordinates with 

estimated optical distortion removed. See the documentation in afw.cameraGeom for more 

details. 

 

Returns 

------- 

a 2-D numpy array in which the first row is the x pixel coordinate 

and the second row is the y pixel coordinate 

""" 

 

return coordUtils.pixelCoordsFromRaDec(ra, dec, pm_ra=pm_ra, pm_dec=pm_dec, 

parallax=parallax, v_rad=v_rad, 

obs_metadata=obs_metadata, 

chipName=chipName, camera=self._camera, 

epoch=epoch, includeDistortion=includeDistortion) 

 

 

 

class LSSTCameraWrapper(coordUtils.DMtoCameraPixelTransformer, 

GalSimCameraWrapper): 

 

def getTanPixelBounds(self, detector_name): 

""" 

Return the min and max pixel values of a detector, assuming 

all radial distortions are set to zero (i.e. using the afwCameraGeom 

TAN_PIXELS coordinate system) 

 

Parameters 

---------- 

detector_name is a string denoting the name of the detector 

 

Returns 

------- 

xmin, xmax, ymin, ymax pixel values 

""" 

if not hasattr(self, '_tan_pixel_bounds_cache'): 

self._tan_pixel_bounds_cache = {} 

 

if detector_name not in self._tan_pixel_bounds_cache: 

dm_xmin, dm_xmax, dm_ymin, dm_ymax = GalSimCameraWrapper.getTanPixelBounds(self, detector_name) 

self._tan_pixel_bounds_cache[detector_name] = (dm_ymin, dm_ymax, dm_xmin, dm_xmax) 

 

return self._tan_pixel_bounds_cache[detector_name] 

 

def pixelCoordsFromPupilCoords(self, xPupil, yPupil, chipName, obs_metadata, 

includeDistortion=True): 

""" 

Get the pixel positions (or nan if not on a chip) for objects based 

on their pupil coordinates. 

 

Paramters 

--------- 

xPupil is the x pupil coordinates in radians. Can be either a float 

or a numpy array. 

 

yPupil is the y pupil coordinates in radians. Can be either a float 

or a numpy array. 

 

chipName designates the names of the chips on which the pixel 

coordinates will be reckoned. Can be either single value, an array, or None. 

If an array, there must be as many chipNames as there are (RA, Dec) pairs. 

If a single value, all of the pixel coordinates will be reckoned on the same 

chip. If None, this method will calculate which chip each(RA, Dec) pair actually 

falls on, and return pixel coordinates for each (RA, Dec) pair on the appropriate 

chip. 

 

obs_metadata is an ObservationMetaData characterizing the telescope 

pointing. 

 

includeDistortion is a boolean. If True (default), then this method will 

return the true pixel coordinates with optical distortion included. If False, this 

method will return TAN_PIXEL coordinates, which are the pixel coordinates with 

estimated optical distortion removed. See the documentation in afw.cameraGeom for more 

details. 

 

Returns 

------- 

a 2-D numpy array in which the first row is the x pixel coordinate 

and the second row is the y pixel coordinate. These pixel coordinates 

are defined in the Camera team system, rather than the DM system. 

""" 

(dm_x_pix, 

dm_y_pix) = coordUtils.pixelCoordsFromPupilCoordsLSST(xPupil, yPupil, 

chipName=chipName, 

band=obs_metadata.bandpass, 

includeDistortion=includeDistortion) 

 

cam_y_pix = dm_x_pix 

if isinstance(chipName, list) or isinstance(chipName, np.ndarray): 

center_pix_dict = {} 

cam_x_pix = np.zeros(len(dm_y_pix)) 

for ix, (det_name, yy) in enumerate(zip(chipName, dm_y_pix)): 

if det_name not in center_pix_dict: 

center_pix = self.getCenterPixel(det_name) 

center_pix_dict[det_name] = center_pix 

else: 

center_pix = center_pix_dict[det_name] 

cam_x_pix[ix] = 2.0*center_pix[0]-yy 

else: 

center_pix = self.getCenterPixel(chipName) 

cam_x_pix = 2.0*center_pix[0] - dm_y_pix 

 

return cam_x_pix, cam_y_pix 

 

def pupilCoordsFromPixelCoords(self, xPix, yPix, chipName, obs_metadata, 

includeDistortion=True): 

""" 

Convert pixel coordinates into pupil coordinates 

 

Parameters 

---------- 

xPix is the x pixel coordinate of the point. 

Can be either a float or a numpy array. 

Defined in the Camera team system (not the DM system). 

 

yPix is the y pixel coordinate of the point. 

Can be either a float or a numpy array. 

Defined in the Camera team system (not the DM system). 

 

chipName is the name of the chip(s) on which the pixel coordinates 

are defined. This can be a list (in which case there should be one chip name 

for each (xPix, yPix) coordinate pair), or a single value (in which case, all 

of the (xPix, yPix) points will be reckoned on that chip). 

 

obs_metadata is an ObservationMetaData characterizing the telescope 

pointing. 

 

includeDistortion is a boolean. If True (default), then this method will 

expect the true pixel coordinates with optical distortion included. If False, this 

method will expect TAN_PIXEL coordinates, which are the pixel coordinates with 

estimated optical distortion removed. See the documentation in afw.cameraGeom for more 

details. 

 

Returns 

------- 

a 2-D numpy array in which the first row is the x pupil coordinate 

and the second row is the y pupil coordinate (both in radians) 

""" 

dm_xPix = yPix 

if isinstance(chipName, list) or isinstance(chipName, np.ndarray): 

dm_yPix = np.zeros(len(xPix)) 

for ix, (det_name, xx) in enumerate(zip(chipName, xPix)): 

came_center_pix = self.getCenterPixel(det_name) 

dm_yPix[ix] = 2.0*cam_center_pix.getX()-xPix[ix] 

else: 

cam_center_pix = self.getCenterPixel(chipName) 

dm_yPix = 2.0*cam_center_pix.getX()-xPix 

return coordUtils.pupilCoordsFromPixelCoordsLSST(dm_xPix, dm_yPix, chipName, 

band=obs_metadata.bandpass, 

includeDistortion=includeDistortion) 

 

def _raDecFromPixelCoords(self, xPix, yPix, chipName, obs_metadata, 

epoch=2000.0, includeDistortion=True): 

""" 

Convert pixel coordinates into RA, Dec 

 

Parameters 

---------- 

xPix is the x pixel coordinate. It can be either 

a float or a numpy array. Defined in the Camera 

team system (not the DM system). 

 

yPix is the y pixel coordinate. It can be either 

a float or a numpy array. Defined in the Camera 

team system (not the DM system). 

 

chipName is the name of the chip(s) on which the pixel coordinates 

are defined. This can be a list (in which case there should be one chip name 

for each (xPix, yPix) coordinate pair), or a single value (in which case, all 

of the (xPix, yPix) points will be reckoned on that chip). 

 

obs_metadata is an ObservationMetaData defining the pointing 

 

epoch is the mean epoch in years of the celestial coordinate system. 

Default is 2000. 

 

includeDistortion is a boolean. If True (default), then this method will 

expect the true pixel coordinates with optical distortion included. If False, this 

method will expect TAN_PIXEL coordinates, which are the pixel coordinates with 

estimated optical distortion removed. See the documentation in afw.cameraGeom for more 

details. 

 

Returns 

------- 

a 2-D numpy array in which the first row is the RA coordinate 

and the second row is the Dec coordinate (both in radians; in the 

International Celestial Reference System) 

 

WARNING: This method does not account for apparent motion due to parallax. 

This method is only useful for mapping positions on a theoretical focal plane 

to positions on the celestial sphere. 

""" 

 

if isinstance(chipName, list) or isinstance(chipName, np.ndarray): 

dm_xPix = yPix 

dm_yPix = np.zeros(len(xPix)) 

for ix, (det_name, xx) in enumerate(zip(chipName, xPix)): 

cam_center_pix = self.getCenterPixel(det_name) 

dm_yPix[ix] = 2.0*cam_center_pix.getX() - xx 

else: 

dm_xPix = yPix 

cam_center_pix = self.getCenterPixel(chipName) 

dm_yPix = 2.0*cam_center_pix.getX() - xPix 

 

return coordUtils._raDecFromPixelCoordsLSST(dm_xPix, dm_yPix, chipName, 

obs_metadata=obs_metadata, 

band=obs_metadata.bandpass, 

epoch=epoch, 

includeDistortion=includeDistortion) 

 

def raDecFromPixelCoords(self, xPix, yPix, chipName, obs_metadata, 

epoch=2000.0, includeDistortion=True): 

""" 

Convert pixel coordinates into RA, Dec 

 

Parameters 

---------- 

xPix is the x pixel coordinate. It can be either 

a float or a numpy array. Defined in the Camera 

team system (not the DM system). 

 

yPix is the y pixel coordinate. It can be either 

a float or a numpy array. Defined in the Camera 

team system (not the DM system). 

 

chipName is the name of the chip(s) on which the pixel coordinates 

are defined. This can be a list (in which case there should be one chip name 

for each (xPix, yPix) coordinate pair), or a single value (in which case, all 

of the (xPix, yPix) points will be reckoned on that chip). 

 

obs_metadata is an ObservationMetaData defining the pointing 

 

epoch is the mean epoch in years of the celestial coordinate system. 

Default is 2000. 

 

includeDistortion is a boolean. If True (default), then this method will 

expect the true pixel coordinates with optical distortion included. If False, this 

method will expect TAN_PIXEL coordinates, which are the pixel coordinates with 

estimated optical distortion removed. See the documentation in afw.cameraGeom for more 

details. 

 

Returns 

------- 

a 2-D numpy array in which the first row is the RA coordinate 

and the second row is the Dec coordinate (both in degrees; in the 

International Celestial Reference System) 

 

WARNING: This method does not account for apparent motion due to parallax. 

This method is only useful for mapping positions on a theoretical focal plane 

to positions on the celestial sphere. 

""" 

 

_ra, _dec = self._raDecFromPixelCoords(xPix, yPix, chipName, 

obs_metadata=obs_metadata, 

epoch=2000.0, includeDistortion=True) 

 

return np.degrees(_ra), np.degrees(_dec) 

 

def _pixelCoordsFromRaDec(self, ra, dec, pm_ra=None, pm_dec=None, parallax=None, v_rad=None, 

obs_metadata=None, 

chipName=None, 

epoch=2000.0, includeDistortion=True): 

""" 

Get the pixel positions (or nan if not on a chip) for objects based 

on their RA, and Dec (in radians) 

 

Parameters 

---------- 

ra is in radians in the International Celestial Reference System. 

Can be either a float or a numpy array. 

 

dec is in radians in the International Celestial Reference System. 

Can be either a float or a numpy array. 

 

pm_ra is proper motion in RA multiplied by cos(Dec) (radians/yr) 

Can be a numpy array or a number or None (default=None). 

 

pm_dec is proper motion in dec (radians/yr) 

Can be a numpy array or a number or None (default=None). 

 

parallax is parallax in radians 

Can be a numpy array or a number or None (default=None). 

 

v_rad is radial velocity (km/s) 

Can be a numpy array or a number or None (default=None). 

 

obs_metadata is an ObservationMetaData characterizing the telescope 

pointing. 

 

epoch is the epoch in Julian years of the equinox against which 

RA is measured. Default is 2000. 

 

chipName designates the names of the chips on which the pixel 

coordinates will be reckoned. Can be either single value, an array, or None. 

If an array, there must be as many chipNames as there are (RA, Dec) pairs. 

If a single value, all of the pixel coordinates will be reckoned on the same 

chip. If None, this method will calculate which chip each(RA, Dec) pair actually 

falls on, and return pixel coordinates for each (RA, Dec) pair on the appropriate 

chip. Default is None. 

 

includeDistortion is a boolean. If True (default), then this method will 

return the true pixel coordinates with optical distortion included. If False, this 

method will return TAN_PIXEL coordinates, which are the pixel coordinates with 

estimated optical distortion removed. See the documentation in afw.cameraGeom for more 

details. 

 

Returns 

------- 

a 2-D numpy array in which the first row is the x pixel coordinate 

and the second row is the y pixel coordinate. These pixel coordinates 

are defined in the Camera team system, rather than the DM system. 

""" 

 

dm_xPix, dm_yPix = coordUtils._pixelCoordsFromRaDecLSST(ra, dec, 

pm_ra=pm_ra, pm_dec=pm_dec, 

parallax=parallax, v_rad=v_rad, 

obs_metadata=obs_metadata, 

chipName=chipName, 

band=obs_metadata.bandpass, 

epoch=epoch, 

includeDistortion=includeDistortion) 

 

return self.cameraPixFromDMPix(dm_xPix, dm_yPix, chipName) 

 

def pixelCoordsFromRaDec(self, ra, dec, pm_ra=None, pm_dec=None, parallax=None, v_rad=None, 

obs_metadata=None, chipName=None, 

epoch=2000.0, includeDistortion=True): 

""" 

Get the pixel positions (or nan if not on a chip) for objects based 

on their RA, and Dec (in degrees) 

 

Parameters 

---------- 

ra is in degrees in the International Celestial Reference System. 

Can be either a float or a numpy array. 

 

dec is in degrees in the International Celestial Reference System. 

Can be either a float or a numpy array. 

 

pm_ra is proper motion in RA multiplied by cos(Dec) (arcsec/yr) 

Can be a numpy array or a number or None (default=None). 

 

pm_dec is proper motion in dec (arcsec/yr) 

Can be a numpy array or a number or None (default=None). 

 

parallax is parallax in arcsec 

Can be a numpy array or a number or None (default=None). 

 

v_rad is radial velocity (km/s) 

Can be a numpy array or a number or None (default=None). 

 

obs_metadata is an ObservationMetaData characterizing the telescope 

pointing. 

 

epoch is the epoch in Julian years of the equinox against which 

RA is measured. Default is 2000. 

 

chipName designates the names of the chips on which the pixel 

coordinates will be reckoned. Can be either single value, an array, or None. 

If an array, there must be as many chipNames as there are (RA, Dec) pairs. 

If a single value, all of the pixel coordinates will be reckoned on the same 

chip. If None, this method will calculate which chip each(RA, Dec) pair actually 

falls on, and return pixel coordinates for each (RA, Dec) pair on the appropriate 

chip. Default is None. 

 

includeDistortion is a boolean. If True (default), then this method will 

return the true pixel coordinates with optical distortion included. If False, this 

method will return TAN_PIXEL coordinates, which are the pixel coordinates with 

estimated optical distortion removed. See the documentation in afw.cameraGeom for more 

details. 

 

Returns 

------- 

a 2-D numpy array in which the first row is the x pixel coordinate 

and the second row is the y pixel coordinate. These pixel coordinates 

are defined in the Camera team system, rather than the DM system. 

""" 

 

if pm_ra is not None: 

pm_ra_out = simsUtils.radiansFromArcsec(pm_ra) 

else: 

pm_ra_out = None 

 

if pm_dec is not None: 

pm_dec_out = simsUtils.radiansFromArcsec(pm_dec) 

else: 

pm_dec_out = None 

 

if parallax is not None: 

parallax_out = simsUtils.radiansFromArcsec(parallax) 

else: 

parallax_out = None 

 

return self._pixelCoordsFromRaDec(np.radians(ra), np.radians(dec), 

pm_ra=pm_ra_out, pm_dec=pm_dec_out, 

parallax=parallax_out, v_rad=v_rad, 

chipName=chipName, obs_metadata=obs_metadata, 

epoch=2000.0, includeDistortion=includeDistortion)