示例#1
0
    def truncate(
        self, y
    ):  # trunca el trapecio con la recta que se le pasa como parametro que es paralela a x
        if y >= self.points[1].y:
            # significa que la recta esta por encima del trapecio
            return trapezoidal(self.points)

        mr1 = slope(
            self.points[0],
            self.points[1])  # pendiente de los dos primero puntos del trapecio
        mr2 = slope(
            self.points[2],
            self.points[3])  # pendiente de los dos ultimos puntos del trapecio

        nr1 = trace(
            mr1, self.points[0]
        )  # traza de la recta formada por los 2 primeros del trapecio
        nr2 = trace(
            mr2, self.points[2]
        )  # traza de la recta formada por los 2 ultimos del trapecio

        x1 = (y -
              nr1) / mr1  # x del punto de interseccion con la primera recta
        x2 = (y -
              nr2) / mr2  # x del punto de interseccion con la segunda recta

        return trapezoidal(
            [self.points[0],
             point(x1, y),
             point(x2, y), self.points[3]])
示例#2
0
    def truncate(
            self, y
    ):  # trunca el triangulo con una recta parametro que es paralela a x
        if y >= self.points[
                1].y:  # significa que la recta esta por encima del triangulo y no lo trunca
            return triangle(self.points)

        mr1 = slope(self.points[0], self.points[1]
                    )  # pendiente de los dos primero puntos del triangulo
        mr2 = slope(self.points[1], self.points[2]
                    )  # pendiente de los dos segundos puntos del triangulo

        nr1 = trace(
            mr1, self.points[0]
        )  # traza de la recta fromada por los 2 primeros puntos del triangulo
        nr2 = trace(
            mr2, self.points[1]
        )  # traza de la recta fromada por los 2 segundos puntos del triangulo

        x1 = (y -
              nr1) / mr1  # x del punto de interseccion con la primera recta
        x2 = (y -
              nr2) / mr1  # x del punto de interseccion con la segunda recta

        return trapezoidal(
            [self.points[0],
             point(x1, y),
             point(x2, y), self.points[2]])
示例#3
0
    def evaluate(self, x):
        if x <= self.points[0].x or x >= self.points[2].x:
            return 0

        if x <= self.points[1].x:
            m = slope(self.points[0], self.points[1])
            n = trace(m, self.points[1])
        else:
            m = slope(self.points[1], self.points[2])
            n = trace(m, self.points[1])

        return m * x - n
示例#4
0
    def truncate(self, y):  # si la recta esta por encima de la funcion
        m = slope(self.points[0], self.points[1])
        if (m > 0 and y >= self.points[1].y) or (m < 0
                                                 and y >= self.points[0].y):
            return regular(self.points)

        m = slope(self.points[0], self.points[1])
        n = trace(m, self.points[0])

        x = (y - n) / m

        if m > 0:
            return regular([self.points[0], point(x, y)])

        return regular([point(x, y), self.points[1]])
示例#5
0
    def evaluate(self, x):
        m = slope(self.points[0], self.points[1])
        if x <= self.points[0].x:
            if m > 0:
                return 0
            return 1

        if x >= self.points[1].x:
            if m > 0:
                return 1
            return 0

        m = slope(self.points[0], self.points[1])
        n = trace(m, self.points[0])

        return m * x + n
示例#6
0
def merge_df_files(df1, gj2, match):
    df2 = geopandas.read_file(open(gj2))
    if len(df1) == 0:
        file_name2 = gj2.split('/')[-2]
        for i in range(df2.shape[0]):
            if df2.iloc[i]['id'] not in match.keys():
                match[df2.iloc[i]['id']] = [(file_name2, df2.iloc[i]['id'])]
        return df2, match
    file_name2 = gj2.split('/')[-2]
    repeat = list()
    table2to1 = dict()
    if not if_overlap(df1, df2):
        for j in range(df2.shape[0]):
            if df2.iloc[j]['id'] + df1.iloc[-1]['id'] + 1 not in match.keys():
                match[df2.iloc[j]['id'] + df1.iloc[-1]['id'] + 1] = [
                    (file_name2, df2.iloc[j]['id'])
                ]
        df2['id'] += df1.iloc[-1]['id'] + 1
        df1 = df1.append(df2)
        df1 = df1.reset_index(drop=True)
    else:
        matched_id = list()
        base_id = df1.iloc[-1]['id'] + 1
        for i in range(df1.shape[0]):
            for j in range(df2.shape[0]):

                row1 = df1.iloc[i]
                line1 = np.array(row1['geometry']).reshape(-1, )
                row2 = df2.iloc[j]
                line2 = np.array(row2['geometry']).reshape(-1, )

                #print("leftright:", leftright)
                if abs(
                        utils.slope(np.array(line1[:2]), np.array(line1[2:])) -
                        utils.slope(np.array(line2[:2]), np.array(line2[2:]))
                ) > 0.2:
                    continue
                if utils.l2_distance_2d(np.array(line1[:2]), np.array(
                        line2[:2])) > 40:
                    continue
                d_line = utils.l2_distance_lines(np.array(line1[:2]),
                                                 np.array(line1[2:]),
                                                 np.array(line2[:2]),
                                                 np.array(line2[2:]))
                if d_line > 2.5:
                    continue
                ymin_coor,ymax_coor, cover_rate, baseline = \
                    utils.line2line_project(np.array(line1[:2]), np.array(line1[2:]),
                                            np.array(line2[:2]), np.array(line2[2:]))
                if utils.l2_distance_2d(ymin_coor, ymax_coor) > 30.0:
                    continue
                #if (cover_rate < 1 and cover_rate > 0.7 and d_line < 0.5) or (cover_rate < 0.7 and d_line < 2.5):
                if (cover_rate < config.cover_rate * 4
                        and d_line < 0.5) or (cover_rate < config.cover_rate
                                              and d_line < 2.5):
                    if row2['id'] in matched_id:
                        pre_1_id = table2to1[row2['id']]
                        repeat.append(row1['id'])
                        index = df1[df1['id'] == pre_1_id].index[0]
                        row_pre = df1.loc[index]
                        line_pre = np.array(row_pre['geometry']).reshape(-1, )
                        ymin_coor,ymax_coor, cover_rate, baseline = \
                            utils.line2line_project(np.array(line_pre[:2]), np.array(line_pre[2:]),
                                                    np.array(line1[:2]), np.array(line1[2:]))

                        merge_line = LineString([(ymin_coor[0], ymin_coor[1]),
                                                 (ymax_coor[0], ymax_coor[1])])

                        df1.loc[index, 'min_h'] = min(row_pre['min_h'],
                                                      row1['min_h'])
                        df1.loc[index, 'max_h'] = min(row_pre['max_h'],
                                                      row1['max_h'])
                        df1.loc[index, 'ref_h'] = (row1['ref_h'] +
                                                   row_pre['ref_h']) / 2
                        df1.loc[index, 'depth'] = (row1['depth'] +
                                                   row_pre['depth']) / 2
                        df1.loc[index, 'dis'] = utils.l2_distance_2d(
                            ymin_coor[:2], ymax_coor[:2])
                        df1.loc[index, 'geometry'] = merge_line

                        filter_pair = list()
                        for pair in match[row1['id']]:
                            if pair not in match[row_pre['id']]:
                                filter_pair.append(pair)
                        if baseline == 1:
                            match[row_pre['id']] = match[
                                row_pre['id']] + filter_pair
                        else:
                            match[row_pre['id']] = filter_pair + match[
                                row_pre['id']]

                    else:
                        table2to1[row2['id']] = row1['id']
                        matched_id.append(row2['id'])

                        merge_line = LineString([(ymin_coor[0], ymin_coor[1]),
                                                 (ymax_coor[0], ymax_coor[1])])
                        index = df1[df1['id'] == row1['id']].index[0]
                        df1.loc[index, 'min_h'] = min(row1['min_h'],
                                                      row2['min_h'])
                        df1.loc[index, 'max_h'] = min(row1['max_h'],
                                                      row2['max_h'])
                        df1.loc[index,
                                'ref_h'] = (row1['ref_h'] + row2['ref_h']) / 2
                        df1.loc[index,
                                'depth'] = (row1['depth'] + row2['depth']) / 2
                        df1.loc[index, 'dis'] = utils.l2_distance_2d(
                            ymin_coor[:2], ymax_coor[:2])
                        df1.loc[index, 'geometry'] = merge_line

                        if baseline == 1:
                            match[row1['id']].append((file_name2, row2['id']))
                        else:
                            match[row1['id']].insert(0,
                                                     (file_name2, row2['id']))

        for i in set(repeat):
            df1.drop(index=df1[df1['id'] == i].index[0], inplace=True)
            match.pop(i)

        count = 1
        base = df1.iloc[-1]['id']
        for i in range(df2.shape[0]):
            if i in matched_id:
                continue
            row2 = df2.iloc[i]
            tmp_row2_id = row2['id']
            row2['id'] = base + count
            if row2['id'] not in match.keys():
                match[row2['id']] = [(file_name2, tmp_row2_id)]
            df1 = df1.append(row2)
            count += 1
    df1 = df1.reset_index(drop=True)
    return df1, match
示例#7
0
INPUT_FILE = '../output/02_19_16/UCBERKELEYAV45_02_19_16_regular_tp.csv'


df = pd.read_csv(INPUT_FILE)
df = df[['RID','EXAMDATE','WHOLECEREBELLUM','FRONTAL','CINGULATE','PARIETAL','TEMPORAL','COMPOSITE','SUMMARYSUVR_WHOLECEREBNORM','BRAIN_STEM']]
df.loc[:,'EXAMDATE'] = df.loc[:,'EXAMDATE'].apply(parseDate)
slopes = []
for rid, rows in df.groupby('RID'):
    if len(rows.index) == 1:
        continue
    rows = rows.sort_values(by='EXAMDATE')
    times = list(rows['EXAMDATE'])
    years = [((t-times[0]).days)/365.0 for t in times]

    brainstem = rows['BRAIN_STEM']
    suvr_slope = slope(zip(years,list(rows['SUMMARYSUVR_WHOLECEREBNORM'])))
    bl_suvr = rows.iloc[0]['SUMMARYSUVR_WHOLECEREBNORM']

    slope_data = {'WHOLECEREBELLUM':slope(zip(years,list(rows['WHOLECEREBELLUM'].divide(brainstem)))),
                  'FRONTAL':slope(zip(years,list(rows['FRONTAL'].divide(brainstem)))),
                  'CINGULATE':slope(zip(years,list(rows['CINGULATE'].divide(brainstem)))),
                  'PARIETAL':slope(zip(years,list(rows['PARIETAL'].divide(brainstem)))),
                  'TEMPORAL':slope(zip(years,list(rows['TEMPORAL'].divide(brainstem)))),
                  'COMPOSITE':slope(zip(years,list(rows['COMPOSITE'].divide(brainstem)))),
                  'SUMMARYSUVR_WHOLECEREBNORM':slope(zip(years,list(rows['SUMMARYSUVR_WHOLECEREBNORM']))),
                  'INCREASER': 1 if suvr_slope > 0 else 0,
                  'BL_SUVR': bl_suvr,
                  'BL_POSITIVE': 1 if bl_suvr > 1.11 else 0,
                  'RID': rid}
    slopes.append(slope_data)
示例#8
0
    def get_max_point(self):
        m = slope(self.points[0], self.points[1])
        if m > 0:
            return self.points[1]

        return self.points[0]