Skip to content

AffineTransformedCoordinateSystem cannot be serialized (session unsaveable for non-autogenerated affine systems) #16

Description

@BrennanTM

AffineTransformedCoordinateSystem has ndarray fields (_transfThisToWorld, _transfWorldToThis) but inherits the base CoordinateSystem.asDict, which calls attrsAsDict with no eqs. The default-equality check then evaluates default == val on an ndarray and raises:

ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()

This is masked in normal use only because every affine system today is isAutogenerated=True and is swapped for a PlaceholderCoordinateSystem in CoordinateSystems.asList before serialization. Any non-autogenerated affine system — e.g. an addon adding a custom template space, or a future transforms panel — makes Session.saveToUnpackedDir raise, i.e. the session becomes unsaveable.

Repro (headless):

import numpy as np
from NaviNIBS.Navigator.Model.Session import Session
from NaviNIBS.Navigator.Model.CoordinateSystems.Affine import AffineTransformedCoordinateSystem

ses = Session.createNew(filepath='/tmp/x.navinibsdir', unpackedSessionDir='/tmp/x.navinibsdir')
ses.coordinateSystems.addItem(AffineTransformedCoordinateSystem(key='X', transfThisToWorld=np.eye(4)))
ses.saveToUnpackedDir()   # ValueError

Suggested fix: override asDict / fromDict on AffineTransformedCoordinateSystem using attrsWithNumpyAsDict / attrsWithNumpyFromDict with npFields=['transfThisToWorld', 'transfWorldToThis'], as other ndarray-bearing model classes do (e.g. Fiducial). NonlinearTransformedCoordinateSystem holds filepaths rather than arrays, so it looks unaffected.

Found while writing tests for the coordinate-system change-handler fix (see linked PR).

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions