Skip to content

Commit

Permalink
Merge pull request #113 from connectome-neuprint/fix-vvd-paths-further
Browse files Browse the repository at this point in the history
Further improves some path issues on Windows.
  • Loading branch information
hubbardp authored Jun 5, 2023
2 parents 5b729d3 + ab94e35 commit 41f93f7
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.10.1
1.10.2
26 changes: 21 additions & 5 deletions neuVid/animateVvd.py
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,7 @@ def add_volumes(input, state, json_data, default_channel):
else:
vol_file = value
channel = default_channel
vol_path = source_base + "/" + vol_file
vol_path = os.path.join(source_base, vol_file)
volumes[full_vol_name] = (vol_path, channel)
state["volumes"] = volumes

Expand Down Expand Up @@ -704,6 +704,16 @@ def describe_volumes(state):
i = 0
for full_vol_name, vol_tuple in state["volumes"].items():
vol_path, channel = vol_tuple

# VVDViewer seems to accept only absolute paths and paths that start with "./"
# So even relative paths like "../elsewhere" need to be "./../elsewhere", oddly.
if not os.path.isabs(vol_path):
vol_path = os.path.join(".", vol_path)

# On Windows, the output of os.path.join does not seem to work for paths in
# VVDViewer project files. But forward slashes do work.
vol_path = vol_path.replace(os.sep, "/")

result += "[data/volume/{}]\n".format(i)
result += "name={}\n".format(full_vol_name)
result += "path={}\n".format(vol_path)
Expand Down Expand Up @@ -820,10 +830,10 @@ def describe_project(input, json_data, default_channel):
return result

# Builds a very simple neuVid description (JSON) file from the volumes in `input_dir`.
def collect_volumes(input_dir, count=-1):
def collect_volumes(input_dir, output_dir_rel, count=-1):
result = {
"volumes": {
"source": os.path.realpath(args.input)
"source": output_dir_rel
},
"animation": [
]
Expand Down Expand Up @@ -876,12 +886,18 @@ def collect_volumes(input_dir, count=-1):
print("Using input directory: {}".format(args.input))
output = args.output
if not output:
output = os.path.splitext(args.input)[0] + ".json"
output = args.input
if output.endswith(os.sep):
output = output[:-1]
output += ".json"
if args.count > 0:
print("Limiting to count: {}".format(args.count))
print("Using output file: {}".format(output))

json_data = collect_volumes(args.input, args.count)
input_dir = os.path.abspath(args.input)
output_dir = os.path.dirname(output)
output_dir_rel = os.path.relpath(input_dir, output_dir)
json_data = collect_volumes(input_dir, output_dir_rel, args.count)
json_str = formatted(json_data)
with open(output, "w") as f:
f.write(json_str)
Expand Down
8 changes: 5 additions & 3 deletions neuVid/fetchVvd.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def find_in_keys(pattern_elements, keys):
# "b": [{"line": "b"}, 2],
# "c": [{"line": "c", "sex": "male"}, 2]
# }
def fetch_volumes(input, json_data):
def fetch_volumes(json_data, output):
if not "volumes" in json_data:
return {}
json_volumes = json_data["volumes"]
Expand All @@ -116,6 +116,8 @@ def fetch_volumes(input, json_data):
vols_path = os.path.join(dir, "neuVidVolumes")
if not os.path.exists(vols_path):
os.mkdir(vols_path)
# Even on Windows, forward slashes work better as path separators for
# paths to be stored as JSON strings.
vols_path_output = "./neuVidVolumes"

for key, val in json_volumes.items():
Expand Down Expand Up @@ -150,7 +152,7 @@ def fetch_volumes(input, json_data):
sys.exit()

vol_name = vol_name.replace(" ", "+")
url = os.path.join(json_source, vol_name)
url = json_source + "/" + vol_name
print("Fetching {}.".format(url))
try:
response = requests.get(url)
Expand Down Expand Up @@ -218,7 +220,7 @@ def update_input(input, updates):
output = args.input

json_data = parse_json(args.input)
updates = fetch_volumes(args.input, json_data)
updates = fetch_volumes(json_data, output)
updated = update_input(args.input, updates)

with open(output, "w") as f:
Expand Down

0 comments on commit 41f93f7

Please sign in to comment.