Exemplo n.º 1
0
def plot_interlevels(file, persFile, output, interval, r, mask=False):
    """
        plots interlevels sets for specified numpy file
        from the height values in associated persFile (USE .BETTI FILE)
        
        output is directory for output files (indv. names come from file + height)
        interval provides info on what frames to save
        (i.e. interval==2 means every other frame )
        
        r perburation to height function (use half of desired window)
        Use half interval to capture every height value (if all height values present)
        
        if mask==True all sublevel values are set to 1
        """
    if not output.endswith("/"):
        output += "/"
    with open(persFile, "r") as f:
        s = f.read()
    f.close()
    data = numpy.load(file)
    heightList = [x[1:-1] for x in re.findall("\[[^\]]*\]", s)]
    # d = numpy.where(data>int(heightList[100]))
    # data[d] = 0
    # rp . save_npy_as_png(data,output+file.split('/')[-1].rstrip('.npy'))
    for ind, h in enumerate(heightList):
        if ind % interval == 0:
            temp = data.copy()
            lower = int(h) - r
            upper = int(h) + r
            temp[(temp > upper) | (temp < lower)] = 0
            if mask:
                temp[numpy.where(temp != 0)] = 1
            outName = file.split("/")[-1].rstrip(".npy") + "_" + h + "-" + str(lower) + "-" + str(upper)
            rp.save_npy_as_png(temp, output + outName + ".png")
Exemplo n.º 2
0
def plot_sublevels_comp(file, slice, output, interval, persFile="NULL", mask=False):
    """
        plots sublevel sets for specified numpy file
        from the height values in associated persFile
        output is directory for output files (indv. names come from file + height)
        interval provides info on what frames to save
        (i.e. interval==2 means every other frame )
        if mask==True all sublevel values are set to 1
        """
    if not output.endswith("/"):
        output += "/"
    data = numpy.load(file)[slice]
    if persFile != "NULL":
        with open(persFile, "r") as f:
            s = f.read()
        f.close()
        heightList = [x[1:-1] for x in re.findall("\[[^\]]*\]", s)]
    else:
        tempMin = data[numpy.where(data > data.min())].min()
        avg = (data.max() - tempMin) / 50
        heightList = numpy.arange(tempMin, data.max(), avg)
    # d = numpy.where(data>int(heightList[100]))
    # data[d] = 0
    # rp . save_npy_as_png(data,output+file.split('/')[-1].rstrip('.npy'))
    for ind, h in enumerate(heightList):
        if ind % interval == 0:
            temp = data.copy()
            temp[numpy.where(temp > int(h))] = 0
            if mask:
                temp[numpy.where(temp != 0)] = 1
            outName = file.split("/")[-1].rstrip(".npy") + "_" + str(slice) + "_" + str(h)
            rp.save_npy_as_png(temp, output + outName + ".png")