Skip to content

Commit f763be6

Browse files
committed
fixed pixel size calculation
1 parent a57d9fd commit f763be6

1 file changed

Lines changed: 5 additions & 27 deletions

File tree

src/xenium_analysis_tools/alignment/confocal_alignment.py

Lines changed: 5 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -16,51 +16,29 @@
1616
def get_confocal_image_sizes(img_name, cf_raw_path, overlap=0.1):
1717
confocal_notes = pd.read_csv(cf_raw_path / 'notes.csv')
1818
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"
2321
sample_npy = list(imgdir_path.glob("ImageData_*.npy"))[0]
2422
shape = np.load(sample_npy, mmap_mode='r').shape # (Z, Y, X)
25-
2623
yaml_path = imgdir_path / 'StagePositionData.yaml'
24+
2725
with open(yaml_path, 'r') as f:
2826
stage_data = yaml.safe_load(f)
29-
3027
coords = np.array(stage_data['StructArrayValues']).reshape(-1, 3)
3128
step_x = np.abs(np.diff(coords[:, 0]))
3229
step_x = np.median(step_x[step_x > 1.0])
33-
3430
phys_x = step_x / (shape[2] * (1 - overlap))
35-
31+
3632
return {
3733
'sizeZ': shape[0],
3834
'sizeY': shape[1],
3935
'sizeX': shape[2],
4036
'sizeC': 1, # Confocal captures are usually single channel per dir
4137
'physical_pixel_size_x': phys_x,
4238
'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
4440
}
4541

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-
6442
def generate_confocal_sdata(zarr_path, raw_confocal_path=None):
6543
cf_name = zarr_path.stem
6644
cf_dt = create_datatree_from_zarr(zarr_path, chan_name=cf_name)

0 commit comments

Comments
 (0)