Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
05f4e26
:sparkles: Developing PerturbationMatrix class
christinahedges Mar 30, 2022
172fbda
:white_check_mark: fixing flake8
christinahedges Mar 30, 2022
fb31d8b
:sparkles: added a 3D matrix
christinahedges Mar 31, 2022
d37a540
:art: fairly good sketch
christinahedges Apr 2, 2022
884f24d
Update src/psfmachine/perturbation.py
christinahedges Apr 5, 2022
18cca59
Update src/psfmachine/perturbation.py
christinahedges Apr 5, 2022
3df9bea
fixing identation and _clean_vectors when segments=True
jorgemarpa Apr 5, 2022
b64b9cc
:zap: faster!
christinahedges Apr 5, 2022
2d55aa1
:art: adding pixel masking
christinahedges Apr 5, 2022
7310ed3
:memo: added docstrings
christinahedges Apr 5, 2022
34d943c
smooth vector fx
jorgemarpa Apr 6, 2022
7648325
improved plots and docstrings
jorgemarpa Apr 6, 2022
b330ee6
machine uses PerturbationMatrix3D
jorgemarpa Apr 6, 2022
cc99962
demoving _time_bin method
jorgemarpa Apr 6, 2022
5e2de68
normalize poscorr/centr and fixing pytest to work with new perturbati…
jorgemarpa Apr 6, 2022
cceeb2b
smooth_vector API improved
jorgemarpa Apr 11, 2022
c3cdfb1
gaussian smooth -> spline smooth
jorgemarpa Apr 11, 2022
e5f3f8e
matching arguments between `perturbation` and `machine`
jorgemarpa Apr 11, 2022
84a064c
:sparkles: Added PCA method
christinahedges Apr 11, 2022
3da1557
:art: added fbpca explicitly as dependency
christinahedges Apr 11, 2022
1520001
:memo: docs
christinahedges Apr 11, 2022
612d3fd
merging from refactor-time
jorgemarpa Apr 12, 2022
78633dc
:bug: fixing pca
christinahedges Apr 12, 2022
14babe3
:bug: fix @jorgemarpa bug
christinahedges Apr 12, 2022
9d4a80f
:memo: update docstrings
christinahedges Apr 12, 2022
88c7493
merging from refactor-time
jorgemarpa Apr 12, 2022
556317d
Update src/psfmachine/perturbation.py
christinahedges Apr 12, 2022
648211e
adding perturbation-pca into machine
jorgemarpa Apr 12, 2022
e97d3f5
:sparkles: now pca has smoothed components
christinahedges Apr 12, 2022
ca3645d
improved spline and gaussian smooth
jorgemarpa Apr 12, 2022
8b4da3d
P3 -> P
jorgemarpa Apr 12, 2022
94c3aaf
hotfix
jorgemarpa Apr 12, 2022
68861a6
flake8
jorgemarpa Apr 12, 2022
0cbde46
:bug: update pca
christinahedges Apr 12, 2022
a00d69c
:art: merge
christinahedges Apr 12, 2022
18fdc55
:art: flake8
christinahedges Apr 12, 2022
de15bfc
perturbed model
jorgemarpa Apr 12, 2022
eb9ce3c
:art: no comment block
christinahedges Apr 12, 2022
2efb963
:memo: docstrings
christinahedges Apr 12, 2022
f7650e5
Merge branch 'refactor-time' of https://github.com/SSDataLab/psfmachi…
jorgemarpa Apr 12, 2022
70af6ac
time_resolution attr
jorgemarpa Apr 13, 2022
514f72b
matrix transpose hotfix
jorgemarpa Apr 13, 2022
c6ebac8
agressive bkg pixel mask
jorgemarpa Apr 13, 2022
eaa807f
:art: updating sane defaults, adding smooth PCA components
christinahedges Apr 15, 2022
e1bc28e
:art: sane defaults
christinahedges Apr 15, 2022
65ef6db
Merge branch 'refactor-time' of https://github.com/SSDataLab/psfmachi…
jorgemarpa Apr 16, 2022
9d336fb
pca smooth time scale arg visible
jorgemarpa Apr 18, 2022
ea876cc
time_resolution kwarg
jorgemarpa Apr 19, 2022
12cd2a2
using time_knots kwarg
jorgemarpa Apr 20, 2022
dc1a8e6
new time model diag plot and components API
jorgemarpa Apr 20, 2022
5aff7e9
Merge branch 'master' of https://github.com/jorgemarpa/psfmachine int…
jorgemarpa Apr 28, 2022
7ac7b71
updated lock
jorgemarpa Apr 28, 2022
1e6b8a4
pytest fixed
jorgemarpa Apr 28, 2022
90385d9
better pixel mask in build_time_model
jorgemarpa Apr 29, 2022
5b18a7e
Update pyproject.toml
jorgemarpa Apr 29, 2022
88ca62c
bump up mac version to 1.1.2, missing docstr and removed dup fx in utils
jorgemarpa Jun 3, 2022
5c4d877
add cbv
jorgemarpa Jun 7, 2022
19db062
better priors for perturb model
jorgemarpa Jun 22, 2022
0eba4d6
accepting other_vectors in time_model to use CBVs
jorgemarpa Jun 22, 2022
54ea59f
plotting psf-nova
jorgemarpa Jun 22, 2022
eb840a4
typo
jorgemarpa Jun 22, 2022
2e7eb70
perturb matrix 3d testing fixed with new synthetic data
jorgemarpa Jun 22, 2022
da580fa
flake8
jorgemarpa Jun 22, 2022
0abbc01
Merge branch 'master' of https://github.com/jorgemarpa/psfmachine int…
jorgemarpa Jun 28, 2022
063e7fb
Merge branch 'master' of https://github.com/jorgemarpa/psfmachine int…
jorgemarpa Jun 28, 2022
991629c
docstrings
jorgemarpa Jun 28, 2022
5a807c8
review fix
jorgemarpa Jul 1, 2022
5f0a323
.
jorgemarpa Jul 1, 2022
355b53e
addind log warning for segments and smoothing
jorgemarpa Jul 1, 2022
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
28 changes: 24 additions & 4 deletions src/psfmachine/machine.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Defines the main Machine object that fit a mean PRF model to sources
"""
import logging
import numpy as np
import pandas as pd
from scipy import sparse
Expand All @@ -19,6 +20,7 @@
from .aperture import optimize_aperture, compute_FLFRCSAP, compute_CROWDSAP
from .perturbation import PerturbationMatrix3D

log = logging.getLogger(__name__)
__all__ = ["Machine"]


Expand Down Expand Up @@ -610,12 +612,14 @@ def build_time_model(
self,
plot=False,
bin_method="bin",
poly_order=3,
segments=False,
focus=False,
focus_exptime=50,
pca_ncomponents=0,
pca_smooth_time_scale=0,
positions=False,
other_vectors=None,
):
"""
Builds a time model that moves the PRF model to account for the scene movement
Expand All @@ -632,6 +636,8 @@ def build_time_model(
Plot a diagnostic figure.
bin_method: string
Type of bin method, options are "bin" and "downsample".
poly_order: int
Degree of the time polynomial used for the time model. Default is 3.
segments : boolean
If `True` will split the light curve into segments to fit different time
models with a common pixel normalization. If `False` will fit the full
Expand All @@ -650,6 +656,11 @@ def build_time_model(
positions : boolean or string
If one of strings `"poscorr", "centroid"` then the perturbation matrix will
add other vectors accounting for position shift.
other_vectors : list or numpy.ndarray
Set of other components used to include in the perturbed model.
See `psfmachine.perturbation.PerturbationMatrix` object for details.
Posible use case are using Kepler CBVs or engeneering data. Shape has to be
(ncomponents, ntimes). Default is `None`.
"""
# create the time and space basis
_whitened_time = (self.time - self.time.mean()) / (
Expand All @@ -667,6 +678,8 @@ def build_time_model(

# add other vectors if asked, centroids or poscorrs
if positions:
if other_vectors is not None:
raise ValueError("When using `positions` do not provide `other_vector`")
if positions == "poscorr" and hasattr(self, "pos_corr1"):
mpc1 = np.nanmedian(self.pos_corr1, axis=0)
mpc2 = np.nanmedian(self.pos_corr2, axis=0)
Expand All @@ -679,10 +692,15 @@ def build_time_model(
)

# smooth the vectors
if not segments:
log.warning(
"Segments will still be used to smooth the position vectors."
"See https://github.com/SSDataLab/psfmachine/pull/63 for details."
)
mpc1_smooth, mpc2_smooth = bspline_smooth(
[mpc1, mpc2],
x=self.time,
do_segments=segments,
do_segments=True,
n_knots=50,
)
# normalize components
Expand All @@ -694,14 +712,16 @@ def build_time_model(
)
# combine them as the first order
other_vectors = [mpc1_smooth, mpc2_smooth, mpc1_smooth * mpc2_smooth]
else:
other_vectors = None
if other_vectors is not None:
if not isinstance(other_vectors, (list, np.ndarray)):
raise ValueError("`other vector` is not a list of arrays or a ndarray")

# create a 3D perturbation matrix
P = PerturbationMatrix3D(
time=_whitened_time,
dx=dx,
dy=dy,
poly_order=poly_order,
segments=segments,
focus=focus,
other_vectors=other_vectors,
Expand Down Expand Up @@ -879,7 +899,7 @@ def plot_time_model(self):
vmin=0.9,
vmax=1.1,
)
ax[1].set(xlabel="Binned Time Index", title="Perturbed Mode")
ax[1].set(xlabel="Binned Time Index", title="Perturbed Model")

cbar = fig2.colorbar(
im, ax=ax[:2], shrink=0.7, orientation="horizontal", location="bottom"
Expand Down
4 changes: 2 additions & 2 deletions src/psfmachine/perturbation.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ def __repr__(self):

@property
def prior_mu(self):
return np.zeros(self.shape[1])
return np.ones(self.shape[1])

@property
def prior_sigma(self):
return np.ones(self.shape[1]) * 1e4
return np.ones(self.shape[1]) * 0.5

@property
def breaks(self):
Expand Down
12 changes: 4 additions & 8 deletions tests/test_perturbation.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,8 @@ def test_perturbation_matrix3d():
dx, dy = dx.ravel(), dy.ravel()

# ntime x npixels
flux = (
np.random.normal(0, 0.01, size=(10, 169))
+ 2 * dx[None, :] ** 2 * 3 * dy[None, :]
)
flux = np.random.normal(1, 0.01, size=(10, 169)) + dx[None, :] * dy[None, :]
# the perturbation model assumes the perturbation is around 1
flux_err = np.ones((10, 169)) * 0.01

p3 = PerturbationMatrix3D(
Expand Down Expand Up @@ -117,10 +115,8 @@ def test_perturbation_matrix3d():
assert chi < 1.5

time = np.arange(0, 100, 1)
flux = (
np.random.normal(0, 0.01, size=(100, 169))
+ 2 * dx[None, :] ** 2 * 3 * dy[None, :]
)
flux = np.random.normal(1, 0.01, size=(100, 169)) + dx[None, :] * dy[None, :]
# the perturbation model assumes the perturbation is around 1
flux_err = np.ones((100, 169)) * 0.01

for bin_method in ["downsample", "bin"]:
Expand Down