dgbowl/yadg

.mpr extractor KeyError 22

Closed this issue · 3 comments

This mpr file throws the error below when using yadg.extractors.extract, found by Clea Burgel

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
Cell In[2], line 2
      1 cell_path =r"G:\Limit\Buergel Clea\Code\20240926_clbu_cell203_Lithiated_Li2Si_SitoSEtoVGCF6to4to1_25C_DCPol_vs_Eoc_1p1Nm_C01.mpr"
----> 2 df, metadata = convert_mpr_to_df(cell_path)
      4 plt.plot(df['time'], df['Ewe'])
      5 plt.xlabel('time [s]')

Cell In[1], line 18
      8 def convert_mpr_to_df(mpr_file: str) -> tuple[pd.DataFrame, dict]:
      9     """ Convert an EC-Lab MPR file to a pandas DataFrame.
     10     
     11     Args:
   (...)
     16         dict: Metadata extracted from the MPR file.
     17     """
---> 18     data = yadg.extractors.extract('eclab.mpr', mpr_file)
     20     # Convert DataTree to pandas DataFrame
     21     df = data.ds.to_dataframe().reset_index()

File c:\Users\clbu\AppData\Local\Programs\Python\Python312\Lib\site-packages\yadg\extractors\__init__.py:54, in extract(filetype, path, timezone, encoding, locale, **kwargs)

     20 """
     21 Extract data and metadata from a path using the supplied filetype.
     22 
   (...)
     43 
     44 """
     45 extractor = ExtractorFactory(
     46     extractor={
     47         "filetype": filetype,
   (...)
     51     }
     52 ).extractor
---> 54 return extract_from_path(path, extractor)

File c:\Users\clbu\AppData\Local\Programs\Python\Python312\Lib\site-packages\yadg\extractors\__init__.py:75, in extract_from_path(path, extractor)
     72 func = getattr(m, "extract")
     74 # Func should always return a datatree.DataTree
---> 75 ret: DataTree = func(fn=path, **vars(extractor))
     76 jsonize_orig_meta(ret)
     78 ret.attrs.update(
     79     {
     80         "yadg_provenance": "yadg extract",
   (...)
     84     }
     85 )

File c:\Users\clbu\AppData\Local\Programs\Python\Python312\Lib\site-packages\yadg\extractors\eclab\mpr.py:610, in extract(fn, timezone, **kwargs)
    608     assert mpr_file.read(len(file_magic)) == file_magic, "invalid file magic"
    609     mpr = mpr_file.read()
--> 610 settings, params, ds, log, loop = process_modules(mpr)
    611 assert settings is not None, "no settings module"
    612 assert ds is not None, "no data module"

File c:\Users\clbu\AppData\Local\Programs\Python\Python312\Lib\site-packages\yadg\extractors\eclab\mpr.py:570, in process_modules(contents)
    568 module_data = module[mhd.itemsize :]
    569 if name == "VMP Set":
--> 570     settings, params = process_settings(module_data, minver)
    571     Eranges = []
    572     Iranges = []

File c:\Users\clbu\AppData\Local\Programs\Python\Python312\Lib\site-packages\yadg\extractors\eclab\mpr.py:260, in process_settings(data, minver)
    258 settings = {}
    259 # First parse the settings right at the top of the data block.
--> 260 technique, params_dtypes = technique_params_dtypes[data[0x0000]]
    261 logger.debug("Found technique '%s'.", technique)
    262 settings["technique"] = technique

KeyError: 22

Fixed in #186. @g-kimbell, how urgently do you need a new release? If it can wait, I'd like to fix some of the other outstanding issues before minting a new one.

Fixed in #186. @g-kimbell, how urgently do you need a new release? If it can wait, I'd like to fix some of the other outstanding issues before minting a new one.

Not urgent, Clea is just manually converting for now

Should be fixed in yadg-5.1.4.