Skip to content

Commit

Permalink
Robust parsing of fps
Browse files Browse the repository at this point in the history
  • Loading branch information
chraibi committed Jun 15, 2023
1 parent 6ad70e6 commit d47cdd8
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions Utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import time
import xml.etree.ElementTree as ET
from collections import defaultdict

import re
from typing import Dict, List, Tuple, Union
from xml.dom.minidom import Document

Expand Down Expand Up @@ -107,7 +107,6 @@ def selected_traj_geo(text: str) -> List[str]:


def download(url: str, filename: str):

try:
r = requests.get(url, stream=True, timeout=10)
logging.info(f"saving to {filename}")
Expand Down Expand Up @@ -188,10 +187,12 @@ def get_header(traj_file: str) -> str:


# todo: update with more rules for more files
def get_fps(traj_file: str): # -> Union[int | str]
def get_fps(line: str):
"""return fps from trajectory (assumes existing framerate:)"""

fps = traj_file.split("framerate:")[-1].split("\n")[0]
pattern = r"#\s*framerate:\s*(\d+)(?:\s*fps)?"
match = re.search(pattern, line)
fps = match.group(1)
try:
fps_int = int(float(fps))
except ValueError:
Expand Down Expand Up @@ -908,7 +909,7 @@ def width_gaussian(fwhm: float) -> float:
def Gauss(x: npt.NDArray[np.float64], a: float) -> npt.NDArray[np.float64]:
"""1 / (np.sqrt(np.pi) * a) * np.e ** (-x ** 2 / a ** 2)"""

return 1 / (1.7724538 * a) * np.e ** (-(x ** 2) / a ** 2)
return 1 / (1.7724538 * a) * np.e ** (-(x**2) / a**2)


def density_field(
Expand Down Expand Up @@ -1245,7 +1246,6 @@ def get_neighbors_special_agent_data(
npt.NDArray[np.float64],
npt.NDArray[np.float64],
]:

at_frame = data[data[:, 1] == frame]
points = at_frame[:, 2:4]
_speeds = at_frame[:, st.session_state.speed_index]
Expand Down

0 comments on commit d47cdd8

Please sign in to comment.