Subclassing BIDSImage?

I’d like to create a few subclasses for BIDSImage with methods for querying modality-specific information, e.g.:

>>> dwi_img.bvals
[ 0. 500. 500. 1000. ...]

I was wondering if there was a way to monkey-patch this behavior into BIDSImage classes produced by BIDSLayout? I’m aware of obj.__class__ = SubClass. When I tested this about a year ago, I found it obliterated some of the indexed metadata in BIDSImage.

I would probably just advise against this approach, as it will be brittle. It’s easier to write a function with the signature:

def get_bvals(bfile: BIDSFile) -> np.ndarray: ...

No worries. I ended up just writing my own class.

class DWIFile:
    def __init__(self, file, bval_scaling):
        ...
    @property
    def bval(self) -> np.ndarray:
        pass
    @property
    def bvec(self) -> np.ndarray:
        pass
    ...