def list_w_p(path, mass):
    '''Return a list of work-power datas caculated from\
       the .txt files within the path.\
       Argument:\
       mass: mass or surface area or volume of the sample'''

    instances = []

    for s in os.listdir(path):
        # find the .txt files
        if '.txt' in s:
            f_path = os.path.join(path, s)
            inst = rd.GV(filename=f_path, mass=mass)
            instances.append(inst)

    # the list for line objects in an axe
    w_p = pd.DataFrame()
    for counter, inst in enumerate(instances):

        w_p = w_p.append(inst.work_power())

    return w_p.reset_index(drop=True)
 def object_generator(path, mass):
     for s in os.listdir(path):
         # find the .txt files
         if '.txt' in s:
             f_path = os.path.join(path, s)
             yield rd.GV(filename=f_path, mass=mass)
def multi_c_d(
        ax,
        path,
        title=None,
        mass=1.0,
        unit=' A/g',
        color_set=['black', 'blue', 'green', 'red', 'pink', 'brown', 'yellow'],
        xlabel=None,
        ylabel=None,
        legend_font=12,
        b_to_a=(1, 0.75),
        **kwargs):
    '''Draw multiple charge/discharge curves on a single axe\
       Arguments:\
       ax\
       path: the path of the file containing .txt files\
       title\
       mass: mass or surface area or volume of the sample'''

    gp.Update_axe(ax, title=title, **kwargs)

    # the list for GV objects
    instances = []

    for s in os.listdir(path):
        # find the .txt files
        if '.txt' in s:
            f_path = os.path.join(path, s)
            inst = rd.GV(filename=f_path, mass=mass)
            instances.append(inst)

    # the list for line objects in an axe
    handles = []

    for counter, inst in enumerate(instances):

        l_char = gp.MultiLine(inst.charge_curve(),
                              ax,
                              label=str(inst.current) + unit,
                              color=color_set[counter])

        gp.MultiLine(inst.discharge_curve(),
                     ax,
                     label=str(inst.current) + unit,
                     color=color_set[counter])
        # line object is a list
        handles += l_char

    if xlabel == None:

        ax.set_xlabel(instances[0].columns[0])

    else:
        ax.set_xlabel(xlabel)

    if ylabel == None:
        ax.set_ylabel(instances[0].columns[1])

    else:
        ax.set_ylabel(ylabel)

    ax.set_xlim(left=0)
    ax.set_ylim(top=0.8, bottom=0)

    ax.legend(handles=handles,
              bbox_to_anchor=b_to_a,
              loc='upper right',
              frameon=False,
              fontsize=legend_font)