コード例 #1
0
ファイル: constraint.py プロジェクト: wdan/territories
 def get_constraint(self, degree):
     degree = min(degree, 3)
     (xA, yA) = interp(self.mid_x, self.mid_y, self.x1, self.y1, degree *
                       self.C)
     (xB, yB) = interp(self.mid_x, self.mid_y, self.x2, self.y2, degree *
                       self.C)
     return (xA, yA, xB, yB)
コード例 #2
0
ファイル: constraint.py プロジェクト: wdan/territories
 def get_constraint(self, degree):
     degree = min(degree, 3)
     (xA, yA) = interp(self.mid_x, self.mid_y, self.x1, self.y1,
                       degree * self.C)
     (xB, yB) = interp(self.mid_x, self.mid_y, self.x2, self.y2,
                       degree * self.C)
     return (xA, yA, xB, yB)
コード例 #3
0
ファイル: polygon.py プロジェクト: wdan/territories
 def add_edge(self, x1, y1, x2, y2, tgt_cluster_id):
     edge_dict = {}
     (xA, yA) = interp(self.mid_x, self.mid_y, x1, y1, self.shrink)
     (xB, yB) = interp(self.mid_x, self.mid_y, x2, y2, self.shrink)
     edge_dict["x1"] = xA
     edge_dict["y1"] = yA
     edge_dict["x2"] = xB
     edge_dict["y2"] = yB
     c = None
     for item in tgt_cluster_id:
         c = item
     edge_dict["tgt_cluster"] = c
     self.edge_list.append(edge_dict)
コード例 #4
0
ファイル: polygon.py プロジェクト: wdan/territories
 def add_edge(self, x1, y1, x2, y2, tgt_cluster_id):
     edge_dict = {}
     (xA, yA) = interp(self.mid_x, self.mid_y, x1, y1, self.shrink)
     (xB, yB) = interp(self.mid_x, self.mid_y, x2, y2, self.shrink)
     edge_dict["x1"] = xA
     edge_dict["y1"] = yA
     edge_dict["x2"] = xB
     edge_dict["y2"] = yB
     c = None
     for item in tgt_cluster_id:
         c = item
     edge_dict["tgt_cluster"] = c
     self.edge_list.append(edge_dict)
コード例 #5
0
def start(input, output):

    valArr = np.zeros([ROW, COL])

    with open(input, 'rb') as f:
        for i in range(ROW):
            for j in range(COL):
                val = list(struct.unpack(">1f", f.read(4)))[0]
                valArr[i][j] = float(val)

    interpVal = U.interp(valArr, tX, tY)

    valTable = interpVal.flatten()

    img = Image.new("RGBA", resolution + 1, (0, 0, 0, 0))

    length = len(latTable)

    for i in range(length):

        val = valTable[i]

        img.putpixel(mercatorMap[i], COLOR.color1(val))

    img = CUT.cut(img)

    img = LEGEND.draw(img, 'l1')

    img.save(output + ".png", 'PNG')
コード例 #6
0
ファイル: polygon.py プロジェクト: wdan/territories
 def points(self, shrink):
     points = []
     min_y = sys.maxint
     index = -1
     self.edge_list.reverse()
     for i, e in enumerate(self.edge_list):
         if e["y1"] < min_y:
             min_y = e["y1"]
             index = i
     self.edge_list = rotate(self.edge_list, index)
     for e in self.edge_list:
         (t_x, t_y) = interp(self.mid_x, self.mid_y, e["x1"], e["y1"], shrink)
         points.append({"x": t_x, "y": t_y})
     return points
コード例 #7
0
ファイル: polygon.py プロジェクト: wdan/territories
 def points(self, shrink):
     points = []
     min_y = sys.maxint
     index = -1
     self.edge_list.reverse()
     for i, e in enumerate(self.edge_list):
         if e["y1"] < min_y:
             min_y = e["y1"]
             index = i
     self.edge_list = rotate(self.edge_list, index)
     for e in self.edge_list:
         (t_x, t_y) = interp(self.mid_x, self.mid_y, e["x1"], e["y1"],
                             shrink)
         points.append({"x": t_x, "y": t_y})
     return points
コード例 #8
0
with open(latlonPath, 'rb') as f:

    for i in range(ROW):
        for j in range(COL):
            val = list(struct.unpack(">1f", f.read(4)))[0]
            latArr[i][j] = float(val)

    for i in range(ROW):
        for j in range(COL):
            val = list(struct.unpack(">1f", f.read(4)))[0]
            lonArr[i][j] = float(val)

tX = np.linspace(0, COL - 1, COL * _P, False)
tY = np.linspace(0, ROW - 1, ROW * _P, False)

interpLat = U.interp(latArr, tX, tY)
interpLon = U.interp(lonArr, tX, tY)

latTable = interpLat.flatten()
lonTable = interpLon.flatten()

upLeft = U.mercator(min(lonTable), max(latTable))
downRight = U.mercator(max(lonTable), min(latTable))
resolution = downRight - upLeft

length = len(latTable)

mercatorMap = np.zeros([length, 2], dtype=np.int)

for i in range(length):
    mercatorMap[i] = U.mercator(lonTable[i], latTable[i]) - upLeft
コード例 #9
0
        # Time interpolation
        for key, value in grib_data.items():
            for key2, value2 in value.items():
                for key3, value3 in value2.parameters.items():
                    try:
                        if grib_data_future[key][key2].parameters[
                                key3].data != '--' and value3.data != '--':
                            x1 = float(0)
                            x2 = datetime.timedelta(hours=3).total_seconds()
                            x_res = (grib_data_future_timestamp -
                                     entry.timestamp).total_seconds()

                            grib_data[key][key2].parameters[
                                key3].data = util.interp(
                                    x1, x2, value3.data, grib_data_future[key]
                                    [key2].parameters[key3].data, x_res)
                    except:
                        print('Key Error')

        # Geo interpolation
        tl_lat = util.round_to_nearest_quarter_up(entry.latitude)
        tl_long = util.round_to_nearest_quarter_down(entry.longitude)
        bl_lat = util.round_to_nearest_quarter_down(entry.latitude)
        bl_long = tl_long
        tr_lat = tl_lat
        tr_long = util.round_to_nearest_quarter_up(entry.longitude)
        br_lat = bl_lat
        br_long = tr_long

        tl_grib_values = grib_data[(tl_lat, tl_long)]