Mrsimulator IO¶
-
mrsimulator.
save
(filename: str, simulator: mrsimulator.simulator.Simulator, signal_processors: Optional[List] = None, application: Optional[Dict] = None, with_units: bool = True)¶ Serialize the Simulator, list of SignalProcessor, and an application dict to a file. Creates a Mrsimulator object and calls save.
- Parameters
filename (str) – The data is serialized to this file.
sim – Simulator object.
signal_processors – A list of PostSimulator objects corresponding to the methods in the Simulator object. Default is None.
application – Dictionary holding metadata to serialize in the file. The dictionary will be held in the application key.
with_units (bool) – If true, physical quantities are represented as string with units. The default is True.
-
mrsimulator.
dict
(simulator: mrsimulator.simulator.Simulator, signal_processors: Optional[List] = None, application: Optional[Dict] = None, with_units: bool = True)¶ Export the Simulator, list of SignalProcessor, and an application dict to a python dictionary. Creates a Mrsimulator object with given arguments and calls json from the Mrsimulator object.
- Parameters
sim – Simulator object.
signal_processors – A list of PostSimulator objects corresponding to the methods in the Simulator object. Default is None.
application – Dictionary holding metadata to serialize in the dict. The dictionary will be held under the application key.
with_units (bool) – If true, physical quantities are represented as string with units. The default is True.
- Returns
Python dictionary
-
mrsimulator.
load
(filename: str, parse_units: bool = True)¶ Load Simulator object, list of SignalProcessor objects and metadata from a JSON searalized file of a
Mrsimulator
object.- Parameters
filename (str) – The location to the .mrsim file.
parse_units (bool) – If true, parse the dictionary for units. The default is True.
- Returns
Simulator, List[SignalProcessor], Dict.
- Return type
Ordered List
-
mrsimulator.
parse
(py_dict, parse_units: bool = True)¶ Parse a dictionary object to the respective Simulator object, list of SignalProcessor objects, and the metadata dictionary. If no signal processors are provided a list of default SignalProcessor objects with length equal to number of methods will be returned.
- Parameters
py_dict (Dict) – Python dictionary representation of a
Mrsimulator
object.parse_units (bool) – If true, parse the dictionary for units. Default is True.
- Returns
Simulator, List[SignalProcessor], Dict.
- Return type
Ordered List
-
mrsimulator.
update_old_file_struct
(oldfile: str, newfile: Optional[str] = None)¶ Convert an old mrsim file where Simulator object keywords existed at the root level along with other seralized attributes to a structure where each object exists under its own keyword. A dictionary representing the new Mrsimulator object is returned. Will write a new mrsim file if newfile arg is provided.
- Parameters
oldfile (str) – String of path to mrsim file with old structure
newfile (str) – Will write new mrsim file to path represented by newfile if given
- Returns
Dictionary representation of Mrsimulator object with new structure
- Return type
Dict