-
-
Notifications
You must be signed in to change notification settings - Fork 422
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
Model configuration output in HDF #1299
Model configuration output in HDF #1299
Conversation
Unit test moved to the config reader tests and the Configuration class is now subclassed to with ConfigWriterMixin, itself a subclass of HDFWriterMixin. get_properties has been overridden to obtain properties from configuration dict keys.
Config is now returned as a dict of dicts instead of a dict containing configurationnamespace objects. Test doesn't need the pytest fixture any more.
Test still fails, but the HDF contains configuration information in CGS units. Scalar output means that some entries are not well formatted. Pandas still cannot read the HDF.
Convert ConfigurationNameSpace to YAML and then dump to string instead? Turn config into string for comparison to the read-in HDF |
Rewrote ConfigWriterMixin, moved it to util.py to match PlasmaWriterMixin, added static method override for to_hdf_util to handle the string output, updated test to do string-to-string comparison
Codecov Report
@@ Coverage Diff @@
## master #1299 +/- ##
==========================================
+ Coverage 80.54% 81.57% +1.03%
==========================================
Files 41 46 +5
Lines 3423 3799 +376
==========================================
+ Hits 2757 3099 +342
- Misses 666 700 +34 Continue to review full report at Codecov.
|
tardis/io/util.py
Outdated
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
def quantity_representer(dumper, data): | |
""" | |
docu goes here | |
""" | |
return dumper.represent_data(str(data)) | |
def cns_representer(dumper, data): | |
""" | |
docu goes here | |
""" | |
return dumper.represent_dict(dict(data)) | |
yaml.add_representer(u.Quantity, quantity_representer) | |
yaml.add_representer(ConfigurationNameSpace, cns_representer) | |
yaml.add_representer(Configuration, cns_representer) |
|
Simplifies ConfigWriterMixin using YAML representers to read Quantities and Configuration objects
tardis_config_verysimple, validate=True, config_dirname="test" | ||
) | ||
expected.to_hdf(hdf_file_path) | ||
actual = pd.read_hdf(hdf_file_path, key="/config/config") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why config/config?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in next commit
* Added test for config -> HDF * Unit test moved and HDFMixin subclassed Unit test moved to the config reader tests and the Configuration class is now subclassed to with ConfigWriterMixin, itself a subclass of HDFWriterMixin. get_properties has been overridden to obtain properties from configuration dict keys. * Improved test and config reading Config is now returned as a dict of dicts instead of a dict containing configurationnamespace objects. Test doesn't need the pytest fixture any more. * Mostly valid HDF is now written out Test still fails, but the HDF contains configuration information in CGS units. Scalar output means that some entries are not well formatted. Pandas still cannot read the HDF. * Test passes, config written to string Rewrote ConfigWriterMixin, moved it to util.py to match PlasmaWriterMixin, added static method override for to_hdf_util to handle the string output, updated test to do string-to-string comparison * Cleanup of unused imports * Rewrite to use yaml representer Simplifies ConfigWriterMixin using YAML representers to read Quantities and Configuration objects * Moved the config to the simulation part of HDF
Description
Unit test added for a
to_hdf
method of the configuration namespace. Successfully converts a configuration to a YAML-formatted string.Motivation and Context
Required to output simulation input parameters as part of the HDF in the standard HDF output from simulations.
How Has This Been Tested?
Unit test added and fails
Screenshots (if appropriate):
Types of changes
Checklist: