Skip to content
Snippets Groups Projects
Commit 16e029d0 authored by Andi Gerken's avatar Andi Gerken
Browse files

Lazy import for pandas and seaborn.

parent 58ed1c08
Branches develop master
Tags 0.4.0
1 merge request!54robofish-io-evaluate2 and lazy imports
Pipeline #66656 passed
......@@ -15,9 +15,8 @@ from pathlib import Path
import matplotlib
import matplotlib.pyplot as plt
import matplotlib.gridspec as gridspec
import seaborn as sns
import numpy as np
import pandas as pd
from typing import Iterable, Union, Callable, List
from scipy import stats
from tqdm import tqdm
......@@ -408,6 +407,12 @@ def evaluate_tank_position(
matplotlib.figure.Figure: The figure of the heatmap.
"""
try:
import seaborn as sns
except ImportError:
print("Seaborn is not installed and could not be imported")
return
if poses_from_paths is None:
poses_from_paths, file_settings = utils.get_all_poses_from_paths(
paths, predicate, max_files=max_files
......@@ -653,6 +658,8 @@ def evaluate_single_plot_tracks(
ax[i].plot(
e[:, 0], e[:, 1], c=cmap(fi / len(poses_per_path)), alpha=0.5
)
ax[i].set_xlim(-50, 50)
ax[i].set_ylim(-50, 50)
ax[i].set_title(labels[i])
ax[i].set_xlabel("x [cm]")
ax[i].set_ylabel("y [cm]")
......@@ -742,6 +749,13 @@ def evaluate_follow_iid(
matplotlib.figure.Figure: The figure of the follow iids.
"""
try:
import pandas as pd
import seaborn as sns
except ImportError:
print("pandas or seaborn is not installed and could not be imported")
return
if poses_from_paths is None:
poses_from_paths, file_settings = utils.get_all_poses_from_paths(
paths, predicate, max_files=max_files
......@@ -1377,9 +1391,9 @@ class SeabornFig2Grid:
def __init__(
self,
seaborngrid: sns.axisgrid.Grid,
fig: matplotlib.figure.Figure,
subplot_spec: matplotlib.gridspec.SubplotSpec,
seaborngrid,
fig,
subplot_spec,
) -> None:
"""Init function.
......@@ -1388,6 +1402,12 @@ class SeabornFig2Grid:
fig(matplotlib.figure.Figure): The figure.
subplot_spec(matplotlib.gridspec.SubplotSpec): The subplot spec.
"""
try:
import seaborn as sns
except ImportError:
print("Pandas is not installed and could not be imported")
return
self.fig = fig
self.sg = seaborngrid
self.subplot = subplot_spec
......
......@@ -5,7 +5,6 @@ from pathlib import Path
import logging
import numpy as np
import pandas
import random
import deprecation
......@@ -47,7 +46,7 @@ def read_multiple_files(
logging.info(f"Reading files from path {paths}")
list_types = (list, np.ndarray, pandas.core.series.Series)
list_types = (list, np.ndarray)
if not isinstance(paths, list_types):
paths = [paths]
......@@ -114,7 +113,7 @@ def read_property_from_multiple_files(
), "Please select an entity property e.g. 'Entity.poses_rad'"
logging.info(f"Reading files from path {paths}")
list_types = (list, np.ndarray, pandas.core.series.Series)
list_types = (list, np.ndarray)
if not isinstance(paths, list_types):
paths = [paths]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment