dvpio.write.shapes.write_lmd

Contents

dvpio.write.shapes.write_lmd#

dvpio.write.shapes.write_lmd(path, annotation, calibration_points, affine_transformation=None, annotation_name_column=None, annotation_well_column=None, custom_attribute_columns=None, overwrite=True)#

Write cell annotations to Leica-compatible .xml file

Parameters:
  • path (str) – Export path for .xml

  • annotation (ShapesModel) – Shapes to export with pyLMD

  • calibration_points (PointsModel) – Calibration points in image coordinates

  • affine_transformation (ndarray | None (default: None)) – Optional. Affine transformation to apply to the data to recover Leica coordinate system. If None, tries to recover the to_lmd coordinate transformation from the annotation spatialdata.models.ShapesModel object

  • annotation_name_column (str | None (default: None)) – Optional. Provide column that specifies a (unique) cell name in annotation spatialdata.models.ShapesModel object. Will be stored as the tag of the Shape.

  • annotation_well_column (str | None (default: None)) – Optional. Provide column that specifies a well in the annotation spatialdata.models.ShapesModel object. Will be stored in as the CapID attribute of the Shape.

  • custom_attribute_columns (str | list[str] | None (default: None)) – Columns in annotation that should be exported as custom tags in the xml file. The column name will become the tag name in the respective shape element. Users must assure themselves that they pass valid arguments.

  • overwrite (bool (default: True)) – Default True. Whether to overwrite existing data.

Return type:

None

Returns:

Saves to path

Example

from spatialdata.models import ShapesModel, PointsModel
from tempfile import mkdtemp
from dvpio.write import write_lmd

annotation = ShapesModel.parse(
    gpd.GeoDataFrame(
        data={"name": ["001"], "well": ["A1"], "area": [0.8], "cell_type": ["T cell"]},
        geometry=[shapely.Polygon([[0, 0], [0, 1], [1, 0], [0, 0]])],
    )
)

calibration_points = PointsModel.parse(np.array([[0, 0], [1, 1], [0, 1]]))

path = os.path.join(mkdtemp(), "test.xml")

write_lmd(
    path=path,
    annotation=annotation,
    calibration_points=calibration_points,
    annotation_name_column=annotation_name_column,
    annotation_well_column=annotation_well_column,
    custom_attribute_columns=["area", "cell_type"],
    overwrite=True,
)