Beispiel #1
0
    def plot_model(self,
                   ax,
                   I0,
                   R,
                   b0,
                   a0,
                   model_kind=None,
                   dimless=True,
                   rdf=True,
                   bg=False):
        plt.rc('text', usetex=True)
        plt.rc('font', family='serif', size=12)

        if ax is None:
            ax = plt.gca()

        if model_kind is None:
            model_kind = SprModelRadial._model_spr

        q0, qn = self.q[0, 0], self.q[-1, 0]
        q = np.linspace(q0, qn, 300).reshape(300, 1)
        q1 = np.linspace(0, q0, 50).reshape(50, 1)

        I = self.model_q(I0, R, q, model_kind) + a0 * np.interp(
            q, self.q.flat, self.b.flat) + b0
        I1 = self.model_q(I0, R, q1, model_kind) + a0 * self.b[0, 0] + b0
        #q = q.reshape(200,1)
        #print("I", I.shape)
        #print("q", q.shape)

        dq = (7.72525183693770716 - 4.49340945790906418) / (math.pi * R) / 9
        if dq < self.dq:
            dq = self.dq

        qr, v, sv, b, sb, nn = SprModelRadial._rdf(self.qi, dq, self.vi,
                                                   self.bi, self.si, self.ei)

        if dimless:
            q = q * R
            q1 = q1 * R
            qr = qr * R
            ax.set_xlabel("$q$")
        else:
            #q = self.q
            ax.set_xlabel("$q, \mathrm{\AA}^{-1}$")

        #idx = I > 0.
        ax.semilogy(q, I - b0, 'C0', linewidth=2)
        ax.semilogy(q1, I1 - b0, 'C0:', linewidth=2)
        if rdf:
            idx = v > 0.
            ax.semilogy(qr, v - b0, 'C1--', linewidth=2)
        if bg:
            idx = b > 0.
            ax.semilogy(qr, a0 * b, 'C2', linewidth=2)

        ax.set_xlim(0, q[-1])
        ax.set_ylabel("$I, \mathrm{photons}$")
Beispiel #2
0
    def plot_model(self,
                   ax,
                   I0,
                   R,
                   b0,
                   a0,
                   model_kind=None,
                   dimless=True,
                   rdf=True,
                   bg=False):

        if ax is None:
            ax = plt.gca()

        if model_kind is None:
            model_kind = SprModelRadial._model_spr

        q0, qn = self.q[0, 0], self.q[-1, 0]
        q = np.linspace(q0, qn, 1000).reshape(1000, 1)
        q1 = np.linspace(0, q0, 50).reshape(50, 1)

        I = self.model_q(
            I0, R, q, model_kind)  #+ a0*np.interp(q, self.q.flat, self.b.flat)
        I1 = self.model_q(I0, R, q1, model_kind) + a0 * self.b[0, 0]

        dq = (7.72525183693770716 - 4.49340945790906418) / (math.pi * R) / 21
        if dq < self.dq:
            dq = self.dq

        qr, v, sv, b, sb, nn = SprModelRadial._rdf(self.qi, dq, self.vi,
                                                   self.bi, self.si, self.ei)

        if dimless:
            q = q * R
            q1 = q1 * R
            qr = qr * R
            ax.set_xlabel("$q$")
        else:
            #q = self.q
            ax.set_xlabel("$q, \mathrm{nm}^{-1}$")

        #idx = I > 0.
#        ax.semilogy(q, I-b0, 'C0', linewidth=2)
        ax.semilogy(q * 10, I, 'C0', linewidth=2)
        #ax.semilogy(q1, I1-b0, 'C0:', linewidth=2)
        if rdf:
            idx = v > 0.
            #ax.semilogy(qr, v-b0, 'C1--', linewidth=2)
            ax.semilogy(qr * 10, v - b0, 'C1--', linewidth=2)
        if bg:
            idx = b > 0.
            ax.semilogy(qr * 10, a0 * b, 'C2', linewidth=2)
#            ax.semilogy(qr, a0*b, 'C2', linewidth=2)

#ax.set_xlim(0, q[-1])
        ax.set_ylabel("$I, \mathrm{photons/pixel}$")
Beispiel #3
0
 def plot(self, ax=None):
     x = [*self.times, self.times[-1] + self.values[-1][1]]
     y = [*(v for v, d in self.values), self.values[-1][0]]
     from matplotlib.pylab import plt
     if ax is None:
         ax = plt.gca()
     ax.step(x, y, where='post')
     ax.set_xlabel('Time (seconds)')
     y_ticks = list(map(int, plt.yticks()[0]))
     ax.set_yticks(y_ticks, list(map(self.format_value.format, y_ticks)))
Beispiel #4
0
def plotJoinTree(real_acts, pred_acts):
    from pandas.plotting import register_matplotlib_converters
    register_matplotlib_converters()
    size = 0.45

    if (len(real_acts) == 0):
        print('real not enough data of this type')
        print(real_acts)
        return
    if (len(pred_acts) == 0):
        #pred_acts=pred_acts.append({'StartTime':real_acts.StartTime.iloc[0],'EndTime':real_acts.EndTime.iloc[0],'Activity':real_acts.Activity.iloc[0]},ignore_index=True)
        print('pred not enough p data of this type')
        print(pred_acts)
        return

    rstart = [r.begin for r in real_acts]
    rend = [r.end for r in real_acts]
    ract = [1 + (size / 2) for r in real_acts]
    # .apply(lambda x:dataset.activities_map[x.Activity], axis=1).tolist()

    pstart = [r.begin for r in pred_acts]
    pend = [r.end for r in pred_acts]
    pact = [1 - (size / 2) for r in pred_acts]
    ax = plt.gca()

    _plotActs(ax,
              ract,
              rstart,
              rend,
              linewidth=1,
              edgecolor='k',
              facecolor='g',
              size=size,
              alpha=.6)

    _plotActs(ax,
              pact,
              pstart,
              pend,
              linewidth=1,
              edgecolor='k',
              facecolor='r',
              size=size,
              alpha=.6)

    ax.set_xticks([])
    ax.set_xlim(min(pstart + rstart), max(pend + rend))
    ax.set_yticks([i for i in [1]])
    ax.yaxis.grid(True)

    #   ax.set_yticklabels([l for l in labels])
    ax.set_ylim(1 - size, 1 + size)
    plt.margins(0.1)
Beispiel #5
0
    def plot(self, ax=None, **kwargs):
        """plot using matplotlib

        : param ax: The axis to plot on(default is plt.gca())
        : param ** kwargs: Additional keyword arguments passed on to plt.Polygon.
        """
        if ax is None:
            ax = plt.gca()

        patch_args = dict(
            alpha=0.5,
            fill=False,
            color='r',
        )
        patch_args.update(kwargs)
        ax.add_patch(plt.Polygon(self.points(), **patch_args))
Beispiel #6
0
    def plot_rdf(self, ax, R=None):
        plt.rc('text', usetex=True)
        plt.rc('font', family='serif', size=12)

        if ax is None:
            ax = plt.gca()

        idx = self.v > 0.
        if R is None:
            ax.loglog(self.q[idx], self.v[idx])
            ax.loglog(self.q[idx], self.v[idx] + self.sv[idx] + self.sb[idx])
            ax.set_xlabel("$q, \mathrm{\AA}^{-1}$")
        else:
            ax.loglog(self.q[idx] * R, self.v[idx])
            ax.loglog(self.q[idx], self.v[idx] + self.sv[idx] + self.sb[idx])
            ax.set_xlabel("$q$")

        ax.set_ylabel("$I, \mathrm{photon}/\mathrm{\AA}^{-2}$")
Beispiel #7
0
def anim_daily_total(data, file_name, kind="cases", minlim=1):
    fig = plt.figure()
    FFMpegWriter = manimation.writers['ffmpeg']
    metadata = dict(title='Corona virus temp evolution',
                    artist='Sylvain Guieu',
                    comment='https://github.com/SylvainGuieu/corona')
    writer = FFMpegWriter(fps=6, metadata=metadata)

    subset = data

    perday = subset.cases.iloc[:, 1:] - np.asarray(subset.cases.iloc[:, 0:-1])
    perday = perday.rolling(4, center=True, axis=1).mean()
    total = subset.cases.iloc[:, 1:]
    mdates = range(2,
                   len(total.iloc[0]) + 1)  # add 1 iddentical graph for pause
    axes = plt.gca()
    xlm = np.nanmax(np.asarray(total), axis=None) * 2
    ylm = np.nanmax(np.asarray(perday), axis=None) * 2
    print(xlm)
    with writer.saving(fig,
                       os.path.join(root, file_name) + ".mp4", len(mdates)):
        for mdate in mdates:
            axes.clear()
            pd1 = perday.subset(end=mdate)
            ttl = total.subset(end=mdate)
            for name, r in pd1.iterrows():
                axes.plot(ttl.loc[name], r, label=name, **styles.get(name, {}))
                axes.plot(ttl.loc[name].iloc[-1], r.iloc[-1], 'k*')
            axes.legend(loc='upper left')
            axes.set(yscale="log",
                     xscale="log",
                     xlabel="Total %s" % kind,
                     ylabel="Daily %s" % kind,
                     xlim=(minlim, xlm),
                     ylim=(minlim, ylm),
                     title=r.index[-1])
            writer.grab_frame()
            print(".", end="")
    print('')
    subprocess.run(
        f"ffmpeg -y -i {root}/{file_name}.mp4 -vf \"fps=10,scale=800:-1:flags=lanczos\" -loop 999 {root}/{file_name}.gif",
        shell=True)
Beispiel #8
0
def ncp(s2n):
    """
    Explore the output of BB as we change the prior on the number of
    change points
    """
    
    nncp = logspace(0.5,1.5,9)
    
    f,t = keptoy.lightcurve(s2n=s2n)
    sig = zeros(len(t)) + std(f)

    for i in range( len(nncp) ):
        last,val = find_blocks.pt( t,f,sig,ncp=nncp[i] )
        blocks(t,f,last,val)
        
        ax = plt.gca()
        ax.set_title('s2n - %.1e, cpts prior - %.2e' % (s2n,nncp[i]) )
        fig = plt.gcf()

        fig.savefig('frames/s2n-%.1e_%02d.png' % (s2n,i) )
        plt.show()
Beispiel #9
0
def plot_graph(g, ax=None, with_labels=True):
    from matplotlib.pylab import plt
    if ax is None:
        ax = plt.gca()
    ax.set_facecolor('lightgray')
    edges = np.array(g.edges())
    edge_scores = np.array([a['score'] for a in g.edges().values()])
    # edge_scores = np.log(edge_scores)
    # edge_scores += edge_scores.min()
    order = np.argsort(edge_scores)

    nx.draw_networkx_nodes(
        g,
        nx.get_node_attributes(g, 'xy'),
        ax=ax,
        node_size=30,
        font_size=9,
        font_color='blue',
        with_labels=with_labels,
    )
    edges = nx.draw_networkx_edges(g,
                                   nx.get_node_attributes(g, 'xy'),
                                   ax=ax,
                                   edgelist=edges[order].tolist(),
                                   edge_color=edge_scores[order],
                                   edge_cmap=plt.cm.gray_r,
                                   node_size=30,
                                   edge_vmin=edge_scores[order[0]],
                                   edge_vmax=edge_scores[order[-1]],
                                   font_size=9,
                                   font_color='blue',
                                   with_labels=with_labels,
                                   connectionstyle='arc3,rad=0.2')

    ax.set_aspect('equal')

    return edges
Beispiel #10
0

import matplotlib
from matplotlib.pylab import plt #load plot library
matplotlib.use('Agg')
from sys import stdout
import sys


filepath = str(sys.argv[1])
print('Reading file ', filepath)

plt.figure(1, figsize = (50,20))
axes = plt.gca()
plt.gca().set_aspect('auto')

vector_l = 2000
bin_size = 0
x_size = vector_l
y_size = 500

axes.set_xlim(0, x_size)

word_hash = "none"
frequency = 0
seq_len = 0

count = 0

xdata_prev = 0
ydata_prev = 0
Beispiel #11
0
import matplotlib
from matplotlib.pylab import plt  #load plot library
matplotlib.use('Agg')
from sys import stdout
import sys

filepath = str(sys.argv[1])
print('Reading file ', filepath)

# Frag,562480,166774007,562667,166774194,f,0,187,66,66,0.352941,0.352941,0,0
#SeqX length : 155270560
#SeqY length : 171031299

plt.figure(1, figsize=(8.5, 11))
axes = plt.gca()
plt.gca().set_aspect('equal')

x_size = 1000
y_size = 1000

axes.set_xlim(0, x_size)
axes.set_ylim(0, y_size)

#ratio_x = x_size / 155270560
#ratio_y = y_size / 171031299

count = 0
with open(filepath) as openfileobject:
    for line in openfileobject:

        if (count == 6):
Beispiel #12
0
subset = subset.sample(n=1000)

plt.figure()
plt.scatter(result['g_auto'] - result['i_auto'], result['g_auto'] - result['r_auto'], s=10, c='gray', edgecolor='none', alpha = 0.5)
plt.scatter(subset['g_auto'] - subset['i_auto'], subset['g_auto'] - subset['r_auto'], s=20, c='blue', edgecolor='none')
plt.scatter(GCs['g_auto'] - GCs['i_auto'], GCs['g_auto'] - GCs['r_auto'], s=10, c='red', edgecolor='none')
plt.xlabel('(g - i)')
plt.ylabel('(g - r)')
plt.xlim(-1,4)
plt.ylim(-1,4)

plt.figure()
plt.scatter(subset['g_auto'] - subset['r_auto'], subset['r_auto'], s=30, c='blue', edgecolor='none')
plt.scatter(GCs['g_auto'] - GCs['r_auto'], GCs['i_auto'], s=8, c='red', edgecolor='none')
plt.ylim(13,24)
plt.gca().invert_yaxis()
plt.xlabel('(g - i)')
plt.ylabel('i')

plt.figure()
plt.scatter(result['g_auto'] - result['u_auto'], result['g_auto'] - result['r_auto'], s=10, c='gray', edgecolor='none', alpha = 0.5)
plt.scatter(subset['g_auto'] - subset['u_auto'], subset['g_auto'] - subset['r_auto'], s=20, c='blue', edgecolor='none')
plt.scatter(GCs['g_auto'] - GCs['u_auto'], GCs['g_auto'] - GCs['r_auto'], s=10, c='red', edgecolor='none')
plt.scatter(galaxies['g_auto'] - galaxies['u_auto'], galaxies['g_auto'] - galaxies['r_auto'], s=10, c='green', edgecolor='none')
plt.xlabel('(g - u)')
plt.ylabel('(g - r)')
plt.xlim(-4,3)
plt.ylim(-1,2)


for i in tqdm(range(0,len(subset))):