Exemplo n.º 1
0
        del input
        d[fl] = [i[0] for i in sorted(enumerate(dlist), key=lambda x: x[1])
                 ]  #, reverse = True)]
    PIK = 'd.dat'
    with open(PIK, "wb") as f:
        pickle.dump(d, f, pickle.HIGHEST_PROTOCOL)
    f.close()
    return (d)


#------------------------------------------------------------------------------------------------------------------

datafiles = get_files_by_file_size(datalocation)

# The first file will contain all the structure data, the rest will contain pointodoses.
dpdata = dose_to_points_data_pb2.DoseToPointsData()

# Start with reading structures, numvoxels and all that.
f = open(datafiles.pop(0), "rb")
dpdata.ParseFromString(f.read())
f.close()
datafiles.sort()
#----------------------------------------------------------------------------------------
# Get the data about the structures
numstructs = len(dpdata.Structures)
structureList = []
structureDict = {
}  # keys are the names of the structure and the value is the corresponding index location (integer)
print("Reading in structures")
for s in range(numstructs):
    print('Reading:', dpdata.Structures[s].Id)
Exemplo n.º 2
0
def individualAnalizer(caseis):
    # What computer am I reading from?
    datalocation = '~'
    if 'radiation-math' == socket.gethostname(): # LAB
        datalocation = "/mnt/fastdata/Data/" + caseis + "/by-Beam/"
        dropbox = "/mnt/datadrive/Dropbox"
        cutter = 44
        if "lung360" == caseis:
            cutter = 43
    elif 'sharkpool' == socket.gethostname(): # MY HOUSE
        datalocation = "/home/wilmer/Dropbox/Data/spine360/by-Beam/"
        dropbox = "/home/wilmer/Dropbox"
        cutter = 51
    elif 'DESKTOP-EA1PG8V' == socket.gethostname(): # MY HOUSE
        datalocation = "C:/Users/wihen/Data/"+ caseis + "/by-Beam/"
        dropbox = "D:/Dropbox"
        cutter = 45
        numcores = 11
        if "lung360" ==  caseis:
            cutter = 44
    elif ('arc-ts.umich.edu' == socket.gethostname().split('.', 1)[-1]): # FLUX
        datalocation = "/scratch/engin_flux/wilmer/" + caseis + "/by-Beam/"
        dropbox = "/home/wilmer/Dropbox"
        cutter = 52
        if "lung360" ==  caseis:
            cutter = 51
    else:
        datalocation = "/home/wilmer/Dropbox/Data/spine360/by-Beam/" # MY LAPTOP
        dropbox = "/home/wilmer/Dropbox"

    datafiles = get_files_by_file_size(datalocation)
    # The first file will contain all the structure data, the rest will contain pointodoses.
    dpdata = dose_to_points_data_pb2.DoseToPointsData()
    print('datafiles:', datafiles)
    f = open(datafiles.pop(0), "rb")
    dpdata.ParseFromString(f.read())
    f.close()
    datafiles.sort()

    XSize = dpdata.Beamlets[0].XSize
    YSize = dpdata.Beamlets[0].YSize
    XSize = 1.0
    YSize = 1.0
    # Read all relevant files for a particular case
    datafiles = get_files_by_file_size('./outputGraphics/')
    matching = [s for s in datafiles if 'outputGraphics/allbeamshapesbefore-save-' +  caseis + '-' in s]
    print('Areas will be calculated in squared milimeters. Same as perimeter in milimeters')
    KellyMeasures = dict()
    MyMeasures = dict()
    if caseis == 'lung360':
        cutter = 50
    else:
        cutter = 51
    mylegends = list()
    for PIK in matching:
        mylegends.append(float(PIK[cutter:-7]))

    print(matching)
    matching = [x for _,x in sorted(zip(mylegends, matching))]
    print(matching)

    mylegends = list()
    pendients = list()
    for myColor, PIK in enumerate(matching):
        print(PIK)
        Cval = float(PIK[cutter:-7])
        mylegends.append(Cval)
        MLCtrip = pickle.load(open(PIK, "rb"))
        KellyMeasures[PIK] = np.zeros(len(MLCtrip))
        MyMeasures[PIK] = np.zeros(len(MLCtrip))
        Perimeters = np.zeros(len(MLCtrip))
        Areas = np.zeros(len(MLCtrip))
        for i, thisbeam in enumerate(MLCtrip):
            l = thisbeam[0]
            r = thisbeam[1]
            Perimeter = (r[0] - l[0])
            Area = 0.0
            for n in range(1, len(l)):
                Area += (r[n] - l[n]) * YSize
                Perimeter += (np.abs(l[n] - l[n-1]) + np.abs(r[n] - r[n-1]) - 2 * np.maximum(0, l[n-1] - r[n]) - 2 * np.maximum(0, l[n] - r[n - 1])) * XSize
            Perimeter += (r[len(r)-1] - l[len(l)-1]) * XSize + np.sign(r[len(r)-1] - l[len(l)-1])
            Kellymeasure = Perimeter / Area
            Mymeasure = 1.0 * Perimeter - 0.55 * Area
            KellyMeasures[PIK][i] = Kellymeasure
            MyMeasures[PIK][i] = Mymeasure
            Perimeters[i] = Perimeter
            Areas[i] = Area
        lm = LinearRegression(fit_intercept=False)
        y = KellyMeasures[PIK] - Perimeters
        y = np.reshape(y, (len(y), 1))
        Areas = np.reshape(Areas, (len(y), 1))
        reg = lm.fit(-Areas, y)
        print(reg, reg.coef_)
        pendients.append((Cval, reg.coef_[0]))
        #print(reg.coef_)

        if mylegends[-1] == 1.0 or mylegends[-1] == 0.001:
            plt.scatter(MyMeasures[PIK], KellyMeasures[PIK], s = 13.0, marker = 'v')
        elif mylegends[-1] == 0.0:
            plt.scatter(MyMeasures[PIK], KellyMeasures[PIK], s=10.0, marker='o')
        else:
            plt.scatter(MyMeasures[PIK], KellyMeasures[PIK], s=1.0)
        plt.title('Comparison of measures for case: ' + caseis)
        plt.xlabel('Our Measure')
        plt.ylabel("Younge's Measure")
        plt.legend(mylegends)
    plt.savefig('outputGraphics/ComparisonOfMeasuresForCase' + caseis + '.png')
    #plt.show()
    return(pendients)