示例#1
0
def test_merge_auto_from_list():
    from cellpy import cellreader

    cdi1 = cellreader.CellpyData()
    cdi2 = cellreader.CellpyData()
    cdi3 = cellreader.CellpyData()

    f1 = fdv.res_file_path
    f2 = fdv.res_file_path2
    assert os.path.isfile(f1)
    assert os.path.isfile(f2)

    files = [f1, f2]
    cdi1.from_raw(f1)
    cdi2.from_raw(f2)
    cdi3.from_raw(files)

    len_first = len(cdi1.cells)
    table_first = cdi1.cells[0].raw.describe()
    count_first = table_first.loc["count", "data_point"]

    len_second = len(cdi2.cells)
    table_second = cdi2.cells[0].raw.describe()
    count_second = table_second.loc["count", "data_point"]

    len_all = len(cdi3.cells)
    table_all = cdi3.cells[0].raw.describe()
    count_all = table_all.loc["count", "data_point"]

    assert len_first == 1
    assert len_second == 1
    assert len_all == 1

    assert pytest.approx(count_all, 0.001) == (count_first + count_second)
示例#2
0
def dataset():
    from cellpy import cellreader
    a = cellreader.CellpyData()
    a.from_raw(fdv.res_file_path)
    a.set_mass(1.0)
    a.make_summary(find_ocv=False, find_ir=True, find_end_voltage=True)
    a.save(fdv.cellpy_file_path)

    b = cellreader.CellpyData()
    b.load(fdv.cellpy_file_path)
    return b
示例#3
0
def test_cellpyfile_roundtrip():
    from cellpy import cellreader
    cdi = cellreader.CellpyData()

    # create a cellpy file from the res-file
    cdi.from_raw(fdv.res_file_path)
    cdi.set_mass(1.0)
    cdi.make_summary(find_ocv=False, find_ir=True, find_end_voltage=True)
    cdi.save(fdv.cellpy_file_path)

    # load the cellpy file
    cdi = cellreader.CellpyData()
    cdi.load(fdv.cellpy_file_path)
    cdi.make_step_table()
    cdi.make_summary(find_ocv=False, find_ir=True, find_end_voltage=True)
示例#4
0
def check_silicon_2():
    log.setup_logging(default_level=logging.INFO)
    my_data = cellreader.CellpyData()
    filename = "../../../testdata/hdf5/20160805_test001_45_cc.h5"
    assert os.path.isfile(filename)
    my_data.load(filename)
    my_data.set_mass(0.1)
    cha, volt = my_data.get_ccap(2)
    v, dq = ica.dqdv(volt, cha)

    # log.setup_logging(default_level=logging.DEBUG)
    print("* creating a silicon peak ensemble:")
    silicon = Silicon(shift=-0.1, max_point=dq.max(), sigma_p1=0.06)
    print(f"hint: {silicon.peaks.param_hints['Si02sigma']}\n"
          f"val: {silicon.params['Si02sigma']}")

    print("Setting crystalline")
    silicon.crystalline = True
    print("Is jitter?", end=" ")
    print(silicon.jitter)
    print(silicon)

    res1 = silicon.fit(-dq, x=v)
    print(silicon)
    print(res1.fit_report())
示例#5
0
def missing_stats_file():
    d = cellreader.CellpyData()
    raw_file_loader = d.loader
    test = raw_file_loader(new_arbin_file)
    d.cells.append(test[0])
    d.set_mass(new_arbin_mass)
    d.make_summary(use_cellpy_stat_file=False)
示例#6
0
def check_backprop():
    print("Checking back prop")
    log.setup_logging(default_level=logging.INFO)
    my_data = cellreader.CellpyData()
    filename = "../../../testdata/hdf5/20160805_test001_45_cc.h5"
    assert os.path.isfile(filename)
    my_data.load(filename)
    my_data.set_mass(0.1)
    cha, volt = my_data.get_ccap(2)
    v, dq = ica.dqdv(volt, cha)

    # log.setup_logging(default_level=logging.DEBUG)
    print("* creating a silicon peak ensemble:")
    silicon = Silicon(shift=-0.1, max_point=dq.max(), sigma_p1=0.06)
    print(silicon)

    print("- peak values -")

    print(f"val: {silicon.params['Si01sigma']}")  # sigma_p1
    print(f"val: {silicon.params['Si01center']}")  # center - b

    print("- setting some new values -")

    silicon.set_param("Si01center", value=0.18)
    print(f"val: {silicon.params['Si01sigma']}")
    print(f"val: {silicon.params['Si01center']}")

    silicon._back_propagation_from_params()
    new_shift = silicon.shift
    new_max_point = silicon.max_point
    new_sigma_p1 = silicon.sigma_p1

    print("- calculated back prop gives the following updated values")
    print(silicon)

    print("- setting the values to a new object")
    another_silicon = Silicon(
        shift=new_shift,
        max_point=new_max_point,
        sigma_p1=new_sigma_p1,
        compress=1.0,
        expand=1.0,
    )
    print(another_silicon)
    print(f"val: {another_silicon.params['Si01sigma']}")
    print(f"val: {another_silicon.params['Si01center']}")
示例#7
0
def create_cellpyfile_in_example_dir(force=False):
    print(79 * "=")
    print("  Create cellpy-file in example folder")
    print(79 * "-")
    from cellpy import cellreader
    if os.path.isfile(test_cellpy_file_full):
        print("cellpy-file exists")
        print(test_cellpy_file_full)
    else:
        print("cellpy-file does not exist")
        print("creating")
        print(test_cellpy_file_full)
        force = True
    if force:
        d = cellreader.CellpyData()
        d.loadcell(test_res_file_full)
        d.make_summary(find_ir=True)
        d.make_step_table()
        d.save(test_cellpy_file_full)
    print(79 * "=")
示例#8
0
def time_routine():
    d = cellreader.CellpyData()
    # size pr chunk used by pandas when loading:
    prms.Instruments.Arbin.chunk_size = 10000
    # stops loading when reaching this:
    prms.Instruments.Arbin.max_chunks = 1
    t1 = time.time()

    load_it(d)
    # set new current chunk
    # append_to_it(d)

    t2 = time.time()

    # d.make_step_table()
    # d.make_summary()
    # info(d)

    print("------------------finished------------------")
    report_time(t1, t2)
示例#9
0
def get_a_cell_to_play_with():
    from cellpy import cellreader
    # -------- defining overall path-names etc ----------
    current_file_path = os.path.dirname(os.path.realpath(__file__))
    print(current_file_path)
    relative_test_data_dir = "../../testdata/hdf5"
    test_data_dir = os.path.abspath(
        os.path.join(current_file_path, relative_test_data_dir))
    # test_data_dir_out = os.path.join(test_data_dir, "out")
    test_cellpy_file = "20160805_test001_45_cc.h5"
    test_cellpy_file_full = os.path.join(test_data_dir, test_cellpy_file)
    # mass = 0.078609164

    # ---------- loading test-data ----------------------
    cell = cellreader.CellpyData()
    cell.load(test_cellpy_file_full)
    list_of_cycles = cell.get_cycle_numbers()
    number_of_cycles = len(list_of_cycles)
    print("you have %i cycles" % number_of_cycles)
    #cell.save(test_cellpy_file_full)
    return cell
示例#10
0
def check_graphite():
    log.setup_logging(default_level=logging.INFO)
    my_data = cellreader.CellpyData()
    filename = "../../../testdata/hdf5/20160805_test001_45_cc.h5"
    assert os.path.isfile(filename)
    my_data.load(filename)
    my_data.set_mass(0.1)
    cha, volt = my_data.get_ccap(2)
    v, dq = ica.dqdv(volt, cha)

    # log.setup_logging(default_level=logging.DEBUG)
    print("* creating a silicon peak ensemble:")
    graphite = Graphite(shift=-0.1)

    print("Is jitter?", end=" ")
    print(graphite.jitter)
    print(graphite)

    res1 = graphite.fit(-dq, x=v)
    print(graphite)
    print(res1.fit_report())
示例#11
0
 def _load_cellpy_file(self, file_name):
     cellpy_data = cellreader.CellpyData()
     cellpy_data.load(file_name, self.parent_level)
     logging.info(f" <- {file_name}")
     return cellpy_data
示例#12
0
def cellpy_data_instance():
    from cellpy import cellreader

    return cellreader.CellpyData()
示例#13
0
def check_silicon():
    log.setup_logging(default_level=logging.INFO)
    my_data = cellreader.CellpyData()
    filename = "../../../testdata/hdf5/20160805_test001_45_cc.h5"
    assert os.path.isfile(filename)
    my_data.load(filename)
    my_data.set_mass(0.1)
    cha, volt = my_data.get_ccap(2)
    v, dq = ica.dqdv(volt, cha)

    # log.setup_logging(default_level=logging.DEBUG)
    print("* creating a silicon peak ensemble:")
    silicon = Silicon(shift=-0.1, max_point=dq.max(), sigma_p1=0.06)
    print(f"hint: {silicon.peaks.param_hints['Si02sigma']}\n"
          f"val: {silicon.params['Si02sigma']}")

    print("* syncing hints:")
    silicon.create_hints_from_parameters()
    print(f"hint: {silicon.peaks.param_hints['Si02sigma']}\n"
          f"val: {silicon.params['Si02sigma']}")

    print("* updating the Si02sigma parameter:")
    silicon.set_param("Si02sigma", minimum=0.02, vary=False)
    print(f"hint: {silicon.peaks.param_hints['Si02sigma']}\n"
          f"val: {silicon.params['Si02sigma']}")

    print("* reset peaks:")
    silicon.reset_peaks()
    print(f"hint: {silicon.peaks.param_hints['Si02sigma']}\n"
          f"val: {silicon.params['Si02sigma']}")

    print("WITH AUTO SYNC")
    print("* creating a silicon peak ensemble:")
    silicon = Silicon(shift=-0.1,
                      max_point=dq.max(),
                      sigma_p1=0.06,
                      sync_model_hints=True)
    print(f"hint: {silicon.peaks.param_hints['Si02sigma']}\n"
          f"val: {silicon.params['Si02sigma']}")

    print("* syncing hints:")
    silicon.create_hints_from_parameters()
    print(f"hint: {silicon.peaks.param_hints['Si02sigma']}\n"
          f"val: {silicon.params['Si02sigma']}")

    print("* updating the Si02sigma parameter:")
    silicon.set_param("Si02sigma", minimum=0.02, vary=False)
    print(f"hint: {silicon.peaks.param_hints['Si02sigma']}\n"
          f"val: {silicon.params['Si02sigma']}")

    print("* reset peaks:")
    silicon.reset_peaks()
    print(f"hint: {silicon.peaks.param_hints['Si02sigma']}\n"
          f"val: {silicon.params['Si02sigma']}")

    print()
    print(" Fitting ".center(80, "-"))
    silicon = Silicon(shift=-0.1, max_point=dq.max(), sigma_p1=0.06)
    print(silicon)
    res1 = silicon.fit(-dq, x=v)
    print(res1.fit_report())
    print()
    print("New meta params")
    print(silicon)

    print("Setting crystalline")
    silicon.crystalline = True
示例#14
0
def load_r_file(filename):
    c = cellreader.CellpyData()
    c.from_raw(filename)
    return c
示例#15
0
def check_backprop_composite():
    print("Checking back prop for composite ensamble")
    log.setup_logging(default_level=logging.INFO)
    my_data = cellreader.CellpyData()
    filename = "../../../testdata/hdf5/20160805_test001_45_cc.h5"
    assert os.path.isfile(filename)
    my_data.load(filename)
    my_data.set_mass(0.1)
    cha, volt = my_data.get_ccap(2)
    v, dq = ica.dqdv(volt, cha)

    # log.setup_logging(default_level=logging.DEBUG)
    print("* creating a silicon peak ensemble:")
    si_g_composite = CompositeEnsemble(
        Silicon(shift=-0.1, max_point=dq.max(), sigma_p1=0.06),
        Graphite(shift=-0.03))

    print(si_g_composite)

    print("peak values:")

    print(f"val: {si_g_composite.params['Si01sigma']}")  # sigma_p1
    print(f"val: {si_g_composite.params['Si01center']}")  # center - b
    print(f"val: {si_g_composite.params['G01center']}")  # center - graphite

    print("\nsetting some new values:")

    si_g_composite.set_param("Si01center", value=0.18)
    si_g_composite.set_param("G01center", value=0.14)
    print(f"val: {si_g_composite.params['Si01sigma']}")
    print(f"val: {si_g_composite.params['Si01center']}")
    print(f"val: {si_g_composite.params['G01center']}")  # center - graphite

    print("BACK PROPAGATION")
    si_g_composite.back_propagation()

    # select by order
    si_ensemble = si_g_composite.ensemble[0]
    g_ensemble = si_g_composite.ensemble[1]

    # select by name
    si_ensemble = si_g_composite.selector["Si"]
    g_ensemble = si_g_composite.selector["G"]

    si_new_shift = si_ensemble.shift
    si_new_max_point = si_ensemble.max_point
    si_new_sigma_p1 = si_ensemble.sigma_p1
    g_new_shift = g_ensemble.shift

    print("- calculated back prop gives the following updated values")
    print(si_g_composite)

    print("- setting the values to a new object")
    another_si_g_composite = CompositeEnsemble(
        Silicon(
            shift=si_new_shift,
            max_point=si_new_max_point,
            sigma_p1=si_new_sigma_p1,
            compress=1.0,
            expand=1.0,
        ),
        Graphite(shift=g_new_shift),
    )

    print(another_si_g_composite)
    print(f"val: {another_si_g_composite.params['Si01sigma']}")
    print(f"val: {another_si_g_composite.params['Si01center']}")
    print(f"val: {another_si_g_composite.params['G01center']}")

    print(another_si_g_composite.prefixes)
    print("PARAM NAMES")
    print(another_si_g_composite.param_names)
    print("NAMES")
    print(another_si_g_composite.names)
    print("SELECTED Si")
    print(another_si_g_composite.selector["Si"])
示例#16
0
files = [
    "20160805_test001_45_cc_01.res",
    "20160805_test001_45_cc_02.res",
]

mass = 0.3

rawfiles = [os.path.join(rawdir, f) for f in files]
print("\n", "your files".center(80, "-"))

for f in rawfiles:
    exists = "OK"
    if not os.path.isfile(f):
        exists = "NOT FOUND"
    print(f"{f} {exists}")

print(80 * "-")

d = cellreader.CellpyData().from_raw(rawfiles)
d.set_mass(mass)
d.make_step_table()
d.make_summary()

summary = d.cell.summary
print(summary.head())

fig, ax = plt.subplots(1, 1)
ax.plot(summary['Cycle_Index'],
        summary['Cumulated_Coulombic_Difference(mAh/g)'])
plt.show()
示例#17
0
def dataset():
    from cellpy import cellreader

    d = cellreader.CellpyData()
    d.load(fdv.cellpy_file_path)
    return d
示例#18
0
文件: ocv_rlx.py 项目: nrgrpg/cellpy
def _main():
    from cellpy import cellreader
    import os
    import matplotlib.pyplot as plt

    print(50 * "=")
    print("FITTING OCV ROUTINES - TEST")
    print(50 * "-")

    # filename(s) and folders etc
    resfilename = "20160809_TF7_A1_04_cc_02.res"
    resfilename = "20160216_snx001_01_cc_01.res"
    resfilename = "20160216_snx001_02_cc_01.res"
    resfilename = "20170310_snx002_03_cc_01.res"
    # resfilename = "20160306_snx001_09_cc_01.res"
    # resfilename = "20150501_TF7_A1_01_cc_01.res"
    resfilename = "20160805_test001_45_cc_01.res"
    resfilename = "20160306_snx001_07_cc_02.res"
    resfilename = "20160306_snx001_08_cc_02.res"
    resfilename = "20160306_snx001_10_cc_01.res"

    single_cell = False

    datafolder_in = r"..\data_ex"
    datafolder_out = r"..\outdata"

    # parameters about the run (mass (mg))
    mass = 0.982

    # cycles to test
    cycles = [i * 10 for i in range(1, 10)]
    cycles = [i * 1 for i in range(1, 100)]
    print(50 * "-")
    print("Loading data")
    print(50 * "-")

    print("loading file", end=" ")
    print(resfilename)

    # Loading dataframe
    d = cellreader.CellpyData()
    # noinspection PyDeprecation
    d.from_raw(os.path.join(datafolder_in, resfilename))
    d.set_mass(mass)
    d.make_step_table()

    if single_cell:
        # Sending data to ocv_fit object and running fit
        ocv_fit = OcvFit()
        ocv_fit.set_cellpydata(d, 1)
        ocv_fit.set_circuits(4)
        ocv_fit.create_model()
        ocv_fit.run_fit()

        fig1 = plt.figure()
        fig1.suptitle("Fit")
        ax1 = fig1.add_subplot(111)

        plot_data = ocv_fit.get_best_fit_data()
        ax1.plot(plot_data[0], plot_data[1])
        ax1.plot(plot_data[0], plot_data[2])

        plt.show()

    else:
        ocv_fit = MultiCycleOcvFit(d, cycles, circuits=3)
        ocv_fit.run_fitting(direction="up")
        ocv_fit.plot_summary([0])
        ocv_fit.plot_summary_translated()
示例#19
0
def load_c_file(filename):
    c = cellreader.CellpyData()
    c.load(filename)
    return c
示例#20
0
    test_raw_file_full = os.path.join(test_data_dir_raw, test_raw_file)

    test_data_dir_cellpy = os.path.join(test_data_dir, "hdf5")
    test_cellpy_file = "geis.h5"
    test_cellpy_file_tmp = "tmpfile.h5"
    test_cellpy_file_full = os.path.join(test_data_dir_cellpy,
                                         test_cellpy_file)
    test_cellpy_file_tmp_full = os.path.join(test_data_dir_cellpy,
                                             test_cellpy_file_tmp)

    raw_file_name = test_raw_file_full
    print("\n======================mpr-dev===========================")
    print(f"Test-file: {raw_file_name}")
    log.setup_logging(default_level="DEBUG")
    instrument = "biologics_mpr"
    cellpy_data_instance = cellreader.CellpyData()
    cellpy_data_instance.set_instrument(instrument=instrument)
    print("starting to load the file")
    cellpy_data_instance.from_raw(raw_file_name)
    print("printing cellpy instance:")
    print(cellpy_data_instance)

    print("---make step table")
    cellpy_data_instance.make_step_table()

    print("---make summary")
    cellpy_data_instance.make_summary(convert_date=False)

    print("---saving to csv")
    try:
        temp_dir = tempfile.mkdtemp()
示例#21
0
import cellpy
from cellpy import log
from cellpy import cellreader
from cellpy.parameters import prms

prms.Reader.use_cellpy_stat_file = False
prms.Reader.cycle_mode = "cathode"
prms.Reader.sorted_data = False
log.setup_logging(default_level="DEBUG", custom_log_dir=os.getcwd())
datapath = "/Users/jepe/scripting/cellpy/dev_data/bugfixing"

filename = Path(datapath) / "20180919_FC_LFP2_cen14_01_cc_01.res"

assert os.path.isfile(filename)

d = cellreader.CellpyData()
d.from_raw(filename)
d.set_mass(0.12)
d.make_step_table()
d.make_summary()

# checking extracting cycles
n = d.get_number_of_cycles()
c = d.get_cycle_numbers()

# checking creating dqdv
cc = d.get_cap()

d.to_csv(datapath)