Exemplo n.º 1
0
def inputexists(input):
    """Test to see if file/folder exists."""
    if not (os.path.isfile(input) or os.path.isdir(input)):
        print "File:", input, "not found"
        print "Folder:", input, "also not found."
        procargs(["h"])
    return 0
Exemplo n.º 2
0
def trials_err(ntrials):
    """Perform basic error check on the number of trials."""
    SENT1 = object()
    NTRIALS = SENT1
    if isinstance(ntrials, str):
        try:
            NTRIALS = int(ntrials)
        except ValueError:
            print "***ERROR***"
            print "Invalid number of trials."
            procargs(["h"])
    if NTRIALS == SENT1:
        return -1
    if NTRIALS <= 0:
        print "Number of trials should be greater than one"
        print "Check command line input."
        sys.exit(1)
    return NTRIALS
Exemplo n.º 3
0
def xstep_err(xstep, INPUT):
    """Check for error in the domain step size.
    Return the step size.
    """
    XSTEP = -1
    if isinstance(xstep, str):
        try:
            OPSTEMP = xstep
            OPSTEMP = float(OPSTEMP)
        except ValueError:
            print "***ERROR***"
            print "Invalid step size."
            print "Expecting an float >= 0."
            procargs(["h"])
        if OPSTEMP >= 0:
            XSTEP = OPSTEMP
        else:
            XSTEP = -1
    #We only care about step size for multi file setup
    if XSTEP == -1 and os.path.isdir(INPUT):
        print "Assuming domain step size is 1 (int)."
        XSTEP = 1
    return XSTEP
Exemplo n.º 4
0
def main():
    ####set up 1ab
    OPTIONS = namedtuple('ops', ['xmin', 'xmax', 'xstep', 'trials'])

    
    ###error processing, parameter extractions
    INPUT, OPTIONS = procargs(sys.argv[1:])
    XMIN, XMAX = xlim_err(OPTIONS.xmin, OPTIONS.xmax)
    XSTEP = xstep_err(OPTIONS.xstep, INPUT)
    TRIALS = trials_err(OPTIONS.trials)

    if TRIALS == -1:
        RESULT_MIN, PARAM_ERR, COORDS, COV = singlefit(INPUT, 
                                                       XMIN, XMAX, XSTEP)
        printerr(RESULT_MIN.x, PARAM_ERR)
        mkplot(COORDS, COV, RESULT_MIN)
        sys.exit(0)
    else:
        list_fit_params = []
        for ctime in range(TRIALS):
           IFILE = proc_folder(INPUT, ctime, "blk")
           NINPUT = os.path.join(INPUT, IFILE)
           RESULT_MIN, PARAM_ERR, COORDS, COV = singlefit(NINPUT, 
                                                          XMIN, XMAX, XSTEP)
           list_fit_params.append(RESULT_MIN.x)
        #todo: make plot section
        TRANSPOSE = np.array(list_fit_params).T.tolist()
        avg_fit_params = [sum(TRANSPOSE[i])/len(TRANSPOSE[i]) for i in range(
        len(TRANSPOSE))]
        if JACKKNIFE == "YES":
            prefactor = (TRIALS-1.0)/(1.0*TRIALS)
        elif JACKKNIFE == "NO":
            prefactor = (1.0)/((TRIALS-1.0)*(1.0*TRIALS))
        else:
            print "***ERROR***"
            print "JACKKNIFE value should be a string with value either"
            print "YES or NO"
            print "Please examine the config file."
            sys.exit(1)
        err_fit_params = [sqrt(sum([(TRANSPOSE[i][j]-avg_fit_params[i])**2
                                    for j in range(len(
                                            TRANSPOSE[i]))])*prefactor)
                          for i in range(len(TRANSPOSE))]
        printerr(avg_fit_params, err_fit_params)
        sys.exit(0)
Exemplo n.º 5
0
def xlim_err(xmin, xmax):
    """Check for errors in the input of xmin and xmax.
    Return xmin and xmax.
    """
    SENT1 = object()
    SENT2 = object()
    XMIN = SENT1
    XMAX = SENT2
    if isinstance(xmax, str):
        try:
            XMAX = float(xmax)
        except ValueError:
            print "***ERROR***"
            print "Invalid xmax."
            procargs(["h"])
    if isinstance(xmin, str):
        try:
            XMIN = float(xmin)
        except ValueError:
            print "***ERROR***"
            print "Invalid xmin."
            procargs(["h"])
    if XMIN == SENT1 or XMAX == SENT2:
        print "Now, input valid domain (abscissa)."
        print "xmin<=x<=xmax"
        if XMIN == SENT1:
            print "x min="
            XMIN = float(raw_input())
        if XMAX == SENT2:
            print "x max="
            XMAX = float(raw_input())
    if XMAX < XMIN:
        while True:
            print "xmax < xmin.  Contradiction."
            print "Swap xmax for xmin? (y/n)"
            RESP = str(raw_input())
            if (RESP == "n" or RESP == "no" or
                    RESP == "No" or RESP == "N"):
                while True:
                    print "Abort? (y/n)"
                    RESP = str(raw_input())
                    if (RESP == "n" or RESP == "no" or
                            RESP == "No" or RESP == "N"):
                        break
                    if (RESP == "y" or RESP == "yes"
                            or RESP == "Yes" or RESP == "Y"):
                        sys.exit(0)
                    else:
                        print "Sorry, I didn't understand that."
                        continue
                print "Input new values."
                print "x min="
                XMIN = float(raw_input())
                print "x max="
                XMAX = float(raw_input())
                if XMAX < XMIN:
                    continue
                else:
                    break
            if (RESP == "y" or RESP == "yes"
                    or RESP == "Yes" or RESP == "Y"):
                XMIN, XMAX = XMAX, XMIN
                break
            else:
                print "Sorry, I didn't understand that."
                continue
    return XMIN, XMAX