Skip to content

Commit 8143911

Browse files
committed
fixed some ugly bugs
1 parent ebf51d9 commit 8143911

File tree

6 files changed

+37
-142
lines changed

6 files changed

+37
-142
lines changed

pyptv/batch_convert_par_dirs_to_yaml.py

Lines changed: 0 additions & 46 deletions
This file was deleted.

pyptv/ptv.py

Lines changed: 16 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -357,71 +357,28 @@ def py_correspondences_proc_c(exp):
357357
"""
358358
frame = 123456789
359359

360+
361+
360362
sorted_pos, sorted_corresp, num_targs = correspondences(
361363
exp.detections, exp.corrected, exp.cals, exp.vpar, exp.cpar
362364
)
363365

364-
# Get sequence parameters to write targets
365-
if hasattr(exp, 'spar') and exp.spar is not None:
366-
# Traditional experiment object with spar
367-
for i_cam in range(exp.num_cams):
368-
base_name = exp.spar.get_img_base_name(i_cam)
369-
write_targets(exp.detections[i_cam], base_name, frame)
370-
elif hasattr(exp, 'get_parameter'):
371-
# MainGUI object - get sequence parameters from ParameterManager
372-
seq_params = exp.get_parameter('sequence')
373-
if seq_params and 'base_name' in seq_params:
374-
for i_cam in range(exp.num_cams):
375-
base_name = seq_params['base_name'][i_cam]
376-
write_targets(exp.detections[i_cam], base_name, frame)
377-
else:
378-
print("Warning: No sequence parameters found, skipping target writing")
379-
else:
380-
print("Warning: No way to determine base names, skipping target writing")
381-
382-
# Generate short_file_bases once per experiment
383366
img_base_names = [exp.spar.get_img_base_name(i) for i in range(exp.num_cams)]
384-
exp.short_file_bases = generate_short_file_bases(img_base_names)
385-
386-
for frame in range(exp.spar.get_first(), exp.spar.get_last() + 1):
387-
detections = []
388-
corrected = []
389-
for i_cam in range(exp.num_cams):
390-
targs = read_targets(exp.short_file_bases[i_cam], frame)
391-
targs.sort_y()
392-
detections.append(targs)
393-
matched_coords = MatchedCoords(targs, exp.cpar, exp.cals[i_cam])
394-
pos, _ = matched_coords.as_arrays()
395-
corrected.append(matched_coords)
396-
sorted_pos, sorted_corresp, _ = correspondences(
397-
detections, corrected, exp.cals, exp.vpar, exp.cpar
398-
)
399-
print(
400-
"Frame "
401-
+ str(frame)
402-
+ " had "
403-
+ repr([s.shape[1] for s in sorted_pos])
404-
+ " correspondences."
405-
)
406-
sorted_pos = np.concatenate(sorted_pos, axis=1)
407-
sorted_corresp = np.concatenate(sorted_corresp, axis=1)
408-
flat = np.array(
409-
[corrected[i].get_by_pnrs(sorted_corresp[i]) for i in range(len(exp.cals))]
410-
)
411-
pos, _ = point_positions(flat.transpose(1, 0, 2), exp.cpar, exp.cals, exp.vpar)
412-
if len(exp.cals) < 4:
413-
print_corresp = -1 * np.ones((4, sorted_corresp.shape[1]))
414-
print_corresp[: len(exp.cals), :] = sorted_corresp
415-
else:
416-
print_corresp = sorted_corresp
417-
rt_is_filename = default_naming["corres"].decode()
418-
rt_is_filename = f"{rt_is_filename}.{frame}"
419-
with open(rt_is_filename, "w", encoding="utf8") as rt_is:
420-
rt_is.write(str(pos.shape[0]) + "\n")
421-
for pix, pt in enumerate(pos):
422-
pt_args = (pix + 1,) + tuple(pt) + tuple(print_corresp[:, pix])
423-
rt_is.write("%4d %9.3f %9.3f %9.3f %4d %4d %4d %4d\n" % pt_args)
367+
short_file_bases = generate_short_file_bases(img_base_names)
424368

369+
for i_cam in range(exp.num_cams):
370+
write_targets(exp.detections[i_cam], short_file_bases[i_cam], frame)
371+
else:
372+
print("Warning: No sequence parameters found, skipping target writing")
373+
374+
print(
375+
"Frame "
376+
+ str(frame)
377+
+ " had "
378+
+ repr([s.shape[1] for s in sorted_pos])
379+
+ " correspondences."
380+
)
381+
425382
return sorted_pos, sorted_corresp, num_targs
426383

427384

pyptv/pyptv_gui.py

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1545,50 +1545,42 @@ def printException():
15451545

15461546
def main():
15471547
"""main function"""
1548-
from pyptv.batch_convert_par_dirs_to_yaml import batch_convert_par_dirs_to_yaml
15491548
software_path = Path.cwd().resolve()
15501549
print(f"Running PyPTV from {software_path}")
15511550

15521551
yaml_file = None
15531552
exp_path = None
15541553

1555-
if len(sys.argv) > 1:
1554+
if len(sys.argv) == 2:
15561555
arg_path = Path(sys.argv[1]).resolve()
15571556
if arg_path.is_file() and arg_path.suffix in {".yaml", ".yml"}:
15581557
yaml_file = arg_path
1559-
exp_path = yaml_file.parent
15601558
print(f"YAML parameter file provided: {yaml_file}")
15611559
elif arg_path.is_dir():
15621560
exp_path = arg_path
1563-
# Convert legacy parameter directories to YAML if needed
1564-
yaml_files = list(exp_path.glob("*.yaml")) + list(exp_path.glob("*.yml"))
1565-
if not yaml_files:
1566-
print("Converting parameter directories to YAML...")
1567-
batch_convert_par_dirs_to_yaml(exp_path)
1568-
yaml_files = list(exp_path.glob("*.yaml")) + list(exp_path.glob("*.yml"))
1569-
if not yaml_files:
1570-
raise OSError(f"No legacy parameter and no YAML files in {exp_path}")
1571-
yaml_file = yaml_files[0]
1561+
exp = Experiment()
1562+
exp.populate_runs(exp_path)
1563+
yaml_file = exp.active_params.yaml_path
15721564
print(f"Using first YAML file found: {yaml_file}")
15731565
else:
15741566
raise OSError(f"Argument must be a directory or YAML file, got: {arg_path}")
15751567
else:
15761568
# Fallback to default test directory
15771569
exp_path = software_path / "tests" / "test_cavity"
1578-
yaml_files = list(exp_path.glob("*.yaml")) + list(exp_path.glob("*.yml"))
1579-
if not yaml_files:
1580-
raise OSError(f"No YAML files found in default test directory {exp_path}")
1581-
yaml_file = yaml_files[0]
1582-
print(f"Without inputs, PyPTV falls back to default {yaml_file}")
1583-
print("Use File -> Open to select another YAML file")
1570+
exp = Experiment()
1571+
exp.populate_runs(exp_path)
1572+
yaml_file = exp.active_params.yaml_path
1573+
print(f"Without inputs, PyPTV uses default case {yaml_file}")
1574+
print("Tip: in PyPTV use File -> Open to select another YAML file")
15841575

15851576
if not yaml_file or not yaml_file.exists():
15861577
raise OSError(f"YAML parameter file does not exist: {yaml_file}")
15871578

15881579
print(f"Changing directory to the working folder {yaml_file.parent}")
1589-
os.chdir(yaml_file.parent)
1580+
15901581

15911582
try:
1583+
os.chdir(yaml_file.parent)
15921584
main_gui = MainGUI(yaml_file)
15931585
main_gui.configure_traits()
15941586
except OSError:
@@ -1597,3 +1589,13 @@ def main():
15971589
finally:
15981590
print(f"Changing back to the original {software_path}")
15991591
os.chdir(software_path)
1592+
1593+
1594+
if __name__ == "__main__":
1595+
try:
1596+
main()
1597+
except Exception as e:
1598+
print("An error occurred in the main function:")
1599+
print(e)
1600+
printException()
1601+
sys.exit(1)

tests/test_cavity/addpar.raw

Lines changed: 0 additions & 1 deletion
This file was deleted.

tests/test_cavity/man_ori.dat

Lines changed: 0 additions & 16 deletions
This file was deleted.

tests/test_cavity/tmp.addpar

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)