Conversation
Currently only supports string and integer attributes,
but should be easy to extend. Only implemented in the NetCDF4 writer,
and other writers will just ignore the attributes.
* DataFile now has setAttribute() function, which adds
string or integer attributes to maps. This should really be better
integrated with the rest of the variable's data (in VarStr), but
that would require more changes. Example:
dump.setAttribute("Ve", "location", "CELL_YLOW");
or for the integer:
dump.setAttribute("Ve", "location", (int) Ve.getLocation());
* Added a python function boutdata.attributes which returns a
dictionary of values
from boutdata import attributes
attributes("Ve")
-> {'location':'CELL_YLOW'}
This only works with the NetCDF4 library; other libraries or
formats (HDF5) will return either None or empty dictionary.
Runs a simple example, which creates attributes for a Field2D and Field3D variable. Loads the attributes into Python and tests that they are as expected.
Documents how to add attributes to the output file, and how to read them into python.
ZedThree
approved these changes
Dec 8, 2017
bendudson
added a commit
that referenced
this pull request
May 1, 2018
The datafile class now sets an attribute "cell_location" for each 2D and 3D field (and vector component). The attribute is a string which is the same as the enum name e.g. CELL_CENTRE, CELL_YLOW etc. To do this, a const map has been added to bout_types.hxx, together with an inline function CELL_LOC_STRING(). This replaces `strLocation` in interpolation.hxx, which used a switch. Together with PR #770 (saving attributes in NetCDF) and #996 (reads attributes into a BoutArray class), this now works (in test-io): ``` > f3d = collect("f3d") > f3d.attributes {'cell_location': 'CELL_CENTRE', 'bout_type': 'Field3D'} ``` Added some checks to `test-io` to check that the cell_location attribute is read correctly.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently only supports string and integer attributes, but should be easy to extend. Only implemented in the NetCDF4 writer, and other writers will just ignore the attributes. Part solution to issue #736
Includes an integrated test and some documentation.
DataFile now has setAttribute() function, which adds string or integer attributes to maps. This should really be better integrated with the rest of the variable's data (in VarStr), but that would require more changes. Example:
dump.setAttribute("Ve", "location", "CELL_YLOW");
or for the integer:
dump.setAttribute("Ve", "location", (int) Ve.getLocation());
Added a python function boutdata.attributes which returns a dictionary of values
from boutdata import attributes
attributes("Ve")
-> {'location':'CELL_YLOW'}
This only works with the NetCDF4 library; other libraries or formats (HDF5) will return either None or empty dictionary.