Skip to content

Commit

Permalink
Added localize_psf to setup.py and setup filter in local script
Browse files Browse the repository at this point in the history
  • Loading branch information
SJShep committed Jul 16, 2024
1 parent c75f003 commit dddaba1
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 4 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.pyc
*.egg-info

# ignore vscode directories
*.code-workspace
.vscode
38 changes: 35 additions & 3 deletions extFOV_SPIM/remote_focus_model/run_experimental_localization.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from localize_psf.fit_psf import gaussian3d_psf_model, average_exp_psfs
from localize_psf.localize import (localize_beads_generic,
get_param_filter,
boundary_filter,
filter,
get_coords,
plot_fit_roi,
plot_bead_locations)
Expand Down Expand Up @@ -47,10 +47,41 @@

t_initial = time.time()

#------------------------------------------------------------------------------#
# create a custom filter for localize_psf
class boundary_filter(filter):
"""
Filter based on distance to boundary and fit sigma_z
"""
def __init__(self,
coords,
sf = 2):
"""
Define a filter based on the bead position and z-size.
"""
self.condition_names = ["z position and PSF too small",
"z position and PSF too large"]
self.coords = coords
self.sf = sf

def filter(self,
fit_params: np.ndarray,
*args,
**kwargs):

z, y, x = self.coords
conditions = np.stack((fit_params[:, 3] >= fit_params[:, 5]*self.sf + z.min(),
fit_params[:, 3] <= z.max() - fit_params[:, 5]*self.sf + z.max()),
axis=1)

return conditions


#------------------------------------------------------------------------------#
# Manage data and saving paths.
root_path = Path(r"E:\SPIM_data\bead_data\SJS\optimization")
savedir = get_unique_dir(root_path, "to_use_lowthreshold_easyfiltering_midcropping")
savedir = get_unique_dir(root_path,
"to_use_lowthreshold_easyfiltering_midcropping")

# Data was taken such that each cuvette position is it's own root name.
cuv_pos_dirs = [_d for _d in root_path.iterdir() if "cuv" in _d.name]
Expand Down Expand Up @@ -137,7 +168,8 @@ def plot_average_psf(r,

for ii in range(len(psf_percentiles)):
# only keep smallest so many percent of spots
sigma_max = np.percentile(fit_params[:, 4][to_keep], psf_percentiles[ii])
sigma_max = np.percentile(fit_params[:, 4][to_keep],
psf_percentiles[ii])
to_use = np.logical_and(to_keep, fit_params[:, 4] <= sigma_max)

# get centers
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
'tqdm',
'dask',
'zarr',
'tifffile'
'ndtiff',
'localize_psf @ git+https://[email protected]/qi2lab/localize-psf@master#egg=localize_psf'
]

extras = None
Expand Down

0 comments on commit dddaba1

Please sign in to comment.