Skip to content

Commit

Permalink
sort data by time only once in fitting functions
Browse files Browse the repository at this point in the history
  • Loading branch information
kbarbary committed Dec 27, 2016
1 parent b65d899 commit 1058f0e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
4 changes: 4 additions & 0 deletions sncosmo/fitting.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ def chisq(data, model, modelcov=False):
chisq : float
"""
data = photometric_data(data)
data.sort_by_time()

if data.fluxcov is None and not modelcov:
mflux = model.bandflux(data.band, data.time,
Expand Down Expand Up @@ -385,6 +386,7 @@ def fit_lc(data, model, vparam_names, bounds=None, method='minuit',

# Standardize data
data = photometric_data(data)
data.sort_by_time()

# Make a copy of the model so we can modify it with impunity.
model = copy.copy(model)
Expand Down Expand Up @@ -751,6 +753,7 @@ def nest_lc(data, model, vparam_names, bounds, guess_amplitude_bound=False,
tied = kwargs.get("tied", None)

data = photometric_data(data)
data.sort_by_time()
model = copy.copy(model)
bounds = copy.copy(bounds) # need to copy this b/c we modify it below

Expand Down Expand Up @@ -998,6 +1001,7 @@ def mcmc_lc(data, model, vparam_names, bounds=None, priors=None,

# Standardize and normalize data.
data = photometric_data(data)
data.sort_by_time()

# Make a copy of the model so we can modify it with impunity.
model = copy.copy(model)
Expand Down
8 changes: 1 addition & 7 deletions sncosmo/photdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,7 @@ def __init__(self, data):
"the data? Use ``sncosmo.select_data(data, mask)`` in "
"place of ``data[mask]`` to properly slice covariance.")

# ensure sorted by time
self._sort_by_time()

def _sort_by_time(self):
def sort_by_time(self):
if not np.all(np.ediff1d(self.time) >= 0.0):
idx = np.argsort(self.time)
self.time = self.time[idx]
Expand All @@ -116,9 +113,6 @@ def __getitem__(self, key):
newdata.fluxcov = (None if self.fluxcov is None else
self.fluxcov[np.ix_(key, key)])

# ensure sorted by time (key could have caused reordering)
newdata._sort_by_time()

return newdata

def normalized(self, zp=25., zpsys='ab'):
Expand Down
4 changes: 3 additions & 1 deletion sncosmo/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,9 @@ def plot_lc(data=None, model=None, bands=None, zp=25., zpsys='ab',

# Standardize and normalize data.
if data is not None:
data = photometric_data(data).normalized(zp=zp, zpsys=zpsys)
data = photometric_data(data)
data.sort_by_time()
data = data.normalized(zp=zp, zpsys=zpsys)

# Bands to plot
if data is None:
Expand Down

0 comments on commit 1058f0e

Please sign in to comment.