def update_X(self, X, i, data, tinterp, len_t, objid, contextual_info, otherinfo): for j, pb in enumerate(self.passbands): if pb not in data: print("No", pb, "in objid:", objid) continue # Drop infinite values data.replace([np.inf, -np.inf], np.nan) # Get data time = data[pb]['time'][0:self.nobs].dropna() flux = data[pb]['flux'][0:self.nobs].dropna() fluxerr = data[pb]['fluxErr'][0:self.nobs].dropna() photflag = data[pb]['photflag'][0:self.nobs].dropna() n = len(flux) # Get vector length (could be less than nobs) if n > 1: if flux.values[-1] > flux.values[ -2]: # If last values are increasing, then set fill_values to zero f = interp1d(time, flux, kind='linear', bounds_error=False, fill_value=0.) else: f = interp1d(time, flux, kind='linear', bounds_error=False, fill_value='extrapolate' ) # extrapolate until all passbands finished. fluxinterp = f(tinterp) fluxinterp = np.nan_to_num(fluxinterp) fluxinterp = fluxinterp.clip(min=0) fluxerrinterp = np.zeros(len_t) for interp_idx, fluxinterp_val in enumerate(fluxinterp): if fluxinterp_val == 0.: fluxerrinterp[interp_idx] = 0 else: nearest_idx = helpers.find_nearest( time, tinterp[interp_idx]) fluxerrinterp[interp_idx] = fluxerr[nearest_idx] X[i][j][0:len_t] = fluxinterp # X[i][j * 2 + 1][0:len_t] = fluxerrinterp # Add contextual information for jj, c_idx in enumerate(contextual_info, 1): try: X[i][j + jj][0:len_t] = otherinfo[c_idx] * np.ones(len_t) except Exception as e: X[i][j + jj][0:len_t] = otherinfo[c_idx].values[0] * np.ones(len_t) return X
def update_X(self, X, i, data, tinterp, len_t, objid, contextual_info, meta_data): for j, pb in enumerate(self.passbands): # Drop infinite or nan values in any row data.remove_rows(np.where(~np.isfinite(data['time']))[0]) data.remove_rows(np.where(~np.isfinite(data['flux']))[0]) data.remove_rows(np.where(~np.isfinite(data['fluxErr']))[0]) # Get data pbmask = data['passband'] == pb time = data[pbmask]['time'].data flux = data[pbmask]['flux'].data fluxerr = data[pbmask]['fluxErr'].data photflag = data[pbmask]['photflag'].data # Mask out times outside of mintime and maxtime timemask = (time > self.mintime) & (time < self.maxtime) time = time[timemask] flux = flux[timemask] fluxerr = fluxerr[timemask] photflag = photflag[timemask] n = len(flux) # Get vector length (could be less than nobs) if n > 1: # if flux[-1] > flux[-2]: # If last values are increasing, then set fill_values to zero # f = interp1d(time, flux, kind='linear', bounds_error=False, fill_value=0.) # else: # f = interp1d(time, flux, kind='linear', bounds_error=False, # fill_value='extrapolate') # extrapolate until all passbands finished. f = interp1d(time, flux, kind='linear', bounds_error=False, fill_value=0.) fluxinterp = f(tinterp) fluxinterp = np.nan_to_num(fluxinterp) fluxinterp = fluxinterp.clip(min=0) fluxerrinterp = np.zeros(len_t) for interp_idx, fluxinterp_val in enumerate(fluxinterp): if fluxinterp_val == 0.: fluxerrinterp[interp_idx] = 0 else: nearest_idx = helpers.find_nearest( time, tinterp[interp_idx]) fluxerrinterp[interp_idx] = fluxerr[nearest_idx] X[i][j][0:len_t] = fluxinterp # X[i][j * 2 + 1][0:len_t] = fluxerrinterp # Add contextual information for jj, c_info in enumerate(contextual_info, 1): X[i][j + jj][0:len_t] = meta_data[c_info] * np.ones(len_t) return X