Closed AOstenfeld closed 4 years ago
Just for reference I've been testing this using the spring.py file in the block-on-spring repo. Add the "interval" keyword to the "Diagnostics" dictionary like so:
"Diagnostics": {
"directory": "output_leapfrog/",
"output_type": "csv",
"clock": {"filename": "time.csv"},
"interval": 2,
"BlockDiagnostic": [
{'component': 'momentum', 'filename': 'block_p.csv'},
{'component': 'position', 'filename': 'block_x.csv'}
]
}
Alright, I think this is ready for review.
@AOstenfeld sorry to spring this on you, but I've made some changes in main
that affect this PR.
I’ve created a new class, IntervalHandler
, which lets you specify a function to call, and an interval at which to call it. This separates out the logic for checking the time step, and should make the code easier to write/maintain. As an example of how to use this class, you can look at my HistoryDiagnostic
class.
For the issue that you are working on for this, I’d like to see you use the new IntervalHandler
class to extend the HistoryDiagnostic
class.
write_interval
IntervalHandler
whose action is to write the output to file. This will require creating a new method in the HistoryDiagnostic
class which writes the data. Something like:
self._write_data():
self._traces.squeeze().to_netcdf(self._filename, 'w’)
diagnose
method to also call perform_action
on the new interval handlerI'm moving this to another PR so that the diagnostics.py file is up to date.
Pull Request
Description
Adds ability to write data to the output files at given time intervals while the program is running.
This pull request addresses #145
Checklist
The following items have been checked for this PR:
pylint
,flake8
, or similar)