Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Export final calibration result as a record #2

Open
FWuellhorst opened this issue Aug 13, 2021 · 1 comment
Open

Export final calibration result as a record #2

FWuellhorst opened this issue Aug 13, 2021 · 1 comment

Comments

@FWuellhorst
Copy link
Collaborator

To make the use of the final calibration result easy, an export to a record should be implemented (as discussed).

In addition to the final values, the most relevant info about the calibration should also be in that record, e.g.:

Name: MODELNAME_Calibrated_DATEOFCALIBRATION.mo
Content:

record TestModel_Calibrated_20191204 "Final values of AixCaliBuHa-Calibration of Model AixCalTest.TestModel: 
  NRMSE = 0.002; Used Method: scipy_minimize - COBYLA"
  parameter Real V=0.02 "Calibrated in bounds min=%s, max=%s";
  parameter Real m_flow_nominal=0.02 "Calibrated in bounds min=%s, max=%s";
   
  annotation (Icon(coordinateSystem(preserveAspectRatio=false)), Diagram(
        coordinateSystem(preserveAspectRatio=false)));
end TestModel_Calibrated_20191204;
@FWuellhorst
Copy link
Collaborator Author

Related to this, it would make sense to also return the tuned parameters directly (similarly to how the final results of the sensitivity analysis are returned) or export the resulting parameters additionally in a format that can be easily read in within python (e.g. JSON).
For example in the following fashion at the end of the method def save_calibration_result(self, best_iterate, model_name, **kwargs) :

        # Save relevant results in JSON
        import json
        results_file_path = os.path.join(os.getcwd(), "calibration_results.json")
        try:
            with open(results_file_path, 'r') as json_file:
                parameter_values = json.load(json_file)
        except:
            parameter_values = {}
        new_parameter_values = dict(zip(list(self.tuner_paras.get_names()), best_iterate["Parameters"]))
        updated_parameter_values = {**parameter_values, **new_parameter_values}
        with open(results_file_path, 'w') as json_file:
            json.dump(updated_parameter_values, json_file , indent=4) 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant