Skip to content

Commit

Permalink
fixed errors
Browse files Browse the repository at this point in the history
  • Loading branch information
CheerfulUser committed Jun 13, 2024
1 parent e6b8efc commit 60cf44e
Show file tree
Hide file tree
Showing 3 changed files with 14,857 additions and 71 deletions.
14,886 changes: 14,824 additions & 62 deletions development/test_statistics_range.ipynb

Large diffs are not rendered by default.

36 changes: 30 additions & 6 deletions tessreduce/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,14 @@
from scipy.interpolate import interp1d
from scipy.interpolate import griddata
from scipy.optimize import minimize
from scipy.signal import fftconvolve
from sklearn.cluster import OPTICS
from sklearn.preprocessing import PolynomialFeatures
from sklearn.linear_model import LinearRegression
from sklearn.pipeline import make_pipeline
from skimage.restoration import inpaint


from astropy.table import Table
from astropy.stats import sigma_clipped_stats
from astropy.stats import sigma_clip
Expand Down Expand Up @@ -996,23 +998,45 @@ def regional_stats_mask(image,size=90,sigma=3,iters=10):
return clip



def subdivide_region(flux,ideal_size=90):
sx, sy = flux.shape
valid = np.arange(0,101)
ystep = valid[np.where(sy / valid == sy // valid)[0]]
xstep = valid[np.where(sx / valid == sx // valid)[0]]

ysteps = ystep[np.argmin((abs((sy / ystep) - ideal_size)))].astype(int)
xsteps = xstep[np.argmin((abs((sx / xstep) - ideal_size)))].astype(int)
ystep = sy//ystep[np.argmin((abs((sy / ystep) - ideal_size)))].astype(int)
xstep = sx//xstep[np.argmin((abs((sx / xstep) - ideal_size)))].astype(int)

regions = np.zeros_like(flux)
counter = 0
for i in range(ysteps):
for j in range(xsteps):
regions[i*ystep:(i+1)*ystep,j*xstep:(j+1)*xstep] = counter
counter += 1

max_reg = np.max(regions)
return regions, max_reg, ystep, xstep

def Surface_names2model(names):
# C[i] * X^n * Y^m
return ' + '.join([
f"C[{i}]*{n.replace(' ','*')}"
for i,n in enumerate(names)])

def clip_background(bkg,mask,sigma=3):
regions, max_reg = subdivide_region(bkg)
def clip_background(bkg,mask,sigma=3,kern_size=5):
regions, max_reg, ystep, xstep = subdivide_region(bkg)
b2 = deepcopy(bkg)
for j in range(2):
for region in range(int(max_reg)):
rx,ry = np.where(regions == region)
y = rx.reshape(ystep,xstep)
x = ry.reshape(ystep,xstep)
ry,rx = np.where(regions == region)
y = ry.reshape(ystep,xstep)
x = rx.reshape(ystep,xstep)
sm = abs((mask & 1)-1)[y,x] * 1.0
sm[sm==0] = np.nan
cut = b2[i,y,x]
cut = b2[y,x]
if j > 0:
masked = cut * sm
else:
Expand Down
6 changes: 3 additions & 3 deletions tessreduce/tessreduce.py
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,7 @@ def _bkg_round_3(self,iters=5):
bkg_3[i] = parallel_bkg3(self.bkg[i],dist_mask[i])
self.bkg = np.array(bkg_3)

def _clip_background(self,sigma=5):
def _clip_background(self,sigma=5,ideal_size=90):
"""
DESCRIPTION
Expand All @@ -625,12 +625,12 @@ def _clip_background(self,sigma=5):
"""

if self.parallel:
bkg_clip = Parallel(n_jobs=self.num_cores)(delayed(clip_background)(self.bkg[i],self.mask,sigma)
bkg_clip = Parallel(n_jobs=self.num_cores)(delayed(clip_background)(self.bkg[i],self.mask,sigma,ideal_size)
for i in np.arange(len(self.bkg)))
else:
bkg_clip = []
for i in range(len(dist_mask)):
bkg_clip[i] = clip_background(self.bkg[i],self.mask)
bkg_clip[i] = clip_background(self.bkg[i],self.mask,ideal_size)
self.bkg = np.array(bkg_clip)

def get_ref(self,start = None, stop = None):
Expand Down

0 comments on commit 60cf44e

Please sign in to comment.