Open LucaMarconato opened 1 year ago
get_centroids()
(https://github.com/scverse/spatialdata/pull/465) needs to be adjusted when the xarray coordinates are not starting from 0.5 (or 0, after https://github.com/scverse/spatialdata/issues/165 is solved), but are implicitly taking into account for the translation.I am not sure if deepcopy()
for SpatialImages
will preserve the xarray coordinates, my guess it's that it will reset the xyz coordiantes (the c are passed explicitly); multiscale spatial image currently doesn't call the parser so it should be fine.
The NGFF transformations specification is going to be merged within a few months! While reviewing the respective RFC, I will list in this comment all the points that needs to be addressed from the spatialdata
side to ensure full compliance. These points could be addressed as part of a PR for this issue, or a follow-up/pre PR.
dim_i
, as in xarray
.arrayCoordinateSystem
field is not implemented for array types is not implemented.(0, 0)
, and the pixel rectangle should be the half-open interval [-0.5, 0.5) x [-0.5, 0.5)
.Implementations are required only to work with Identity
, Translation
and Scale
, so we do not need to implement the following. Still, listing all the points here for completeness.
NgffTransformations
classes, but not in the spatialdata.transformations
classesThe points in this paragraph require some deep changes that maybe it's worth to make directly in a package upstream rather than in the spatialdata.
{'c', 'x', 'y', 'z'}
. Also we treat the 'c'
differently from 'x'
, 'y'
, 'z'
. For instance we can't define a translation involving 'c'
.mapAxis
transformations is a bit more strict, I don't remember exactly the difference (please look at the code)"coordinateTransformations"
.scale
array SHOULD be non-zero. We could raise a warning when we detect a zero (it would be a not very useful transformation, and not invertible).Coordinate transformations from array to physical coordinates MUST be stored in multiscales
and MUST be duplicated in the attributes of the zarr array
transformations
list of a byDimensions
transformation MUST provide input
and output
as arrays of strings corresponding to axis names of the parent transformation's input and output coordinate systems (see below for details).[0, 0, ..., 0, 1]
. In memory we store also that row. We should:
Identity
have input and output axes that are different (assuming they have the same dim)? Answer: yes.
The new coordinate transformations system is explained in this talk https://youtu.be/7HzMn_ooJmk?t=1391 from minute 23:11 to 31:45.
Pragmatically, it requires the following:
Data model
elements.attrs['coordinate_system']
(or maybe with the shorter name'cs'
), will be added; this will be a single 'string'elements.attrs['transform'] will be removed; the information on coordinate transformation will be moved to the
SpatialData` level; transformations will be defined between coordinate systems, not between elements and coordinate systems, coordinate systems and elements, nor elements and elementsxarray
coordinatesBaseTransformation
(and so alsoNGFFBaseTransformation
) andxarray
coordinates. How coordinates are converted needs to be agreed on (discussion here https://github.com/scverse/spatialdata/issues/165#issuecomment-1939260813).xarray
coordinates will not be saved (this is not supported by NGFF); instead the above conversion will be usedAPIs
SpatialData
objects. In fact, elements will not contain coordinate transformations anymore.SpatialData.transform_element_to_coordinate_system()
will be incorporated intoSpatialData.transform_to_coordinate_system()
, by the use of extra arguments. Also it will become a wrapper aroundtransform()
.transform(data, transformation, to_coordinate_system)
will have the following behaviortransformation
is passed,to_coordinate_system
must beNone
. This will modify the data in-place, and not involve/modify any coordinate system transformation. It's ok to call this function if there is only one coordinate system, but if multiple coordinate systems are being used, this usage will probably be undesirable, so we should raise a warning.transformation
isNone
,to_coordinate_system
must be provided. This will transform the data to the desired coordinate system (=change the xarray coordinates, e.g. translations/scale; and also change the data when required, e.g. rotation); also the coordinate system metadata for the element will be updated.maintain_positioning
must be removed, because now we can't modify one element and compensate the transformations departing from it with the inverse transformations. In fact, now the transformations will involve the whole coordinate system. We can consider adding an helper function that mimics the current behavior ofmaintain_positioning
File format
Release
CC @melonora