Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Node store #4

Merged
merged 58 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
58 commits
Select commit Hold shift + click to select a range
f88b262
home page in more or less working state
Jhsmit Sep 27, 2024
ea7b88d
add duration property
Jhsmit Oct 2, 2024
af10527
fix burstfigure plot settings
Jhsmit Oct 2, 2024
bad85c2
burst figure controller model
Jhsmit Oct 17, 2024
deedf4d
add select vue component
Jhsmit Oct 17, 2024
dd2a63c
add tcspc graphs
Jhsmit Oct 17, 2024
e3da965
move some stuff around
Jhsmit Oct 24, 2024
4c169dc
improve nested selections
Jhsmit Oct 24, 2024
f81f16f
add trace figure
Jhsmit Oct 24, 2024
da40e11
add initial version of filter editor
Jhsmit Oct 28, 2024
9c8b74b
add liststore functionality
Jhsmit Oct 28, 2024
9f349b6
filters as liststore
Jhsmit Oct 28, 2024
22026b4
figurfromtask component
Jhsmit Oct 28, 2024
e3d8457
comment on how to improve wrap_callback
Jhsmit Oct 28, 2024
f3d1465
add new filters dialog
Jhsmit Oct 29, 2024
e79188d
update traces/burst view
Jhsmit Oct 29, 2024
d5868ed
ruff
Jhsmit Oct 29, 2024
574f311
remove comment
Jhsmit Oct 29, 2024
e453503
cleanup
Jhsmit Oct 29, 2024
6a5e63a
use reactive for edit settings
Jhsmit Oct 29, 2024
9bfcf6c
generate selectors from object
Jhsmit Oct 29, 2024
9e9e010
to done!
Jhsmit Oct 29, 2024
5ea407b
file selectors
Jhsmit Oct 30, 2024
4ce8765
load style from script path
Jhsmit Oct 30, 2024
f6a762d
trace selection in global scope
Jhsmit Oct 30, 2024
caeebc0
fix altair not showing on initial open of the dialog
Jhsmit Oct 30, 2024
627098d
major cleanup
Jhsmit Oct 30, 2024
8a88ee4
delete unused file
Jhsmit Oct 30, 2024
6abd60f
use liststore
Jhsmit Oct 30, 2024
797a4db
add missing requirements
Jhsmit Oct 30, 2024
9344258
download
Jhsmit Nov 5, 2024
8aac582
booleans to enable/disable pages
Jhsmit Nov 5, 2024
c595ad5
burst figure as standalone component
Jhsmit Nov 5, 2024
71d48cc
revert defaults page active
Jhsmit Nov 5, 2024
856cc76
refactor move new models to models.py
Jhsmit Nov 5, 2024
d6be859
figures should take the value rather than reactive
Jhsmit Nov 5, 2024
7526287
add missing typevar
Jhsmit Nov 5, 2024
0831ff1
refactor to datamanager
Jhsmit Nov 5, 2024
0107870
set diable pages to false in testing
Jhsmit Nov 5, 2024
337cf8d
cleanup datamanager
Jhsmit Nov 5, 2024
8a2dc50
remove comments
Jhsmit Nov 6, 2024
528d51d
clean up dataload template
Jhsmit Nov 6, 2024
ec9ad07
docstring typo
Jhsmit Nov 6, 2024
e457242
fix order of returned results
Jhsmit Nov 6, 2024
ad62640
update ui test
Jhsmit Nov 6, 2024
4f7d53d
ignore hook warning
Jhsmit Nov 6, 2024
fcd225d
snackbar as composed reactive
Jhsmit Nov 6, 2024
01ecce9
reactives as stores
Jhsmit Nov 6, 2024
638aa87
fix comma placement
Jhsmit Nov 6, 2024
7429b5f
drop py39
Jhsmit Nov 6, 2024
d2b2934
make function to create burst nodes
Jhsmit Nov 6, 2024
c9c2a9d
fix tying on get node
Jhsmit Nov 6, 2024
95dfe37
update liststore, see use_reactive
Jhsmit Nov 6, 2024
b946998
simplify web models
Jhsmit Nov 6, 2024
04bf4a4
fix web test
Jhsmit Nov 6, 2024
ee36a94
fix task burst search test
Jhsmit Nov 6, 2024
a6e8fd1
python version in quotes
Jhsmit Nov 6, 2024
c5a48ed
cleaning
Jhsmit Nov 6, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/pin_requirements.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, windows-latest, macOS-latest]
python-version: ["3.9", "3.10"]
python-version: ["3.10"]
steps:
- name: Checkout code
uses: actions/checkout@v3
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pypi_main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jobs:
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Python 3.9
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: 3.9
python-version: "3.10"
- name: Install Hatch
run: pip install hatch
- name: Build
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/pypi_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ jobs:
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Set up Python 3.9
- name: Set up Python 3.10
uses: actions/setup-python@v4
with:
python-version: 3.9
python-version: "3.10"
- name: Install Hatch
run: pip install hatch
- name: Build
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ jobs:
fail-fast: false
matrix:
os: [ "ubuntu-latest", "macos-latest" , "windows-latest"]
python-version: ["3.9", "3.10" ]
python-version: ["3.10" ]
defaults:
run:
shell: bash
Expand Down
1 change: 1 addition & 0 deletions dont_fret/config/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class BurstFilterItem:
name: str
min: Optional[float] = field(default=None)
max: Optional[float] = field(default=None)
active: bool = field(default=True)

def as_expr(self) -> list[pl.Expr]:
expr = []
Expand Down
25 changes: 23 additions & 2 deletions dont_fret/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ def cps(self) -> float:
"""Average count rate (counts per second / Hz)"""
return len(self) / float(self.photon_times.max()) # type: ignore

@property
def duration(self) -> Optional[float]:
"""user-specified duration in seconds, obtained from metadata"""
return self.metadata.get("acquisition_duration")

def __getitem__(self, key):
# TODO sort when slicing backwards?
return self.__class__(self.data[key], metadata=self.metadata, cfg=self.cfg)
Expand Down Expand Up @@ -132,7 +137,7 @@ def nanotimes_unit(self) -> Optional[float]:
def tau_mean(self) -> float:
"""Mean of the nanotimes (in seconds). Sometimes referred to as 'fast lifetime' as it is fast to compute"""
if self.nanotimes is not None and self.nanotimes_unit is not None:
return self.nanotimes.mean() * self.nanotimes_unit
return self.nanotimes.mean() * self.nanotimes_unit # type: ignore
else:
return np.nan

Expand Down Expand Up @@ -365,10 +370,16 @@ def __init__(
self.metadata: dict = metadata or {}
self.cfg = cfg

# number of photons per stream per burst
agg = [(pl.col("stream") == stream).sum().alias(f"n_{stream}") for stream in cfg.streams]

# mean nanotimes per stream per burst
agg.extend(
[
pl.when(pl.col("stream") == k).then(pl.col("nanotimes")).mean().alias(f"tau_{k}")
pl.when(pl.col("stream") == k)
.then(pl.col("nanotimes"))
.mean()
.alias(f"nanotimes_{k}")
for k in cfg.streams
]
)
Expand All @@ -387,6 +398,8 @@ def __init__(
photon_data["burst_index"].unique_counts().alias("n_photons"),
]

# TODO These should move somewhere else; possibly some second step conversion
# from raw stamps to times
t_unit = self.metadata.get("timestamps_unit", None)
if t_unit is not None:
columns.extend(
Expand All @@ -397,6 +410,14 @@ def __init__(
),
]
)
nanotimes_unit = self.metadata.get("nanotimes_unit", None)
if nanotimes_unit is not None:
columns.extend(
[
pl.col(f"nanotimes_{stream}").mul(nanotimes_unit).alias(f"tau_{stream}")
for stream in cfg.streams
]
)

self.burst_data = (
self.photon_data.group_by("burst_index", maintain_order=True)
Expand Down
2 changes: 1 addition & 1 deletion dont_fret/process.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ def search_and_save(


def write_dataframe(df: pl.DataFrame, path: Path) -> None:
"""Write a dataframe to disk. Writier used depends on path suffix."""
"""Write a dataframe to disk. Writer used depends on path suffix."""
if path.suffix == ".pq":
df.write_parquet(path)
elif path.suffix == ".csv":
Expand Down
64 changes: 33 additions & 31 deletions dont_fret/tmp.py
Original file line number Diff line number Diff line change
@@ -1,51 +1,53 @@
import uuid
from dataclasses import replace
from functools import reduce
from itertools import chain
from operator import and_
from pathlib import Path
from typing import Callable, Dict, List, Optional, Type, TypedDict, Union

import altair as alt
import numpy as np
import solara
import solara.lab
import yaml

import dont_fret.web.state as state
from dont_fret.config.config import cfg
from dont_fret.web.dev import load_burst_items, load_file_items
from dont_fret.config.config import BurstFilterItem, cfg
from dont_fret.web.bursts import BurstPage
from dont_fret.web.bursts.components import BurstFigure, BurstFigureSelection
from dont_fret.web.components import RegexSelectDialog
from dont_fret.web.home import HomePage
from dont_fret.web.main import Page as MainPage
from dont_fret.web.models import FRETNode
from dont_fret.web.models import BurstNode, ListStore, PhotonNode
from dont_fret.web.trace import TracePage
from dont_fret.web.utils import (
find_index,
find_object,
get_bursts,
make_selector_nodes,
wrap_callback,
)

data = yaml.safe_load(Path("default_testing.yaml").read_text())
cfg.update(data)

style = """
.vega-embed {
overflow: visible;
width: 100% !important;
}
"""

# TODO default burst searches from config
DCBS_TEST = {"DD + DA": {"L": 50, "M": 35, "T": 0.0005}, "AA": {"L": 50, "M": 35, "T": 0.0005}}
APBS_TEST = {"DD + DA + AA": {"L": 50, "M": 35, "T": 0.0005}}
my_selection = ListStore([])

pth = "ds2"
photon_file_items = load_file_items(pth)
# burst_items = load_burst_items(pth, suffix=".csv")
values = ["a", "b1", "c1", "d3"]

fret_nodes = [
FRETNode(
name="FRET NOT",
photons=photon_file_items,
# bursts=burst_items,
),
]

# %%
state.disable_burst_page.set(False)
state.disable_trace_page.set(False)


@solara.component
def Page():
def preload():
# state.FRET_NODES.set([])
if len(state.fret_nodes.value) == 0:
state.fret_nodes.extend(fret_nodes)

solara.use_effect(preload, dependencies=[])
nodes = state.fret_nodes.value

if len(nodes) != 0:
with solara.Column(style={"height": "100%"}):
MainPage()
else:
solara.Text("Loading fret nodes...")
solara.Style(style)
MainPage()
Loading
Loading