def plot_timeVfreq(date_operator, collection): if collection == "drop": field = "pickup_time" elif collection == "pickup": field = "drop_time" else: raise Exception( "Error: the collection arguments to timeVfreq are 'drop', or 'pickup'. Not", collection) graph_size = {"hour": (0, 23), "dayOfYear": (1, 366), "dayOfWeek": (1, 8)} if date_operator not in graph_size.keys(): raise Exception( "Error: the date_operator argument to timeVfreq must be 'hour', 'dayOfWeek', or 'dayOfYear'. Not", date_operator) tvf = get_timeVfreq(date_operator, collection, field) min_freq = ndarray.min(tvf[1]) max_freq = ndarray.max(tvf[1]) fig = pyplot.figure(1, figsize=(7, 6)) myplot = fig.add_subplot(111) myplot.set_xlim(graph_size[date_operator]) norm = colors.Normalize(min_freq, max_freq) for i in range(len(tvf[0])): color = colors.rgb2hex(cm.cool(norm(tvf[1][i]))) pyplot.bar(tvf[0][i], tvf[1][i], color=color, ec=color, align='edge') pyplot.xlabel(date_operator) pyplot.ylabel("# of rides") pyplot.savefig(date_operator + "_" + collection, dpi=180)
def plot_timeVfreq(date_operator, collection): if collection == "drop": field = "pickup_time" elif collection == "pickup": field = "drop_time" else: raise Exception("Error: the collection arguments to timeVfreq are 'drop', or 'pickup'. Not", collection) graph_size = {"hour":(0, 23), "dayOfYear":(1,366), "dayOfWeek":(1,8)} if date_operator not in graph_size.keys(): raise Exception("Error: the date_operator argument to timeVfreq must be 'hour', 'dayOfWeek', or 'dayOfYear'. Not", date_operator) tvf = get_timeVfreq(date_operator, collection, field) min_freq = ndarray.min(tvf[1]) max_freq = ndarray.max(tvf[1]) fig = pyplot.figure(1, figsize=(7, 6)) myplot = fig.add_subplot(111) myplot.set_xlim(graph_size[date_operator]) norm = colors.Normalize(min_freq, max_freq) for i in range(len(tvf[0])): color = colors.rgb2hex(cm.cool(norm(tvf[1][i]))) pyplot.bar(tvf[0][i], tvf[1][i], color=color, ec=color, align='edge') pyplot.xlabel(date_operator) pyplot.ylabel("# of rides") pyplot.savefig(date_operator + "_" + collection, dpi=180)
def min(self, *args, **kwargs): """ Returns the minimum Date. For a description of the input parameters, please refer to numpy.min. """ obj = ndarray.min(self, *args, **kwargs) if not obj.shape: return Date(self.freq, obj) return obj
def BackgroundImage(request): chad = User.objects.get(id=1) image = ThreeDimensional.objects.filter(user=chad)[0] image_handle = nibabel.load(image.brain_image.file.name) image_data = image_handle.get_data() image_list_data = image_data.tolist() #for some reason ndarray.max returns an ndarray with 1 member #which is a numpy.flaot32. this converts all that to a regular python float max = ndarray.max(image_data).tolist() min = ndarray.min(image_data).tolist() json_object = { 'data' : image_list_data, 'max' : max, 'min' : min, } json_data = json.dumps(json_object) return HttpResponse(json_data, mimetype='application/json')
def main_test(): # As a main function, this function tests other functions written in domain_functions.py: # - compute triangulation of domain # - nodes = np.array([[0., 0.], [0., 10.], [15., 10.], [15., 0.], [6., 10.], [9., 10.], [11., 0.], [2., 8.], [8., 7.], [11., 2.], [5., 5.]]) tri = spatial.Delaunay(nodes) print '' print 'Entered points, triangles by vertex, and neighbors:' print tri.points # Numbering of the points is in order of input print '' print tri.simplices # From point numbers, give the triangles, starting with # 0 print '' print tri.neighbors # Give the triangle number of neighbors, and -1 for boundary # Test which triangle: # print tri.find_simplex(np.array([2., 2.])) # Choose a simplex and facet control idx: num = 0 facet_id = 0 # Extract points: points = tri.points vertices = tri.simplices vertices_here = vertices[num, :] print '' print 'vertices_here:' print vertices_here # Extract normals: nhat_array = nhat_tri_facet(tri, num) print '' print 'Local normal vectors:' print nhat_array u_optimal, fg_array = u_for_F_v1(tri, num, 0.01, np.eye(2), facet_id) u_stay, fg_array_stay = u_for_stay_v1(tri, num, 0.01, np.eye(2)) print '' print 'Optimal u at each vertex:' print u_optimal print '' print 'fg_array for select triangle and facet:' print fg_array print '' print 'Optimal u to stay:' print u_stay fg_master_array = fg_for_domain(tri, 0.01, np.eye(2), 2) print '' print 'fg_master_array:' print fg_master_array x_array = points[vertices_here, 0] y_array = points[vertices_here, 1] x_lim = np.array([ndarray.min(x_array), ndarray.max(x_array)]) y_lim = np.array([ndarray.min(y_array), ndarray.max(y_array)]) domain_plot = 1 control_plot = 1 # Plot partitioning of domain: if domain_plot == 1: plt.rc('text', usetex=True) plt.rc('font', family='serif') plt.triplot(nodes[:, 0], nodes[:, 1], tri.simplices.copy()) plt.plot(nodes[:, 0], nodes[:, 1], 'o') plt.title('Partitioned Domain') plt.grid(linestyle="--", linewidth=0.1, color='.25', zorder=-10) # Quiver velocity field to leave selected triangle: if control_plot == 1: X, Y = np.meshgrid(np.arange(x_lim[0] - 0.5, x_lim[1] + 0.5, 0.5), np.arange(y_lim[0] - 0.5, y_lim[1] + 0.5, 0.5)) U = fg_array[0, 0] * X + fg_array[0, 1] * Y + fg_array[0, 2] V = fg_array[1, 0] * X + fg_array[1, 1] * Y + fg_array[1, 2] fig = plt.figure() ax = fig.add_subplot(1, 1, 1) plt.rc('text', usetex=True) plt.rc('font', family='serif') plt.title( 'Control Vector Field for Chosen Simplex - Exit Chosen Facet') ax.triplot(nodes[:, 0], nodes[:, 1], tri.simplices.copy()) ax.plot(nodes[:, 0], nodes[:, 1], 'o') ax.quiver(X, Y, U, V) ax.grid(linestyle="--", linewidth=0.1, color='.25', zorder=-10) # ax.set_xlim(x_lim) # ax.set_ylim(y_lim) X, Y = np.meshgrid(np.arange(x_lim[0] - 0.5, x_lim[1] + 0.5, 0.5), np.arange(y_lim[0] - 0.5, y_lim[1] + 0.5, 0.5)) U = fg_array_stay[0, 0] * X + fg_array_stay[0, 1] * Y + fg_array_stay[ 0, 2] V = fg_array_stay[1, 0] * X + fg_array_stay[1, 1] * Y + fg_array_stay[ 1, 2] fig = plt.figure() ax = fig.add_subplot(1, 1, 1) plt.rc('text', usetex=True) plt.rc('font', family='serif') plt.title('Control Vector Field for Chosen Simplex - Remain') ax.triplot(nodes[:, 0], nodes[:, 1], tri.simplices.copy()) ax.plot(nodes[:, 0], nodes[:, 1], 'o') ax.quiver(X, Y, U, V) ax.grid(linestyle="--", linewidth=0.1, color='.25', zorder=-10) # ax.set_xlim(x_lim) # ax.set_ylim(y_lim) if (domain_plot == 1) or (control_plot == 1): plt.show() return # Execute test: # main_test()