Skip to content
This repository was archived by the owner on Aug 27, 2025. It is now read-only.

Commit 3a1ce4f

Browse files
renaming: pixelsize to pixel_size
1 parent 465b75f commit 3a1ce4f

8 files changed

Lines changed: 37 additions & 32 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
## [0.1.x] - tbd
1+
## [0.1.6] - tbd
2+
3+
### Breaking changes
4+
- `pixelsize` is now renamed `pixel_size`
25

36
## [0.1.5] - 2024-01-30
47

docs/cli.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ $ spatialdata_xenium_explorer write [OPTIONS] SDATA_PATH
106106
* `--shapes-key TEXT`: Name of the cell shapes (key of `sdata.shapes`). This argument doesn't need to be provided if there is only one shapes key or a table with only one region.
107107
* `--points-key TEXT`: Name of the transcripts (key of `sdata.points`). This argument doesn't need to be provided if there is only one points key.
108108
* `--gene-column TEXT`: Column name of the points dataframe containing the gene names
109-
* `--pixelsize FLOAT`: Number of microns in a pixel. Invalid value can lead to inconsistent scales in the Explorer. [default: 0.2125]
109+
* `--pixel_size FLOAT`: Number of microns in a pixel. Invalid value can lead to inconsistent scales in the Explorer. [default: 0.2125]
110110
* `--spot / --no-spot`: Whether the technology is based on spots [default: no-spot]
111111
* `--layer TEXT`: Layer of `sdata.table` where the gene counts are saved. If `None`, uses `sdata.table.X`.
112112
* `--lazy / --no-lazy`: If `True`, will not load the full images in memory (except if the image memory is below `ram_threshold_gb`) [default: lazy]

spatialdata_xenium_explorer/_constants.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ def group_attrs() -> dict:
7777
}
7878

7979

80-
def experiment_dict(run_name: str, region_name: str, num_cells: int, pixelsize: float) -> dict:
80+
def experiment_dict(run_name: str, region_name: str, num_cells: int, pixel_size: float) -> dict:
8181
return {
8282
"major_version": Versions.EXPERIMENT[0],
8383
"minor_version": Versions.EXPERIMENT[1],
@@ -97,7 +97,7 @@ def experiment_dict(run_name: str, region_name: str, num_cells: int, pixelsize:
9797
"panel_organism": "Human",
9898
"panel_num_targets_predesigned": 0,
9999
"panel_num_targets_custom": 0,
100-
"pixel_size": pixelsize,
100+
"pixel_size": pixel_size,
101101
"instrument_sn": "N/A",
102102
"instrument_sw_version": "N/A",
103103
"analysis_sw_version": "xenium-1.3.0.5",
@@ -122,12 +122,12 @@ def experiment_dict(run_name: str, region_name: str, num_cells: int, pixelsize:
122122
}
123123

124124

125-
def image_metadata(channel_names: list[str], pixelsize: float) -> dict:
125+
def image_metadata(channel_names: list[str], pixel_size: float) -> dict:
126126
return {
127127
"SignificantBits": 8,
128-
"PhysicalSizeX": pixelsize,
128+
"PhysicalSizeX": pixel_size,
129129
"PhysicalSizeXUnit": "µm",
130-
"PhysicalSizeY": pixelsize,
130+
"PhysicalSizeY": pixel_size,
131131
"PhysicalSizeYUnit": "µm",
132132
"Channel": {"Name": channel_names},
133133
}

spatialdata_xenium_explorer/cli/app.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def write(
2727
gene_column: str = typer.Option(
2828
None, help="Column name of the points dataframe containing the gene names"
2929
),
30-
pixelsize: float = typer.Option(
30+
pixel_size: float = typer.Option(
3131
0.2125,
3232
help="Number of microns in a pixel. Invalid value can lead to inconsistent scales in the Explorer.",
3333
),
@@ -68,7 +68,7 @@ def write(
6868
shapes_key=shapes_key,
6969
points_key=points_key,
7070
gene_column=gene_column,
71-
pixelsize=pixelsize,
71+
pixel_size=pixel_size,
7272
spot=spot,
7373
layer=layer,
7474
lazy=lazy,

spatialdata_xenium_explorer/converter.py

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def write(
2727
shapes_key: str | None = None,
2828
points_key: str | None = None,
2929
gene_column: str | None = None,
30-
pixelsize: float = 0.2125,
30+
pixel_size: float = 0.2125,
3131
spot: bool = False,
3232
layer: str | None = None,
3333
polygon_max_vertices: int = 13,
@@ -64,7 +64,7 @@ def write(
6464
shapes_key: Name of the cell shapes (key of `sdata.shapes`). This argument doesn't need to be provided if there is only one shapes key or a table with only one region.
6565
points_key: Name of the transcripts (key of `sdata.points`). This argument doesn't need to be provided if there is only one points key.
6666
gene_column: Column name of the points dataframe containing the gene names.
67-
pixelsize: Number of microns in a pixel. Invalid value can lead to inconsistent scales in the Explorer.
67+
pixel_size: Number of microns in a pixel. Invalid value can lead to inconsistent scales in the Explorer.
6868
spot: Whether the technology is based on spots
6969
layer: Layer of `sdata.table` where the gene counts are saved. If `None`, uses `sdata.table.X`.
7070
polygon_max_vertices: Maximum number of vertices for the cell polygons. A higher value will display smoother cells.
@@ -106,7 +106,7 @@ def write(
106106

107107
geo_df = utils._standardize_shapes(geo_df)
108108

109-
write_polygons(path, geo_df.geometry, polygon_max_vertices, pixelsize=pixelsize)
109+
write_polygons(path, geo_df.geometry, polygon_max_vertices, pixel_size=pixel_size)
110110

111111
### Saving transcripts
112112
if spot and sdata.table is not None:
@@ -117,17 +117,19 @@ def write(
117117

118118
if _should_save(mode, "t") and df is not None:
119119
if gene_column is not None:
120-
write_transcripts(path, df, gene_column, pixelsize=pixelsize)
120+
write_transcripts(path, df, gene_column, pixel_size=pixel_size)
121121
else:
122122
log.warn("The argument 'gene_column' has to be provided to save the transcripts")
123123

124124
### Saving image
125125
if _should_save(mode, "i"):
126-
write_image(path, image, lazy=lazy, ram_threshold_gb=ram_threshold_gb, pixelsize=pixelsize)
126+
write_image(
127+
path, image, lazy=lazy, ram_threshold_gb=ram_threshold_gb, pixel_size=pixel_size
128+
)
127129

128130
### Saving experiment.xenium file
129131
if _should_save(mode, "m"):
130-
write_metadata(path, image_key, shapes_key, _get_n_obs(sdata, geo_df), pixelsize)
132+
write_metadata(path, image_key, shapes_key, _get_n_obs(sdata, geo_df), pixel_size)
131133

132134
log.info(f"Saved files in the following directory: {path}")
133135
log.info(f"You can open the experiment with 'open {path / FileNames.METADATA}'")
@@ -164,7 +166,7 @@ def write_metadata(
164166
shapes_key: str = "NA",
165167
n_obs: int = 0,
166168
is_dir: bool = True,
167-
pixelsize: float = 0.2125,
169+
pixel_size: float = 0.2125,
168170
):
169171
"""Create an `experiment.xenium` file that can be open by the Xenium Explorer.
170172
@@ -177,10 +179,10 @@ def write_metadata(
177179
shapes_key: Key of `SpatialData` object containing the boundaries shown on the explorer.
178180
n_obs: Number of cells
179181
is_dir: If `False`, then `path` is a path to a single file, not to the Xenium Explorer directory.
180-
pixelsize: Number of microns in a pixel. Invalid value can lead to inconsistent scales in the Explorer.
182+
pixel_size: Number of microns in a pixel. Invalid value can lead to inconsistent scales in the Explorer.
181183
"""
182184
path = utils.explorer_file_path(path, FileNames.METADATA, is_dir)
183185

184186
with open(path, "w") as f:
185-
metadata = experiment_dict(image_key, shapes_key, n_obs, pixelsize)
187+
metadata = experiment_dict(image_key, shapes_key, n_obs, pixel_size)
186188
json.dump(metadata, f, indent=4)

spatialdata_xenium_explorer/core/images.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ class MultiscaleImageWriter:
2929
resolutionunit = "CENTIMETER"
3030
dtype = np.uint8
3131

32-
def __init__(self, image: MultiscaleSpatialImage, tile_width: int, pixelsize: float):
32+
def __init__(self, image: MultiscaleSpatialImage, tile_width: int, pixel_size: float):
3333
self.image = image
3434
self.tile_width = tile_width
35-
self.pixelsize = pixelsize
35+
self.pixel_size = pixel_size
3636

3737
self.scale_names = list(image.children)
3838
self.channel_names = list(map(str, image[self.scale_names[0]].c.values))
3939
self.channel_names = _set_colors(self.channel_names)
40-
self.metadata = image_metadata(self.channel_names, pixelsize)
40+
self.metadata = image_metadata(self.channel_names, pixel_size)
4141
self.data = None
4242

4343
self.lazy = True
@@ -74,7 +74,7 @@ def _scale(self, array: np.ndarray):
7474

7575
def _write_image_level(self, tif: tf.TiffWriter, scale_index: int, **kwargs):
7676
xarr: xr.DataArray = next(iter(self.image[self.scale_names[scale_index]].values()))
77-
resolution = 1e4 * 2**scale_index / self.pixelsize
77+
resolution = 1e4 * 2**scale_index / self.pixel_size
7878

7979
if not self._should_load_memory(xarr.shape, xarr.dtype):
8080
n_tiles = xarr.shape[0] * self._n_tiles_axis(xarr, 1) * self._n_tiles_axis(xarr, 2)
@@ -172,7 +172,7 @@ def write_image(
172172
lazy: bool = True,
173173
tile_width: int = 1024,
174174
n_subscales: int = 5,
175-
pixelsize: float = 0.2125,
175+
pixel_size: float = 0.2125,
176176
ram_threshold_gb: int | None = 4,
177177
is_dir: bool = True,
178178
):
@@ -184,7 +184,7 @@ def write_image(
184184
lazy: If `False`, the image will not be read in-memory (except if the image size is below `ram_threshold_gb`). If `True`, all the images levels are always loaded in-memory.
185185
tile_width: Xenium tile width (do not update).
186186
n_subscales: Number of sub-scales in the pyramidal image.
187-
pixelsize: Xenium pixel size (do not update).
187+
pixel_size: Xenium pixel size (do not update).
188188
ram_threshold_gb: If an image (of any level of the pyramid) is below this threshold, it will be loaded in-memory.
189189
is_dir: If `False`, then `path` is a path to a single file, not to the Xenium Explorer directory.
190190
"""
@@ -197,7 +197,7 @@ def write_image(
197197

198198
image: MultiscaleSpatialImage = to_multiscale(image, [2] * n_subscales)
199199

200-
image_writer = MultiscaleImageWriter(image, pixelsize=pixelsize, tile_width=tile_width)
200+
image_writer = MultiscaleImageWriter(image, pixel_size=pixel_size, tile_width=tile_width)
201201
image_writer.write(path, lazy=lazy, ram_threshold_gb=ram_threshold_gb)
202202

203203

spatialdata_xenium_explorer/core/points.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ def write_transcripts(
2323
gene: str = "gene",
2424
max_levels: int = 15,
2525
is_dir: bool = True,
26-
pixelsize: float = 0.2125,
26+
pixel_size: float = 0.2125,
2727
):
2828
"""Write a `transcripts.zarr.zip` file containing pyramidal transcript locations
2929
@@ -33,19 +33,19 @@ def write_transcripts(
3333
gene: Column of `df` containing the genes names.
3434
max_levels: Maximum number of levels in the pyramid.
3535
is_dir: If `False`, then `path` is a path to a single file, not to the Xenium Explorer directory.
36-
pixelsize: Number of microns in a pixel. Invalid value can lead to inconsistent scales in the Explorer.
36+
pixel_size: Number of microns in a pixel. Invalid value can lead to inconsistent scales in the Explorer.
3737
"""
3838
path = explorer_file_path(path, FileNames.POINTS, is_dir)
3939

4040
# TODO: make everything using dask instead of pandas
4141
df = df.compute()
4242

4343
num_transcripts = len(df)
44-
grid_size = ExplorerConstants.GRID_SIZE / ExplorerConstants.PIXELS_TO_MICRONS * pixelsize
44+
grid_size = ExplorerConstants.GRID_SIZE / ExplorerConstants.PIXELS_TO_MICRONS * pixel_size
4545
df[gene] = df[gene].astype("category")
4646

4747
location = df[["x", "y"]]
48-
location *= pixelsize
48+
location *= pixel_size
4949
location = np.concatenate([location, np.zeros((num_transcripts, 1))], axis=1)
5050

5151
if location.min() < 0:

spatialdata_xenium_explorer/core/shapes.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def write_polygons(
4949
polygons: Iterable[Polygon],
5050
max_vertices: int,
5151
is_dir: bool = True,
52-
pixelsize: float = 0.2125,
52+
pixel_size: float = 0.2125,
5353
) -> None:
5454
"""Write a `cells.zarr.zip` file containing the cell polygonal boundaries
5555
@@ -58,13 +58,13 @@ def write_polygons(
5858
polygons: A list of `shapely` polygons to be written
5959
max_vertices: The number of vertices per polygon (they will be transformed to have the right number of vertices)
6060
is_dir: If `False`, then `path` is a path to a single file, not to the Xenium Explorer directory.
61-
pixelsize: Number of microns in a pixel. Invalid value can lead to inconsistent scales in the Explorer.
61+
pixel_size: Number of microns in a pixel. Invalid value can lead to inconsistent scales in the Explorer.
6262
"""
6363
path = explorer_file_path(path, FileNames.SHAPES, is_dir)
6464

6565
log.info(f"Writing {len(polygons)} cell polygons")
6666
coordinates = np.stack([pad_polygon(p, max_vertices) for p in polygons])
67-
coordinates *= pixelsize
67+
coordinates *= pixel_size
6868

6969
num_cells = len(coordinates)
7070
cells_fourth = ceil(num_cells / 4)

0 commit comments

Comments
 (0)