Skip to content

Commit

Permalink
Merge pull request #81 from jeromekelleher/logging-again
Browse files Browse the repository at this point in the history
Basic logging via daiquiri
  • Loading branch information
jeromekelleher authored Sep 4, 2023
2 parents e068297 + a38469a commit 43200ae
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
12 changes: 10 additions & 2 deletions app.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
import logging
import pathlib
import sys
import time
import traceback

import daiquiri
import panel as pn
import tskit

import model
import pages


logger = logging.Logger(__file__)
daiquiri.setup(level="INFO")
logger = daiquiri.getLogger("app")


# Usage: panel serve app.py --args /path/to/trees-file
path = pathlib.Path(sys.argv[1])
logger.info(f"Loading {path}")
tsm = model.TSModel(tskit.load(path), path.name)

pn.extension(sizing_mode="stretch_width")
Expand All @@ -31,9 +35,13 @@


def show(page):
logger.info(f"Showing page {page}")
yield pn.indicators.LoadingSpinner(value=True, width=50, height=50)
try:
before = time.time()
content = pages[page](tsm)
duration = time.time() - before
logger.info(f"Loaded page {page} in {duration:.2f}s")
except Exception as e:
error_message = f"An error occurred: {str(e)}"
error_traceback = traceback.format_exc().replace("\n", "<br>")
Expand Down
8 changes: 8 additions & 0 deletions model.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import dataclasses
from functools import cached_property

import daiquiri
import numba
import numpy as np
import pandas as pd
import tskit

logger = daiquiri.getLogger("model")

spec = [
("num_edges", numba.int64),
("sequence_length", numba.float64),
Expand Down Expand Up @@ -287,6 +290,7 @@ def summary_df(self):
df = pd.DataFrame(
{"property": [d[0] for d in data], "value": [d[1] for d in data]}
)
logger.info("Computed summary dataframe")
return df.set_index("property")

def _repr_html_(self):
Expand Down Expand Up @@ -355,6 +359,7 @@ def mutations_df(self):
}
)

logger.info("Computed mutations dataframe")
return df.astype(
{
"id": "int",
Expand Down Expand Up @@ -395,6 +400,7 @@ def edges_df(self):
}
)

logger.info("Computed edges dataframe")
return df.astype(
{
"left": "float64",
Expand Down Expand Up @@ -424,6 +430,7 @@ def nodes_df(self):
"is_sample": is_sample,
}
)
logger.info("Computed nodes dataframe")
return df.astype(
{
"time": "float64",
Expand Down Expand Up @@ -460,6 +467,7 @@ def trees_df(self):
}
)

logger.info("Computed trees dataframe")
return df.astype(
{
"left": "int",
Expand Down
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
daiquiri
panel
hvplot
xarray
datashader
tskit
seaborn
pre-commit
pytest
pytest

0 comments on commit 43200ae

Please sign in to comment.