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

from builtins import object 

import numpy as np 

from lsst.sims.catalogs.decorators import compound, cached 

from lsst.sims.utils import _galacticFromEquatorial, sphericalFromCartesian, \ 

cartesianFromSpherical 

 

from lsst.sims.utils import _applyProperMotion 

from lsst.sims.utils import _observedFromICRS, _pupilCoordsFromRaDec 

from lsst.sims.utils import _appGeoFromObserved 

from lsst.sims.utils import _icrsFromAppGeo 

from lsst.sims.utils import _pupilCoordsFromObserved 

from lsst.sims.utils import rotationMatrixFromVectors 

from lsst.sims.coordUtils.CameraUtils import chipNameFromPupilCoords, pixelCoordsFromPupilCoords 

from lsst.sims.coordUtils.LsstCameraUtils import chipNameFromPupilCoordsLSST 

from lsst.sims.coordUtils.LsstCameraUtils import pixelCoordsFromPupilCoordsLSST 

from lsst.sims.coordUtils.LsstCameraUtils import focalPlaneCoordsFromPupilCoordsLSST 

from lsst.sims.coordUtils.CameraUtils import focalPlaneCoordsFromPupilCoords 

 

from lsst.sims.catUtils.mixins.PhoSimSupport import _FieldRotator 

from lsst.sims.utils import _angularSeparation, arcsecFromRadians 

 

__all__ = ["AstrometryBase", "AstrometryStars", "AstrometryGalaxies", "AstrometrySSM", 

"PhoSimAstrometryBase", "PhoSimAstrometryStars", "PhoSimAstrometryGalaxies", 

"PhoSimAstrometrySSM", 

"CameraCoords", "CameraCoordsLSST"] 

 

 

class AstrometryBase(object): 

"""Collection of astrometry routines that operate on numpy arrays""" 

 

@compound('glon', 'glat') 

def get_galactic_coords(self): 

""" 

Getter for galactic coordinates, in case the catalog class does not provide that 

 

Reads in the ra and dec from the data base and returns columns with galactic 

longitude and latitude. 

 

All angles are in radians 

""" 

ra = self.column_by_name('raJ2000') 

dec = self.column_by_name('decJ2000') 

 

glon, glat = _galacticFromEquatorial(ra, dec) 

 

return np.array([glon, glat]) 

 

@compound('x_pupil', 'y_pupil') 

def get_pupilFromSky(self): 

""" 

Take an input RA and dec from the sky and convert it to coordinates 

in the pupil. 

""" 

 

raObs = self.column_by_name('raObserved') 

decObs = self.column_by_name('decObserved') 

 

return _pupilCoordsFromObserved(raObs, decObs, epoch=self.db_obj.epoch, 

obs_metadata=self.obs_metadata) 

 

 

class CameraCoords(AstrometryBase): 

"""Methods for getting coordinates from the camera object""" 

camera = None 

allow_multiple_chips = False # this is a flag which, if true, would allow 

# chipNameFromPupilCoords to return objects that land on 

# multiple chips; only the first chip would be 

# written to the catalog 

 

@cached 

def get_chipName(self): 

"""Get the chip name if there is one for each catalog entry""" 

xPupil, yPupil = (self.column_by_name('x_pupil'), self.column_by_name('y_pupil')) 

if len(xPupil) == 0: 

return np.array([]) 

if self.camera is None: 

raise RuntimeError("No camera defined; cannot find chipName") 

return chipNameFromPupilCoords(xPupil, yPupil, camera=self.camera, 

allow_multiple_chips=self.allow_multiple_chips) 

 

@compound('xPix', 'yPix') 

def get_pixelCoordinates(self): 

"""Get the pixel positions (or nan if not on a chip) for all objects in the catalog""" 

xPupil, yPupil = (self.column_by_name('x_pupil'), self.column_by_name('y_pupil')) 

chipNameList = self.column_by_name('chipName') 

if len(xPupil) == 0: 

return np.array([[],[]]) 

if self.camera is None: 

raise RuntimeError("No camera is defined; cannot calculate pixel coordinates") 

return pixelCoordsFromPupilCoords(xPupil, yPupil, chipName=chipNameList, 

camera=self.camera) 

 

@compound('xFocalPlane', 'yFocalPlane') 

def get_focalPlaneCoordinates(self): 

"""Get the focal plane coordinates for all objects in the catalog.""" 

xPupil, yPupil = (self.column_by_name('x_pupil'), self.column_by_name('y_pupil')) 

if len(xPupil) == 0: 

return np.array([[],[]]) 

if self.camera is None: 

raise RuntimeError("No camera defined. Cannot calculate focal plane coordinates") 

return focalPlaneCoordsFromPupilCoords(xPupil, yPupil, camera=self.camera) 

 

 

class CameraCoordsLSST(CameraCoords): 

 

@cached 

def get_chipName(self): 

"""Get the chip name if there is one for each catalog entry""" 

xPupil, yPupil = (self.column_by_name('x_pupil'), self.column_by_name('y_pupil')) 

if len(xPupil) == 0: 

return np.array([]) 

 

return chipNameFromPupilCoordsLSST(xPupil, yPupil, 

allow_multiple_chips=self.allow_multiple_chips) 

 

@compound('xPix', 'yPix') 

def get_pixelCoordinates(self): 

"""Get the pixel positions (or nan if not on a chip) for all objects in the catalog""" 

xPupil, yPupil = (self.column_by_name('x_pupil'), self.column_by_name('y_pupil')) 

chipNameList = self.column_by_name('chipName') 

if len(xPupil) == 0: 

return np.array([[],[]]) 

return pixelCoordsFromPupilCoordsLSST(xPupil, yPupil, chipName=chipNameList, 

band=self.obs_metadata.bandpass) 

 

@compound('xFocalPlane', 'yFocalPlane') 

def get_focalPlaneCoordinates(self): 

"""Get the focal plane coordinates for all objects in the catalog.""" 

xPupil, yPupil = (self.column_by_name('x_pupil'), self.column_by_name('y_pupil')) 

if len(xPupil) == 0: 

return np.array([[],[]]) 

return focalPlaneCoordsFromPupilCoords(xPupil, yPupil, band=self.obs_metadata.bandpass) 

 

 

class AstrometryGalaxies(AstrometryBase): 

""" 

This mixin contains astrometry getters for objects with zero parallax, proper motion, or radial 

velocity (i.e. extragalactic sources). 

 

Available getters are: 

raICRS, decICRS -- the RA, Dec of the object in the International Celestial Reference System 

 

raObserved, decObserved -- the result of applying precession, nutation, aberration, and refraction 

to raICRS, decICRS 

""" 

 

@compound('raICRS', 'decICRS') 

def get_icrsCoordinates(self): 

"""Getter for RA, Dec in the International Celestial Reference System with effects 

due to proper motion and radial velocity applied""" 

return np.array([self.column_by_name('raJ2000'), self.column_by_name('decJ2000')]) 

 

@compound('raObserved', 'decObserved') 

def get_observedCoordinates(self): 

"""Getter for observed RA, Dec (i.e. RA and Dec with all effects due to the motion 

of the Earth and refraction by the atmosphere applied)""" 

ra = self.column_by_name('raJ2000') 

dec = self.column_by_name('decJ2000') 

return _observedFromICRS(ra, dec, obs_metadata=self.obs_metadata, epoch=self.db_obj.epoch) 

 

 

class AstrometryStars(AstrometryBase): 

""" 

This mixin contains getters for objects with non-zero parallax, proper motion, and radial 

velocities (i.e. sources in the Milky Way). 

 

Available getters are: 

raICRS, decICRS -- the RA, Dec of the object in the International Celestial Reference System 

with proper motion and radial velocity applied 

 

raObserved, decObserved -- the result of applying precession, nutation, aberration, parallax, 

and refraction to raICRS, decICRS 

""" 

 

def observedStellarCoordinates(self, includeRefraction = True): 

""" 

Getter which converts mean coordinates in the International Celestial 

Reference Frame to observed coordinates. 

""" 

 

# TODO 

# are we going to store proper motion in raw radians per year 

# or in sky motion = cos(dec) * (radians per year) 

# PAL asks for radians per year inputs 

 

pr = self.column_by_name('properMotionRa') # in radians per year 

pd = self.column_by_name('properMotionDec') # in radians per year 

px = self.column_by_name('parallax') # in radians 

rv = self.column_by_name('radialVelocity') # in km/s; positive if receding 

ra = self.column_by_name('raJ2000') 

dec = self.column_by_name('decJ2000') 

 

return _observedFromICRS(ra, dec, pm_ra = pr, pm_dec = pd, parallax = px, v_rad = rv, 

includeRefraction = includeRefraction, obs_metadata=self.obs_metadata, 

epoch=self.db_obj.epoch) 

 

@compound('raObserved', 'decObserved') 

def get_observedCoordinates(self): 

"""Getter for observed RA, Dec (i.e. RA and Dec with all effects due to the motion 

of the Earth and refraction by the atmosphere applied)""" 

return self.observedStellarCoordinates() 

 

@compound('raICRS', 'decICRS') 

def get_icrsCoordinates(self): 

"""Getter for RA, Dec in the International Celestial Reference System with effects 

due to proper motion and radial velocity applied""" 

ra0 = self.column_by_name('raJ2000') 

dec0 = self.column_by_name('decJ2000') 

pr = self.column_by_name('properMotionRa') # in radians per year 

pd = self.column_by_name('properMotionDec') # in radians per year 

px = self.column_by_name('parallax') # in radians 

rv = self.column_by_name('radialVelocity') # in km/s; positive if receding 

 

ra_corr, dec_corr = _applyProperMotion(ra0, dec0, pr, pd, px, rv, mjd=self.obs_metadata.mjd) 

return np.array([ra_corr, dec_corr]) 

 

 

class AstrometrySSM(AstrometryBase): 

""" 

This mixin will provide getters for astrometric columns customized to Solar System Object tables 

""" 

 

@compound('raICRS', 'decICRS') 

def get_icrsCoordinates(self): 

return np.array([self.column_by_name('raJ2000'), self.column_by_name('decJ2000')]) 

 

def observedSSMCoordinates(self, includeRefraction = True): 

""" 

Reads in ICRS coordinates from the database. Returns observed coordinates 

with refraction toggled on or off based on the input boolean includeRefraction 

""" 

ra = self.column_by_name('raJ2000') # in radians 

dec = self.column_by_name('decJ2000') # in radians 

 

return _observedFromICRS(ra, dec, includeRefraction=includeRefraction, 

obs_metadata=self.obs_metadata, epoch=self.db_obj.epoch) 

 

@compound('raObserved', 'decObserved') 

def get_observedCoordinates(self): 

return self.observedSSMCoordinates(includeRefraction = True) 

 

@cached 

def get_skyVelocity(self): 

""" 

Gets the skyVelocity in radians per day 

""" 

 

dradt = self.column_by_name('velRa') # in radians per day (actual sky velocity; 

# i.e., no need to divide by cos(dec)) 

 

ddecdt = self.column_by_name('velDec') # in radians per day 

 

return np.sqrt(np.power(dradt, 2) + np.power(ddecdt, 2)) 

 

 

class PhoSimAstrometryBase(object): 

""" 

This mixin contains the _dePrecess method necessary to create PhoSim 

images that are astrometrically consistent with their input catalogs. 

""" 

 

def _dePrecess(self, ra_in, dec_in, obs): 

""" 

Transform a set of RA, Dec pairs by subtracting out a rotation 

which represents the effects of precession, nutation, and aberration. 

 

Specifically: 

 

Calculate the displacement between the boresite and the boresite 

corrected for precession, nutation, and aberration (not refraction). 

 

Convert boresite and corrected boresite to Cartesian coordinates. 

 

Calculate the rotation matrix to go between those Cartesian vectors. 

 

Convert [ra_in, dec_in] into Cartesian coordinates. 

 

Apply the rotation vector to those Cartesian coordinates. 

 

Convert back to ra, dec-like coordinates 

 

@param [in] ra_in is a numpy array of RA in radians 

 

@param [in] dec_in is a numpy array of Dec in radians 

 

@param [in] obs is an ObservationMetaData 

 

@param [out] ra_out is a numpy array of de-precessed RA in radians 

 

@param [out] dec_out is a numpy array of de-precessed Dec in radians 

""" 

 

if len(ra_in) == 0: 

return np.array([[], []]) 

 

 

precessedRA, precessedDec = _observedFromICRS(obs._pointingRA,obs._pointingDec, 

obs_metadata=obs, epoch=2000.0, 

includeRefraction=False) 

 

if (not hasattr(self, '_icrs_to_phosim_rotator') or 

arcsecFromRadians(_angularSeparation(obs._pointingRA, obs._pointingDec, 

self._icrs_to_phosim_rotator._ra1, 

self._icrs_to_phosim_rotator._dec1))>1.0e-6 or 

arcsecFromRadians(_angularSeparation(precessedRA, precessedDec, 

self._icrs_to_phosim_rotator._ra0, 

self._icrs_to_phosim_rotator._dec0))>1.0e-6): 

 

self._icrs_to_phosim_rotator = _FieldRotator(precessedRA, precessedDec, 

obs._pointingRA, obs._pointingDec) 

 

ra_deprecessed, dec_deprecessed = self._icrs_to_phosim_rotator.transform(ra_in, dec_in) 

 

return np.array([ra_deprecessed, dec_deprecessed]) 

 

@classmethod 

def _appGeoFromPhoSim(self, raPhoSim, decPhoSim, obs): 

""" 

This method will convert from the 'deprecessed' coordinates expected by 

PhoSim to apparent geocentric coordinates 

 

Parameters 

---------- 

raPhoSim is the PhoSim RA-like coordinate (in radians) 

 

decPhoSim is the PhoSim Dec-like coordinate (in radians) 

 

obs is an ObservationMetaData characterizing the 

telescope pointing 

 

Returns 

------- 

apparent geocentric RA in radians 

 

apparent geocentric Dec in radians 

""" 

precessedRA, precessedDec = _observedFromICRS(obs._pointingRA,obs._pointingDec, 

obs_metadata=obs, epoch=2000.0, 

includeRefraction=False) 

 

if (not hasattr(self, '_phosim_to_icrs_rotator') or 

arcsecFromRadians(_angularSeparation(obs._pointingRA, obs._pointingDec, 

self._phosim_to_icrs_rotator._ra0, 

self._phosim_to_icrs_rotator._dec0))>1.0e-6 or 

arcsecFromRadians(_angularSeparation(precessedRA, precessedDec, 

self._phosim_to_icrs_rotator._ra1, 

self._phosim_to_icrs_rotator._dec1))>1.0e-6): 

 

self._phosim_to_icrs_rotator = _FieldRotator(obs._pointingRA, obs._pointingDec, 

precessedRA, precessedDec) 

 

ra_obs, dec_obs = self._phosim_to_icrs_rotator.transform(raPhoSim, decPhoSim) 

 

return _appGeoFromObserved(ra_obs, dec_obs, includeRefraction=False, 

obs_metadata=obs) 

 

@classmethod 

def appGeoFromPhoSim(self, raPhoSim, decPhoSim, obs_metadata): 

""" 

This method will convert from the 'deprecessed' coordinates expected by 

PhoSim to apparent geocentric coordinates 

 

Parameters 

---------- 

raPhoSim is the PhoSim RA-like coordinate (in degrees) 

 

decPhoSim is the PhoSim Dec-like coordinate (in degrees) 

 

obs_metadata is an ObservationMetaData characterizing the 

telescope pointing 

 

Returns 

------- 

apparent geocentric RA in degrees 

 

apparent geocentric Dec in degrees 

""" 

ra_appGeo, dec_appGeo = self._appGeoFromPhoSim(np.radians(raPhoSim), 

np.radians(decPhoSim), 

obs_metadata) 

 

return np.degrees(ra_appGeo), np.degrees(dec_appGeo) 

 

@classmethod 

def _icrsFromPhoSim(self, raPhoSim, decPhoSim, obs_metadata): 

""" 

This method will convert from the 'deprecessed' coordinates expected by 

PhoSim to ICRS coordinates 

 

Parameters 

---------- 

raPhoSim is the PhoSim RA-like coordinate (in radians) 

 

decPhoSim is the PhoSim Dec-like coordinate (in radians) 

 

obs_metadata is an ObservationMetaData characterizing the 

telescope pointing 

 

Returns 

------- 

raICRS in radians 

 

decICRS in radians 

""" 

 

(ra_appGeo, 

dec_appGeo) = self._appGeoFromPhoSim(raPhoSim, decPhoSim, obs_metadata) 

 

# convert to ICRS coordinates 

return _icrsFromAppGeo(ra_appGeo, dec_appGeo, mjd=obs_metadata.mjd, 

epoch=2000.0) 

 

@classmethod 

def icrsFromPhoSim(self, raPhoSim, decPhoSim, obs_metadata): 

""" 

This method will convert from the 'deprecessed' coordinates expected by 

PhoSim to ICRS coordinates 

 

Parameters 

---------- 

raPhoSim is the PhoSim RA-like coordinate (in degrees) 

 

decPhoSim is the PhoSim Dec-like coordinate (in degrees) 

 

obs_metadata is an ObservationMetaData characterizing the 

telescope pointing 

 

Returns 

------- 

raICRS in degrees 

 

decICRS in degrees 

""" 

ra, dec = PhoSimAstrometryBase._icrsFromPhoSim(np.radians(raPhoSim), 

np.radians(decPhoSim), 

obs_metadata) 

return np.degrees(ra), np.degrees(dec) 

 

 

class PhoSimAstrometryStars(AstrometryStars, PhoSimAstrometryBase): 

""" 

This mixin contains the getter method that calculates raPhoSim, 

decPhoSim (the coordinates necessary for a PhoSim-readable 

InstanceCatalog) in the case of stellar sources. 

""" 

 

@compound('raPhoSim', 'decPhoSim') 

def get_phoSimCoordinates(self): 

"""Getter for RA, Dec coordinates expected by PhoSim. 

 

These are observed RA, Dec coordinates with the effects of nutation, aberration, 

and precession subtracted out by the PhosimInputBase._dePrecess() method. 

This preserves the relative effects of nutation, aberration, and precession while 

re-aligning the catalog with the boresite RA, Dec so that astrometric solutions 

make sense.""" 

 

raObs, decObs = self.observedStellarCoordinates(includeRefraction = False) 

return self._dePrecess(raObs, decObs, self.obs_metadata) 

 

 

class PhoSimAstrometryGalaxies(AstrometryGalaxies, PhoSimAstrometryBase): 

""" 

This mixin contains the getter method that calculates raPhoSim, 

decPhoSim (the coordinates necessary for a PhoSim-readable 

InstanceCatalog) in the case of extra-galactic sources. 

""" 

 

@compound('raPhoSim', 'decPhoSim') 

def get_phoSimCoordinates(self): 

"""Getter for RA, Dec coordinates expected by PhoSim. 

 

These are observed RA, Dec coordinates with the effects of nutation, aberration, 

and precession subtracted out by the PhosimInputBase._dePrecess() method. 

This preserves the relative effects of nutation, aberration, and precession while 

re-aligning the catalog with the boresite RA, Dec so that astrometric solutions 

make sense.""" 

 

ra = self.column_by_name('raJ2000') 

dec = self.column_by_name('decJ2000') 

raObs, decObs = _observedFromICRS(ra, dec, includeRefraction = False, obs_metadata=self.obs_metadata, 

epoch=self.db_obj.epoch) 

 

return self._dePrecess(raObs, decObs, self.obs_metadata) 

 

 

class PhoSimAstrometrySSM(AstrometrySSM, PhoSimAstrometryBase): 

""" 

This mixin contains the getter method that calculates raPhoSim, 

decPhoSim (the coordinates necessary for a PhoSim-readable 

InstanceCatalog) in the case of solar system sources. 

""" 

 

@compound('raPhoSim', 'decPhoSim') 

def get_phoSimCoordinates(self): 

raObs, decObs = self.observedSSMCoordinates(includeRefraction = False) 

return self._dePrecess(raObs, decObs, self.obs_metadata)