or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

asteroseismology.mdcore-data.mddata-search.mdindex.mdprf-modeling.mdsystematics-correction.mdtime-series-analysis.md

prf-modeling.mddocs/

0

# Point Spread Function Modeling

1

2

Sophisticated PSF modeling and photometry for extracting precise light curves from pixel data. Particularly useful for crowded fields, faint targets, and high-precision photometry.

3

4

## Capabilities

5

6

### Basic PRF Models

7

8

```python { .api }

9

class KeplerPRF:

10

"""

11

Kepler Point Response Function model for PSF photometry.

12

Provides accurate PSF shape modeling across the Kepler field.

13

"""

14

15

def __init__(self, channel, shape, column, row):

16

"""

17

Initialize Kepler PRF model.

18

19

Parameters:

20

- channel: int - Kepler CCD channel (1-84)

21

- shape: tuple - Shape of PRF model (rows, cols)

22

- column: float - Column position on detector

23

- row: float - Row position on detector

24

"""

25

26

def evaluate(self, column, row, flux, **kwargs):

27

"""

28

Evaluate PRF model at given positions.

29

30

Parameters:

31

- column: float or array - Column positions

32

- row: float or array - Row positions

33

- flux: float or array - Source fluxes

34

35

Returns:

36

2D array with evaluated PRF

37

"""

38

39

class SimpleKeplerPRF(KeplerPRF):

40

"""Simplified Kepler PRF model with reduced complexity"""

41

```

42

43

### Advanced PRF Photometry (requires oktopus)

44

45

#### Prior Distributions

46

47

```python { .api }

48

class GaussianPrior:

49

"""Gaussian prior distribution for Bayesian PRF fitting"""

50

51

def __init__(self, mean, var):

52

"""

53

Parameters:

54

- mean: float - Prior mean

55

- var: float - Prior variance

56

"""

57

58

class UniformPrior:

59

"""Uniform prior distribution"""

60

61

def __init__(self, lower, upper):

62

"""

63

Parameters:

64

- lower: float - Lower bound

65

- upper: float - Upper bound

66

"""

67

68

class FixedValuePrior:

69

"""Fixed value prior for known parameters"""

70

71

def __init__(self, value):

72

"""

73

Parameters:

74

- value: float - Fixed parameter value

75

"""

76

77

class StarPrior:

78

"""Prior for stellar position and flux parameters"""

79

80

class BackgroundPrior:

81

"""Prior for background level parameters"""

82

83

class FocusPrior:

84

"""Prior for telescope focus parameters"""

85

86

class MotionPrior:

87

"""Prior for spacecraft motion parameters"""

88

```

89

90

#### Parameter Containers

91

92

```python { .api }

93

class StarParameters:

94

"""Container for star-related model parameters"""

95

96

def __init__(self, stars):

97

"""

98

Parameters:

99

- stars: list - List of star parameter dictionaries

100

"""

101

102

class BackgroundParameters:

103

"""Container for background model parameters"""

104

105

class FocusParameters:

106

"""Container for focus model parameters"""

107

108

class MotionParameters:

109

"""Container for motion model parameters"""

110

111

class TPFModelParameters:

112

"""Container for all target pixel file model parameters"""

113

114

def __init__(self, stars=None, background=None, focus=None, motion=None):

115

"""

116

Parameters:

117

- stars: StarParameters - Star model parameters

118

- background: BackgroundParameters - Background parameters

119

- focus: FocusParameters - Focus parameters

120

- motion: MotionParameters - Motion parameters

121

"""

122

```

123

124

#### PRF Model and Photometry

125

126

```python { .api }

127

class TPFModel:

128

"""

129

Complete target pixel file model for PRF photometry.

130

Combines PRF, background, focus, and motion models.

131

"""

132

133

def __init__(self, params):

134

"""

135

Parameters:

136

- params: TPFModelParameters - Model parameters

137

"""

138

139

def evaluate(self, **kwargs):

140

"""Evaluate complete TPF model"""

141

142

def gradient(self, **kwargs):

143

"""Compute model gradients for optimization"""

144

145

class PRFPhotometry:

146

"""

147

High-level interface for PRF photometry analysis.

148

Provides complete workflow from model setup to light curve extraction.

149

"""

150

151

def __init__(self, tpf):

152

"""

153

Initialize PRF photometry.

154

155

Parameters:

156

- tpf: TargetPixelFile - Target pixel file for analysis

157

"""

158

159

def setup_model(self, star_priors=None, **kwargs):

160

"""

161

Set up PRF model with priors.

162

163

Parameters:

164

- star_priors: list - Prior distributions for stars

165

- background_prior: Prior - Background level prior

166

- focus_prior: Prior - Focus parameter prior

167

- motion_prior: Prior - Motion parameter prior

168

169

Returns:

170

Configured TPFModel

171

"""

172

173

def fit(self, model=None, **kwargs):

174

"""

175

Fit PRF model to data.

176

177

Parameters:

178

- model: TPFModel - Model to fit (uses setup_model if None)

179

- method: str - Optimization method ('gradient', 'mcmc')

180

- max_iterations: int - Maximum optimization iterations

181

182

Returns:

183

Fitted model parameters and uncertainties

184

"""

185

186

def extract_lightcurve(self, fitted_params, **kwargs):

187

"""

188

Extract light curve from fitted PRF model.

189

190

Parameters:

191

- fitted_params: Fitted model parameters

192

- star_id: int - Which star to extract (for multi-star models)

193

194

Returns:

195

LightCurve object with PRF photometry

196

"""

197

```

198

199

## Usage Examples

200

201

### Basic PRF Evaluation

202

203

```python

204

import lightkurve as lk

205

206

# Download target pixel file

207

search = lk.search_targetpixelfile('Kepler-10')

208

tpf = search[0].download()

209

210

# Initialize PRF model

211

channel = tpf.channel

212

prf = lk.KeplerPRF(channel=channel,

213

shape=tpf.flux[0].shape,

214

column=tpf.column,

215

row=tpf.row)

216

217

# Evaluate PRF at target position

218

prf_model = prf.evaluate(column=tpf.column + 2,

219

row=tpf.row + 2,

220

flux=1000)

221

222

# Visualize PRF

223

import matplotlib.pyplot as plt

224

plt.imshow(prf_model, origin='lower')

225

plt.title('Kepler PRF Model')

226

```

227

228

### Advanced PRF Photometry

229

230

```python

231

# Note: Requires oktopus package

232

try:

233

# Initialize PRF photometry

234

prf_phot = lk.PRFPhotometry(tpf)

235

236

# Set up priors for target star

237

star_priors = [

238

{

239

'column': lk.GaussianPrior(tpf.column + 2, 0.1),

240

'row': lk.GaussianPrior(tpf.row + 2, 0.1),

241

'flux': lk.UniformPrior(500, 2000)

242

}

243

]

244

245

# Configure model

246

model = prf_phot.setup_model(star_priors=star_priors)

247

248

# Fit model to data

249

fitted_params = prf_phot.fit(model, method='gradient')

250

251

# Extract precise light curve

252

prf_lc = prf_phot.extract_lightcurve(fitted_params)

253

254

# Compare with simple aperture photometry

255

aperture_lc = tpf.to_lightcurve()

256

257

aperture_lc.plot(label='Aperture Photometry')

258

prf_lc.plot(label='PRF Photometry')

259

260

print(f"Aperture CDPP: {aperture_lc.estimate_cdpp():.1f} ppm")

261

print(f"PRF CDPP: {prf_lc.estimate_cdpp():.1f} ppm")

262

263

except ImportError:

264

print("Advanced PRF features require the oktopus package")

265

print("Install with: pip install oktopus")

266

```

267

268

### Multi-Star PRF Modeling

269

270

```python

271

# Model multiple stars in the same TPF

272

try:

273

# Define priors for multiple stars

274

multi_star_priors = [

275

{ # Primary target

276

'column': lk.GaussianPrior(tpf.column + 2, 0.1),

277

'row': lk.GaussianPrior(tpf.row + 2, 0.1),

278

'flux': lk.UniformPrior(800, 1200)

279

},

280

{ # Nearby contaminating star

281

'column': lk.GaussianPrior(tpf.column + 4, 0.2),

282

'row': lk.GaussianPrior(tpf.row + 1, 0.2),

283

'flux': lk.UniformPrior(100, 400)

284

}

285

]

286

287

# Fit multi-star model

288

prf_phot = lk.PRFPhotometry(tpf)

289

model = prf_phot.setup_model(star_priors=multi_star_priors)

290

fitted_params = prf_phot.fit(model)

291

292

# Extract light curves for each star

293

primary_lc = prf_phot.extract_lightcurve(fitted_params, star_id=0)

294

contaminator_lc = prf_phot.extract_lightcurve(fitted_params, star_id=1)

295

296

primary_lc.plot(label='Primary Star')

297

contaminator_lc.plot(label='Contaminating Star')

298

299

except ImportError:

300

print("Multi-star PRF modeling requires oktopus package")

301

```

302

303

### Crowded Field Analysis

304

305

```python

306

# Analyze crowded field with multiple sources

307

try:

308

# Download TPF for crowded region

309

crowded_search = lk.search_targetpixelfile('M67', radius=0.1)

310

crowded_tpf = crowded_search[0].download()

311

312

# Set up many-star model (example with 5 stars)

313

star_positions = [

314

(5, 5), (7, 6), (3, 8), (9, 4), (6, 9)

315

]

316

317

crowded_priors = []

318

for col, row in star_positions:

319

crowded_priors.append({

320

'column': lk.GaussianPrior(col, 0.5),

321

'row': lk.GaussianPrior(row, 0.5),

322

'flux': lk.UniformPrior(50, 500)

323

})

324

325

# Fit crowded field model

326

crowded_prf = lk.PRFPhotometry(crowded_tpf)

327

crowded_model = crowded_prf.setup_model(star_priors=crowded_priors)

328

crowded_fit = crowded_prf.fit(crowded_model, max_iterations=1000)

329

330

# Extract individual light curves

331

for star_id in range(len(star_positions)):

332

star_lc = crowded_prf.extract_lightcurve(crowded_fit, star_id=star_id)

333

star_lc.plot(label=f'Star {star_id+1}')

334

335

except ImportError:

336

print("Crowded field analysis requires oktopus package")

337

```

338

339

### Custom PRF Model Setup

340

341

```python

342

# Advanced model configuration with all parameter types

343

try:

344

prf_phot = lk.PRFPhotometry(tpf)

345

346

# Define comprehensive priors

347

star_priors = [{

348

'column': lk.GaussianPrior(tpf.column + 2, 0.1),

349

'row': lk.GaussianPrior(tpf.row + 2, 0.1),

350

'flux': lk.UniformPrior(500, 1500)

351

}]

352

353

background_prior = lk.GaussianPrior(10, 5) # Background level

354

focus_prior = lk.GaussianPrior(1.0, 0.1) # Focus parameter

355

motion_prior = lk.GaussianPrior(0.0, 0.05) # Motion parameter

356

357

# Set up complete model

358

model = prf_phot.setup_model(

359

star_priors=star_priors,

360

background_prior=background_prior,

361

focus_prior=focus_prior,

362

motion_prior=motion_prior

363

)

364

365

# Fit with MCMC for uncertainty estimation

366

fitted_params = prf_phot.fit(model, method='mcmc')

367

368

# Extract light curve with uncertainties

369

prf_lc = prf_phot.extract_lightcurve(fitted_params)

370

371

except ImportError:

372

print("Advanced PRF modeling requires oktopus package")

373

```