Skip to content

Commit 5360ccd

Browse files
committed
improve pathing
1 parent 4cee102 commit 5360ccd

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

flyvis/__init__.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,14 @@ def timetz(*args):
3535

3636
import datamate
3737

38+
repo_dir = Path(__file__).parent.parent
39+
3840

3941
def resolve_root_dir():
4042
"Resolving the root directory in which all data is downloaded and stored."
4143

4244
# Try to get root directory from environment variable
43-
root_dir_env = os.getenv(
44-
"FLYVIS_ROOT_DIR", str(Path(__file__).parent.parent / "data")
45-
)
45+
root_dir_env = os.getenv("FLYVIS_ROOT_DIR", str(repo_dir / "data"))
4646
return Path(root_dir_env).expanduser().absolute()
4747

4848

@@ -51,10 +51,10 @@ def resolve_root_dir():
5151
results_dir = root_dir / "results"
5252
renderings_dir = root_dir / "renderings"
5353
sintel_dir = root_dir / "SintelDataSet"
54-
connectome_file = root_dir / "connectome/fib25-fib19_v2.2.json"
55-
source_dir = (repo_dir := Path(__file__).parent.parent) / "flyvis"
54+
connectome_file = repo_dir / "data/connectome/fib25-fib19_v2.2.json"
55+
source_dir = repo_dir / "flyvis"
5656
config_dir = repo_dir / "config"
57-
script_dir = Path(__file__).parent.parent / "flyvis_cli"
57+
script_dir = repo_dir / "flyvis_cli"
5858
examples_dir = repo_dir / "examples"
5959

6060
datamate.set_root_dir(root_dir)

flyvis/connectome/connectome.py

+11-2
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,18 @@ class ConnectomeFromAvgFilters(Directory):
161161
```
162162
"""
163163

164-
def __init__(self, file=flyvis.connectome_file, extent=15, n_syn_fill=1) -> None:
165-
if not Path(file).exists():
164+
def __init__(self, file=flyvis.connectome_file.name, extent=15, n_syn_fill=1) -> None:
165+
# case 0: file is an absolute path
166+
if (Path(file)).exists():
167+
file = Path(file)
168+
# case 1: file is specified relative to package directory
169+
elif (flyvis.repo_dir / "data/connectome" / file).exists():
170+
file = flyvis.repo_dir / "data/connectome" / file
171+
# case 2: file is specified relative to root directory
172+
elif (flyvis.root_dir / "connectome" / file).exists():
166173
file = flyvis.root_dir / "connectome" / file
174+
else:
175+
raise FileNotFoundError(f"Connectome file {file} not found.")
167176

168177
# Load the connectome spec.
169178
spec = json.loads(Path(file).read_text())

0 commit comments

Comments
 (0)