1

I am trying to Structuring Data from Cell Cycler using BEEP(Battery Evaluation and Early Prediction) toolbox in python. The code is as follows:

import os
import json

import pandas as pd

from beep.structure import BEEPDatapath


class CyclerDatapath(BEEPDatapath):
    COLUMN_MAPPING = {
        "test_time (s)": "test_time",
        "steptime": "step_time",
        "stepix": "step_index",
        "cycle_index": "cycle_index",
        "current (a)": "current",
        "voltage (v)": "voltage",
        "charge_capacity (ah)": "charge_capacity",
        "discharge_capacity (ah)": "discharge_capacity",
        "charge_energy (wh)": "charge_energy",
        "discharge_energy (wh)": "discharge_energy",    
    }

    DATA_TYPES = {
        "test_time": "float64",
        "step_time": "float32",
        "step_index": "int32",
        "cycle_index": "int32",
        "current": "float32",
        "voltage": "float32",
        "charge_capacity": "float64",
        "discharge_capacity": "float64",
        "charge_energy": "float64",
        "discharge_energy": "float64",
    }
    @classmethod
    def from_file(cls, filename, metadata_path=None):

        data = pd.read_csv(filename)
        data.rename(columns=cls.COLUMN_MAPPING, inplace=True)
        print(1)
        
        
        for column, dtype in cls.DATA_TYPES.items():
            if column in data:
                if not data[column].isnull().values.any():
                    data[column] = data[column].astype(dtype)

        if metadata_path:
            print(1)
            with open(metadata_path, "r") as f:
                metadata = json.load(f)
        else:
            metadata = {}
        path = filename
 
        paths = {
           "raw": path,
           "metadata": path + "_metadata"
       }

        return cls(data, metadata, paths)
    
    
    from beep.structure import NewareDatapath


cycler_file = ("Trial_Writing.csv")

datapath = CyclerDatapath.from_file(cycler_file)

datapath.to_json_file("my_processed_neware_data.json")

I get an error as follows:

`ValueError: raw: 
  File "C:\base.py", line 181, in __init__
    raise ValueError(f"{path_ref}: '{path}' is not absolute! All paths must be absolute.")

I tried to debug that code and found that the code works fine till here:

  # Read in metadata from a separate json file, for example
            if metadata_path:
                print(1)
                with open(metadata_path, "r") as f:
                    metadata = json.load(f)

After this point i get the error.

Anyone with knowledge in BEEP library knows what I am going wrong?

Alt1139
  • 21
  • 1
  • 5
  • You're giving a relative path instead of an absolute path. The function you're using expects an absolute path. – Stef May 18 '22 at 12:32
  • You need to get that file's absolute path before you call that function. See this related question: [Find the current directory and file's directory](https://stackoverflow.com/questions/5137497/find-the-current-directory-and-files-directory) – Stef May 18 '22 at 12:34
  • Also, please edit your question to include the full error trace rather than just the last message in the error trace. i.e., not just `ValueError: raw: 'Trial_Writing.csv' is not absolute! All paths must be absolute.` but the whole `Traceback (most recent call last): File "code.py", line 12, in File "code.py", line 2, in myfunction File "code.py", line 7, in myclassmethod File "code.py", line 3, in myotherfunction ValueError: raw: 'Trial_Writing.csv' is not absolute! All paths must be absolute. ` – Stef May 18 '22 at 12:36

1 Answers1

0

As mentioned by others I had to add the specific directory of the file:

Had to change the code to this:

this_dir = os.path.dirname(os.path.abspath(__file__))
cycler_file = os.path.join(this_dir,("Trial_Writing.csv"))
Alt1139
  • 21
  • 1
  • 5