utils
Full documentation pages are generated for docstring reference only and may contain symbols imported from other modules. Imported symbols are not distinguished from locally defined symbols and will appear in any module that they are imported into. For better information on where symbols should be imported from, review the sourcecode on the github.
FoSpy.json.utils
Synthesis
Bases: FileBlock
Represents a Synthesis loaded from a FOS file.
Source code in FoSpy/blocks/synthesis.py
insert_material
block_from_file
Load a block from a JSON file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file_path
|
str
|
The path to the JSON file. |
required |
block_class
|
class
|
The class of the block to instantiate. Defaults to SingleBlock. |
Synthesis
|
Source code in FoSpy/json/utils.py
build_property_dict
Build a property dictionary from a data dictionary and a mapping dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_dict
|
dict
|
The data dictionary containing the values. |
required |
map_dict
|
dict
|
The mapping dictionary mirroring the structure of the data
dictionary, where values are replaced with destination property
names to be passed to |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
The constructed property dictionary. |
Source code in FoSpy/json/utils.py
fill_properties
Fill the properties of a block dictionary with additional keyword arguments.
Property strings in kwargs can be used to specify nested properties using dot notation for nested dictionaries and bracket notation for lists.
Example
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
block_dict
|
dict
|
The block dictionary to fill. |
required |
**kwargs
|
Additional properties to add to the block dictionary. |
{}
|
Source code in FoSpy/json/utils.py
map_data_from_json
Map a data JSON file to a property dictionary using a mapping JSON file. Optional missing values can be provided in a separated JSON file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_path
|
str
|
The path to the JSON file containing the data. |
required |
map_path
|
str
|
The path to the JSON file containing the mapping. |
required |
missing_path
|
str
|
The path to the JSON file containing any missing values. Defaults to an empty dictionary. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
dict |
The constructed property dictionary. |
Source code in FoSpy/json/utils.py
map_data_to_properties
Map a data dictionary to a property dictionary using a mapping dictionary.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data_dict
|
dict
|
The data dictionary containing the values. |
required |
map_dict
|
dict
|
The mapping dictionary mirroring the structure of the data
dictionary, where values are replaced with destination property
names to be passed to |
required |
Returns:
| Name | Type | Description |
|---|---|---|
dict |
The constructed property dictionary. |