Reference
Reference of the smos-walker project
smos_walker.api
Entrypoint to smos_walker
The module's facade does expose the following functions:
index_datablock- Index a datablock (DBL) according to its schema.create_query- Query object over an indexed datablock.
smos_walker.api.facade
SmosWalker
Instantiate an object to help manipulating datablocks
See test_smoswalker_highlevel_api for a practical example of usage.
Attributes:
| Name | Type | Description |
|---|---|---|
xsd_path |
str
|
Path pointing towards the XSD file, also known as "binx.xsd". |
xml_schema_path |
str
|
Path pointing towards an XML schema file. |
datablock_folder_path |
str | None
|
Path pointing towards the folder containing the data block. |
statically_decorated_tree |
BaseNode
|
A statically-decorated tree. Does not require a datablock. Corresponds to "Step 2" |
indexed_datablock |
IndexedDataBlock | None
|
The indexed datablock |
Source code in smos_walker\api\facade.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 | |
datablock_info
property
Information about the indexed datablock
type_info
property
Information about a path in the typesystem hierarchy
__init__(xsd_path, xml_schema_path, datablock_folder_path=None)
Constructor
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xsd_path |
str
|
Path pointing towards the XSD file, also known as "binx.xsd". |
required |
xml_schema_path |
str
|
Path pointing towards an XML schema file. |
required |
datablock_folder_path |
str | None
|
Path pointing towards the folder containing the data block. |
None
|
Source code in smos_walker\api\facade.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
create_query(path)
Factory method to instantiate queries over the indexed datablock.
Unless needed, use the query method directly.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path |
str | None
|
Slash-separated path pointing to a node in the typesystem hierarchy. To see a list of available paths, use str_query(). |
required |
Returns:
| Type | Description |
|---|---|
IndexedDataBlockQuery
|
IndexedDataBlockQuery object |
Source code in smos_walker\api\facade.py
253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 | |
get_dimensionality(path)
Get the dimensionality of the node. It is the count of integer indexes to provide when using query.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path |
str
|
Slash-separated path pointing to a node in the typesystem hierarchy. To see a list of available paths, use str_query(). |
required |
Returns:
| Type | Description |
|---|---|
int | None
|
the dimensionality |
Source code in smos_walker\api\facade.py
241 242 243 244 245 246 247 248 249 250 251 | |
get_info(path=None)
alias forstr_dynamic_tree
Source code in smos_walker\api\facade.py
186 187 188 | |
get_length(path, *coordinates)
Gives the max index of the list of dynamic offsets, and navigate through coordinates if needed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path |
str
|
Slash-separated path pointing to a node in the typesystem hierarchy. To see a list of available paths, use str_query(). |
required |
coordinates |
int
|
Optional extra coordinates to uniquely identify a node (some type hierarchies have a high-dimensionality, usually due to the nested use of Array Variables in the schema description) |
()
|
Returns:
| Type | Description |
|---|---|
int | None
|
max index if possible, else None (eg, if the dimension of the node is 0) |
Source code in smos_walker\api\facade.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | |
get_type_info(path=None)
Information about a path in the typesystem hierarchy
Source code in smos_walker\api\facade.py
123 124 125 | |
get_typesystem_node(path=None)
Tries to retrieve the original typesystem node for the given path
Applies to the dynamically decorated tree obtained from the indexed datablock.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path |
str | None
|
Slash-separated path pointing to a node in the typesystem hierarchy. To see a list of available paths, use str_query(). |
None
|
Returns:
| Type | Description |
|---|---|
ConcreteNodeType | None
|
typesystem node if found. |
Source code in smos_walker\api\facade.py
208 209 210 211 212 213 214 215 216 217 218 219 220 | |
query(path, *coordinates)
Fetch data from the index datablock
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path |
str
|
Slash-separated path pointing to a node in the typesystem hierarchy. To see a list of available paths, use str_query(path). |
required |
coordinates |
int
|
Optional extra coordinates to uniquely identify a node (some type hierarchies have a high-dimensionality, usually due to the nested use of Array Variables in the schema description) |
()
|
Raises:
| Type | Description |
|---|---|
SmosWalkerException
|
error message containing help to uniquely identify a node in the typesystem hierarchy. |
Returns:
| Type | Description |
|---|---|
NumpifiedDataBlockType | None
|
A Numpy's ndarray if the node could be located in the typesystem and the datablock. |
Source code in smos_walker\api\facade.py
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 | |
set_datablock(datablock_folder_path)
Sets the datablock path and index it
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
datablock_folder_path |
str
|
Path pointing towards the folder containing the data block. |
required |
Source code in smos_walker\api\facade.py
66 67 68 69 70 71 72 73 | |
str_dynamic_tree(path=None)
Print a user-friendly representation of the dynamically decorated tree (aka Step 3 in the XML schema parsing)
Requires an indexed datablock. Use set_datablock if no datablock is set yet.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path |
str | None
|
Slash-separated path pointing to a node in the typesystem hierarchy. To see a list of available paths, use str_query(). No path given means print the whole tree from the root. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
text representation of the dynamically decorated tree |
Source code in smos_walker\api\facade.py
190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 | |
str_static_tree()
Print a user-friendly representation of the statically decorated tree (aka Step 2 in the XML schema parsing)
Returns:
| Type | Description |
|---|---|
str
|
text representation of the statically decorated tree |
Source code in smos_walker\api\facade.py
134 135 136 137 138 139 140 | |
create_query(indexed_datablock)
Creates a query object for a given data block.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indexed_datablock |
IndexedDataBlock
|
The indexed data block. |
required |
Returns:
| Type | Description |
|---|---|
IndexedDataBlockQuery
|
The query object. |
Source code in smos_walker\api\facade.py
330 331 332 333 334 335 336 337 338 339 | |
index_datablock(xsd_path, xml_schema_path, datablock_folder_path)
Computes an index for a given datablock, with the help of its schema definition.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xsd_path |
str
|
Path pointing towards the XSD file, also known as "binx.xsd". |
required |
xml_schema_path |
str
|
Path pointing towards an XML schema file. |
required |
datablock_folder_path |
str
|
Path pointing towards the folder containing the data block. |
required |
Returns:
| Type | Description |
|---|---|
IndexedDataBlock
|
The resulting datablock-specific index. |
Source code in smos_walker\api\facade.py
305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 | |
smos_walker.api.tools
Useful high-level tools that are too specific to be part of the API's facade
ProblematicSchema
Bases: TypedDict
Description of schema that cannot be successfully statically decorated
Source code in smos_walker\api\tools.py
24 25 26 27 28 | |
generate_human_readable_statically_decorated_schemas(schemas_base_path)
Generates human-readable text files of statically decorated XML data schemas.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schemas_base_path |
Path
|
Home path containing all schemas as well as the XSD file. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
list |
ConsumerResultsType
|
All files that did pose a problem during text generation (empty if full success) |
Source code in smos_walker\api\tools.py
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 | |
output_tree_to_json(tree)
Outputs a tree to JSON
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tree |
BaseNode
|
Statically- or dynamically-decorated type system tree |
required |
Returns:
| Type | Description |
|---|---|
str
|
JSON-representation of the tree |
Source code in smos_walker\api\tools.py
135 136 137 138 139 140 141 142 143 144 145 146 | |
output_tree_to_txt(tree, **kwargs)
Outputs a tree to TXT
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tree |
BaseNode
|
Statically- or dynamically-decorated type system tree |
required |
Returns:
| Type | Description |
|---|---|
str
|
TXT-representation of the tree |
Source code in smos_walker\api\tools.py
149 150 151 152 153 154 155 156 157 158 159 160 | |
provide_statically_decorated_trees(schemas_base_path, consumers, *, verbose=True)
Provide statically decorated trees, by iterating over all binXschema files contained in the given folder.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
schemas_base_path |
Path
|
Home path containing all schemas as well as the XSD file. |
required |
consumers |
list[DecoratedTreeConsumer]
|
List of decorated tree consumers. The current path is also provided. |
required |
verbose |
bool
|
Log progress |
True
|
Returns:
| Type | Description |
|---|---|
ConsumerResultsType
|
list[ProblematicSchema]: description |
Source code in smos_walker\api\tools.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 | |
smos_walker.cli
Command-line interface for smos_walker
The module's facade does expose an entrypoint.
smos_walker.cli.facade
entrypoint(xsd_path, xml_schema_path, *, datablock_folder_path=None, output_format='json', step=1)
summary
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xsd_path |
str
|
Path pointing towards the XSD file, also known as "binx.xsd". |
required |
xml_schema_path |
str
|
Path pointing towards an XML schema file. |
required |
datablock_folder_path |
str | None
|
Required by step 3 (dynamic indexing). Defaults to None. |
None
|
output_format |
Literal['txt', 'json']
|
Output format. |
'json'
|
step |
Literal[1, 2, 3]
|
Step |
1
|
Returns:
| Type | Description |
|---|---|
str
|
String-representation of the working tree |
Source code in smos_walker\cli\facade.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
smos_walker.core
Contains core smos_walker's logic
smos_walker.core.node
ArrayFixedNode
Bases: BaseNode
Array Fixed Node: the nicest array node.
It is analoguous to static arrays in programming languages such as C.
It satisfies the following properties:
- It has one or more dimensions. Their naming is optional.
- It is static when its unique child is static.
- When static, it can be mapped to a Numpy's
dtype - It has one child, that can be a leaf or a struct
Property known to be wrong - If the child is a struct, it has to be static. => It can contain other arrayvariables
To prove these, the PredicateNodeVisitor could be used.
Attributes:
| Name | Type | Description |
|---|---|---|
dimensions |
list[NodeDimension]
|
The name of the type containing the structure. |
cardinality |
int
|
Total number of children accross all dimensions. |
child |
LeafNode | StructNode
|
The type of data contained in the array. |
Source code in smos_walker\core\node.py
223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 | |
ArrayVariableNode
Bases: BaseNode
Array Variable Node: the one that did create the need for this project in the first place.
It is analoguous to dynamically allocated arrays in programming languages such as C.
It satisfies the following properties:
- It has only one variable dimension
- It is never static, as its total size cannot be determined without an instance of a datablock providing its length
- When quasi-static, it can be mapped to a Numpy's
dtype - The only dimension is always named
- Children are always Struct (uncertain, as ArrayFixed node can reference LeafNodes directly)
size_refis always a Leaf (very likely, as it stores a scalar describing the dimension)
Properties to be proved formally:
- The most nested ArrayVariable in a schema hierarchy is quasi-static.
Warning
Currently, the child attribute can only be a StructNode,
but this is likely to be a StructNode | LeafNode, though not encountered yet.
To prove these, the PredicateNodeVisitor could be used.
Attributes:
| Name | Type | Description |
|---|---|---|
size_ref |
LeafNode
|
A leaf node describing the array length. It can only be determined as runtime.
The size_ref is the header of an array variable. Related to the |
dynamic_size |
RecursiveListOfIntegers | None
|
Like |
child |
StructNode
|
The type of data contained in the array. |
Source code in smos_walker\core\node.py
280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 | |
BaseNode
Base Node: The abstract base node that all others inherit from.
A convention followed in this class hierarchy is to prefix by dynamic attributes that can only
determined with a concrete instance of a datablock.
It means that they cannot be determined solely from the type system XML schema.
Attributes:
| Name | Type | Description |
|---|---|---|
name |
str
|
Mandatory node's name (static) |
label |
str | None
|
Optional label over the node (static) |
block_byte_size |
int | None
|
Computed at compile time, if possible (static) |
dynamic_dimensionality |
int | None
|
Dimensionality: number of integers required to uniquely identify the node |
dynamic_coverage |
int | None
|
Accumulated size obtained during each of the node's visit when reading the binary data block |
dynamic_offset |
RecursiveListOfIntegers | None
|
Dynamic offset while reading. The array is of dimension |
Source code in smos_walker\core\node.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 | |
static: bool
property
cached
True if the node's children block size is known in advance (static)
To be overriden by subclasses
__init__(name, label=None)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name |
str
|
Mandatory node's name |
required |
label |
str | None
|
Optional label over the node |
None
|
Source code in smos_walker\core\node.py
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
LeafNode
Bases: BaseNode
Leaf Node: the final concrete data described by the type system.
It is analoguous to primitive types in programming languages.
It satisfies the following properties:
- it is always
static - it has no children (as its name indicated, like a leaf on a tree)
Attributes:
| Name | Type | Description |
|---|---|---|
primitive_type |
str
|
A string representing the primitive of the node. No type checking is performed ; an unexpected value will engender a runtime error. |
Source code in smos_walker\core\node.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 | |
NodeDimension
Bases: TypedDict
A Node's dimension is composed of an optional name and a mandatory size.
Source code in smos_walker\core\node.py
41 42 43 44 45 | |
NodeVisitor
Bases: Visitor
Generic interface for the visitor pattern, used for tree exploration
Source code in smos_walker\core\node.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 | |
StructNode
Bases: BaseNode
Struct Node: the abstract data structure containing the others.
It is analoguous to structures in programming languages such as C.
More specifically, structures are closely related to the type system.
Indeed, the "structure" and "type" concepts are merged into one in this parser.
In the original XML schema files, useType tags often have an only struct tag child.
However, it can also contains one ArrayFixed or one ArrayVariable.
If that is the case, the array node child is wrapped into a list containing itself,
to simulate a structure node having it as a child.
It satisfies the following properties:
- It has a list of children. They can be of all type deriving
BaseNode. - It is static when all its children are static
- When static, it can be mapped to a Numpy's
dtype
Attributes:
| Name | Type | Description |
|---|---|---|
type_name |
str
|
The name of the type containing the structure. |
children |
list[BaseNode]
|
Members of the structure. |
Source code in smos_walker\core\node.py
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | |
smos_walker.core.visitors
Catalog of Visitors that do visit the decorated typesystem tree.
AbstractPredicateNodeVisitor
Bases: NodeVisitor
Base predicate node visitor. Needs to be extended.
Source code in smos_walker\core\visitors.py
233 234 235 236 237 238 239 240 | |
DictExportNodeVisitor
Bases: NodeVisitor
Export all known information about a node (both static and dynamic)
Source code in smos_walker\core\visitors.py
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | |
DictIndexNodeVisitor
Bases: NodeVisitor
Index all nodes by their name for easy index, and fill the path member of nodes IN PLACE
Note
Modifies IN PLACE the hierarchy.
Warning
- names should be unique for a given parent node.
- the last visited node will have precedence over the other synonymous nodes in case of conflicts.
Source code in smos_walker\core\visitors.py
344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 | |
ExistentialPredicateNodeVisitor
Bases: AbstractPredicateNodeVisitor
Verify existence of a node in the tree that do match a particular condition
Source code in smos_walker\core\visitors.py
258 259 260 261 262 263 264 265 266 267 268 269 270 | |
HumanReadableNodeVisitor
Bases: NodeVisitor
Renders a human-readable text-representation of a node.
Various flags to control displayed data
Source code in smos_walker\core\visitors.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | |
__init__(*, indent_pattern=' ', write_dimension_name_flag=False, write_dynamic_attributes=False, write_primitive_type=False, write_path=True, write_static=False, write_numpifiable=False, write_block_byte_size=False, ignore_static_nodes=False, ignore_non_dimensional_nodes=False)
Constructor
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
indent_pattern |
str
|
Indentation string. |
' '
|
write_dimension_name_flag |
bool
|
Write the names of dimensions for Array Fixed. |
False
|
write_dynamic_attributes |
bool
|
Write dynamic attributes. Relevant only for dynamically decorated trees.
See |
False
|
write_primitive_type |
bool
|
Write the primitive type names for Leaf Nodes (eg |
False
|
write_path |
bool
|
Write the typesystem path pointing to the node. Useful for copypasting node reference for later querying. |
True
|
write_static |
bool
|
Write information about the staticity / quasi-staticity of a node. |
False
|
write_numpifiable |
bool
|
Write the node's |
False
|
ignore_static_nodes |
bool
|
Ignore static nodes. Recommended for printing highest-level recommended numpifiable nodes, and decluttering the final output. |
False
|
ignore_non_dimensional_nodes |
bool
|
Ignore nodes with |
False
|
Source code in smos_walker\core\visitors.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |
ShallowDictExportNodeVisitor
Bases: NodeVisitor
Plain Visitor using the native dict representation methods of Nodes.
Source code in smos_walker\core\visitors.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 | |
SimpleQueryNodeVisitor
Bases: NodeVisitor
Query node by attribute. Tries to find at least one matching attribute in the node's dict
Return the first found node. name should be unique ideally.
Source code in smos_walker\core\visitors.py
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 | |
UniversalPredicateNodeVisitor
Bases: AbstractPredicateNodeVisitor
Verify that all nodes in the tree do match a particular condition
Source code in smos_walker\core\visitors.py
243 244 245 246 247 248 249 250 251 252 253 254 255 | |
render_dimensions(dimensions, write_dimension=True, separator=', ')
Renders a string-representation of an ArrayFixed's dimensions.
You can test this function using doctest:
poetry run python -m doctest smos_walker/core/visitors.py
Examples:
>>> render_dimensions([{'name': 'model', 'size': 3}, {'name': 'pol', 'size': 8}])
'model=3, pol=8'
>>> render_dimensions([{'name': None, 'size': 2}])
'2'
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dimensions |
list[NodeDimension]
|
List of dimensions |
required |
write_dimension |
bool
|
When enabled, writes the dimension's name into the rendered string. Defaults to True. |
True
|
separator |
str
|
Separator between the rendered dimensions. Defaults to ", ". |
', '
|
Returns:
| Type | Description |
|---|---|
str
|
Rendered dimensions |
Source code in smos_walker\core\visitors.py
402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 | |
smos_walker.core.exception
SmosWalkerException
Bases: Exception
Generic exception related to the project.
Source code in smos_walker\core\exception.py
1 2 | |
smos_walker.data_reader
Reads datablocks.
smos_walker.data_reader.facade
read_dbl(datablock_folder_path)
Reads a Data Block file. A Data Block file (*.DBL) is a binary file respecting a XML binx schema.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
datablock_folder_path |
str
|
Path pointing towards the folder containing the datablock file ( |
required |
Returns:
| Type | Description |
|---|---|
DataBlockType | None
|
A data block (numpy array of |
Source code in smos_walker\data_reader\facade.py
12 13 14 15 16 17 18 19 20 21 | |
smos_walker.typesystem_parser
Step 1: Typesystem parser
smos_walker.typesystem_parser.facade
render_typesystem_parsed_tree_from_xml(xsd_path, xml_schema_path)
Generates the most basic tree from the XML schema, with the only addition being the developed typesystem.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xsd_path |
str
|
Path pointing towards the XSD file, also known as "binx.xsd". |
required |
xml_schema_path |
str
|
Path pointing towards an XML schema file. |
required |
Returns:
| Type | Description |
|---|---|
RawNode
|
A basic tree constituted of dicts, with the explicited typesystem. |
Source code in smos_walker\typesystem_parser\facade.py
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | |
smos_walker.typesystem_static_decorator
Step 2: Typesystem static decorator
smos_walker.typesystem_static_decorator.facade
get_statically_decorated_tree(typesystem_parsed_tree)
Statically decorates a typesystem-developed raw tree. Uses the dedicated BaseNode data structure.
Takes the resulting tree from the typesystem parsing component and statically decorate it.
Note
The return tree is a new data structure. It should be leaving the passed argument unaltered.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
typesystem_parsed_tree |
any
|
The typesystem-parsed tree resulting from the |
required |
Returns:
| Type | Description |
|---|---|
BaseNode
|
A statically decorated tree |
Source code in smos_walker\typesystem_static_decorator\facade.py
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | |
load_statically_decorated_tree(xsd_path, xml_schema_path)
User-friendly way to load statically-decorated tree. It includes the usage of the typesystem parser.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
xsd_path |
str
|
Path pointing towards the XSD file, also known as "binx.xsd". |
required |
xml_schema_path |
str
|
Path pointing towards an XML schema file. |
required |
Returns:
| Type | Description |
|---|---|
BaseNode
|
A statically decorated tree |
Source code in smos_walker\typesystem_static_decorator\facade.py
25 26 27 28 29 30 31 32 33 34 35 36 37 38 | |
smos_walker.typesystem_dynamic_decorator
Step 3: Typesystem dynamic decorator
smos_walker.typesystem_dynamic_decorator.facade
dynamically_decorate_tree(statically_decorated_tree, datablock)
Dynamically decorates a statically-decorated typesystem tree IN-PLACE
Takes the resulting tree from the static decoration part and dynamically decorate it with the help of a concrete datablock complying to the typesystem described in the XML schema.
Warning
The tree is mutated IN-PLACE, this is NOT a pure function.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
statically_decorated_tree |
BaseNode
|
The statically-decorated tree resulting from
the |
required |
datablock |
DataBlockType
|
A whole datablock ( |
required |
Raises:
| Type | Description |
|---|---|
SmosWalkerException
|
When the provided |
Returns:
| Type | Description |
|---|---|
DynamicIndexerNodeVisitor
|
The visitor used to dynamically analyze the tree. |
Source code in smos_walker\typesystem_dynamic_decorator\facade.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | |
smos_walker.node_to_ndarray
Logic to convert nodes to numpy arrays (after dyanamic decoration)
smos_walker.node_to_ndarray.facade
mask_clip(tipping_point, size)
Clip values superior to a given tipping_point.
No check is performed to verify that tipping_point < size.
Examples:
>>> mask_values(5, 8)
array([False, False, False, False, False, True, True, True])
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tipping_point |
int
|
Before this index, values are not masked, after, they do. |
required |
size |
int
|
Size of desired mask |
required |
Returns:
| Type | Description |
|---|---|
BooleanNumpyArrayType
|
the mask |
Source code in smos_walker\node_to_ndarray\facade.py
203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | |
node_to_ndarray_quasi_static(node, datablock, dynamic_size)
Numpy-typed view of a datablock's slice using a quasi-static array variable node
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node |
ArrayVariableNode
|
Dynamically-decorated node |
required |
datablock |
DataBlockType
|
A datablock's slice |
required |
dynamic_size |
int
|
Dynamic-size of the array variable.
Note that this has to be an |
required |
Raises:
| Type | Description |
|---|---|
SmosWalkerException
|
When the provided node is not a quasi-static array variable (guard). |
SmosWalkerException
|
When the provided datablock's size does not match the one described by
the provided node and provided |
Returns:
| Type | Description |
|---|---|
NumpifiedDataBlockType
|
A numpy-typed view of the datablock's slice |
Source code in smos_walker\node_to_ndarray\facade.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 | |
node_to_ndarray_static(node, datablock)
Numpy-typed view of a datablock's slice using a static node (Leaf, Struct, ArrayFixed)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node |
LeafNode | StructNode | ArrayFixedNode
|
Dynamically-decorated static node |
required |
datablock |
DataBlockType
|
A datablock's slice |
required |
Raises:
| Type | Description |
|---|---|
SmosWalkerException
|
When the provided node is not static (guard) |
SmosWalkerException
|
When the provided datablock's size does not match the one described by the provided node (guard). |
Returns:
| Type | Description |
|---|---|
NumpifiedDataBlockType
|
A numpy-typed view of the datablock's slice |
Source code in smos_walker\node_to_ndarray\facade.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | |
node_to_ndarray_static_one_dynamic_dimensional(node, datablock)
summary
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
node |
LeafNode | StructNode | ArrayFixedNode
|
Dynamically-decorated static node |
required |
datablock |
DataBlockType
|
A datablock's slice |
required |
Raises:
| Type | Description |
|---|---|
SmosWalkerException
|
When the provided node is not static (guard) |
SmosWalkerException
|
When the provided node's |
SmosWalkerException
|
When the provided datablock's detected contiguous bytes size does not match with the expected one described by the provided node (guard). |
Returns:
| Type | Description |
|---|---|
NumpifiedDataBlockType
|
A numpy-typed view of the datablock's slice |
Source code in smos_walker\node_to_ndarray\facade.py
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 | |