py21cmfast.wrapper.inputs.InputStruct ===================================== .. py:class:: py21cmfast.wrapper.inputs.InputStruct A convenient interface to create a C structure with defaults specified. It is provided for the purpose of *creating* C structures in Python to be passed to C functions, where sensible defaults are available. Structures which are created within C and passed back do not need to be wrapped. This provides a *fully initialised* structure, and will fail if not all fields are specified with defaults. .. note:: The actual C structure is gotten by calling an instance. This is auto-generated when called, based on the parameters in the class. .. warning:: This class will *not* deal well with parameters of the struct which are pointers. All parameters should be primitive types, except for strings, which are dealt with specially. :Parameters: **ffi** (*cffi object*) -- The ffi object from any cffi-wrapped library. .. !! processed by numpydoc !! .. py:method:: asdict() -> dict Return a dict representation of the instance. .. rubric:: Examples This dict should be such that doing the following should work, i.e. it can be used exactly to construct a new instance of the same object:: >>> inp = InputStruct(**params) >>> newinp =InputStruct(**inp.asdict()) >>> inp == newinp .. !! processed by numpydoc !! .. py:method:: clone(**kwargs) Make a fresh copy of the instance with arbitrary parameters updated. .. !! processed by numpydoc !! .. py:method:: from_subdict(dct: dict[str, Any], safe: bool = True) -> Self :classmethod: Construct an instance of this class from a dictionary. .. !! processed by numpydoc !! .. py:method:: new(x: dict | Self | None = None, **kwargs) :classmethod: Create a new instance of the struct. :Parameters: **x** (*dict | InputStruct | None*) -- Initial values for the struct. If `x` is a dictionary, it should map field names to their corresponding values. If `x` is an instance of this class, its attributes will be used as initial values. If `x` is None, the struct will be initialised with default values. :Other Parameters: * **All other parameters should be passed as if directly to the class constructor** * **(i.e. as parameter names).** .. rubric:: Examples >>> params = SimulationOptions.new({'HII_DIM': 250}) >>> params.HII_DIM 250 >>> params = SimulationOptions.new(params) >>> params.HII_DIM 250 >>> params = SimulationOptions.new() >>> params.HII_DIM 200 >>> params = SimulationOptions.new(HII_DIM=256) >>> params.HII_DIM 256 .. !! processed by numpydoc !! .. py:property:: cdict :type: dict A python dictionary containing the properties of the wrapped C-struct. The memory pointed to by this dictionary is *not* owned by the wrapped C-struct, but is rather just a python dict. However, in contrast to :meth:`asdict`, this method transforms the properties to what they should be in C (e.g. linear space vs. log-space) before putting them into the dict. This dict also contains *only* the properties of the wrapped C-struct, rather than all properties of the :class:`InputStruct` instance (some attributes of the python instance are there only to guide setting of defaults, and don't appear in the C-struct at all). .. !! processed by numpydoc !!