Skip to content

Commit

Permalink
fusion.json: Fix metadata parsing (#199)
Browse files Browse the repository at this point in the history
* Fix metadata parsing & add test.

* docs
  • Loading branch information
PeterKraus authored Nov 11, 2024
1 parent 0b1f8d4 commit cc988fd
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 22 deletions.
11 changes: 6 additions & 5 deletions docs/source/version.5_2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ Developed in the `ConCat Lab <https://tu.berlin/en/concat>`_ at Technische Unive

New features in ``yadg-5.2`` are:

- Implemented support for merged/appended files in :mod:`~yadg.extractors.eclab.mpr`. Test files taken from the data available at https://zenodo.org/doi/10.5281/zenodo.12165685. Thanks to Arnd Koeppe from KIT for bringing the issue up.
- Implemented support for the Modular Potentio technique in :mod:`~yadg.extractors.eclab.mpr`. Thanks to Graham Kimbell and Clea Burgel from Empa for providing test data.
- Implemented support for the Constant Current and Constant Voltage techniques in :mod:`~yadg.extractors.eclab.mpr`. Thanks to Carla Terboven from HZB for providing test data.
- Implemented support for merged/appended files in :mod:`yadg.extractors.eclab.mpr`. Test files taken from the data available at https://zenodo.org/doi/10.5281/zenodo.12165685. Thanks to Arnd Koeppe from KIT for bringing the issue up.
- Implemented support for the Modular Potentio technique in :mod:`yadg.extractors.eclab.mpr`. Thanks to Graham Kimbell and Clea Burgel from Empa for providing test data.
- Implemented support for the Constant Current and Constant Voltage techniques in :mod:`yadg.extractors.eclab.mpr`. Thanks to Carla Terboven from HZB for providing test data.

Other changes in ``yadg-5.2`` are:

Bug fixes in ``yadg-5.2`` include:

- Increased supported I-range values in :mod:`~yadg.extractors.eclab` up to 193.
- Implemented support for a 33-parameter GCPL file in :mod:`~yadg.extractors.eclab.mpr`.
- Increased supported I-range values in :mod:`yadg.extractors.eclab` up to 193.
- Implemented support for a 33-parameter GCPL file in :mod:`yadg.extractors.eclab.mpr`.
- Fixed parsing of optional metadata in :mod:`yadg.extractors.fusion.json`. Thanks to Emiliano Dal Molin for finding the bug and providing test data.
24 changes: 7 additions & 17 deletions src/yadg/extractors/fusion/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,13 @@


def chromdata(jsdata: dict, uts: float) -> Dataset:
metadata = {
"method": jsdata.get("methodName", "n/a"),
"version": jsdata.get("softwareVersion", {}).get("version", None),
"datafile": jsdata.get("sequence", {}).get("location", None),
}

sampleid = jsdata.get("annotations", {}).get("name", None)
if sampleid is not None:
metadata["sampleid"] = sampleid
metadata = {}
metadata["method"] = jsdata["methodName"]
metadata["version"] = jsdata["softwareVersion"]["version"]
if jsdata.get("sequence") is not None:
metadata["datafile"] = jsdata["sequence"].get("location")
if jsdata.get("annotations") is not None:
metadata["sampleid"] = jsdata["annotations"].get("name", None)

units = {
"height": None,
Expand Down Expand Up @@ -138,13 +136,6 @@ def chromdata(jsdata: dict, uts: float) -> Dataset:


def chromtrace(jsdata: dict, uts: float) -> DataTree:
metadata = {
"method": jsdata.get("methodName", "n/a"),
"sampleid": jsdata.get("annotations", {}).get("name", None),
"version": jsdata.get("softwareVersion", {}).get("version", None),
"datafile": jsdata.get("sequence", {}).get("location", None),
}

# sort detector keys to ensure alphabetic order for ID matching
traces = sorted(jsdata["detectors"].keys())
vals = {}
Expand Down Expand Up @@ -184,7 +175,6 @@ def chromtrace(jsdata: dict, uts: float) -> DataTree:
vals[detname] = fvals

dt = DataTree.from_dict(vals)
dt.attrs = dict(original_metadata=metadata)
return dt


Expand Down
1 change: 1 addition & 0 deletions tests/test_x_fusion_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"15p-Cu-10mA-01 - Jun 08 2022, 16;23.fusion-data",
"AgPTFE28_100mA_NaS_01 - Aug 13 2021, 17;56.fusion-data",
"AgPTFE28_100mA_NaS_01 - Aug 13 2021, 18;18.fusion-data",
"issue_198.fusion-data",
],
)
def test_fusion_json(infile, datadir):
Expand Down
1 change: 1 addition & 0 deletions tests/test_x_fusion_json/issue_198.fusion-data

Large diffs are not rendered by default.

Binary file not shown.

0 comments on commit cc988fd

Please sign in to comment.