controlling array storage in to_yaml_tree methods
In the legacy API the complete AsdfFile context was accessible in the to_tree(cls, node, ctx: AsdfFile) classmethods
This allowed to control the array storage mode (e.g. "inline") for individual numpy arrays directly during the to_tree call like so
@classmethod
def to_tree(cls, node, ctx: AsdfFile):
if node.array.ndim < 3: # let's assume node.array is np.ndarray
ctx.set_array_storage(node.array, "inline")
return {"data" : node.data}
With the new API ctx in to_yaml_tree(self, obj, tag, ctx) is now asdf.asdf.SerializationContext which doesn't allow setting the array storage mode.
Is there a way to pass the option down to the AsdfFile from to_yaml_tree(self, obj, tag, ctx) ?
It would be great to have this control again
I agree that we should support this, probably by adding a similar method to SerializationContext. The reason why we'd like to avoid calling AsdfFile.set_array_storage is that it modifies the currently open AsdfFile instance, which isn't supposed to happen when the file is being written using AsdfFile.write_to.