|
16 | 16 | def get_confocal_image_sizes(img_name, cf_raw_path, overlap=0.1): |
17 | 17 | confocal_notes = pd.read_csv(cf_raw_path / 'notes.csv') |
18 | 18 | capture_name = confocal_notes.loc[confocal_notes['note'] == img_name, 'capture names'].values[0] |
19 | | - imgdir_path = cf_raw_path / f"{capture_name}.imgdir" |
20 | | - if not imgdir_path.exists(): |
21 | | - imgdir_path = list(cf_raw_path.glob(f"*{capture_name}*.imgdir"))[0] |
22 | | - |
| 19 | + sldy_dir = list(cf_raw_path.glob("*.dir"))[0] |
| 20 | + imgdir_path = sldy_dir / f"{capture_name}.imgdir" |
23 | 21 | sample_npy = list(imgdir_path.glob("ImageData_*.npy"))[0] |
24 | 22 | shape = np.load(sample_npy, mmap_mode='r').shape # (Z, Y, X) |
25 | | - |
26 | 23 | yaml_path = imgdir_path / 'StagePositionData.yaml' |
| 24 | + |
27 | 25 | with open(yaml_path, 'r') as f: |
28 | 26 | stage_data = yaml.safe_load(f) |
29 | | - |
30 | 27 | coords = np.array(stage_data['StructArrayValues']).reshape(-1, 3) |
31 | 28 | step_x = np.abs(np.diff(coords[:, 0])) |
32 | 29 | step_x = np.median(step_x[step_x > 1.0]) |
33 | | - |
34 | 30 | phys_x = step_x / (shape[2] * (1 - overlap)) |
35 | | - |
| 31 | + |
36 | 32 | return { |
37 | 33 | 'sizeZ': shape[0], |
38 | 34 | 'sizeY': shape[1], |
39 | 35 | 'sizeX': shape[2], |
40 | 36 | 'sizeC': 1, # Confocal captures are usually single channel per dir |
41 | 37 | 'physical_pixel_size_x': phys_x, |
42 | 38 | 'physical_pixel_size_y': phys_x, # Typically square |
43 | | - 'physical_pixel_size_z': 1.0 # Placeholder if not in YAML |
| 39 | + 'physical_pixel_size_z': 1.0 # Placeholder if not in YAML |
44 | 40 | } |
45 | 41 |
|
46 | | -# def get_confocal_image_sizes(img_name, cf_raw_path): |
47 | | -# sld_path = list(cf_raw_path.glob('*.sldy'))[0] |
48 | | -# r = Reader(str(sld_path)) |
49 | | -# confocal_notes = pd.read_csv(cf_raw_path / 'notes.csv') |
50 | | -# capture_name = confocal_notes.loc[confocal_notes['note']==img_name,'capture names'].values[0] |
51 | | -# img_reader = None |
52 | | -# for i in range(len(r._images)): |
53 | | -# if r._images[i].image_directory.stem==capture_name: |
54 | | -# img_reader = r._images[i] |
55 | | -# break |
56 | | -# if img_reader is None: |
57 | | -# raise ValueError(f"Could not find capture name {capture_name} in confocal sldy file") |
58 | | - |
59 | | -# reader_attrs = list(img_reader.__dict__.keys()) |
60 | | -# size_attrs = [attr for attr in reader_attrs if 'size' in attr] |
61 | | -# size_attrs = {attr: getattr(img_reader, attr) for attr in size_attrs} |
62 | | -# return size_attrs |
63 | | - |
64 | 42 | def generate_confocal_sdata(zarr_path, raw_confocal_path=None): |
65 | 43 | cf_name = zarr_path.stem |
66 | 44 | cf_dt = create_datatree_from_zarr(zarr_path, chan_name=cf_name) |
|
0 commit comments