You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Based on reviewing PR #163 I am proposing the following as a common API:
Each format for which we want a convert_to() should implement a static method on it's main class from_grid(grid, **kwargs) that will create the object from a grid (and use any additional optional arguments while ignoring any that it cannot process) (EDIT: from_grid() will create the GDF wrapper itself, e.g., MRC.from_grid() will create a gridData.mrc.MRC instance)
This method is essentially taking the code from the corresponding Grid._export_<FORMAT>() method that already does exactly that.
Having this code live in the module of the format is better because it keeps all the code for creating such an object in the same place.
Refactor Grid._export_<FORMAT> methods to use from_grid(): For example, the MRC writer becomes
Create a new Grid.convert_to(format, **kwargs) -> obj method that creates an instance of the class belonging to format:
EDIT: For each of our wrapper classes (mrc.MRC, OpenVDB.OpenVDBField) implement an attribute .native that contains an instance of the native instance from the underlying library, i.e., for MRC.native is an instance of mrcfile.MrcFile; for our own OpenDX we can supply a complete OpenDX.field)
Add a class-level attribute Grid.converter that lists the known formats, like
The initial implementation should just be for the two formats that have an exporter
DX
MRC
Eventually we may be able to also refactor the _export_<FORMAT> methods into a single export() that uses Grid.converters but for right now, leave them explicit.
This looks good. One thing we should probably clarify to avoid any ambiguity, is the return type of from_grid. This comment and comment from PR #148 seem to indicate that it will be a native object, but the examples above seem to refer to the corresponding wrapper in GDF. (For example, there is no write in a native MrcFile object of mrcfile). I think returning our GDF wrapper here is fine (and probably better). For the vdb case, the native object can be made available through an attribute of the wrapper object for power users. Thanks
Good observation. The original idea was indeed to return native objects and not wrappers. We could have all our wrappers have a Wrapper.native attribute that holds the native instance. But for true API interoperability it’s cleaner for convert_to to return the native instance itself. Will have to see if we can still clean up our code. Perhaps just do both by introducing a _convert_to_wrapper() first?
Activity
orbeckst commentedon Feb 9, 2026
We can create sub-issues for MRC and VDB.
orbeckst commentedon Mar 6, 2026
Based on reviewing PR #163 I am proposing the following as a common API:
Each format for which we want a
convert_to()should implement a static method on it's main classfrom_grid(grid, **kwargs)that will create the object from agrid(and use any additional optional arguments while ignoring any that it cannot process) (EDIT:from_grid()will create the GDF wrapper itself, e.g.,MRC.from_grid()will create agridData.mrc.MRCinstance)This method is essentially taking the code from the corresponding
Grid._export_<FORMAT>()method that already does exactly that.Having this code live in the module of the format is better because it keeps all the code for creating such an object in the same place.
Refactor
Grid._export_<FORMAT>methods to usefrom_grid(): For example, the MRC writer becomesCreate a new
Grid.convert_to(format, **kwargs) -> objmethod that creates an instance of the class belonging to format:EDIT: For each of our wrapper classes (
mrc.MRC,OpenVDB.OpenVDBField) implement an attribute.nativethat contains an instance of the native instance from the underlying library, i.e., forMRC.nativeis an instance ofmrcfile.MrcFile; for our own OpenDX we can supply a completeOpenDX.field)Add a class-level attribute
Grid.converterthat lists the known formats, likeThen we can write the
convert_to()method as (EDIT: included.native)The initial implementation should just be for the two formats that have an exporter
Eventually we may be able to also refactor the
_export_<FORMAT>methods into a singleexport()that usesGrid.convertersbut for right now, leave them explicit.Does this make sense?
orbeckst commentedon Mar 6, 2026
@PardhavMaradani @BradyAJohnston and @spyke7 what do you think about the proposed API?
PardhavMaradani commentedon Mar 7, 2026
This looks good. One thing we should probably clarify to avoid any ambiguity, is the return type of
from_grid. This comment and comment from PR #148 seem to indicate that it will be a native object, but the examples above seem to refer to the corresponding wrapper in GDF. (For example, there is nowritein a nativeMrcFileobject ofmrcfile). I think returning our GDF wrapper here is fine (and probably better). For thevdbcase, the native object can be made available through an attribute of the wrapper object for power users. Thanksorbeckst commentedon Mar 7, 2026
Good observation. The original idea was indeed to return native objects and not wrappers. We could have all our wrappers have a Wrapper.native attribute that holds the native instance. But for true API interoperability it’s cleaner for convert_to to return the native instance itself. Will have to see if we can still clean up our code. Perhaps just do both by introducing a _convert_to_wrapper() first?
orbeckst commentedon Mar 7, 2026
from_grid() should still create the wrapper. We just need an intermediate method that returns the true native instance.
BradyAJohnston commentedon Mar 8, 2026
Looks good and I agree that return the GDF wrapper is the way to go.
orbeckst commentedon Mar 8, 2026
I updated #161 (comment) to take the discussion into account.
API update for OpenDX and MRC (#164)