dctools.utilities.format_converter.convert_format1_to_format2
- dctools.utilities.format_converter.convert_format1_to_format2(format1_results, metric_name=None)
Convert Format1 results to Format2.
- Parameters:
format1_results (Dict[str, List[float]] | Dict[str, Dict[str, float]]) – Format1 Results Simple format: {‘Variable name’: [value], …} Nested format: {‘metric_name’: {‘Variable name’: value, …}, …}
metric_name (str, optional) – Metric name (e.g., ‘rmse’, ‘mae’) Required for simple format, optional for nested format
- Returns:
- Format2 Results
Format: [{‘Metric’: ‘metric_name’, ‘Variable’: ‘variable_name’, ‘Value’: value}, …]
- Return type:
List[Dict[str, Union[str, float]]]
Examples
>>> # Simple format >>> format1 = { ... 'Surface salinity': [0.7800133290485501], ... '50m salinity': [0.36502441182776185] ... } >>> convert_format1_to_format2(format1, 'rmse') [ {'Metric': 'rmse', 'Variable': 'Surface salinity', 'Value': 0.7800133290485501}, {'Metric': 'rmse', 'Variable': '50m salinity', 'Value': 0.36502441182776185} ]
>>> # Nested format >>> format1_nested = { ... 'rmsd': { ... 'Surface salinity': 0.7957517181075711, ... '50m salinity': 0.35141580091326013 ... } ... } >>> convert_format1_to_format2(format1_nested) [ {'Metric': 'rmsd', 'Variable': 'Surface salinity', 'Value': 0.7957517181075711}, {'Metric': 'rmsd', 'Variable': '50m salinity', 'Value': 0.35141580091326013} ]