Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tf -> scipy #198

Open
wants to merge 29 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
44f626a
create new psf branch
benmontet Sep 8, 2020
aa1aa2c
added zernike model
aditya-sengupta Sep 8, 2020
2afa9d0
added Zernike functionality and slightly generalized psf_lightcurve
aditya-sengupta Sep 8, 2020
c8e22c9
added Lygos, bugfixing Zernike
aditya-sengupta Sep 9, 2020
fb19b49
syntax fixes and moving closer to actual fits
aditya-sengupta Sep 9, 2020
a9a7d12
tensorflow variable composition issues
aditya-sengupta Sep 9, 2020
b2db2e0
day 1 wrap up
aditya-sengupta Sep 9, 2020
be1b11b
save before moffat-alt test
aditya-sengupta Sep 9, 2020
a3f6c24
confirmed tf issues
aditya-sengupta Sep 9, 2020
0990675
tensorflow death
aditya-sengupta Sep 9, 2020
7bba631
lygos finally fitting!
aditya-sengupta Sep 9, 2020
8972bd1
fitting is happening!
aditya-sengupta Sep 10, 2020
ccf9de2
recentering zernikes
aditya-sengupta Sep 10, 2020
d64800a
decent-looking zernike fit!
aditya-sengupta Sep 10, 2020
ce3da06
first look at optimizers
aditya-sengupta Sep 17, 2020
02a4335
quick fix to tesscut_size
aditya-sengupta Sep 21, 2020
7c66824
merge tf changes with tesscut_size change
aditya-sengupta Sep 21, 2020
8269a15
dropin scipy replacement for tf
aditya-sengupta Sep 21, 2020
95e09b7
scipy the same as tf
aditya-sengupta Sep 22, 2020
91fad25
test consistent
aditya-sengupta Sep 22, 2020
1c91ea8
roll back from here
aditya-sengupta Sep 22, 2020
032c7b1
second set of rollbacks
aditya-sengupta Sep 22, 2020
e7f3015
stable with no tf
aditya-sengupta Sep 22, 2020
428b4ca
ready for upgrade test
aditya-sengupta Sep 22, 2020
351a279
ready for merge
aditya-sengupta Sep 22, 2020
f41389c
finally ready for PR
aditya-sengupta Sep 22, 2020
5f4b3b3
background fit first steps
aditya-sengupta Oct 3, 2020
4f2bdff
workaround for unit issue
aditya-sengupta Oct 3, 2020
d0eac4b
fix merge conflict with master
aditya-sengupta Oct 4, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ before_install:
install:
- pip install tornado==5.1.1
- pip install lightkurve
- pip install tensorflow
- pip install astropy
- pip install astroquery
- pip install tqdm
Expand Down
27 changes: 7 additions & 20 deletions docs/getting_started/tips_tricks.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -54,27 +54,14 @@
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"INFO: Found cached file /Users/bmontet/.eleanor/mastDownload/HLSP/hlsp_eleanor_tess_ffi_postcard-s0001-4-1-cal-0902-1078_tess_v2_pc/hlsp_eleanor_tess_ffi_postcard-s0001-4-1-cal-0902-1078_tess_v2_bkg.fits with expected size 78955200. [astroquery.query]\n",
"INFO: Found cached file /Users/bmontet/.eleanor/mastDownload/HLSP/hlsp_eleanor_tess_ffi_postcard-s0001-4-1-cal-0902-1078_tess_v2_pc/hlsp_eleanor_tess_ffi_postcard-s0001-4-1-cal-0902-1078_tess_v2_pc.fits with expected size 158022720. [astroquery.query]\n",
"INFO: Found cached file /Users/bmontet/.eleanor/mastDownload/HLSP/hlsp_eleanor_tess_ffi_postcard-s0001-4-1-cal-0902-1078_tess_v2_pc/hlsp_eleanor_tess_ffi_postcard-s0001-4-1_tess_v2_pm.txt with expected size 237847. [astroquery.query]\n",
"WARNING:tensorflow:From /Users/bmontet/research/tess/eleanor/eleanor/targetdata.py:837: The name tf.logging.set_verbosity is deprecated. Please use tf.compat.v1.logging.set_verbosity instead.\n",
"\n",
"WARNING:tensorflow:From /Users/bmontet/research/tess/eleanor/eleanor/targetdata.py:837: The name tf.logging.ERROR is deprecated. Please use tf.compat.v1.logging.ERROR instead.\n",
"\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 1282/1282 [00:10<00:00, 113.98it/s]\n"
]
"name": "stdout",
"text": "INFO: Found cached file /Users/adityasengupta/.eleanor/mastDownload/HLSP/hlsp_eleanor_tess_ffi_postcard-s0001-4-1-cal-0902-1078_tess_v2_pc/hlsp_eleanor_tess_ffi_postcard-s0001-4-1-cal-0902-1078_tess_v2_bkg.fits with expected size 78955200. [astroquery.query]\nINFO: Found cached file /Users/adityasengupta/.eleanor/mastDownload/HLSP/hlsp_eleanor_tess_ffi_postcard-s0001-4-1-cal-0902-1078_tess_v2_pc/hlsp_eleanor_tess_ffi_postcard-s0001-4-1-cal-0902-1078_tess_v2_pc.fits with expected size 158022720. [astroquery.query]\nINFO: Found cached file /Users/adityasengupta/.eleanor/mastDownload/HLSP/hlsp_eleanor_tess_ffi_postcard-s0001-4-1-cal-0902-1078_tess_v2_pc/hlsp_eleanor_tess_ffi_postcard-s0001-4-1_tess_v2_pm.txt with expected size 237847. [astroquery.query]\n100%|██████████| 1282/1282 [00:40<00:00, 31.83it/s]\n"
}
],
"source": [
Expand Down Expand Up @@ -977,9 +964,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.7.9-final"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
}
70 changes: 18 additions & 52 deletions docs/getting_started/tutorial.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -58,17 +58,14 @@
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"INFO: Found cached file /Users/bmontet/.eleanor/mastDownload/HLSP/hlsp_eleanor_tess_ffi_postcard-s0001-4-1-cal-0902-1078_tess_v2_pc/hlsp_eleanor_tess_ffi_postcard-s0001-4-1-cal-0902-1078_tess_v2_bkg.fits with expected size 78955200. [astroquery.query]\n",
"INFO: Found cached file /Users/bmontet/.eleanor/mastDownload/HLSP/hlsp_eleanor_tess_ffi_postcard-s0001-4-1-cal-0902-1078_tess_v2_pc/hlsp_eleanor_tess_ffi_postcard-s0001-4-1-cal-0902-1078_tess_v2_pc.fits with expected size 158022720. [astroquery.query]\n",
"INFO: Found cached file /Users/bmontet/.eleanor/mastDownload/HLSP/hlsp_eleanor_tess_ffi_postcard-s0001-4-1-cal-0902-1078_tess_v2_pc/hlsp_eleanor_tess_ffi_postcard-s0001-4-1_tess_v2_pm.txt with expected size 237847. [astroquery.query]\n",
"Found TIC 38846515 (Gaia 4675352109658261376), with TESS magnitude 10.3157, RA 68.9597092399964, and Dec -64.0270368810381\n"
]
"name": "stdout",
"text": "INFO: Found cached file /Users/adityasengupta/.eleanor/mastDownload/HLSP/hlsp_eleanor_tess_ffi_postcard-s0001-4-1-cal-0902-1078_tess_v2_pc/hlsp_eleanor_tess_ffi_postcard-s0001-4-1-cal-0902-1078_tess_v2_bkg.fits with expected size 78955200. [astroquery.query]\nINFO: Found cached file /Users/adityasengupta/.eleanor/mastDownload/HLSP/hlsp_eleanor_tess_ffi_postcard-s0001-4-1-cal-0902-1078_tess_v2_pc/hlsp_eleanor_tess_ffi_postcard-s0001-4-1-cal-0902-1078_tess_v2_pc.fits with expected size 158022720. [astroquery.query]\nINFO: Found cached file /Users/adityasengupta/.eleanor/mastDownload/HLSP/hlsp_eleanor_tess_ffi_postcard-s0001-4-1-cal-0902-1078_tess_v2_pc/hlsp_eleanor_tess_ffi_postcard-s0001-4-1_tess_v2_pm.txt with expected size 237847. [astroquery.query]\nFound TIC 38846515 (Gaia 4675352109658261376), with TESS magnitude 10.3157, RA 68.9597092399964, and Dec -64.0270368810381\n"
}
],
"source": [
Expand All @@ -92,35 +89,14 @@
{
"cell_type": "code",
"execution_count": 4,
"metadata": {},
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"INFO: Found cached file /Users/bmontet/.eleanor/mastDownload/HLSP/hlsp_eleanor_tess_ffi_postcard-s0001-4-1-cal-0902-1078_tess_v2_pc/hlsp_eleanor_tess_ffi_postcard-s0001-4-1-cal-0902-1078_tess_v2_bkg.fits with expected size 78955200. [astroquery.query]\n",
"INFO: Found cached file /Users/bmontet/.eleanor/mastDownload/HLSP/hlsp_eleanor_tess_ffi_postcard-s0001-4-1-cal-0902-1078_tess_v2_pc/hlsp_eleanor_tess_ffi_postcard-s0001-4-1-cal-0902-1078_tess_v2_pc.fits with expected size 158022720. [astroquery.query]\n",
"INFO: Found cached file /Users/bmontet/.eleanor/mastDownload/HLSP/hlsp_eleanor_tess_ffi_postcard-s0001-4-1-cal-0902-1078_tess_v2_pc/hlsp_eleanor_tess_ffi_postcard-s0001-4-1_tess_v2_pm.txt with expected size 237847. [astroquery.query]\n",
"Found TIC 38846515 (Gaia 4675352109658261376), with TESS magnitude 10.3157, RA 68.95970916666666, and Dec -64.02703666666666\n",
"INFO: Found cached file /Users/bmontet/.eleanor/mastDownload/HLSP/hlsp_eleanor_tess_ffi_postcard-s0001-4-1-cal-0902-1078_tess_v2_pc/hlsp_eleanor_tess_ffi_postcard-s0001-4-1-cal-0902-1078_tess_v2_bkg.fits with expected size 78955200. [astroquery.query]\n",
"INFO: Found cached file /Users/bmontet/.eleanor/mastDownload/HLSP/hlsp_eleanor_tess_ffi_postcard-s0001-4-1-cal-0902-1078_tess_v2_pc/hlsp_eleanor_tess_ffi_postcard-s0001-4-1-cal-0902-1078_tess_v2_pc.fits with expected size 158022720. [astroquery.query]\n",
"INFO: Found cached file /Users/bmontet/.eleanor/mastDownload/HLSP/hlsp_eleanor_tess_ffi_postcard-s0001-4-1-cal-0902-1078_tess_v2_pc/hlsp_eleanor_tess_ffi_postcard-s0001-4-1_tess_v2_pm.txt with expected size 237847. [astroquery.query]\n",
"Found TIC 38846515 (Gaia 4675352109658261376), with TESS magnitude 10.3157, RA 68.959732, and Dec -64.02704\n",
"Created TAP+ (v1.2.1) - Connection:\n",
"\tHost: gea.esac.esa.int\n",
"\tUse HTTPS: True\n",
"\tPort: 443\n",
"\tSSL Port: 443\n",
"Created TAP+ (v1.2.1) - Connection:\n",
"\tHost: geadata.esac.esa.int\n",
"\tUse HTTPS: True\n",
"\tPort: 443\n",
"\tSSL Port: 443\n",
"INFO: Found cached file /Users/bmontet/.eleanor/mastDownload/HLSP/hlsp_eleanor_tess_ffi_postcard-s0001-4-1-cal-0902-1078_tess_v2_pc/hlsp_eleanor_tess_ffi_postcard-s0001-4-1-cal-0902-1078_tess_v2_bkg.fits with expected size 78955200. [astroquery.query]\n",
"INFO: Found cached file /Users/bmontet/.eleanor/mastDownload/HLSP/hlsp_eleanor_tess_ffi_postcard-s0001-4-1-cal-0902-1078_tess_v2_pc/hlsp_eleanor_tess_ffi_postcard-s0001-4-1-cal-0902-1078_tess_v2_pc.fits with expected size 158022720. [astroquery.query]\n",
"INFO: Found cached file /Users/bmontet/.eleanor/mastDownload/HLSP/hlsp_eleanor_tess_ffi_postcard-s0001-4-1-cal-0902-1078_tess_v2_pc/hlsp_eleanor_tess_ffi_postcard-s0001-4-1_tess_v2_pm.txt with expected size 237847. [astroquery.query]\n",
"Found TIC 38846515 (Gaia 4675352109658261376), with TESS magnitude 10.3157, RA 68.95981586357303, and Dec -64.02703903114245\n"
]
"name": "stdout",
"text": "INFO: Found cached file /Users/adityasengupta/.eleanor/mastDownload/HLSP/hlsp_eleanor_tess_ffi_postcard-s0001-4-1-cal-0902-1078_tess_v2_pc/hlsp_eleanor_tess_ffi_postcard-s0001-4-1-cal-0902-1078_tess_v2_bkg.fits with expected size 78955200. [astroquery.query]\nINFO: Found cached file /Users/adityasengupta/.eleanor/mastDownload/HLSP/hlsp_eleanor_tess_ffi_postcard-s0001-4-1-cal-0902-1078_tess_v2_pc/hlsp_eleanor_tess_ffi_postcard-s0001-4-1-cal-0902-1078_tess_v2_pc.fits with expected size 158022720. [astroquery.query]\nINFO: Found cached file /Users/adityasengupta/.eleanor/mastDownload/HLSP/hlsp_eleanor_tess_ffi_postcard-s0001-4-1-cal-0902-1078_tess_v2_pc/hlsp_eleanor_tess_ffi_postcard-s0001-4-1_tess_v2_pm.txt with expected size 237847. [astroquery.query]\nFound TIC 38846515 (Gaia 4675352109658261376), with TESS magnitude 10.3157, RA 68.95970916666666, and Dec -64.02703666666666\nINFO: Found cached file /Users/adityasengupta/.eleanor/mastDownload/HLSP/hlsp_eleanor_tess_ffi_postcard-s0001-4-1-cal-0902-1078_tess_v2_pc/hlsp_eleanor_tess_ffi_postcard-s0001-4-1-cal-0902-1078_tess_v2_bkg.fits with expected size 78955200. [astroquery.query]\nINFO: Found cached file /Users/adityasengupta/.eleanor/mastDownload/HLSP/hlsp_eleanor_tess_ffi_postcard-s0001-4-1-cal-0902-1078_tess_v2_pc/hlsp_eleanor_tess_ffi_postcard-s0001-4-1-cal-0902-1078_tess_v2_pc.fits with expected size 158022720. [astroquery.query]\nINFO: Found cached file /Users/adityasengupta/.eleanor/mastDownload/HLSP/hlsp_eleanor_tess_ffi_postcard-s0001-4-1-cal-0902-1078_tess_v2_pc/hlsp_eleanor_tess_ffi_postcard-s0001-4-1_tess_v2_pm.txt with expected size 237847. [astroquery.query]\nFound TIC 38846515 (Gaia 4675352109658261376), with TESS magnitude 10.3157, RA 68.959732, and Dec -64.02704\nCreated TAP+ (v1.2.1) - Connection:\n\tHost: gea.esac.esa.int\n\tUse HTTPS: True\n\tPort: 443\n\tSSL Port: 443\nCreated TAP+ (v1.2.1) - Connection:\n\tHost: geadata.esac.esa.int\n\tUse HTTPS: True\n\tPort: 443\n\tSSL Port: 443\nINFO: Found cached file /Users/adityasengupta/.eleanor/mastDownload/HLSP/hlsp_eleanor_tess_ffi_postcard-s0001-4-1-cal-0902-1078_tess_v2_pc/hlsp_eleanor_tess_ffi_postcard-s0001-4-1-cal-0902-1078_tess_v2_bkg.fits with expected size 78955200. [astroquery.query]\nINFO: Found cached file /Users/adityasengupta/.eleanor/mastDownload/HLSP/hlsp_eleanor_tess_ffi_postcard-s0001-4-1-cal-0902-1078_tess_v2_pc/hlsp_eleanor_tess_ffi_postcard-s0001-4-1-cal-0902-1078_tess_v2_pc.fits with expected size 158022720. [astroquery.query]\nINFO: Found cached file /Users/adityasengupta/.eleanor/mastDownload/HLSP/hlsp_eleanor_tess_ffi_postcard-s0001-4-1-cal-0902-1078_tess_v2_pc/hlsp_eleanor_tess_ffi_postcard-s0001-4-1_tess_v2_pm.txt with expected size 237847. [astroquery.query]\nFound TIC 38846515 (Gaia 4675352109658261376), with TESS magnitude 10.3157, RA 68.95981586357303, and Dec -64.02703903114245\n"
}
],
"source": [
Expand Down Expand Up @@ -168,24 +144,14 @@
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"WARNING:tensorflow:From /Users/bmontet/research/tess/eleanor/eleanor/targetdata.py:837: The name tf.logging.set_verbosity is deprecated. Please use tf.compat.v1.logging.set_verbosity instead.\n",
"\n",
"WARNING:tensorflow:From /Users/bmontet/research/tess/eleanor/eleanor/targetdata.py:837: The name tf.logging.ERROR is deprecated. Please use tf.compat.v1.logging.ERROR instead.\n",
"\n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"100%|██████████| 1282/1282 [00:10<00:00, 120.90it/s]\n"
]
"name": "stdout",
"text": "Loading file hlsp_eleanor_tess_ffi_tic38846515_s01_tess_v1.0.5_lc.fits found on disk\n"
}
],
"source": [
Expand Down Expand Up @@ -577,7 +543,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"PSF modeling (`do_psf=True`) seems to work very well for relatively bright, isolated stars. Presently the only PSF models usable are Gaussian and Moffat profiles. Both Gaussian and Poisson likelihood functions are possible as well. Do note that this requires tensorflow<2.0. Note that PSF modeling is very much in beta and our current implementation has known issues for very faint stars (fainter than I ~ 15, generally). "
"PSF modeling (`do_psf=True`) seems to work very well for relatively bright, isolated stars. Presently the only PSF models usable are Gaussian and Moffat profiles. Both Gaussian and Poisson likelihood functions are possible as well. Note that PSF modeling is very much in beta and our current implementation has known issues for very faint stars (fainter than I ~ 15, generally). "
]
},
{
Expand Down Expand Up @@ -605,9 +571,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.7.9-final"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
}
2 changes: 1 addition & 1 deletion eleanor/mast.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ def crossmatch_distance(pos, match):
c2 = SkyCoord(match[0]*u.deg, match[1]*u.deg, frame='icrs')
return c1.separation(c2).to(u.arcsec)

def tic_by_contamination(pos, r, contam, tmag_lim):
def tic_by_contamination(pos, r, contam, tmag_lim, call_internal=False):
"""Allows the user to perform a counts only query.

When unsure how many results are expcted, it is best to first perform
Expand Down
190 changes: 137 additions & 53 deletions eleanor/models.py
Original file line number Diff line number Diff line change
@@ -1,70 +1,154 @@
import math

import os
from astropy.io import fits as pyfits
from lightkurve.utils import channel_to_module_output
import numpy as np
import tensorflow as tf
import warnings
from abc import ABC

# Vaneska models of Ze Vinicius

class Model:
"""
Pretty dumb Gaussian model.
Attributes
----------
shape : tuple
shape of the TPF. (row_shape, col_shape)
col_ref, row_ref : int, int
column and row coordinates of the bottom
left corner of the TPF
"""
def __init__(self, shape, col_ref, row_ref):
self.shape = shape
self.col_ref = col_ref
self.row_ref = row_ref
self._init_grid()
class Model(ABC):
"""
Base PSF-fitting model.
Attributes
----------
shape : tuple
shape of the TPF. (row_shape, col_shape)
col_ref, row_ref : int, int
column and row coordinates of the bottom
left corner of the TPF
"""
def __init__(self, shape, col_ref, row_ref, xc, yc, nstars, bkg0, **kwargs):
self.shape = shape
self.col_ref = col_ref
self.row_ref = row_ref
self.xc = xc
self.yc = yc
self.nstars = nstars
self.bkg0 = bkg0
self._init_grid()

def __call__(self, *params):
return self.evaluate(*params)

def _init_grid(self):
r, c = self.row_ref, self.col_ref
s1, s2 = self.shape
self.y, self.x = np.mgrid[r:r+s1-1:1j*s1, c:c+s2-1:1j*s2]

def _init_grid(self):
r, c = self.row_ref, self.col_ref
s1, s2 = self.shape
self.y, self.x = np.mgrid[r:r+s1-1:1j*s1, c:c+s2-1:1j*s2]
def mean(self, flux, xshift, yshift, bkg, optpars):
return np.sum([self.evaluate(flux[j], self.xc[j]+xshift, self.yc[j]+yshift, *optpars) for j in range(self.nstars)], axis=0) + bkg

def get_default_par(self, d0):
return np.concatenate((np.max(d0) * np.ones(self.nstars,), np.array([0, 0, self.bkg0], self.get_default_optpars())))

class Gaussian(Model):
def __call__(self, *params):
return self.evaluate(*params)
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.bounds = np.vstack((
np.tile([0, np.infty], (self.nstars, 1)),
np.array([
[-1.0, 1.0],
[-1.0, 1.0],
[0, np.infty],
[0, np.infty],
[-0.5, 0.5],
[0, np.infty],
])
))

def get_default_optpars(self):
return np.array([1, 0, 1], dtype=np.float64)

def evaluate(self, flux, xo, yo, a, b, c):
"""
Evaluate the Gaussian model
Parameters
----------
flux : np.ndarray, (nstars,)
xo, yo : tf.Variable, tf.Variable
Center coordinates of the Gaussian.
a, b, c : tf.Variable, tf.Variable
Parameters that control the rotation angle
and the stretch along the major axis of the Gaussian,
such that the matrix M = [a b ; b c] is positive-definite.
References
----------
https://en.wikipedia.org/wiki/Gaussian_function#Two-dimensional_Gaussian_function
"""
dx = self.x - xo
dy = self.y - yo
psf = np.exp(-(a * dx ** 2 + 2 * b * dx * dy + c * dy ** 2))
psf_sum = np.sum(psf)
return flux * psf / psf_sum

class MultiGaussian(Model):
"""

"""
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.bounds = np.vstack((
np.tile([0, np.infty], (self.nstars, 1)),
np.array([
[-1.0, 1.0],
[-1.0, 1.0],
[0, np.infty],
[0, np.infty],
[-0.5, 0.5],
[0, np.infty],
])
))

def evaluate(self, flux, xo, yo, a, b, c):
"""
Evaluate the Gaussian model
Parameters
----------
flux : tf.Variable
xo, yo : tf.Variable, tf.Variable
Center coordiantes of the Gaussian.
a, b, c : tf.Variable, tf.Variable
Parameters that control the rotation angle
and the stretch along the major axis of the Gaussian,
such that the matrix M = [a b ; b c] is positive-definite.
References
----------
https://en.wikipedia.org/wiki/Gaussian_function#Two-dimensional_Gaussian_function
"""
dx = self.x - xo
dy = self.y - yo
psf = tf.exp(-(a * dx ** 2 + 2 * b * dx * dy + c * dy ** 2))
psf_sum = tf.reduce_sum(psf)
return flux * psf / psf_sum
def get_default_optpars(self):
return np.array([1, 0, 1], dtype=np.float64)

def evaluate(self, flux, xo, yo, a, b, c):
"""
Evaluate the Gaussian model
Parameters
----------
flux : np.ndarray, (nstars,)
xo, yo : tf.Variable, tf.Variable
Center coordinates of the Gaussian.
a, b, c : tf.Variable, tf.Variable
Parameters that control the rotation angle
and the stretch along the major axis of the Gaussian,
such that the matrix M = [a b ; b c] is positive-definite.
References
----------
https://en.wikipedia.org/wiki/Gaussian_function#Two-dimensional_Gaussian_function
"""
dx = self.x - xo
dy = self.y - yo
psf = np.exp(-(a * dx ** 2 + 2 * b * dx * dy + c * dy ** 2))
psf_sum = np.sum(psf)
return flux * psf / psf_sum


class Moffat(Model):
def __call__(self, *params):
return self.evaluate(*params)
def __init__(self, **kwargs):
super().__init__(**kwargs)
self.bounds = np.vstack((
np.tile([0, np.infty], (self.nstars, 1)),
np.array([
[-2.0, 2.0],
[-2.0, 2.0],
[0, np.infty],
[0., 3.0],
[-0.5, 0.5],
[0., 3.0],
])
))

def evaluate(self, flux, xo, yo, a, b, c, beta):
dx = self.x - xo
dy = self.y - yo
psf = tf.divide(1., tf.pow(1. + a * dx ** 2 + 2 * b * dx * dy + c * dy ** 2, beta))
psf_sum = tf.reduce_sum(psf)
return flux * psf / psf_sum
def get_default_optpars(self):
return np.array([1, 0, 1, 1], dtype=np.float64)

def evaluate(self, flux, xo, yo, a, b, c, beta):
dx = self.x - xo
dy = self.y - yo
psf = np.divide(1., np.pow(1. + a * dx ** 2 + 2 * b * dx * dy + c * dy ** 2, beta))
psf_sum = np.sum(psf)
return flux * psf / psf_sum

Loading