示例#1
0
def demo_divine_figure_10():
    """Note that the figure has broken x axes!

    It's a bit of a hassle to try to reproduce the temperature lines going
    through our functions, but the fundamental computation is pretty
    straightforward. So we don't bother with the outer-disk temperature.

    """
    import omega as om

    bc_lon = 0.0  # arbitrary since we choose lats to put us in the disk plane
    r_A = np.linspace(1, 9.5, 100)
    r_B = np.linspace(9.5, 95, 50)
    r_C = np.linspace(95., 170, 30)

    # We need to choose coordinates fairly precisely to stay in the disk
    # midplane, which appears to be what DG83 plot.

    bc_lat_A = equatorial_latitude(bc_lon, r_A)
    bc_lat_B = equatorial_latitude(bc_lon, r_B)
    bc_lat_C = equatorial_latitude(bc_lon, r_C)

    N_A, kT_A = cold_e_maxwellian_parameters(bc_lat_A, bc_lon, r_A)
    N_B, kT_B = cold_e_maxwellian_parameters(bc_lat_B, bc_lon, r_B)
    N_C, kT_C = cold_e_maxwellian_parameters(bc_lat_C, bc_lon, r_C)

    kT_A *= 1e6  # MeV => eV
    kT_B *= 1e6
    kT_C *= 1e6

    hb = om.layout.HBox(3)
    hb.setWeight(2, 0.5)

    hb[0] = om.quickXY(r_A, N_A, 'n_e (cm^-3)')
    hb[0].addXY(r_A, kT_A, 'kT (eV)')
    hb[0].setLinLogAxes(False, True)
    hb[0].setBounds(1, 9.5, 3e-4, 3e4)
    hb[0].setYLabel('Density or temperature')

    hb[1] = om.quickXY(r_B, N_B, None)
    hb[1].addXY(r_B, kT_B, None)
    hb[1].setLinLogAxes(False, True)
    hb[1].setBounds(9.5, 95, 3e-4, 3e4)
    hb[1].lpainter.paintLabels = False
    hb[1].setXLabel('Jovicentric distance')

    hb[2] = om.quickXY(r_C, N_C, None)
    hb[2].addXY(r_C, kT_C, None)
    hb[2].setLinLogAxes(False, True)
    hb[2].setBounds(95, 170, 3e-4, 3e4)
    hb[2].lpainter.paintLabels = False

    return hb
示例#2
0
    def plotUVDs(self):
        import omega
        from bisect import bisect

        d = ArrayGrower(2)
        bpd = self.ccs[0].bpData
        idxs = xrange(0, len(bpd))

        for bp, uvdsa in self.uvdists.iteritems():
            uvd = uvdsa.mean() * 0.001

            # FIXME: slooooooow
            for i in idxs:
                if bpd[i][0] == bp:
                    break
            else:
                continue

            val = bpd[i][1]
            d.add(uvd, val)

        d = d.finish()

        p = omega.quickXY(d[:, 0], d[:, 1], 'Closure values', lines=False)
        p.setLabels('UV Distance (kilolambda)',
                    '%s closure' % self.ccs[0].item)
        return p
示例#3
0
文件: fk10.py 项目: vlslv/pwkit
def make_figure9_plot(shlib_path, use_lowlevel=True, **kwargs):
    """Reproduce Figure 9 of the Fleischman & Kuznetsov (2010) paper, using our
    low-level interfaces. Uses OmegaPlot, of course.

    Input parameters, etc., come from the file ``Flare071231a.pro`` that is
    distributed with the paper’s Supplementary Data archive.

    Invoke with something like::

      from pwkit import fk10
      fk10.make_figure9_plot('path/to/libGS_Std_HomSrc_CEH.so.64').show()

    """
    import omega as om

    if use_lowlevel:
        out_vals = do_figure9_calc_lowlevel(shlib_path, **kwargs)
    else:
        out_vals = do_figure9_calc_highlevel(shlib_path, **kwargs)

    freqs = out_vals[:, OUT_VAL_FREQ]
    tot_ints = out_vals[:, OUT_VAL_OINT] + out_vals[:, OUT_VAL_XINT]
    pos = (tot_ints > 0)

    p = om.quickXY(freqs[pos], tot_ints[pos], 'Calculation', xlog=1, ylog=1)

    nu_obs = np.array([1.0, 2.0, 3.75, 9.4, 17.0, 34.0])
    int_obs = np.array([12.0, 43.0, 29.0, 6.3, 1.7, 0.5])
    p.addXY(nu_obs, int_obs, 'Observations', lines=False)

    p.defaultKeyOverlay.hAlign = 0.93
    p.setBounds(0.5, 47, 0.1, 60)
    p.setLabels('Emission frequency, GHz', 'Total intensity, sfu')
    return p
示例#4
0
文件: data.py 项目: vlslv/pwkit
    def plot_lightcurve (self, ccd_id=None, bin_energies=False):
        # XXX CIAO COPY/PASTE DOES THIS EVEN WORK???
        import omega as om
        from ...bblocks import tt_bblock
        from ..ciao.data import tight_bounds

        if ccd_id is None:
            if len (self.gti) != 1:
                raise Exception ('must specify ccd_id')
            ccd_id = list(self.gti.keys())[0]

        kev = self.events['pi'] * 1e-3 # XXXXXXX
        vb = om.layout.VBox (2)

        if kev.size == 0:
            vb[0] = om.RectPlot()
            vb[1] = om.RectPlot()
            tmin = self.gti[ccd_id]['start_dmjd'].min()
            tmax = self.gti[ccd_id]['stop_dmjd'].max()
            if np.isnan(tmin):
                tmin, tmax = -1., 1.
            emin, emax = -1., 1.
            rmin, rmax = -1., 1.
        else:
            bbinfo = tt_bblock (
                self.gti[ccd_id]['start_dmjd'],
                self.gti[ccd_id]['stop_dmjd'],
                self.events['dmjd'].sort_values(),
                intersect_with_bins = True,
            )
            cps = bbinfo.rates / 86400

            tmin, tmax = tight_bounds (bbinfo.ledges[0], bbinfo.redges[-1])
            emin, emax = tight_bounds (kev.min (), kev.max ())
            rmin, rmax = tight_bounds (cps.min (), cps.max ())

            vb[0] = om.RectPlot ()
            csp = om.rect.ContinuousSteppedPainter (keyText='%d events' % (self.events.shape[0]))
            csp.setFloats (np.concatenate ((bbinfo.ledges, bbinfo.redges[-1:])),
                           np.concatenate ((cps, [0])))
            vb[0].add (csp)

            if bin_energies:
                vb[1] = self._plot_binned_event_energies(
                    bbinfo,
                    energy_scale = 1e-3,
                    dsn = 0
                )
            else:
                vb[1] = om.quickXY (self.events['dmjd'], kev, None, lines=0)

        vb[0].setBounds (tmin, tmax, rmin, rmax)
        vb[0].setYLabel ('Count rate (ct/s)')
        vb[0].bpainter.paintLabels = False
        self._plot_add_gtis (vb[0], ccd_id)

        vb[1].setBounds (tmin, tmax, emin, emax)
        vb[1].setLabels ('MJD - %d' % self.mjd0, 'Energy (keV)')
        self._plot_add_gtis (vb[1], ccd_id)
        return vb
示例#5
0
文件: closanal.py 项目: aimran/pwpy
    def plotUVDs (self):
        import omega
        from bisect import bisect

        d = ArrayGrower (2)
        bpd = self.ccs[0].bpData
        idxs = xrange (0, len (bpd))

        for bp, uvdsa in self.uvdists.iteritems ():
            uvd = uvdsa.mean () * 0.001

            # FIXME: slooooooow
            for i in idxs:
                if bpd[i][0] == bp:
                    break
            else:
                continue

            val = bpd[i][1]
            d.add (uvd, val)

        d = d.finish ()

        p = omega.quickXY (d[:,0], d[:,1], 'Closure values', lines=False)
        p.setLabels ('UV Distance (kilolambda)', '%s closure' % self.ccs[0].item)
        return p
示例#6
0
def shprits06_figure_1(kev=300):
    import omega as om

    alpha_star = 0.16  # = 2.5**-2
    E = kev / 511  # normalized to 511 keV
    x_m = 0.35
    delta_x = 0.15
    B_wave = 0.1  # nT
    max_wave_lat = 15 * np.pi / 180

    # Omega_e = e B / m_e c for equatorial B at L = 3.5. B ~ B_surf * L**-3.
    #
    # In Summers 2005, at L = 4.5 f_ce = Omega_e/2pi = 9.54 kHz, implying
    # Omega_e = 59.9 rad/s and B_eq = 3.41 mG = 340 nT. Therefore B0 = 31056
    # nT. Extrapolating to L = 3.5, we get the following. (Shorter version:
    # Omega_e(L2) = Omega_e(L1) * (L1/L2)**3.)

    Omega_e = 127400.

    # R = (Delta B / B)**2. At fixed Delta B, R(L2) = R(L1) * (L2/L1)**6

    R = 1.9e-8

    degrees = np.linspace(2, 87, 100)
    sinas = np.sin(degrees * np.pi / 180)
    Daa = compute(E,
                  sinas,
                  Omega_e,
                  alpha_star,
                  R,
                  x_m,
                  delta_x,
                  'R',
                  max_wave_lat,
                  p_scaled=True)[0]
    Dee = compute_dee_on_e2(E, sinas, Omega_e, alpha_star, R, x_m, delta_x,
                            max_wave_lat, 'R')

    hb = om.layout.HBox(2)
    pee = hb[0] = om.quickXY(degrees, Dee, str(kev), ylog=True)
    paa = hb[1] = om.quickXY(degrees, Daa, str(kev), ylog=True)

    pee.setBounds(0, 90, 1e-7, 0.1)
    paa.setBounds(0, 90, 1e-7, 0.1)

    return hb
示例#7
0
def ellplot(maj, min, pa):
    """Utility for debugging."""
    _ellcheck(maj, min, pa)
    import omega as om

    th = np.linspace(0, 2 * np.pi, 200)
    x, y = ellpoint(maj, min, pa, th)
    return om.quickXY(x, y,
                      'maj=%f min=%f pa=%f' % (maj, min, pa * 180 / np.pi))
示例#8
0
def ellplot (mjr, mnr, pa):
    """Utility for debugging."""
    _ellcheck (mjr, mnr, pa)
    import omega as om

    th = np.linspace (0, 2 * np.pi, 200)
    x, y = ellpoint (mjr, mnr, pa, th)
    return om.quickXY (x, y, 'mjr=%f mnr=%f pa=%f' %
                       (mjr, mnr, pa * 180 / np.pi))
示例#9
0
    def plot_cube(self, c):
        import omega as om

        med_g = np.median(c, axis=(1, 2))
        med_a = np.median(c, axis=(0, 2))
        med_l = np.median(c, axis=(0, 1))
        mn = min(med_g.min(), med_a.min(), med_l.min())
        mx = max(med_g.max(), med_a.max(), med_l.max())
        delta = abs(mx - mn) * 0.02
        mx += delta
        mn -= delta

        hb = om.layout.HBox(3)
        hb[0] = om.quickXY(self.g_edges, med_g, u'g', ymin=mn, ymax=mx)
        hb[1] = om.quickXY(self.alpha_edges, med_a, u'α', ymin=mn, ymax=mx)
        hb[1].lpainter.paintLabels = False
        hb[2] = om.quickXY(self.L_edges, med_l, u'L', ymin=mn, ymax=mx)
        hb[2].lpainter.paintLabels = False
        hb.setWeight(0, 1.1)  # extra room for labels
        return hb
示例#10
0
def view_lc_cli(args):
    import omega as om

    settings = make_view_lc_parser().parse_args(args=args)
    ii = IntegratedImages(settings.path)

    lc = ii.lightcurve(settings.ifreq, settings.stokes)
    desc = '%s freq=%.2f stokes=%s' % (settings.path, ii.freqs[settings.ifreq],
                                       settings.stokes)

    p = om.quickXY(ii.cmls, lc, None)
    p.setLabels('CML (deg)', '%s (uJy)' % desc)
    p.show()
示例#11
0
文件: impl.py 项目: pkgw/neurosynchro
    def ns_plot(self, param_index, plot_err=False, to_phys=False, thin=100):
        """Make a diagnostic plot comparing the approximation to the "actual" results
        from the calculator.

        """
        import omega as om

        par, act, nn = self.ns_validate(filter=True, to_phys=to_phys)

        if plot_err:
            err = nn - act
            p = om.quickXY(par[::thin, param_index],
                           err[::thin],
                           'Error',
                           lines=0)
        else:
            p = om.quickXY(par[::thin, param_index],
                           act[::thin],
                           'Full calc',
                           lines=0)
            p.addXY(par[::thin, param_index], nn[::thin], 'Neural', lines=0)

        return p
示例#12
0
def main():
    """Following the discussion of appropriate values of the timestep (delta_s) in
    Du Toit Strauss (arxiv:1703.06192), in our problem a sensible target
    length scale would be l = 0.1, leading to delta_s = 0.0025 . This doesn't
    give amazingly accurate answers; l = 0.01 is noticeably better, at a big
    runtime penalty, of course.

    """
    x0s, results = calculate(10, n_pcle=1024, delta_s=0.0025)

    p = om.quickXY([0., 1.], [0., 1.], 'Analytic')
    p.addXY(x0s, results, 'SDE', lines=False)
    p.setLabels('x', 'Distribution function')
    p.show()
示例#13
0
文件: data.py 项目: dkhikhlukha/pwkit
    def plot_lightcurve (self, ccd_id=None):
        import omega as om
        from ...bblocks import tt_bblock

        if ccd_id is None:
            if len (self.gti) != 1:
                raise Exception ('must specify ccd_id')
            ccd_id = self.gti.keys ()[0]

        kev = self.events['energy'] * 1e-3

        bbinfo = tt_bblock (
            self.gti[ccd_id]['start_dmjd'],
            self.gti[ccd_id]['stop_dmjd'],
            self.events['dmjd']
        )

        cps = bbinfo.rates / 86400

        tmin, tmax = tight_bounds (bbinfo.ledges[0], bbinfo.redges[-1])
        emin, emax = tight_bounds (kev.min (), kev.max ())
        rmin, rmax = tight_bounds (cps.min (), cps.max ())

        vb = om.layout.VBox (2)

        vb[0] = om.RectPlot ()
        csp = om.rect.ContinuousSteppedPainter (keyText='%d events' % (self.events.shape[0]))
        csp.setFloats (np.concatenate ((bbinfo.ledges, bbinfo.redges[-1:])),
                       np.concatenate ((cps, [0])))
        vb[0].add (csp)
        vb[0].setBounds (tmin, tmax, rmin, rmax)
        vb[0].setYLabel ('Count rate (ct/s)')
        vb[0].bpainter.paintLabels = False
        self._plot_add_gtis (vb[0], ccd_id)

        vb[1] = om.quickXY (self.events['dmjd'], kev, None, lines=0)
        vb[1].setBounds (tmin, tmax, emin, emax)
        vb[1].setLabels ('MJD - %d' % self.mjd0, 'Energy (keV)')
        self._plot_add_gtis (vb[1], ccd_id)

        return vb
示例#14
0
def demo_divine_figure_1():
    """The outer radii in my plot do not resemble D&G's Figure 1, but the power laws
    show that my values are scaling as intended. Therefore I guess that the figure is
    just somewhat inaccurate.

    """
    import omega as om

    L = np.logspace(np.log10(1.), np.log10(200), 100)
    d4 = JupiterD4Field()

    dc_lat = 0.
    dc_lon = 0.
    dc_r = L * np.cos(dc_lat)**2
    bc = d4._from_dc(dc_lat, dc_lon, dc_r)
    bmag = d4.bmag(*bc)

    bmag *= G2NT

    bcut = B_cutoff(L) * G2NT

    r0_inner = 1.
    b0_inner = d4.bmag(0., 0., r0_inner) * G2NT
    r_inner = np.logspace(0, 1, 5)
    b_inner = b0_inner * (r_inner / r0_inner)**-3

    r0_outer = 20.
    b0_outer = d4.bmag(0., 0., r0_outer) * G2NT
    r_outer = np.logspace(1, 2.5, 5)
    b_outer = b0_outer * (r_outer / r0_outer)**-1.6

    p = om.quickXY(L, bmag, 'Eq field strength', xlog=True, ylog=True)
    p.addXY(L, bcut, 'B_cutoff')
    p.addXY(r_inner, b_inner, 'r^-3')
    p.addXY(r_outer, b_outer, 'r^-1.6')
    p.defaultKeyOverlay.vAlign = 0.9
    p.setBounds(1, 200, 1, 2e6)
    p.setLabels('L or RJ', '|B| (nT)')
    return p
def main():
    pg = om.makeDisplayPager()

    for ident, flitem, geojson in postprocess.get_events():
        for ftnum, feature in enumerate(
                geojson['features'][0]['geometry']['coordinates']):
            x_orig = np.array([t[0] for t in feature])
            y_orig = np.array([t[1] for t in feature])
            area, x, y = postprocess.fix_polygon_handedness(x_orig, y_orig)

            if area < postprocess.AREA_CUTOFF_68:
                print('skipping %s+%d: A=%.1f' % (ident, ftnum + 1, area))
                continue

            x, y = postprocess.smooth_polygon(x, y)

            p = om.quickXY(x_orig, y_orig,
                           'Original %s+%d: A=%.1f' % (ident, ftnum + 1, area))
            p.addXY(x, y, 'Smoothed')
            pg.send(p)

    pg.done()
示例#16
0
文件: dolfin.py 项目: pkgw/vernon
 def l_plot(self, v, **kwargs):
     import omega as om
     return om.quickXY(self.l_sort(), self.l_sort(v), **kwargs)