Skip to content

Commit

Permalink
refactor and test process photon data method
Browse files Browse the repository at this point in the history
  • Loading branch information
Jhsmit committed Nov 26, 2024
1 parent 452a871 commit f2574e1
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
6 changes: 3 additions & 3 deletions dont_fret/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from tqdm.auto import tqdm

from dont_fret.config import cfg
from dont_fret.config.config import BurstColor, DontFRETConfig
from dont_fret.config.config import BurstColor
from dont_fret.fileIO import PhotonFile
from dont_fret.models import Bursts, PhotonData

Expand Down Expand Up @@ -73,10 +73,10 @@ def batch_search_and_save(
f.result()


def full_search(
def process_photon_data(
photon_data: PhotonData, burst_colors: list[BurstColor], hooks: dict = cfg.hooks
) -> Bursts:
"""search and alex / fret cde"""
"""search and apply hooks"""
bursts = photon_data.burst_search(burst_colors)

# Apply hooks
Expand Down
6 changes: 4 additions & 2 deletions dont_fret/web/datamanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
from dont_fret.config.config import BurstColor, DontFRETConfig, cfg
from dont_fret.fileIO import PhotonFile
from dont_fret.models import Bursts, PhotonData
from dont_fret.process import full_search
from dont_fret.process import process_photon_data
from dont_fret.web.methods import get_duration, get_info, make_burst_dataframe
from dont_fret.web.models import BurstNode, PhotonNode

Expand Down Expand Up @@ -78,7 +78,9 @@ async def get_bursts(

try:
photon_data = await self.get_photons(photon_node)
bursts = await self.run(full_search, photon_data, burst_colors, self.cfg.hooks)
bursts = await self.run(
process_photon_data, photon_data, burst_colors, self.cfg.hooks
)

future.set_result(bursts)
except Exception as e:
Expand Down
4 changes: 2 additions & 2 deletions dont_fret/web/methods.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from dont_fret.config.config import BurstColor
from dont_fret.fileIO import PhotonFile
from dont_fret.models import Bursts, PhotonData
from dont_fret.process import full_search
from dont_fret.process import process_photon_data
from dont_fret.web.models import BurstFilterItem, BurstNode, FRETNode, PhotonNode


Expand Down Expand Up @@ -58,7 +58,7 @@ def make_burst_nodes(

hooks = hooks or {}
for name, burst_colors in burst_settings.items():
bursts = [full_search(photon_data, burst_colors, hooks) for photon_data in photons]
bursts = [process_photon_data(photon_data, burst_colors, hooks) for photon_data in photons]
# bursts = [photons.burst_search(burst_colors) for photons in photons]
# if alex_2cde:
# bursts = [b.alex_2cde(photons) for b, photons in zip(bursts, photons)]
Expand Down
14 changes: 14 additions & 0 deletions tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from dont_fret.config.config import BurstColor
from dont_fret.fileIO import PhotonFile
from dont_fret.models import BinnedPhotonData, Bursts, PhotonData
from dont_fret.process import process_photon_data

cwd = Path(__file__).parent
input_data_dir = cwd / "test_data" / "input"
Expand Down Expand Up @@ -80,6 +81,8 @@ def test_load_save_bursts(dcbs_bursts: Bursts, tmp_path: Path):
assert dcbs_bursts.burst_data.equals(bursts_load.burst_data)
assert dcbs_bursts.photon_data.equals(bursts_load.photon_data)
assert dcbs_bursts.cfg == bursts_load.cfg
assert dcbs_bursts.cfg
assert bursts_load.cfg
assert asdict(dcbs_bursts.cfg) == asdict(bursts_load.cfg)
assert dcbs_bursts.metadata == bursts_load.metadata

Expand Down Expand Up @@ -109,6 +112,17 @@ def test_burst_search(ph_ds1: PhotonData):
assert (df_ref["time_max"] == df_test["timestamps_max"] * ph_ds1.timestamps_unit).all()


def test_process_photon_data(ph_ds1: PhotonData):
hooks = {
"alex_2cde": {},
"fret_2cde": {},
}

bursts = process_photon_data(ph_ds1, APBS_TEST, hooks=hooks)
assert "alex_2cde" in bursts.burst_data.columns
assert "fret_2cde" in bursts.burst_data.columns


def test_binning(ph_ds1):
trace = BinnedPhotonData(ph_ds1, bounds=(0, ph_ds1.tmax))
assert len(trace) == 81439
Expand Down

0 comments on commit f2574e1

Please sign in to comment.