Example #1
0
    def add_points_on_rings(self, areas):
        for polygon in areas:
            for ring in (polygon.exterior, ) + tuple(polygon.interiors):
                for linestring in assert_multilinestring(
                        ring.intersection(self.clear_geometry)):
                    coords = tuple(linestring.coords)
                    if len(coords) == 2:
                        path = Path(coords)
                        length = abs(
                            np.linalg.norm(path.vertices[0] -
                                           path.vertices[1]))
                        for coord in tuple(
                                path.interpolated(int(length / 1.0 +
                                                      1)).vertices):
                            self.add_point(coord)
                        continue

                    start = 0
                    for segment in zip(coords[:-1], coords[1:]):
                        path = Path(segment)
                        length = abs(
                            np.linalg.norm(path.vertices[0] -
                                           path.vertices[1]))
                        if length < 1.0:
                            coords = (path.vertices[1 if start == 0 else 0], )
                        else:
                            coords = tuple(
                                path.interpolated(int(length / 1.0 +
                                                      0.5)).vertices)[start:]
                        for coord in coords:
                            self.add_point(coord)
                        start = 1
Example #2
0
 def transform_path_non_affine(self, path):
     # Adaptive interpolation:
     # we keep adding control points, till all control points
     # have an error of less than 0.01 (about 1%)
     # or if the number of control points is > 80.
     ra0 = self.ra0
     path = path.cleaned(curves=False)
     v = path.vertices
     diff = v[:, 0] - v[0, 0]
     v00 = v[0][0] - ra0
     while v00 > 180:
         v00 -= 360
     while v00 < -180:
         v00 += 360
     v00 += ra0
     v[:, 0] = v00 + diff
     nonstop = path.codes > 0
     path = Path(v[nonstop], path.codes[nonstop])
     isteps = int(path._interpolation_steps * 1.5)
     if isteps < 10: isteps = 10
     while True:
         ipath = path.interpolated(isteps)
         tiv = self.transform(ipath.vertices)
         itv = Path(self.transform(
             path.vertices)).interpolated(isteps).vertices
         if np.mean(np.abs(tiv - itv)) < 0.01:
             break
         if isteps > 20:
             break
         isteps = int(isteps * 1.5)
     return Path(tiv, ipath.codes)
Example #3
0
 def transform_path_non_affine(self, path):
     # Adaptive interpolation:
     # we keep adding control points, till all control points
     # have an error of less than 0.01 (about 1%)
     # or if the number of control points is > 80.
     ra0 = self.ra0
     path = path.cleaned(curves=False)
     v = path.vertices
     diff = v[:, 0] - v[0, 0]
     v00 = v[0][0] - ra0
     while v00 > 180: v00 -= 360
     while v00 < -180: v00 += 360
     v00 += ra0
     v[:, 0] = v00 + diff
     nonstop = path.codes > 0
     path = Path(v[nonstop], path.codes[nonstop])
     isteps = path._interpolation_steps * 2
     while True:
         ipath = path.interpolated(isteps)
         tiv = self.transform(ipath.vertices)
         itv = Path(self.transform(path.vertices)).interpolated(isteps).vertices
         if np.mean(np.abs(tiv - itv)) < 0.01:
             break
         if isteps > 20:
             break
         isteps = isteps * 2
     return Path(tiv, ipath.codes)
    plot_data[cell.y - 1][cell.x - 1] = (cell[0] - cell[1])

figure, axis = plot.subplots(figsize=(6, 7))

newset = trackset.get_tracks_random(1)

max_biomass = numpy.amax(newset.biomasses())

track = newset[0]

area = numpy.pi * (5)**2 # dot radius of 5
plot.scatter(track.x[0]/25, track.y[0]/25, c="green", s=area, zorder=3)
plot.scatter(track.x[-1]/25, track.y[-1]/25, c="red", s=area, zorder=3)

path = Path(numpy.column_stack([track.x/25, track.y/25]))
verts = path.interpolated(steps=3).vertices
x, y = verts[:, 0], verts[:, 1]
data = numpy.true_divide(track.biomasses, max_biomass)
axis.add_collection(colorline(x, y, data))

axis.set_title("Lifetime - Biomass")
axis.set_xlim([0, 100])
axis.set_ylim([0, 100])

figure.subplots_adjust(bottom=0.235)
colorbar_axis = figure.add_axes([0.15, .12, .73, .05])

grid_image = axis.imshow(plot_data, interpolation='none', origin="lower", cmap=plot.get_cmap("Blues_r"), vmin=-1, vmax=1, extent=[0, 100, 0, 100], aspect="equal")
colorbar = plot.colorbar(grid_image, cax=colorbar_axis, orientation='horizontal')
colorbar.set_ticks([-1, 0, 1])
colorbar.set_ticklabels([-1, 0, 1])
# ax.plot(longitudes, latitudes, altitudes)
# ax.set_xlabel('Longitude')
# ax.set_ylabel('Latitude')
# ax.set_zlabel('Altitude')

# fig = plt.figure()
# ax = fig.gca(projection='3d')
# N = len(longitudes)
# for i in range(N - 1):
#     ax.plot(longitudes[i:i + 2], latitudes[i:i + 2], altitudes[i:i + 2], color=plt.cm.jet(int(255 * i / N)))
# ax.set_xlabel('Longitude')
# ax.set_ylabel('Latitude')
# ax.set_zlabel('Altitude')

codes = [Path.MOVETO] + [Path.LINETO] * (len(vertices) - 1)
path = Path(vertices, codes)
verts = path.interpolated(steps=3).vertices
x, y = verts[:, 0], verts[:, 1]
fig, ax = plt.subplots()
ax.set_xlim(min(longitudes) - 1, max(longitudes) + 1)
ax.set_ylim(min(latitudes) - 1, max(latitudes) + 1)
z = np.linspace(0, 1, len(x))
colorline(x, y, z, cmap=plt.get_cmap('jet'), linewidth=2)

plt.figure()
plt.xlabel('Timestamp')
plt.ylabel('Altitude')
plt.plot(timestamps, altitudes, '.', markersize=0.5)

plt.show()