py21cmfast.input_serialization ============================== .. py:module:: py21cmfast.input_serialization .. autoapi-nested-parse:: Functions for handling InputParameters for various purposes, e.g. I/O and unstructuring. .. !! processed by numpydoc !! Functions --------- .. autoapisummary:: py21cmfast.input_serialization.convert_inputs_to_dict py21cmfast.input_serialization.deserialize_inputs py21cmfast.input_serialization.prepare_inputs_for_serialization Module Contents --------------- .. py:function:: convert_inputs_to_dict(inputs, mode = 'full', only_structs = True, camel = True, only_cstruct_params = False, use_aliases = True) Convert an InputParameters object to a dictionary, with various options. While the :class:`~py21cmfast.wrapper.inputs.InputParameters.asdict` method allows several options for "unstructuring" the inputs to a dictionary, this function is much more flexible, having options that cover a number of use-cases. :Parameters: * **inputs** -- The input parameters to convert to a dict. * **mode** -- Either 'minimal' to get the minimal dictionary required to specify the parameters (on top of defaults) or 'full' to keep all parameters. * **only_structs** -- Whether to only return InputStruct objects (unstructured to dicts), otherwise also return other attributes (e.g. random_seed). * **camel** -- Whether the keys of the returned dict should be camel-case, e.g. SimulationOptions. Otherwise, return as snake_case. Only applies to InputStruct attributes of the inputs (i.e. not node_redshifts or random_seed). * **only_cstruct_params** -- Only return parameters that are part of the Cstruct, rather than all fields of the class. This is useful for pretty-printing. * **use_aliases** -- If True, use correct aliases for parameters, which allows the dictionary to be passed back into the InputStruct constructors (e.g. use DIM instead of _DIM). .. !! processed by numpydoc !! .. py:function:: deserialize_inputs(dict_of_structdicts, safe = True, **loose_params) Construct a dictionary of InputStructs ready to be converted to InputParameters. :Parameters: **dict_of_structdicts** -- A dictionary whose keys are names of InputStruct attributes of InputParameters (e.g. CosmoParams, SimulationOptions), and whose values are dictionaries of parameters specific to each struct. Not every parameter of every struct is required. :Other Parameters: * **All other parameters are considered "loose" parameters of one of the InputStructs,** * **and will *override* the parameter matching their name if it is found in one of the** * **structs.** :returns: *dict_of_structs* -- A dictionary whose keys are attribute names of the InputParameters class, and whose values are InputStruct instances, ready to instantiate an InputParameters class, e.g. ``InputParameters(**dict_of_structs, random_seed=1)``. .. !! processed by numpydoc !! .. py:function:: prepare_inputs_for_serialization(inputs, mode = 'full', only_structs = True, camel = True) Prepare an inputs class for serialization (to e.g. TOML, YAML or HDF5). This is a thin wrapper around :func:`~convert_inputs_to_dict` that also ensures that 'None' values are removed (so long as their default is also None) and that the parameter names map back to aliases of InputStruct attributes. .. !! processed by numpydoc !!