Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 14 additions & 0 deletions .github/workflows/ruff.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
name: Ruff

on: [push, pull_request]

jobs:
ruff:
if: github.event_name == 'push' || (github.event_name == 'pull_request' && github.event.pull_request.head.repo.fork == true)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: astral-sh/ruff-action@v3
with:
version: "0.15.6"
args: "check --exclude examples/"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -165,3 +165,4 @@ cython_debug/
*.bak

docs/source/generated/
gsoc_env/
4 changes: 1 addition & 3 deletions examples/sensorium/data.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
"%load_ext autoreload\n",
"%autoreload 2\n",
"\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import torch"
"import matplotlib.pyplot as plt"
]
},
{
Expand Down
5 changes: 1 addition & 4 deletions examples/sensorium/experiment.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
"import numpy as np\n",
"import matplotlib.pyplot as plt\n",
"import matplotlib.animation as animation\n",
"from pathlib import Path\n",
"from IPython.display import HTML"
]
},
Expand All @@ -33,9 +32,7 @@
"if p not in sys.path:\n",
" sys.path.append(p)\n",
"\n",
"from experanto.experiment import Experiment\n",
"from experanto.interpolators import Interpolator\n",
"from experanto.interpolators import ScreenInterpolator"
"from experanto.experiment import Experiment"
]
},
{
Expand Down
4 changes: 0 additions & 4 deletions examples/sensorium/sensorium_min_example.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
"import numpy as np\n",
"from tqdm import tqdm\n",
"import matplotlib.pyplot as plt\n",
"from torch.utils.data import DataLoader\n",
"from collections import OrderedDict"
]
},
Expand Down Expand Up @@ -444,8 +443,6 @@
"\n",
"set_random_seed(seed)\n",
"\n",
"from sensorium.datasets.mouse_video_loaders import mouse_video_loader\n",
"from sensorium.utility.scores import get_correlations\n",
"from nnfabrik.builder import get_trainer\n",
"from sensorium.models.make_model import make_video_model"
]
Expand Down Expand Up @@ -744,7 +741,6 @@
"source": [
"import yaml\n",
"import os\n",
"from tqdm import tqdm\n",
"from collections import Counter"
]
},
Expand Down
3 changes: 1 addition & 2 deletions experanto/configs.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@

from pathlib import Path

from hydra import compose, initialize, initialize_config_dir
from omegaconf import OmegaConf, open_dict
from omegaconf import OmegaConf

# get config relative to this file
script_dir = Path(__file__).parent
Expand Down
8 changes: 1 addition & 7 deletions experanto/dataloaders.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import logging
import os
import time
import warnings
from pathlib import Path
from typing import Any, Dict, List, Optional, Type, Union
from typing import Dict, List, Optional, Union

import numpy as np
from omegaconf import DictConfig
from torch.utils.data import DataLoader

from .datasets import ChunkDataset
from .utils import (
Expand Down Expand Up @@ -158,7 +153,6 @@ def get_multisession_concat_dataloader(
datasets = []
session_names = []

start_time = time.time()
for i, (path, cfg) in enumerate(zip(paths, configs)):
# Create dataset with deterministic seed
path_hash = hash(path) % 10000
Expand Down
11 changes: 3 additions & 8 deletions experanto/datasets.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,31 @@
from __future__ import annotations

import functools
import importlib
import json
import logging
import os
from collections.abc import Iterable
from pathlib import Path
from typing import Any, Dict, List, Optional, Union
from typing import Any, Dict, List, Optional

import numpy as np
import torch
import torchvision
from hydra.utils import instantiate
from omegaconf import DictConfig, ListConfig, OmegaConf
from omegaconf import DictConfig, ListConfig
from torch.utils.data import Dataset
from torchvision.transforms import v2
from torchvision.transforms.v2 import Compose, Lambda, ToTensor

from .configs import DEFAULT_MODALITY_CONFIG
from .experiment import Experiment
from .interpolators import ImageTrial, VideoTrial
from .intervals import (
TimeInterval,
find_intersection_between_two_interval_arrays,
get_stats_for_valid_interval,
)
from .utils import add_behavior_as_channels, replace_nan_with_batch_mean
from .utils import add_behavior_as_channels

# see .configs.py for the definition of DEFAULT_MODALITY_CONFIG
DEFAULT_MODALITY_CONFIG = dict()

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -768,7 +764,6 @@ def __getitem__(self, idx: int) -> dict:
for device_name in self.device_names:
sampling_rate = self.sampling_rates[device_name]
chunk_size = self.chunk_sizes[device_name]
chunk_s = chunk_size / sampling_rate

# convert everything to int to avoid numerical issues
start_time = int(round(s * self.scale_precision))
Expand Down
4 changes: 1 addition & 3 deletions experanto/experiment.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
from __future__ import annotations

import logging
import re
import warnings
from collections.abc import Sequence
from pathlib import Path
from typing import Optional, Union
from typing import Union

import numpy as np
from hydra.utils import instantiate
Comment on lines 1 to 9
Expand Down
5 changes: 2 additions & 3 deletions experanto/interpolators.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

import cv2
import numpy as np
import numpy.lib.format as fmt
import yaml
from numba import njit, prange
from scipy.ndimage import gaussian_filter1d
Expand Down Expand Up @@ -326,7 +325,7 @@ def interpolate(

else:
raise NotImplementedError(
f"interpolation_mode should be linear or nearest_neighbor"
"interpolation_mode should be linear or nearest_neighbor"
)

def close(self) -> None:
Expand Down Expand Up @@ -454,7 +453,7 @@ def interpolate(

else:
raise NotImplementedError(
f"interpolation_mode should be linear or nearest_neighbor"
"interpolation_mode should be linear or nearest_neighbor"
)


Expand Down
2 changes: 1 addition & 1 deletion experanto/intervals.py
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ def get_stats_for_valid_interval(
"""
total_duration = end_time - start_time
if total_duration <= 0:
return f"Error: Invalid time range (end_time <= start_time). Total duration must be positive."
return "Error: Invalid time range (end_time <= start_time). Total duration must be positive."

# Ensure intervals are unique and sorted, then clamp them to the analysis window
unique_intervals = uniquefy_interval_array(intervals)
Expand Down
19 changes: 3 additions & 16 deletions experanto/utils.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,15 @@
import bisect
import logging
import math
import multiprocessing

# inbuilt libraries
import os
import queue
import random
import threading
import time
import warnings
from collections import defaultdict
from copy import deepcopy
from functools import partial
from typing import Any, Dict, Iterator, List, Optional, Tuple, Union

# third-party libraries
import numpy as np
import torch
from omegaconf import DictConfig
from torch.utils.data import ConcatDataset, DataLoader, Dataset, Sampler
from torch.utils.data import DataLoader, Dataset, Sampler

# local libraries
from .intervals import TimeInterval

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -58,7 +45,7 @@ def add_behavior_as_channels(data: dict[str, torch.Tensor]) -> dict:

# Process eye_tracker
if len(eye_tracker.shape) == 2: # (t, c_eye)
c_eye = eye_tracker.shape[1]

# Reshape to (c_eye, t, h, w)
eye_tracker = eye_tracker.transpose(0, 1) # (c_eye, t)
eye_tracker = eye_tracker.unsqueeze(-1).unsqueeze(-1) # (c_eye, t, 1, 1)
Expand All @@ -69,7 +56,7 @@ def add_behavior_as_channels(data: dict[str, torch.Tensor]) -> dict:

# Process treadmill
if len(treadmill.shape) == 2: # (t, c_tread)
c_tread = treadmill.shape[1]

# Reshape to (c_tread, t, h, w)
treadmill = treadmill.transpose(0, 1) # (c_tread, t)
treadmill = treadmill.unsqueeze(-1).unsqueeze(-1) # (c_tread, t, 1, 1)
Expand Down
Loading
Loading