omegat = np.arange(0, 360, 1) a, b = orientation(lK, Rg, alpha, betas, beta, delta, omegat, pos) alpha = a betas = b Ma = np.mean(Marzsum(lK, Rg, a, b, beta, delta, omegat, pos)) Mg = np.mean(Marzsum(lK, Rg, a, b, beta, delta, omegat, pos)) return alpha, betas, Ma, Mg def Marzmean0(lK, Rg, alpha, betas, beta, delta): pos = np.array([0, 0.5 * np.pi, np.pi, 1.5 * np.pi]) omegat = np.arange(0, 360, 1) return np.mean(Marzsum(lK, Rg, alpha, betas, beta, delta, omegat, pos)) vMarzmean = np.vectorize(Marzmean) vMarzmean0 = np.vectorize(Marzmean0) f, (ax1, ax2) = plt.subplots(1, 2) alpha = np.radians(60) # 90 - beta | 62.3608549873 betas = np.radians(0) # 4.38381787735 lK = 2 Rg = 1 N = 4 delta = np.arange(0, 181, 1) beta = np.radians(30) a, b, Ma, Mg = vMarzmean(lK, Rg, alpha, betas, beta, np.radians(delta)) ax1.plot(delta, np.degrees(a), 'r', label=r"\$\alpha\$")
from __future__ import unicode_literals import datetime import json from analyzer.models import Project from django.contrib.postgres.fields import JSONField from django.db import models import pandas as pd from collections import defaultdict, OrderedDict # Create your models here. from administrator.models import SSHKey from pylab import np dateconv = np.vectorize(datetime.datetime.fromtimestamp) class ProjectGraphiteSettings(models.Model): project = models.ForeignKey(Project, on_delete=models.CASCADE) name = models.CharField(max_length=1000, default="") value = models.CharField(max_length=10000, default="") class Meta: db_table = 'project_graphite_settings' unique_together = (('project', 'value')) class Proxy(models.Model): port = models.IntegerField(default=0) pid = models.IntegerField(default=0) destination = models.CharField(max_length=200, default="https://dest") destination_port = models.IntegerField(default=443) delay = models.FloatField() started = models.BooleanField(default=False) class Meta:
def plot_customer_firm_choices(self, period=50): # Data positions = self.results["positions"][-period:] prices = self.results["prices"][-period:] n_firms = len(self.results["positions"][0]) customer_firm_choices = self.results["customer_firm_choices"][-period:] t_max, n_positions = customer_firm_choices.shape # Create fig and axes fig = plt.figure(figsize=(t_max, n_positions)) gs = gridspec.GridSpec(24, 20) ax = fig.add_subplot(gs[:20, :20]) ax2 = fig.add_subplot(gs[-1, 8:12]) # Prepare normalization for 'imshow' mapping = dict([(x, y) for x, y in zip(np.arange(-1, n_firms), np.linspace(0, 1, n_firms + 1))]) f_mapping = lambda x: mapping[x] # Function adapted for numpy array v_func = np.vectorize(f_mapping) # Format customer choices (reordering + normalization) formatted_customer_firm_choices = v_func(customer_firm_choices.T[::-1]) # Colors for different firms firm_colors = cm.ScalarMappable(norm=None, cmap="gist_rainbow").to_rgba( np.linspace(0, 1, n_firms)) # Prepare customized colormap colors = np.zeros((n_firms + 1, 4)) colors[0] = 1, 1, 1, 1 # White colors[1:] = firm_colors cmap_name = "manual_colormap" n_bins = n_firms + 1 manual_cm = LinearSegmentedColormap.from_list(cmap_name, colors, N=n_bins) # Plot customer choices ax.imshow(formatted_customer_firm_choices, interpolation='nearest', origin="lower", norm=NoNorm(), alpha=0.5, cmap=manual_cm) # Offsets for positions plot and prices plot offsets = np.linspace(-0.25, 0.25, n_firms) # Plot positions for i in range(n_firms): ax.plot(np.arange(t_max) + offsets[i], n_positions - positions[:, i], "o", color=firm_colors[i], markersize=10) # Plot prices for t in range(t_max): for i in range(n_firms): ax.text(t + offsets[i] - 0.1, n_positions - positions[t, i] + 0.2, prices[t, i]) # Customize axes ax.set_xlim(-0.5, t_max - 0.5) ax.set_ylim(-0.5, n_positions - 0.5) # Add grid (requires to customize axes) ax.set_yticks(np.arange(0.5, n_positions - 0.5, 1), minor=True) ax.set_xticks(np.arange(0.5, t_max - 0.5, 1), minor=True) ax.grid(which='minor', axis='y', linewidth=2, linestyle=':', color='0.75') ax.grid(which='minor', axis='x', linewidth=2, linestyle='-', color='0.25') # After positioning grid, replace ticks for placing labels ax.set_xticks(range(t_max)) ax.set_yticks(range(n_positions)) # Top is position 1. ax.set_yticklabels(np.arange(1, n_positions + 1)[::-1]) # Set axes labels ax.set_xlabel('t', fontsize=14) ax.set_ylabel('Position', fontsize=14) # Remove ticks ax.xaxis.set_ticks_position('none') ax.yaxis.set_ticks_position('none') # Legend possibilities = v_func(np.arange(-1, n_firms)) ax2.imshow(np.atleast_2d(possibilities), interpolation='nearest', origin="lower", norm=NoNorm(), cmap=manual_cm) # Customize ticks ax2.xaxis.set_ticks_position('none') ax2.yaxis.set_ticks_position('none') ax2.set_yticks([]) lab = [str(i) for i in np.arange(-1, n_firms)] ax2.set_xticks(np.arange(n_firms + 1)) ax2.set_xticklabels(lab) plt.savefig(self.format_fig_name("customers_choices")) plt.close()
return np.sqrt(ltx * ltx + lty * lty + ltz * ltz) # min tether length over cycle def ltmin(lK, Rg, beta, delta): omegat = np.arange(0, 360, 1) return np.amin(lt(lK, Rg, beta, delta, omegat)) # max tether length over cycle def ltmax(lK, Rg, beta, delta): omegat = np.arange(0, 360, 1) return np.amax(lt(lK, Rg, beta, delta, omegat)) vltfreemin = np.vectorize(ltfreemin) vltfreemax = np.vectorize(ltfreemax) vltmin = np.vectorize(ltmin) vltmax = np.vectorize(ltmax) f, (ax1, ax2) = plt.subplots(1, 2) lK = 2 Rg = 1 beta = np.radians(np.arange(0, 91, 1)) delta = np.radians(0) ax1.plot(np.degrees(beta), vltmax(lK, Rg, beta, delta), 'r') ax1.plot(np.degrees(beta), vltmin(lK, Rg, beta, delta), 'b') #print 'ltmin & ltmax ', ltmin(lK, Rg, np.radians(30), delta), ltmax(lK, Rg, np.radians(30), delta) delta = np.radians(30) ax1.plot(np.degrees(beta), vltmax(lK, Rg, beta, delta), 'r')