fameio 1.8.2__py3-none-any.whl → 2.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. CHANGELOG.md +224 -0
  2. fameio/scripts/__init__.py +8 -6
  3. fameio/scripts/__init__.py.license +3 -0
  4. fameio/scripts/convert_results.py +31 -35
  5. fameio/scripts/convert_results.py.license +3 -0
  6. fameio/scripts/make_config.py +14 -17
  7. fameio/scripts/make_config.py.license +3 -0
  8. fameio/source/cli/__init__.py +3 -0
  9. fameio/source/cli/convert_results.py +84 -0
  10. fameio/source/cli/make_config.py +62 -0
  11. fameio/source/cli/options.py +58 -0
  12. fameio/source/cli/parser.py +238 -0
  13. fameio/source/loader.py +10 -11
  14. fameio/source/logs.py +90 -35
  15. fameio/source/results/conversion.py +11 -13
  16. fameio/source/results/csv_writer.py +16 -5
  17. fameio/source/results/data_transformer.py +6 -22
  18. fameio/source/results/input_dao.py +163 -0
  19. fameio/source/results/reader.py +25 -14
  20. fameio/source/results/yaml_writer.py +28 -0
  21. fameio/source/scenario/agent.py +56 -39
  22. fameio/source/scenario/attribute.py +9 -12
  23. fameio/source/scenario/contract.py +55 -40
  24. fameio/source/scenario/exception.py +11 -9
  25. fameio/source/scenario/generalproperties.py +11 -17
  26. fameio/source/scenario/scenario.py +19 -14
  27. fameio/source/schema/agenttype.py +75 -27
  28. fameio/source/schema/attribute.py +8 -7
  29. fameio/source/schema/java_packages.py +69 -0
  30. fameio/source/schema/schema.py +44 -15
  31. fameio/source/series.py +148 -25
  32. fameio/source/time.py +8 -8
  33. fameio/source/tools.py +13 -2
  34. fameio/source/validator.py +138 -58
  35. fameio/source/writer.py +120 -113
  36. fameio-2.1.0.dist-info/LICENSES/Apache-2.0.txt +178 -0
  37. fameio-2.1.0.dist-info/LICENSES/CC-BY-4.0.txt +395 -0
  38. fameio-2.1.0.dist-info/LICENSES/CC0-1.0.txt +121 -0
  39. {fameio-1.8.2.dist-info → fameio-2.1.0.dist-info}/METADATA +706 -660
  40. fameio-2.1.0.dist-info/RECORD +53 -0
  41. {fameio-1.8.2.dist-info → fameio-2.1.0.dist-info}/WHEEL +1 -2
  42. fameio-2.1.0.dist-info/entry_points.txt +4 -0
  43. fameio/source/cli.py +0 -253
  44. fameio-1.8.2.dist-info/RECORD +0 -40
  45. fameio-1.8.2.dist-info/entry_points.txt +0 -3
  46. fameio-1.8.2.dist-info/top_level.txt +0 -1
  47. {fameio-1.8.2.dist-info → fameio-2.1.0.dist-info}/LICENSE.txt +0 -0
CHANGELOG.md ADDED
@@ -0,0 +1,224 @@
1
+ <!-- SPDX-FileCopyrightText: 2024 German Aerospace Center <fame@dlr.de>
2
+
3
+ SPDX-License-Identifier: CC0-1.0 -->
4
+
5
+ # Changelog
6
+
7
+ ## [2.1.0](https://gitlab.com/fame-framework/fame-io/-/tags/v2.1.0) - 2024-05-11
8
+ ### Changed
9
+ - Changed format of auto-created timeseries from constant values #196 (@dlr-cjs)
10
+ - Changed default log level to "WARNING" #191 (@dlr_fn @dlr-cjs)
11
+ - Adapted link-formatting in Changelog !155 (@dlr-cjs)
12
+
13
+ ### Added
14
+ - Read java package names from Schema and write to input.pb #198 (@dlr-cjs)
15
+
16
+ ### Fixed
17
+ - Fix docstrings in CLI `handle_args()` #190 (@dlr-cjs @dlr_fn)
18
+ - Fix potential duplicates in logging #191 (@dlr_fn @dlr-cjs)
19
+
20
+ ## [2.0.1](https://gitlab.com/fame-framework/fame-io/-/tags/v2.0.1) - 2024-04-05
21
+ ### Fix
22
+ - Fix potential missing columns when memory-saving-mode `-m` is enabled #194 (@dlr_fn @dlr-cjs)
23
+
24
+ ### Remove
25
+ - Remove convert results option `-cc MERGE` #194 (@dlr_fn @dlr-cjs)
26
+
27
+ ## [2.0.0](https://gitlab.com/fame-framework/fame-io/-/tags/v2.0.0) - 2024-04-03
28
+ ### Changed
29
+ - **Breaking**: Removed support for `python==3.8` #163 (@dlr-cjs @dlr_fn)
30
+ - **Breaking**: Signature of `run` functions in `make_config.py` and `convert_results.py` changed: the input file is now read from the configuration dictionary #163 (@dlr-cjs @dlr_fn)
31
+ - **Breaking**: Created protobuf files now have a header section -> minimum required FAME-Core version is now 1.6.0 #183 (@dlr-cjs @dlr_fn)
32
+ - Raise error for NaN float values in scenario and time series #165 (@dlr-cjs @dlr_fn)
33
+ - Enhance Schema to include metadata and output fields #156 (@dlr-cjs @litotes18 @dlr_fn)
34
+ - Enhance Contracts to include metadata #158 (@dlr-cjs @litotes18 @dlr_fn)
35
+ - Enhance Agents to include metadata #159 (@dlr-cjs @litotes18 @dlr_fn)
36
+ - Improve general handling of CLI arguments #163 (@dlr_fn @dlr-cjs)
37
+ - Ensure `fameio` logger is used consistently !126 (@dlr-cjs @dlr_fn)
38
+ - Enhanced error message if mandatory attribute is not defined by logging `full_name` #177 (@dlr_fn)
39
+ - Switch to pyproject.toml #173 (@dlr-cjs)
40
+ - Restrict supported pandas versions #171 (@dlr-cjs)
41
+ - Enable to specify defaults for MERGE_TIME parameters #179 (@dlr-cjs)
42
+ - Conserve order of keys in YAML files #186 (@dlr-cjs @dlr_fn)
43
+ - Update to `fameprotobuf==1.4.0` #189 (@dlr-cjs @dlr_fn)
44
+ - Update `CHANGELOG.md` to conform with Common Changelog format #172 (@dlr-cjs @dlr_fn)
45
+
46
+ ### Added
47
+ - Write Schema and Metadata of Contracts and Agents to protobuf file #160 (@dlr-cjs @litotes18 @dlr_fn)
48
+ - Add option to recover input data `--input-recovery`/`--no-input-recovery` #163 (@litotes18 @dlr_fn @dlr-cjs)
49
+ - Add pipeline tests for all major Python versions >= 3.8 #173 (@dlr-cjs)
50
+ - Read all input from protobuf file #162 (@dlr-cjs @litotes18 @dlr_fn)
51
+ - Write all input from protobuf to disk #163 (@litotes18 @dlr_fn @dlr-cjs)
52
+ - Add header section to input protobuf enabling recovering of inputs from protobuf #183 (@dlr-cjs @dlr_fn)
53
+ - Add pipeline tests for all major Python versions >= 3.8, < 3.12 #173 (@dlr-cjs)
54
+ - Enable comments in timeseries using '#' #184 (@dlr-cjs)
55
+ - Raise Warning if Agent has no Contracts attributed #187 (@dlr_fn)
56
+ - Add JOSS Paper in folder paper/ #139 (@dlr-cjs @litotes18 @dlr_fn)
57
+ - Add `CONTRIBUTING.md` #102 (@dlr-cjs @dlr_fn)
58
+ - Add `Citation.cff` #166 (@dlr-cjs)
59
+
60
+ ### Removed
61
+ - Remove deprecated protobuf test !127 (@dlr-cjs @dlr_fn)
62
+
63
+ ### Fixed
64
+ - Fix deprecated arguments in pandas groupby !129 (@maurerle)
65
+ - Fix breaking tests in Pytest 8.0 #176 (@dlr-cjs)
66
+ - Fix PyTests for Python 3.12 #182 (@dlr_fn)
67
+
68
+ ## [1.8.1](https://gitlab.com/fame-framework/fame-io/-/tags/v1.8.1) - 2023-05-04
69
+ ### Fixed
70
+ - Fix fail of `ConvertFameResults` when `merge-times` was not specified
71
+
72
+ ## [1.8.0](https://gitlab.com/fame-framework/fame-io/-/tags/v1.8) - 2023-04-14
73
+ ### Changed
74
+ - Update repository to be compliant to `REUSE` standard
75
+ - Accept custom `date_format` (default: `"%Y-%m-%d_%H:%M:%S"`) for `FameTime.convert_fame_time_step_to_datetime()`
76
+ - Parse command-line arguments case-insensitive for arguments with predefined options
77
+ - Handle potentially missing cli arguments in `cli.update_default_config` for `makeFameRunConfig` and `convertFameResults` in a robust way.
78
+
79
+ ### Added
80
+ - **Breaking**: Add option to define conversion of time steps to given format (default=`UTC`) by `-t/--time {UTC, INT, FAME}` for `convertFameResults`
81
+ - Add option to merge time steps in results with `convertFameResults`
82
+ - Add pre-commit hooks enforcing high coding standards and reducing CI runner minutes during development
83
+
84
+ ## [1.7.0](https://gitlab.com/fame-framework/fame-io/-/tags/v1.7) - 2023-02-20
85
+ ### Added
86
+ - Support dictionaries in Schema for field `Products` in elements of `AgentTypes`
87
+ - Support dictionaries in Schema for field `Values` in elements of `Attributes`
88
+
89
+ ### Changed
90
+ - Use `Pathlib` for path handling
91
+ - Improve error message when no valid `YAML` file is specified for `makeFameRunConfig`
92
+
93
+ ### Remove
94
+ - **Breaking**: `Products` in Schema no longer support single non-list values
95
+
96
+ ## [1.6.3](https://gitlab.com/fame-framework/fame-io/-/tags/v1.6.3) - 2022-11-04
97
+ ### Added
98
+ - Allow parsing `Help` for `Attributes` in `schema`
99
+
100
+ ## [1.6.1](https://gitlab.com/fame-framework/fame-io/-/tags/v1.6.1) - 2022-11-02
101
+ ### Changed
102
+ - Use existing logger if already set up to avoid duplicates when `fameio` is used as dependency in third party workflows
103
+
104
+ ## [1.6.0](https://gitlab.com/fame-framework/fame-io/-/tags/v1.6) - 2022-07-08
105
+ ### Added
106
+ - Add option to enable memory saving mode using the flag `-m` or `--memory-saving`
107
+ - Add options to deal with complex indexed output columns using the flag `-cc` or `--complex-column` with
108
+ options `IGNORE`, `MERGE` or `SPLIT`
109
+
110
+ ### Changed
111
+ - **Breaking**: Update requirement to `python>=3.8`
112
+ - **Breaking**: Update requirement to `fameprotobuf==v1.2`
113
+ - Enable parsing of protobuf output files > 2 GB
114
+ - Reduce memory profile for `convertFameResults`
115
+ - Extract `source` scripts relevant for `convertFameResults` to be hosted in subpackage `results`
116
+
117
+ ## [1.5.4](https://gitlab.com/fame-framework/fame-io/-/tags/v1.5.4) - 2022-06-01
118
+ ### Changed
119
+ - Limit `protobuf` dependency to `>=3.19,<4.0`
120
+
121
+ ## [1.5.3](https://gitlab.com/fame-framework/fame-io/-/tags/v1.5.3) - 2022-03-18
122
+ ### Changed
123
+ - Harmonize interface with `famegui`
124
+ - Return `None` on failure of `resolve_series_file_path` instead of raising a `FileNotFoundError`
125
+
126
+ ## [1.5.2](https://gitlab.com/fame-framework/fame-io/-/tags/v1.5.2) - 2022-03-10
127
+ ### Changed
128
+ - Allow interfacing of `famegui` with `scenario` (e.g. serialization, error handling)
129
+ - Move `scenario` validation to `validator.py`
130
+ - Extract `path_resolver.py`
131
+ - Increase test coverage by incorporating [AMIRIS examples](https://gitlab.com/dlr-ve/esy/amiris/examples)
132
+
133
+ ## [1.5.1](https://gitlab.com/fame-framework/fame-io/-/tags/v1.5.1) - 2022-01-10
134
+ ### Added
135
+ - Provide documentation on installation using `pipx`
136
+ - Add optional argument `-se`/`--singleexport` for exporting individual files for each agent
137
+ - Add compatibility hook for `famegui` integration
138
+
139
+ ### Changed
140
+ - Refactor `scenario.py`
141
+ - Ensure code formatting using `black`
142
+
143
+ ## [1.5.0](https://gitlab.com/fame-framework/fame-io/-/tags/v1.5) - 2021-06-30
144
+ ### Added
145
+ - Support specifying an output folder in command line interface of `convert_results.py`
146
+
147
+ ### Changed
148
+ - Update to latest protobuf package
149
+ - Refactor code
150
+
151
+ ## [1.4.0](https://gitlab.com/fame-framework/fame-io/-/tags/v1.4) - 2021-06-10
152
+ ### Added
153
+ - Enable "Default" values for Attributes - these are used in case a mandatory attribute is not specified in the Scenario
154
+ - Allow "List" Attributes with multiple values
155
+ - Add new AttributeTypes "Long", "String" and "TimeStamp"
156
+ - Add compact definition of multiple contracts: enable lists for senders and receivers
157
+
158
+ ### Changed
159
+ - **Breaking**: Update requirement to `fameprotobuf==1.1.4`
160
+ - Refactor `make_config.py`: split into several classes and packages, improved exception handling
161
+ - Switch to pytest and improved test coverage
162
+ - Make keywords in Schema and Scenario case-insensitive
163
+ - Improve validations for Schema and Scenario
164
+
165
+ ### Fixed
166
+ - Fixed minor bugs
167
+
168
+ ## [1.3.0](https://gitlab.com/fame-framework/fame-io/-/tags/v1.3) - 2021-04-13
169
+ ### Added
170
+ - Enable `Attributes` in agents (formerly known as `Fields`) to be structured in complex tree-like data dictionaries
171
+ - Allow contracts to support `Attributes` of type `int`, `float`, `enum` or `dict`
172
+ - Add coverage report badge
173
+ - Add `CHANGELOG.md`
174
+
175
+ ### Changed
176
+ - **Breaking**: Use new format `DataStorage` for input and output protobuf files allowing `FAME-Core` input and output to be written to the same file (requires `FAME-Core > 1.0`)
177
+ - **Breaking**: Update requirement to `fameprotobuf==1.1.2`
178
+ - Enable automatic detection of `TimeStamps` by string format and conversion to int64
179
+ - Raise proper error when file can not be loaded triggered by `!include` command
180
+ - Raise critical error when trying to convert empty protobuf output file
181
+ - Check if `product` in `contract` is valid according to `schema.yaml`
182
+
183
+ ## [1.2.4](https://gitlab.com/fame-framework/fame-io/-/tags/v1.2.4) - 2021-02-26
184
+ ### Changed
185
+ - Move `is_compatible` function to class `AttributeType`
186
+
187
+ ## [1.2.3](https://gitlab.com/fame-framework/fame-io/-/tags/v1.2.3) - 2021-02-24
188
+ ### Fixed
189
+ - Fix file prefix `IGNORE_` (used when loading a set of contract files with the !include argument) is now working consistently
190
+
191
+ ## [1.2.2](https://gitlab.com/fame-framework/fame-io/-/tags/v1.2.2) - 2021-02-18
192
+ ### Changed
193
+ - **Breaking**: Rename `fieldtype` to `attributetype` in `schema.yaml`
194
+ - Derive protobuf imports from `fameprotobuf` package
195
+ - Improve handling of cases for keys in `scenario.yaml`
196
+ - Improve handling of time stamp strings
197
+
198
+ ## [1.2.1](https://gitlab.com/fame-framework/fame-io/-/tags/v1.2.1) - 2021-02-10
199
+ ### Changed
200
+ - Improve key handling for contracts which are now case-insensitive
201
+
202
+ ## [1.2.0](https://gitlab.com/fame-framework/fame-io/-/tags/v1.2) - 2021-02-04
203
+ ### Added
204
+ - Add `!include` command to yaml loading to allow integrating additional yaml files
205
+
206
+ ### Changed
207
+ - **Breaking**: Rename package to `fameio`
208
+ - Improve executables
209
+ - Restructure logging
210
+ - Improve documentation
211
+
212
+ ### Fixed
213
+ - Fix bugs
214
+
215
+ ## [1.1.0](https://gitlab.com/fame-framework/fame-io/-/tags/v1.1) - 2020-12-09
216
+ ### Added
217
+ - Package to PyPI
218
+ - Provide executables for calling `makeFameRunConfig` and `convertFameResults`
219
+
220
+ ### Changed
221
+ - Improve documentation
222
+
223
+ ## [1.0.0](https://gitlab.com/fame-framework/fame-io/-/tags/v1.0) - 2020-11-17
224
+ _Initial release of `famepy`_
@@ -3,16 +3,18 @@ import sys
3
3
 
4
4
  from fameio.scripts.convert_results import DEFAULT_CONFIG as DEFAULT_CONVERT_CONFIG
5
5
  from fameio.scripts.convert_results import run as convert_results
6
- from fameio.scripts.make_config import DEFAULT_CONFIG as DEFAULT_MAKE_CONFIG
7
6
  from fameio.scripts.make_config import run as make_config
8
- from fameio.source.cli import arg_handling_convert_results, arg_handling_make_config
7
+ from fameio.source.cli.convert_results import handle_args as handle_convert_results_args
8
+ from fameio.source.cli.make_config import handle_args as handle_make_config_args
9
9
 
10
10
 
11
+ # noinspection PyPep8Naming
11
12
  def makeFameRunConfig():
12
- input_file, run_config = arg_handling_make_config(sys.argv[1:], DEFAULT_MAKE_CONFIG)
13
- make_config(input_file, run_config)
13
+ run_config = handle_make_config_args(sys.argv[1:])
14
+ make_config(run_config)
14
15
 
15
16
 
17
+ # noinspection PyPep8Naming
16
18
  def convertFameResults():
17
- input_file, run_config = arg_handling_convert_results(sys.argv[1:], DEFAULT_CONVERT_CONFIG)
18
- convert_results(input_file, run_config)
19
+ run_config = handle_convert_results_args(sys.argv[1:], DEFAULT_CONVERT_CONFIG)
20
+ convert_results(run_config)
@@ -0,0 +1,3 @@
1
+ SPDX-FileCopyrightText: 2024 German Aerospace Center <fame@dlr.de>
2
+
3
+ SPDX-License-Identifier: Apache-2.0
@@ -1,75 +1,71 @@
1
1
  #!/usr/bin/env python
2
2
 
3
- import logging as log
4
3
  import sys
5
4
  from pathlib import Path
6
- from typing import Union
7
5
 
8
- from fameio.source.cli import (
9
- Options,
10
- ResolveOptions,
11
- arg_handling_convert_results,
12
- update_default_config,
13
- TimeOptions,
14
- )
15
- from fameio.source.logs import log_and_raise_critical, set_up_logger
6
+ from fameio.source.cli.convert_results import handle_args, CLI_DEFAULTS as DEFAULT_CONFIG
7
+ from fameio.source.cli.options import Options
8
+ from fameio.source.cli.parser import update_default_config
9
+ from fameio.source.logs import log_and_raise_critical, fameio_logger, log
16
10
  from fameio.source.results.agent_type import AgentTypeLog
17
11
  from fameio.source.results.conversion import apply_time_option, apply_time_merging
18
12
  from fameio.source.results.csv_writer import CsvWriter
19
13
  from fameio.source.results.data_transformer import DataTransformer
14
+ from fameio.source.results.input_dao import InputDao
20
15
  from fameio.source.results.output_dao import OutputDAO
21
16
  from fameio.source.results.reader import Reader
22
-
23
- DEFAULT_CONFIG = {
24
- Options.LOG_LEVEL: "info",
25
- Options.LOG_FILE: None,
26
- Options.AGENT_LIST: None,
27
- Options.OUTPUT: None,
28
- Options.SINGLE_AGENT_EXPORT: False,
29
- Options.MEMORY_SAVING: False,
30
- Options.RESOLVE_COMPLEX_FIELD: ResolveOptions.SPLIT.name,
31
- Options.TIME: TimeOptions.UTC.name,
32
- Options.TIME_MERGING: {},
33
- }
17
+ from fameio.source.results.yaml_writer import data_to_yaml_file
34
18
 
35
19
  ERR_MEMORY_ERROR = "Out of memory. Try using `-m` or `--memory-saving` option."
36
20
  ERR_MEMORY_SEVERE = "Out of memory despite memory-saving mode. Reduce output interval in `FAME-Core` and rerun model"
37
21
 
38
22
 
39
- def run(file_path: Union[str, Path], config: dict = None) -> None:
40
- """Reads file in protobuf format at given `file_path` and extracts its content to .csv file(s)"""
23
+ def run(config: dict = None) -> None:
24
+ """Reads file in protobuf format for configures FILE and extracts its content to .csv file(s)"""
41
25
  config = update_default_config(config, DEFAULT_CONFIG)
42
- set_up_logger(level_name=config[Options.LOG_LEVEL], file_name=config[Options.LOG_FILE])
26
+ fameio_logger(log_level_name=config[Options.LOG_LEVEL], file_name=config[Options.LOG_FILE])
43
27
 
44
- writer = CsvWriter(config[Options.OUTPUT], Path(file_path), config[Options.SINGLE_AGENT_EXPORT])
28
+ file_path = config[Options.FILE]
29
+ output_writer = CsvWriter(config[Options.OUTPUT], Path(file_path), config[Options.SINGLE_AGENT_EXPORT])
45
30
  file_stream = open(Path(file_path), "rb")
46
31
 
47
32
  if config[Options.MEMORY_SAVING]:
48
- log.info("Memory saving mode enabled: Disable on conversion of small files for performance improvements.")
33
+ log().info("Memory saving mode enabled: Disable on conversion of small files for performance improvements.")
49
34
 
50
- log.info("Reading and extracting data...")
35
+ log().info("Reading and extracting data...")
51
36
  reader = Reader.get_reader(file=file_stream, read_single=config[Options.MEMORY_SAVING])
52
37
  agent_type_log = AgentTypeLog(requested_agents=config[Options.AGENT_LIST])
53
38
  data_transformer = DataTransformer.build(config[Options.RESOLVE_COMPLEX_FIELD])
54
39
  try:
40
+ input_dao = InputDao()
55
41
  while data_storages := reader.read():
42
+ if config[Options.INPUT_RECOVERY]:
43
+ input_dao.store_inputs(data_storages)
56
44
  output = OutputDAO(data_storages, agent_type_log)
57
45
  for agent_name in output.get_sorted_agents_to_extract():
58
- log.debug(f"Extracting data for {agent_name}...")
46
+ log().debug(f"Extracting data for {agent_name}...")
59
47
  data_frames = output.get_agent_data(agent_name, data_transformer)
60
48
  apply_time_merging(data_frames, config[Options.TIME_MERGING])
61
49
  apply_time_option(data_frames, config[Options.TIME])
62
- log.debug(f"Writing data for {agent_name}...")
63
- writer.write_to_files(agent_name, data_frames)
64
- log.info("Data conversion completed.")
50
+ log().debug(f"Writing data for {agent_name}...")
51
+ output_writer.write_to_files(agent_name, data_frames)
52
+
53
+ if config[Options.INPUT_RECOVERY]:
54
+ log().info("Recovering inputs...")
55
+ timeseries, scenario = input_dao.recover_inputs()
56
+ series_writer = CsvWriter(Path(config[Options.OUTPUT], "./recovered"), Path("./"), False)
57
+ series_writer.write_time_series_to_disk(timeseries)
58
+ data_to_yaml_file(scenario.to_dict(), Path(config[Options.OUTPUT], "./recovered/scenario.yaml"))
59
+
60
+ log().info("Data conversion completed.")
65
61
  except MemoryError:
66
62
  log_and_raise_critical(ERR_MEMORY_SEVERE if Options.MEMORY_SAVING else ERR_MEMORY_ERROR)
67
63
 
68
64
  file_stream.close()
69
65
  if not agent_type_log.has_any_agent_type():
70
- log.error("Provided file did not contain any output data.")
66
+ log().error("Provided file did not contain any output data.")
71
67
 
72
68
 
73
69
  if __name__ == "__main__":
74
- input_file, run_config = arg_handling_convert_results(sys.argv[1:], DEFAULT_CONFIG)
75
- run(input_file, run_config)
70
+ run_config = handle_args(sys.argv[1:])
71
+ run(run_config)
@@ -0,0 +1,3 @@
1
+ SPDX-FileCopyrightText: 2024 German Aerospace Center <fame@dlr.de>
2
+
3
+ SPDX-License-Identifier: Apache-2.0
@@ -1,37 +1,34 @@
1
1
  #!/usr/bin/env python
2
- import logging as log
3
2
  import sys
4
3
  from pathlib import Path
5
- from typing import Union
6
4
 
7
- from fameio.source.cli import Options, arg_handling_make_config, update_default_config
5
+ from fameio.source.cli.make_config import handle_args, CLI_DEFAULTS as DEFAULT_CONFIG
6
+ from fameio.source.cli.options import Options
7
+ from fameio.source.cli.parser import update_default_config
8
8
  from fameio.source.loader import load_yaml, check_for_yaml_file_type
9
- from fameio.source.logs import set_up_logger
9
+ from fameio.source.logs import fameio_logger, log
10
10
  from fameio.source.scenario import Scenario
11
11
  from fameio.source.validator import SchemaValidator
12
12
  from fameio.source.writer import ProtoWriter
13
13
 
14
- DEFAULT_CONFIG = {
15
- Options.LOG_LEVEL: "info",
16
- Options.LOG_FILE: None,
17
- Options.OUTPUT: Path("config.pb"),
18
- }
19
14
 
20
-
21
- def run(file: Union[str, Path], config: dict = None) -> None:
15
+ def run(config: dict = None) -> None:
22
16
  """Executes the main workflow for the building of a FAME configuration file"""
23
17
  config = update_default_config(config, DEFAULT_CONFIG)
24
- set_up_logger(level_name=config[Options.LOG_LEVEL], file_name=config[Options.LOG_FILE])
18
+ fameio_logger(log_level_name=config[Options.LOG_LEVEL], file_name=config[Options.LOG_FILE])
25
19
 
20
+ file = config[Options.FILE]
26
21
  check_for_yaml_file_type(Path(file))
27
22
  scenario = Scenario.from_dict(load_yaml(Path(file)))
28
- SchemaValidator.ensure_is_valid_scenario(scenario)
29
- writer = ProtoWriter(config[Options.OUTPUT])
23
+ SchemaValidator.check_agents_have_contracts(scenario)
24
+
25
+ timeseries_manager = SchemaValidator.validate_scenario_and_timeseries(scenario)
26
+ writer = ProtoWriter(config[Options.OUTPUT], timeseries_manager)
30
27
  writer.write_validated_scenario(scenario)
31
28
 
32
- log.info("Configuration completed.")
29
+ log().info("Configuration completed.")
33
30
 
34
31
 
35
32
  if __name__ == "__main__":
36
- input_file, run_config = arg_handling_make_config(sys.argv[1:], DEFAULT_CONFIG)
37
- run(input_file, run_config)
33
+ run_config = handle_args(sys.argv[1:])
34
+ run(run_config)
@@ -0,0 +1,3 @@
1
+ SPDX-FileCopyrightText: 2024 German Aerospace Center <fame@dlr.de>
2
+
3
+ SPDX-License-Identifier: Apache-2.0
@@ -0,0 +1,3 @@
1
+ # SPDX-FileCopyrightText: 2024 German Aerospace Center <fame@dlr.de>
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
@@ -0,0 +1,84 @@
1
+ # SPDX-FileCopyrightText: 2024 German Aerospace Center <fame@dlr.de>
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
4
+ import argparse
5
+ from typing import List, Dict, Any, Optional
6
+
7
+ from fameio.source.cli.options import Options, ResolveOptions, TimeOptions
8
+ from fameio.source.cli.parser import (
9
+ add_file_argument,
10
+ add_log_level_argument,
11
+ add_logfile_argument,
12
+ add_output_argument,
13
+ add_select_agents_argument,
14
+ add_single_export_argument,
15
+ add_memory_saving_argument,
16
+ add_resolve_complex_argument,
17
+ add_time_argument,
18
+ add_merge_time_parser,
19
+ add_inputs_recovery_argument,
20
+ map_namespace_to_options_dict,
21
+ )
22
+
23
+ CLI_DEFAULTS = {
24
+ Options.FILE: None,
25
+ Options.LOG_LEVEL: "WARN",
26
+ Options.LOG_FILE: None,
27
+ Options.AGENT_LIST: None,
28
+ Options.OUTPUT: None,
29
+ Options.SINGLE_AGENT_EXPORT: False,
30
+ Options.MEMORY_SAVING: False,
31
+ Options.RESOLVE_COMPLEX_FIELD: ResolveOptions.SPLIT,
32
+ Options.TIME: TimeOptions.UTC,
33
+ Options.TIME_MERGING: {},
34
+ Options.INPUT_RECOVERY: False,
35
+ }
36
+
37
+ _INFILE_PATH_HELP = "Provide path to protobuf file"
38
+ _OUTFILE_PATH_HELP = "Provide path to folder to store output .csv files"
39
+
40
+
41
+ def handle_args(args: List[str], defaults: Optional[Dict[Options, Any]] = None) -> Dict[Options, Any]:
42
+ """
43
+ Handles command line arguments and returns `run_config` for convert_results script
44
+
45
+ Args:
46
+ args: list of (command line) arguments, e.g., ['-f', 'my_file']; arg values take precedence over defaults
47
+ defaults: optional default values used for unspecified parameters; missing defaults are replaced by CLI defaults
48
+
49
+ Returns:
50
+ final configuration compiled from (given) `defaults` and given `args`
51
+ """
52
+ parser = _prepare_parser(defaults)
53
+ parsed = parser.parse_args(args)
54
+ return map_namespace_to_options_dict(parsed)
55
+
56
+
57
+ def _prepare_parser(defaults: Optional[Dict[Options, Any]]) -> argparse.ArgumentParser:
58
+ """
59
+ Creates a parser with given defaults to handle `make_config` configuration arguments
60
+
61
+ Returns:
62
+ new parser using given defaults for its arguments; if a default is not specified, hard-coded defaults are used
63
+ """
64
+ defaults = defaults if (defaults is not None) else {}
65
+ parser = argparse.ArgumentParser()
66
+
67
+ add_file_argument(parser, _get_default(defaults, Options.FILE), _INFILE_PATH_HELP)
68
+ add_log_level_argument(parser, _get_default(defaults, Options.LOG_LEVEL))
69
+ add_logfile_argument(parser, _get_default(defaults, Options.LOG_FILE))
70
+ add_output_argument(parser, _get_default(defaults, Options.OUTPUT), _OUTFILE_PATH_HELP)
71
+ add_select_agents_argument(parser, _get_default(defaults, Options.AGENT_LIST))
72
+ add_single_export_argument(parser, _get_default(defaults, Options.SINGLE_AGENT_EXPORT))
73
+ add_memory_saving_argument(parser, _get_default(defaults, Options.MEMORY_SAVING))
74
+ add_resolve_complex_argument(parser, _get_default(defaults, Options.RESOLVE_COMPLEX_FIELD))
75
+ add_time_argument(parser, _get_default(defaults, Options.TIME))
76
+ add_merge_time_parser(parser)
77
+ add_inputs_recovery_argument(parser, _get_default(defaults, Options.INPUT_RECOVERY))
78
+
79
+ return parser
80
+
81
+
82
+ def _get_default(defaults: dict, option: Options) -> Any:
83
+ """Returns default for given `option` or its cli default"""
84
+ return defaults.get(option, CLI_DEFAULTS[option])
@@ -0,0 +1,62 @@
1
+ # SPDX-FileCopyrightText: 2024 German Aerospace Center <fame@dlr.de>
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
4
+ import argparse
5
+ from pathlib import Path
6
+ from typing import List, Dict, Any, Optional
7
+
8
+ from fameio.source.cli.options import Options
9
+ from fameio.source.cli.parser import (
10
+ add_file_argument,
11
+ add_log_level_argument,
12
+ add_logfile_argument,
13
+ add_output_argument,
14
+ map_namespace_to_options_dict,
15
+ )
16
+
17
+ CLI_DEFAULTS = {
18
+ Options.FILE: None,
19
+ Options.LOG_LEVEL: "WARN",
20
+ Options.LOG_FILE: None,
21
+ Options.OUTPUT: Path("config.pb"),
22
+ }
23
+
24
+ _INFILE_PATH_HELP = "provide path to configuration file"
25
+ _OUTFILE_PATH_HELP = "provide file-path for the file to generate"
26
+
27
+
28
+ def handle_args(args: List[str], defaults: Optional[Dict[Options, Any]] = None) -> Dict[Options, Any]:
29
+ """
30
+ Converts given `arguments` and returns a configuration for the make_config script
31
+
32
+ Args:
33
+ args: list of (command line) arguments, e.g., ['-f', 'my_file']; arg values take precedence over defaults
34
+ defaults: optional default values used for unspecified parameters; missing defaults are replaced by CLI defaults
35
+
36
+ Returns:
37
+ final configuration compiled from (given) `defaults` and given `args`
38
+ """
39
+ parser = _prepare_parser(defaults)
40
+ parsed = parser.parse_args(args)
41
+ return map_namespace_to_options_dict(parsed)
42
+
43
+
44
+ def _prepare_parser(defaults: Optional[Dict[Options, Any]]) -> argparse.ArgumentParser:
45
+ """
46
+ Creates a parser with given defaults to handle `make_config` configuration arguments
47
+
48
+ Returns:
49
+ new parser using given defaults for its arguments; if a default is not specified, hard-coded defaults are used
50
+ """
51
+ defaults = defaults if (defaults is not None) else {}
52
+ parser = argparse.ArgumentParser()
53
+ add_file_argument(parser, _get_default(defaults, Options.FILE), _INFILE_PATH_HELP)
54
+ add_log_level_argument(parser, _get_default(defaults, Options.LOG_LEVEL))
55
+ add_logfile_argument(parser, _get_default(defaults, Options.LOG_FILE))
56
+ add_output_argument(parser, _get_default(defaults, Options.OUTPUT), _OUTFILE_PATH_HELP)
57
+ return parser
58
+
59
+
60
+ def _get_default(defaults: dict, option: Options) -> Any:
61
+ """Returns default for given `option` or, if missing, its cli default"""
62
+ return defaults.get(option, CLI_DEFAULTS[option])
@@ -0,0 +1,58 @@
1
+ # SPDX-FileCopyrightText: 2024 German Aerospace Center <fame@dlr.de>
2
+ #
3
+ # SPDX-License-Identifier: Apache-2.0
4
+ import argparse
5
+ from enum import Enum, auto
6
+
7
+
8
+ class ParsableEnum(Enum):
9
+ """Extend this to create an enum that can be parsed with argparse"""
10
+
11
+ @classmethod
12
+ def instantiate(cls, name: str) -> Enum:
13
+ try:
14
+ return cls[name]
15
+ except KeyError:
16
+ raise argparse.ArgumentTypeError(f"'{name}' is not a valid option")
17
+
18
+ def __str__(self):
19
+ return self.name
20
+
21
+
22
+ class Options(Enum):
23
+ """Specifies command line configuration options"""
24
+
25
+ FILE = auto()
26
+ LOG_LEVEL = auto()
27
+ LOG_FILE = auto()
28
+ OUTPUT = auto()
29
+ AGENT_LIST = auto()
30
+ SINGLE_AGENT_EXPORT = auto()
31
+ MEMORY_SAVING = auto()
32
+ RESOLVE_COMPLEX_FIELD = auto()
33
+ TIME = auto()
34
+ TIME_MERGING = auto()
35
+ INPUT_RECOVERY = auto()
36
+
37
+
38
+ class TimeOptions(ParsableEnum, Enum):
39
+ """Specifies options for conversion of time in output"""
40
+
41
+ INT = auto()
42
+ UTC = auto()
43
+ FAME = auto()
44
+
45
+
46
+ class ResolveOptions(ParsableEnum, Enum):
47
+ """Specifies options for resolving complex fields in output files"""
48
+
49
+ IGNORE = auto()
50
+ SPLIT = auto()
51
+
52
+
53
+ class MergingOptions(Enum):
54
+ """Specifies options for merging TimeSteps"""
55
+
56
+ FOCAL_POINT = auto()
57
+ STEPS_BEFORE = auto()
58
+ STEPS_AFTER = auto()