Exemple #1
0
def _test_FEATHER_retract_only(fec, threshold, tau):
    """
    :param fec: the force-extension curve, from (e.g.)
    _command_line_config.make_fec

    :param threshold: the significance threshold
    :param tau: the fractional smoothing
    :return:
    """
    # # Next, we show how to get do event detection based only on the approach
    # We do the following steps(1-4), below
    #       (1) Create a new FEC based only on the retract
    # first, we get just the retract, which starts at t=(TriggerTime+DwellTime)
    retract = Analysis.zero_and_split_force_extension_curve(fec, tau).retract
    # next, we use <pct_pseudo_approach> of the retract to make an approach
    pct_pseudo_approach = 0.1
    split = UtilFEATHER._split_from_retract(retract, pct_pseudo_approach, tau)
    # combined the 'fake' approach and retract
    to_save = FEC_Util._create_psuedo_fec_to_save(split)
    to_save.Meta.SourceFile = "TemporaryFEC"
    #       (2) Save the FEC out to a csv
    file_saved = FEC_Util._save_single_csv(out_dir="./", fec_to_save=to_save)
    #       (3) Run FEATHER on the CSV, just as we did above
    time, sep, force, file_dict = _get_file_info(file_saved)
    meta_dict = dict(threshold=threshold, tau=tau, **file_dict)
    event_indices_1 = _command_line_config.run_feather(in_file=file_saved,
                                                       **meta_dict)
    _plot_results(time, force, event_indices_1)
Exemple #2
0
def _analyze_file(in_file):
    threshold = 1e-3
    tau = 2e-2
    time, sep, force, file_dict = _get_file_info(in_file)
    meta_dict = dict(threshold=threshold, tau=tau, **file_dict)
    event_indices_1 = _command_line_config.run_feather(in_file=in_file,
                                                       **meta_dict)
    # # (2) directly, using python arrays and a constructed fec object. This is
    # #    likely to be much faster, since there is no extra file IO.
    fec = _command_line_config.make_fec(time=time,
                                        separation=sep,
                                        force=force,
                                        **meta_dict)
    event_indices_2 = _command_line_config.predict_indices(fec,
                                                           tau_fraction=tau,
                                                           threshold=threshold)
    # make sure the two methods are consistent
    assert np.allclose(event_indices_1,event_indices_2) , \
        "Programming error; FEATHER methods should be identical"
    # POST: they are consistent. go ahead and plot force vs time, add lines
    # where an event is predicted
    print("Found events at indices: {}".format(event_indices_1))
    # # Next, we show how to get do event detection based only on the approach
    # We do the following steps(1-4), below
    #       (1) Create a new FEC based only on the retract
    #       (2) Save the FEC out to a csv
    #       (3) Run FEATHER on the CSV, just as we did above
    _test_FEATHER_retract_only(fec, threshold, tau)
Exemple #3
0
def run():
    """
    <Description>

    Args:
        param1: This is the first param.
    
    Returns:
        This is a description of what is returned.
    """
    # there are a couple of ways to call FEATHER in python.
    # # (1) through an intermediate '.csv' file
    in_file = '../Data/example_0.csv'
    data = np.loadtxt(in_file, delimiter=',', skiprows=0)
    header_info = _command_line_config._parse_csv_header(in_file)
    time, sep, force = data[:, 0], data[:, 1], data[:, 2]
    threshold = 1e-3
    tau = 2e-2
    meta_dict = dict(threshold=threshold,
                     tau=tau,
                     spring_constant=header_info.spring_constant,
                     trigger_time=header_info.trigger_time,
                     dwell_time=header_info.dwell_time)
    event_indices_1 = _command_line_config.run_feather(in_file=in_file,
                                                       **meta_dict)
    # # (2) directly, using python arrays and a constructed fec object. This is
    # #    likely to be much faster, since there is no extra file IO.
    fec = _command_line_config.make_fec(time=time,
                                        separation=sep,
                                        force=force,
                                        **meta_dict)
    event_indices_2 = _command_line_config.predict_indices(fec,
                                                           tau_fraction=tau,
                                                           threshold=threshold)
    # make sure the two methods are consistent
    assert np.allclose(event_indices_1,event_indices_2) , \
        "Programming error; FEATHEr methods are identical"
    # POST: they are consistent. go ahead and plot force vs time, add lines
    # where an event is predicted
    print("Found events at indices: {}".format(event_indices_1))
    plt.plot(time, force * (-1e12))
    for i in event_indices_1:
        plt.axvline(time[i])
    plt.xlabel("Time (s)")
    plt.ylabel("Force (pN)")
    plt.show()
Exemple #4
0
def parse_and_run():
    """
    uses argparse to get the arguments _command_line_config.run_feather needs

    Args:
        none, but assumes called from command line properly
    Returns:
        event_indices, as predicted by FEATHER
    """
    description = 'Predict event locations in a data file'
    parser = argparse.ArgumentParser(description=description)
    common = dict(required=True)
    # # feathers options
    parser.add_argument('-tau',
                        metavar='tau',
                        type=float,
                        help='tau fraction of curve (0,1)',
                        required=False,
                        default=1e-2)
    parser.add_argument('-threshold',
                        metavar='threshold',
                        type=float,
                        help='probability threshold (0,1)',
                        **common)
    # # 'meta' variables
    parser.add_argument('-spring_constant',
                        metavar='spring_constant',
                        type=float,
                        help='spring constant of the probe',
                        **common)
    parser.add_argument('-trigger_time',
                        metavar='trigger_time',
                        type=float,
                        help='time at which approach ends',
                        **common)
    parser.add_argument('-dwell_time',
                        metavar='dwell_time',
                        type=float,
                        help='time between end of approach and retract start',
                        **common)
    # path to the file
    parser.add_argument('-file_input',
                        metavar="file_input",
                        type=str,
                        help="path to the force-extension curve file",
                        **common)
    parser.add_argument('-file_output',
                        metavar="file_output",
                        type=str,
                        help="path to output the associated data",
                        **common)
    # parse all the inputs
    args = parser.parse_args()
    out_file = os.path.normpath(args.file_output)
    in_file = os.path.normpath(args.file_input)
    # get the indices
    feather_dict = dict(in_file=in_file,
                        threshold=args.threshold,
                        tau=args.tau,
                        spring_constant=args.spring_constant,
                        dwell_time=args.dwell_time,
                        trigger_time=args.trigger_time)
    # call feather
    event_indices = _command_line_config.run_feather(**feather_dict)
    # done with the log file...
    np.savetxt(fname=out_file,
               delimiter=",",
               newline="\n",
               fmt="%d",
               header="(C) PRH 2017\nEvent Indices",
               X=event_indices)
    return event_indices