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

 

import lsst.pex.config 

from .pluginsBase import BasePlugin 

from .pluginRegistry import generateAlgorithmName, register 

from .apCorrRegistry import addApCorrName 

from .sfm import SingleFramePlugin, SingleFramePluginConfig 

from .forcedMeasurement import ForcedPlugin, ForcedPluginConfig 

 

__all__ = ("wrapSingleFrameAlgorithm", "wrapForcedAlgorithm", "wrapSimpleAlgorithm", "wrapTransform", 

"GenericPlugin") 

 

 

class WrappedSingleFramePlugin(SingleFramePlugin): 

 

def __init__(self, config, name, schema, metadata, logName=None): 

SingleFramePlugin.__init__(self, config, name, schema, metadata, logName=logName) 

if hasattr(self, "hasLogName") and self.hasLogName and logName is not None: 

self.cpp = self.factory(config, name, schema, metadata, logName=logName) 

else: 

self.cpp = self.factory(config, name, schema, metadata) 

 

def measure(self, measRecord, exposure): 

self.cpp.measure(measRecord, exposure) 

 

def measureN(self, measCat, exposure): 

self.cpp.measureN(measCat, exposure) 

 

def fail(self, measRecord, error=None): 

self.cpp.fail(measRecord, error.cpp if error is not None else None) 

 

 

class WrappedForcedPlugin(ForcedPlugin): 

 

def __init__(self, config, name, schemaMapper, metadata, logName=None): 

ForcedPlugin.__init__(self, config, name, schemaMapper, metadata, logName=logName) 

if hasattr(self, "hasLogName") and self.hasLogName and logName is not None: 

self.cpp = self.factory(config, name, schemaMapper, metadata, logName=logName) 

else: 

self.cpp = self.factory(config, name, schemaMapper, metadata) 

 

def measure(self, measRecord, exposure, refRecord, refWcs): 

self.cpp.measureForced(measRecord, exposure, refRecord, refWcs) 

 

def measureN(self, measCat, exposure, refCat, refWcs): 

self.cpp.measureNForced(measCat, exposure, refCat, refWcs) 

 

def fail(self, measRecord, error=None): 

self.cpp.fail(measRecord, error.cpp if error is not None else None) 

 

 

def wrapAlgorithmControl(Base, Control, module=2, hasMeasureN=False): 

"""! 

Wrap a C++ algorithm's control class into a Python Config class. 

 

@param[in] Base Base class for the returned ConfigClass; one of SingleFramePluginConfig or 

ForcedPluginConfig 

@param[in] Control Control class to be wrapped (a Swigged C++ class) 

@param[in] module Either a module object, a string specifying the name of the module, or an 

integer specifying how far back in the stack to look for the module to use: 

0 is pex.config.wrap, 1 is lsst.meas.base.wrappers, 2 is the immediate 

caller, etc. This will be used to set __module__ for the new config class, 

and the class will also be added to the module. The default is to use the 

callers' module. 

@param[in] hasMeasureN Whether the plugin supports fitting multiple objects at once (if so, a 

config option to enable/disable this will be added). 

 

@return a new subclass of lsst.pex.config.Config 

 

This function is generally only called by wrapAlgorithm; it is unlikely users will have to call it 

directly. 

""" 

72 ↛ 77line 72 didn't jump to line 77, because the condition on line 72 was never true if hasMeasureN: 

# We need to add a Config field to enable multi-object measurement, to replace 

# the simple bool class attribute that's on the base class. To do that, we 

# create the Config class dynamically here, then call makeControlClass to finish 

# it off by adding fields from the control object. 

cls = type( 

Control.__name__.replace("Control", "Config"), 

(Base,), 

{"doMeasureN": lsst.pex.config.Field(dtype=bool, default=True, 

doc="whether to run this plugin in multi-object mode")} 

) 

ConfigClass = lsst.pex.config.makeConfigClass(Control, module=module, cls=cls) 

else: 

# If we don't have to add that Config field, we can delegate all of the work to 

# pex_config's makeControlClass 

ConfigClass = lsst.pex.config.makeConfigClass(Control, module=module, base=Base) 

return ConfigClass 

 

 

def wrapAlgorithm(Base, AlgClass, factory, executionOrder, name=None, Control=None, 

ConfigClass=None, TransformClass=None, doRegister=True, shouldApCorr=False, 

apCorrList=(), hasLogName=False, **kwds): 

"""! 

Wrap a C++ Algorithm class into a Python Plugin class. 

 

@param[in] Base Base class for the returned Plugin; one of SingleFramePlugin or 

ForcedPlugin 

@param[in] AlgClass Swigged C++ Algorithm class to convert; must be a subclass of 

SingleFrameAlgorithm or ForcedAlgorithm (matching the Base argument), or 

an unrelated class with the same measure() and measureN() signatures as 

those base classes. 

@param[in] factory A callable that is used to construct an instance of AlgClass. It must take 

four arguments, either (config, name, schema, metadata) or 

(config, name, schemaMapper, metadata), depending on whether the algorithm is 

single-frame or forced. 

@param[in] executionOrder The order this plugin should be run, relative to others 

(see BasePlugin.getExecutionOrder()). 

@param[in] name String to use when registering the algorithm. Ignored if doRegistry=False, 

set to generateAlgorithmName(AlgClass) if None. 

@param[in] Control Swigged C++ Control class for the algorithm; AlgClass.Control is used if None. 

Ignored if ConfigClass is not None. 

@param[in] ConfigClass Python Config class that wraps the C++ Algorithm's swigged Control class. If 

None, wrapAlgorithmControl is called to generate a Config class using the 

Control argument. 

@param[in] TransformClass Transformation which may be used to post-process the results of measurement. 

If None, the default (defined by BasePlugin) is used. 

@param[in] doRegister If True (the default), register the plugin with Base's registry, allowing it 

to be used by measurement Tasks. 

@param[in] shouldApCorr Does this algorithm measure a instFlux that can be aperture corrected? This is 

shorthand for apCorrList=[name] and is ignored if apCorrList is specified. 

@param[in] apCorrList List of field name prefixes for instFlux fields that to be aperture corrected. 

If an algorithm produces a single instFlux that should be 

aperture corrected then it is simpler to set shouldApCorr=True. But if an 

algorithm produces multiple such fields then it must specify apCorrList, 

instead. For example modelfit_CModel produces 3 such fields: apCorrList= 

("modelfit_CModel_exp", "modelfit_CModel_exp", "modelfit_CModel_def") 

If apCorrList is non-empty then shouldApCorr is ignored. 

If non-empty and doRegister is True then the names are added to the set 

retrieved by getApCorrNameSet 

@param[in] hasLogName Plugin supports a logName as a constructor argument 

 

 

@param[in] **kwds Additional keyword arguments passed to generateAlgorithmControl, including: 

- hasMeasureN: Whether the plugin supports fitting multiple objects at once 

(if so, a config option to enable/disable this will be added). 

- executionOrder: If not None, an override for the default executionOrder for 

this plugin (the default is 2.0, which is usually appropriate for fluxes). 

 

@return the new Plugin class, a subclass of Base 

 

This function is generally only called by the public wrapSingleFrameAlgorithm, wrapForcedAlgorithm, and 

wrapSimpleAlgorithm functions; it is unlikely users will have to call it directly. 

""" 

145 ↛ 150line 145 didn't jump to line 150, because the condition on line 145 was never false if ConfigClass is None: 

146 ↛ 147line 146 didn't jump to line 147, because the condition on line 146 was never true if Control is None: 

Control = AlgClass.Control 

ConfigClass = wrapAlgorithmControl(Base.ConfigClass, Control, **kwds) 

 

def getExecutionOrder(): 

return executionOrder 

typeDict = dict(AlgClass=AlgClass, ConfigClass=ConfigClass, factory=staticmethod(factory), 

getExecutionOrder=staticmethod(getExecutionOrder)) 

if TransformClass: 

typeDict['getTransformClass'] = staticmethod(lambda: TransformClass) 

PluginClass = type(AlgClass.__name__ + Base.__name__, (Base,), typeDict) 

if doRegister: 

if name is None: 

name = generateAlgorithmName(AlgClass) 

Base.registry.register(name, PluginClass) 

if shouldApCorr: 

addApCorrName(name) 

PluginClass.hasLogName = hasLogName 

return PluginClass 

 

 

def wrapSingleFrameAlgorithm(AlgClass, executionOrder, name=None, needsMetadata=False, hasMeasureN=False, 

hasLogName=False, **kwds): 

"""! 

Wrap a C++ SingleFrameAlgorithm class into a Python SingleFramePlugin class. 

 

@param[in] AlgClass Swigged C++ Algorithm class to convert; must be a subclass of 

SingleFrameAlgorithm, or an unrelated class with the same measure(), 

measureN(), and fail() signatures. 

@param[in] executionOrder The order this plugin should be run, relative to others 

(see BasePlugin.getExecutionOrder()). 

@param[in] name String to use when registering the algorithm. Ignored if doRegistry=False, 

set to generateAlgorithmName(AlgClass) if None. 

@param[in] needsMetadata Sets whether the AlgClass's constructor should be passed a PropertySet 

metadata argument. 

@param[in] hasMeasureN Whether the algorithm supports simultaneous measurement of multiple sources. 

If True, a bool doMeasureN field will be added to the generated Config class, 

and its value will be passed as the last argument when calling the AlgClass 

constructor. 

@param[in] hasLogName Plugin supports a logName as a constructor argument 

@param[in] **kwds Additional keyword arguments passed to the lower-level wrapAlgorithm and 

wrapAlgorithmControl classes. These include: 

- Control: Swigged C++ Control class for the algorithm; AlgClass.Control 

is used if None. Ignored if ConfigClass is not None. 

- ConfigClass: Python Config class that wraps the C++ Algorithm's swigged 

Control class. If None, wrapAlgorithmControl is called to generate a 

Config class using the Control argument. 

- doRegister: If True (the default), register the plugin with 

SingleFramePlugin.registry, allowing it to be used by 

SingleFrameMeasurementTask. 

- shouldApCorr: does this algorithm measure a instFlux that can be aperture 

corrected? This is shorthand for apCorrList=[name] and is ignored if 

apCorrList is specified. 

- apCorrList: list of field name prefixes for instFlux fields that should be 

aperture corrected. If an algorithm produces a single instFlux that should be 

aperture corrected then it is simpler to set shouldApCorr=True. But if an 

algorithm produces multiple such fields then it must specify apCorrList, 

instead. For example modelfit_CModel produces 3 such fields: apCorrList= 

("modelfit_CModel_exp", "modelfit_CModel_exp", "modelfit_CModel_def") 

If apCorrList is non-empty then shouldApCorr is ignored. 

If non-empty and doRegister is True then the names are added to the set 

retrieved by getApCorrNameSet 

- executionOrder: If not None, an override for the default executionOrder for 

this plugin (the default is 2.0, which is usually appropriate for fluxes). 

 

@return the new SingleFramePlugin subclass 

 

The needsMetadata and hasMeasureN arguments combine to determine the expected constructor signature; 

we always expect the first three arguments to be: 

@verbatim 

Control const & ctrl, std::string const & name, Schema & schema 

@endverbatim 

If needsMetadata, we also append: 

@verbatim 

PropertySet & metadata 

@endverbatim 

If hasMeasureN, we also append: 

@verbatim 

bool doMeasureN 

@endverbatim 

If hasLogName, we also append: 

@verbatim 

std::string logName 

@endverbatim 

If more than one is True, the metadata PropertySet precedes the doMeasureN bool 

and the logName comes last of the three 

""" 

233 ↛ 234line 233 didn't jump to line 234, because the condition on line 233 was never true if hasMeasureN: 

if needsMetadata: 

def factory(config, name, schema, metadata, **kwargs): 

return AlgClass(config.makeControl(), name, schema, metadata, config.doMeasureN, **kwargs) 

else: 

def factory(config, name, schema, metadata, **kwargs): 

return AlgClass(config.makeControl(), name, schema, config.doMeasureN, **kwargs) 

else: 

if needsMetadata: 

def factory(config, name, schema, metadata, **kwargs): 

return AlgClass(config.makeControl(), name, schema, metadata, **kwargs) 

else: 

def factory(config, name, schema, metadata, **kwargs): 

return AlgClass(config.makeControl(), name, schema, **kwargs) 

 

return wrapAlgorithm(WrappedSingleFramePlugin, AlgClass, executionOrder=executionOrder, name=name, 

factory=factory, hasMeasureN=hasMeasureN, hasLogName=hasLogName, **kwds) 

 

 

def wrapForcedAlgorithm(AlgClass, executionOrder, name=None, needsMetadata=False, 

hasMeasureN=False, needsSchemaOnly=False, hasLogName=False, **kwds): 

"""! 

Wrap a C++ ForcedAlgorithm class into a Python ForcedPlugin class. 

 

@param[in] AlgClass Swigged C++ Algorithm class to convert; must be a subclass of 

ForcedAlgorithm, or an unrelated class with the same measure(), measureN(), 

and fail() signatures. 

@param[in] executionOrder The order this plugin should be run, relative to others 

(see BasePlugin.getExecutionOrder()). 

@param[in] name String to use when registering the algorithm. Ignored if doRegistry=False, 

set to generateAlgorithmName(AlgClass) if None. 

@param[in] needsMetadata Sets whether the AlgClass's constructor should be passed a PropertySet 

metadata argument. 

@param[in] hasMeasureN Whether the algorithm supports simultaneous measurement of multiple sources. 

If True, a bool doMeasureN field will be added to the generated Config class, 

and its value will be passed as the last argument when calling the AlgClass 

constructor. 

@param[in] hasLogName Plugin supports a logName as a constructor argument 

@param[in] needsSchemaOnly Whether the algorithm constructor expects a Schema argument (representing the 

output Schema) rather than the full SchemaMapper (which provides access to 

both the reference Schema and the output Schema). 

@param[in] **kwds Additional keyword arguments passed to the lower-level wrapAlgorithm and 

wrapAlgorithmControl classes. These include: 

- Control: Swigged C++ Control class for the algorithm; AlgClass.Control 

is used if None. Ignored if ConfigClass is not None. 

- ConfigClass: Python Config class that wraps the C++ Algorithm's swigged 

Control class. If None, wrapAlgorithmControl is called to generate a 

Config class using the Control argument. 

- doRegister: If True (the default), register the plugin with 

ForcedPlugin.registry, allowing it to be used by ForcedMeasurementTask. 

- shouldApCorr: does this algorithm measure a instFlux that can be aperture 

corrected? This is shorthand for apCorrList=[name] and is ignored if 

apCorrList is specified. 

- apCorrList: list of field name prefixes for instFlux fields that should be 

aperture corrected. If an algorithm produces a single instFlux that should be 

aperture corrected then it is simpler to set shouldApCorr=True. But if an 

algorithm produces multiple such fields then it must specify apCorrList, 

instead. For example modelfit_CModel produces 3 such fields: apCorrList= 

("modelfit_CModel_exp", "modelfit_CModel_exp", "modelfit_CModel_def") 

If apCorrList is non-empty then shouldApCorr is ignored. 

If non-empty and doRegister is True then the names are added to the set 

retrieved by getApCorrNameSet 

- executionOrder: If not None, an override for the default executionOrder for 

this plugin (the default is 2.0, which is usually appropriate for fluxes). 

 

@return the new ForcedPlugin subclass 

 

The needsMetadata, hasMeasureN, and needsSchemaOnly arguments combine to determine the expected 

constructor signature; we always expect the first two arguments to be: 

@verbatim 

Control const & ctrl, std::string const & name 

@endverbatim 

If needsSchemaOnly is True, then the third argument will be 

@verbatim 

Schema & schema 

@endverbatim 

otherwise, it will be: 

@verbatim 

SchemaMapper & schemaMapper 

@endverbatim 

If needsMetadata, we also append: 

@verbatim 

PropertySet & metadata 

@endverbatim 

If hasMeasureN, we also append: 

@verbatim 

bool doMeasureN 

@endverbatim 

If hasLogName, we also append: 

@verbatim 

std::string logName 

@endverbatim 

If more than one is True, the metadata PropertySet precedes the doMeasureN bool 

and the logName comes last of the three 

""" 

328 ↛ 332line 328 didn't jump to line 332, because the condition on line 328 was never false if needsSchemaOnly: 

def extractSchemaArg(m): 

return m.editOutputSchema() 

else: 

def extractSchemaArg(m): 

return m 

334 ↛ 335line 334 didn't jump to line 335, because the condition on line 334 was never true if hasMeasureN: 

if needsMetadata: 

def factory(config, name, schemaMapper, metadata, **kwargs): 

return AlgClass(config.makeControl(), name, extractSchemaArg(schemaMapper), 

metadata, config.doMeasureN, **kwargs) 

else: 

def factory(config, name, schemaMapper, metadata, **kwargs): 

return AlgClass(config.makeControl(), name, extractSchemaArg(schemaMapper), 

config.doMeasureN, **kwargs) 

else: 

if needsMetadata: 

def factory(config, name, schemaMapper, metadata, **kwargs): 

return AlgClass(config.makeControl(), name, extractSchemaArg(schemaMapper), 

metadata, **kwargs) 

else: 

def factory(config, name, schemaMapper, metadata, **kwargs): 

return AlgClass(config.makeControl(), name, extractSchemaArg(schemaMapper), **kwargs) 

 

return wrapAlgorithm(WrappedForcedPlugin, AlgClass, executionOrder=executionOrder, name=name, 

factory=factory, hasLogName=hasLogName, **kwds) 

 

 

def wrapSimpleAlgorithm(AlgClass, executionOrder, name=None, needsMetadata=False, hasMeasureN=False, 

hasLogName=False, **kwds): 

"""! 

Wrap a C++ SimpleAlgorithm class into both a Python SingleFramePlugin and ForcedPlugin classes 

 

@param[in] AlgClass Swigged C++ Algorithm class to convert; must be a subclass of 

simpleAlgorithm, or an unrelated class with the same measure(), measureN(), 

and fail() signatures. 

@param[in] executionOrder The order this plugin should be run, relative to others 

(see BasePlugin.getExecutionOrder()). 

@param[in] name String to use when registering the algorithm. Ignored if doRegistry=False, 

set to generateAlgorithmName(AlgClass) if None. 

@param[in] needsMetadata Sets whether the AlgClass's constructor should be passed a PropertySet 

metadata argument. 

@param[in] hasMeasureN Whether the algorithm supports simultaneous measurement of multiple sources. 

If True, a bool doMeasureN field will be added to the generated Config class, 

and its value will be passed as the last argument when calling the AlgClass 

constructor. 

@param[in] hasLogName Plugin supports a logName as a constructor argument 

@param[in] **kwds Additional keyword arguments passed to the lower-level wrapAlgorithm and 

wrapAlgorithmControl classes. These include: 

- Control: Swigged C++ Control class for the algorithm; AlgClass.Control 

is used if None. Ignored if ConfigClass is not None. 

- ConfigClass: Python Config class that wraps the C++ Algorithm's swigged 

Control class. If None, wrapAlgorithmControl is called to generate a 

Config class using the Control argument. 

- doRegister: If True (the default), register the plugins with Base's 

registry, allowing it to be used by measurement Tasks. 

- shouldApCorr: does this algorithm measure a instFlux that can be aperture 

corrected? This is shorthand for apCorrList=[name] and is ignored if 

apCorrList is specified. 

- apCorrList: list of field name prefixes for instFlux fields that should be 

aperture corrected. If an algorithm produces a single instFlux that should be 

aperture corrected then it is simpler to set shouldApCorr=True. But if an 

algorithm produces multiple such fields then it must specify apCorrList, 

instead. For example modelfit_CModel produces 3 such fields: apCorrList= 

("modelfit_CModel_exp", "modelfit_CModel_exp", "modelfit_CModel_def") 

If apCorrList is non-empty then shouldApCorr is ignored. 

If non-empty and doRegister is True then the names are added to the set 

retrieved by getApCorrNameSet 

- executionOrder: If not None, an override for the default executionOrder for 

this plugin (the default is 2.0, which is usually appropriate for fluxes). 

 

@return a two-element tuple, containing the new SingleFramePlugin and ForcedPlugin subclasses 

 

The needsMetadata and hasMeasureN arguments combine to determine the expected constructor signature; 

we always expect the first three arguments to be: 

@verbatim 

Control const & ctrl, std::string const & name, Schema & schema 

@endverbatim 

If needsMetadata, we also append: 

@verbatim 

PropertySet & metadata 

@endverbatim 

If hasMeasureN, we also append: 

@verbatim 

bool doMeasureN 

@endverbatim 

If hasLogName, we also append: 

@verbatim 

std::string logName 

@endverbatim 

If more than one is True, the metadata PropertySet precedes the doMeasureN bool 

and the logName comes last of the three 

""" 

return (wrapSingleFrameAlgorithm(AlgClass, executionOrder=executionOrder, name=name, 

needsMetadata=needsMetadata, hasLogName=hasLogName, **kwds), 

wrapForcedAlgorithm(AlgClass, executionOrder=executionOrder, name=name, 

needsMetadata=needsMetadata, hasLogName=hasLogName, 

needsSchemaOnly=True, **kwds)) 

 

 

def wrapTransform(transformClass, hasLogName=False): 

"""Modify a C++ Transform class so that it can be configured with either a Config or a Control. 

 

Parameters 

---------- 

transformClass: class 

A Transform class. Its constructor must take a Control, a string, and 

a SchemaMapper, in that order. 

""" 

oldInit = transformClass.__init__ 

 

def _init(self, ctrl, name, mapper, logName=None): 

if hasattr(ctrl, "makeControl"): 

ctrl = ctrl.makeControl() 

# logName signature needs to be on this Class __init__, but is not needed by the C++ plugin 

oldInit(self, ctrl, name, mapper) 

 

transformClass.__init__ = _init 

 

 

class GenericPlugin(BasePlugin): 

"""Abstract base class for a generic plugin 

 

A generic plugin can be used with the `singleFramePluginFromGeneric` 

and/or `forcedPluginFromGeneric` wrappers to create classes that can 

be used for single frame measurement and/or forced measurement (as 

appropriate). The only real difference between `SingleFramePlugin` 

and `ForcedPlugin` is the `measure` method; this class introduces 

a shared signature for the `measure` method that, in combination 

with the afore-mentioned wrappers, allows both plugin styles to 

share a single implementation. 

 

This doesn't use abc.ABCMeta because I couldn't get it to work 

with a superclass. 

 

Sub-classes should set `ConfigClass` and implement the `measure` 

and `measureN` methods. They may optionally provide alternative 

implementations for the `__init__`, `fail` and `getExecutionOrder` 

methods. 

 

Constructor parameters 

---------------------- 

config : `lsst.pex.config.Config` 

An instance of this class' ConfigClass. 

name : `str` 

Name of this measurement plguin, for registering. 

schema : `lsst.afw.table.Schema` 

The catalog schema. New fields should be added here to 

hold measurements produced by this plugin. 

metadata : `lsst.daf.base.PropertySet` 

Metadata that will be attached to the output catalog. 

logName : `str` 

Name of log component. 

""" 

ConfigClass = None 

 

@classmethod 

def getExecutionOrder(cls): 

return 0 

 

def __init__(self, config, name, schema, metadata, logName=None): 

"""Constructor 

 

This default implementation simply adds a field for recording 

a fatal failure of the measurement plugin. 

""" 

BasePlugin.__init__(self, config, name, logName=logName) 

self._failKey = schema.addField(name + '_flag', type="Flag", doc="Set for any fatal failure") 

 

def measure(self, measRecord, exposure, center): 

"""Measure source 

 

It is the responsibility of this method to perform the desired 

measurement and record the result in the `measRecord`. 

 

Parameters 

---------- 

measRecord : `lsst.afw.table.SourceRecord` 

Catalog record for the source being measured. 

exposure : `lsst.afw.image.Exposure` 

Exposure on which the source is being measured. 

center : `lsst.geom.Point2D` 

Pixel coordinates of the object. 

 

Raises 

------ 

`MeasurementError` 

If the measurement fails for a known/justifiable reason. 

""" 

raise NotImplementedError() 

 

def measureN(self, measCat, exposure, refCat, refWcs): 

"""Measure multiple sources 

 

It is the responsibility of this method to perform the desired 

measurement and record the result in the `measCat`. 

 

Parameters 

---------- 

measCat : `lsst.afw.table.SourceCatalog` 

Catalog for the sources being measured. 

exposure : `lsst.afw.image.Exposure` 

Exposure on which the source is being measured. 

refCat : `lsst.afw.table.SourceCatalog` 

Reference catalog. 

refWcs : `lsst.afw.image.Wcs` 

Astrometric solution for the reference image. 

 

Raises 

------ 

`MeasurementError` 

If the measurement fails for a known/justifiable reason. 

""" 

raise NotImplementedError() 

 

def fail(self, measRecord, error=None): 

"""Record failure 

 

This default implementation simply records the failure 

in the source record. 

 

Parameters 

---------- 

measRecord : `lsst.afw.table.SourceRecord` 

Catalog record for the source being measured. 

error : `Exception` 

Error causing failure, or `None`. 

""" 

measRecord.set(self._failKey, True) 

 

@classmethod 

def makeSingleFramePlugin(cls, name): 

"""Produce a SingleFramePlugin sub-class from this GenericPlugin class 

 

The class is also registered. 

 

Parameters 

---------- 

name : `str` 

Name of plugin to register. 

""" 

class SingleFrameFromGenericConfig(cls.ConfigClass, SingleFramePluginConfig): 

pass 

 

@register(name) 

class SingleFrameFromGenericPlugin(SingleFramePlugin): 

ConfigClass = SingleFrameFromGenericConfig 

 

def __init__(self, config, name, schema, metadata, logName=None): 

SingleFramePlugin.__init__(self, config, name, schema, metadata, logName=logName) 

self._generic = cls(config, name, schema, metadata) 

 

def measure(self, measRecord, exposure): 

center = measRecord.getCentroid() 

return self._generic.measure(measRecord, exposure, center) 

 

def measureN(self, measCat, exposure, refCat, refWcs): 

return self._generic.measureN(measCat, exposure, refCat, refWcs) 

 

def fail(self, measRecord, error=None): 

self._generic.fail(measRecord, error if error is not None else None) 

 

@staticmethod 

def getExecutionOrder(): 

return cls.getExecutionOrder() 

 

def getTransformClass(self): 

return self._generic.getTransformClass() 

 

return SingleFrameFromGenericPlugin 

 

@classmethod 

def makeForcedPlugin(cls, name): 

"""Produce a ForcedPlugin sub-class from this GenericPlugin class 

 

The class is also registered. 

 

Parameters 

---------- 

name : `str` 

Name of plugin to register. 

""" 

class ForcedFromGenericConfig(cls.ConfigClass, ForcedPluginConfig): 

pass 

 

@register(name) 

class ForcedFromGenericPlugin(ForcedPlugin): 

ConfigClass = ForcedFromGenericConfig 

 

def __init__(self, config, name, schemaMapper, metadata, logName=None): 

ForcedPlugin.__init__(self, config, name, schemaMapper, metadata, logName=logName) 

schema = schemaMapper.editOutputSchema() 

self._generic = cls(config, name, schema, metadata) 

 

def measure(self, measRecord, exposure, refRecord, refWcs): 

center = exposure.getWcs().skyToPixel(refWcs.pixelToSky(refRecord.getCentroid())) 

return self._generic.measure(measRecord, exposure, center) 

 

def measureN(self, measCat, exposure, refCat, refWcs): 

return self._generic.measureN(measCat, exposure, refCat, refWcs) 

 

def fail(self, measRecord, error=None): 

self._generic.fail(measRecord, error if error is not None else None) 

 

@staticmethod 

def getExecutionOrder(): 

return cls.getExecutionOrder() 

 

def getTransformClass(self): 

return self._generic.getTransformClass() 

 

return ForcedFromGenericPlugin