Exemplo n.º 1
0
    def _plot_labels(self, gmt, ipage):

        xhave = {}
        yhave = {}

        nxwidgets, nywidgets = self.nwidgets()

        for trace in self.traces:
            ixwidget, iywidget, ipage_ = self.group_to_widget_and_page(
                self.map_xgroup(trace), self.map_ygroup(trace),
                self.map_zgroup(trace))

            if ipage != ipage_: continue

            if iywidget not in yhave:
                left_widget = self.widgets[0, iywidget]
                left_scaler = gmtpy.ScaleGuru([([0,
                                                 left_widget.width()], [-1,
                                                                        1])])

                mleft = self.margins[0]
                smleft = self.subplot_margins[0]
                x, y, size, angle, fontno, justify, text = (
                    -0.5 * mleft - smleft, 0.0, self.font_size, 0., 1, 'MC',
                    self.label_ygroup(self.map_ygroup(trace)))

                gmt.pstext(in_rows=[(x, y, size, angle, fontno, justify, text)
                                    ],
                           N=True,
                           *(left_widget.JXY() + left_scaler.R()))

                yhave[iywidget] = True

                for ixauxwidget in range(self.nxauxwidgets):
                    widget = self.xauxwidgets[ixauxwidget, iywidget]
                    self.draw_xaux(gmt, widget, trace)

            if ixwidget not in xhave:
                top_widget = self.widgets[ixwidget, 0]
                top_scaler = gmtpy.ScaleGuru([([-1,
                                                1], [0, top_widget.height()])])

                mtop = self.margins[3]
                smtop = self.subplot_margins[3]
                x, y, size, angle, fontno, justify, text = (
                    0.0, top_widget.height() + 0.5 * mtop + smtop, 10., 0., 1,
                    'MC', self.label_xgroup(self.map_xgroup(trace)))

                gmt.pstext(in_rows=[(x, y, size, angle, fontno, justify, text)
                                    ],
                           N=True,
                           *(top_widget.JXY() + top_scaler.R()))

                xhave[ixwidget] = True
Exemplo n.º 2
0
    def test_grid_layout(self):
        for version in gmtpy.all_installed_gmt_versions():
            gmt = gmtpy.GMT(version=version, config_papersize='a3')
            nx, ny = 2, 5
            grid = gmtpy.GridLayout(nx, ny)

            layout = gmt.default_layout()
            layout.set_widget('center', grid)

            widgets = []
            for iy in range(ny):
                for ix in range(nx):
                    inner = gmtpy.FrameLayout()
                    inner.set_fixed_margins(
                        1.*cm*golden_ratio, 1.*cm*golden_ratio, 1.*cm, 1.*cm)

                    grid.set_widget(ix, iy, inner)
                    inner.set_vertical(0, (iy+1.))
                    widgets.append(inner.get_widget('center'))

            gmt.draw_layout(layout)
            for widget in widgets:
                x = num.linspace(0., 10., 5)
                y = num.sin(x)
                xax = gmtpy.Ax(approx_ticks=4, snap=True)
                yax = gmtpy.Ax(approx_ticks=4, snap=True)
                guru = gmtpy.ScaleGuru([(x, y)], axes=(xax, yax))
                gmt.psbasemap(*(widget.JXY() + guru.RB(ax_projection=True)))
                gmt.psxy(in_columns=(x, y), *(widget.JXY() + guru.R()))

            fname = 'gmtpy_test_grid_layout.png'
            fpath = self.fpath(fname)
            gmt.save(fpath, resolution=75)
Exemplo n.º 3
0
    def test_layout(self):
        x = num.linspace(0., math.pi*6, 1001)
        y1 = num.sin(x) * 1e-9
        y2 = 2.0 * num.cos(x) * 1e-9

        xax = gmtpy.Ax(label='Time', unit='s')
        yax = gmtpy.Ax(
            label='Amplitude', unit='m', scaled_unit='nm',
            scaled_unit_factor=1e9, approx_ticks=5, space=0.05)

        guru = gmtpy.ScaleGuru([(x, y1), (x, y2)], axes=(xax, yax))

        for version in gmtpy.all_installed_gmt_versions():
            width = 8*inch
            height = 3*inch

            gmt = gmtpy.GMT(
                version=version,
                config_papersize=(width, height))

            layout = gmt.default_layout()
            widget = layout.get_widget()

            gmt.draw_layout(layout)

            gmt.psbasemap(*(widget.JXY() + guru.RB(ax_projection=True)))
            gmt.psxy(
                in_columns=(x, y1), W='1p,red', *(widget.JXY() + guru.R()))
            gmt.psxy(
                in_columns=(x, y2), W='1p,blue', *(widget.JXY() + guru.R()))

            fname = 'gmtpy_test_layout.png'
            fpath = self.fpath(fname)
            gmt.save(fpath)
Exemplo n.º 4
0
 def set_traces(self, traces):
     tracy.Tracy.set_traces(self, traces)
     dists = [tr.distance_deg for tr in traces]
     azimuths = [tr.azimuth for tr in traces]
     conf = dict(xmode='off',
                 xlimits=(0., 360.),
                 xinc=45.,
                 masking=False,
                 ymode='0-max',
                 yspace=0.1)
     axes = [gmtpy.simpleconf_to_ax(conf, x) for x in 'xy']
     self.azidist_scaler = gmtpy.ScaleGuru([(azimuths, dists)], axes)
Exemplo n.º 5
0
    def _update_scalers(self):
        xranges = self.xminmax(self.traces)
        yranges = self.yminmax(self.traces)

        scalekeys = set()
        for trace in self.traces:
            scalekeys.add((self.map_xscaling(trace), self.map_yscaling(trace)))

        self.scalers = {}
        for xscale_key, yscale_key in scalekeys:
            xr, yr = xranges[xscale_key], yranges[yscale_key]
            axes = [gmtpy.simpleconf_to_ax(self.axconfig, x) for x in 'xy']
            scaler = gmtpy.ScaleGuru([(xr, yr)], axes=axes)
            xscaler, yscaler = self._scaling_extra(scaler)
            self.scalers[xscale_key, yscale_key] = scaler, xscaler, yscaler
Exemplo n.º 6
0
    def test_basic2(self):
        for version in gmtpy.all_installed_gmt_versions():
            if version.startswith('5'):
                gmt = gmtpy.GMT(
                    version=version,
                    config={'MAP_FRAME_TYPE': 'fancy'},
                    eps_mode=True)
            else:
                gmt = gmtpy.GMT(
                    version=version,
                    config={'BASEMAP_TYPE': 'fancy'})

            layout = gmt.default_layout()
            widget = layout.get_widget()

            xax = gmtpy.Ax(label='Lon', mode='min-max')
            yax = gmtpy.Ax(label='Lat', mode='min-max')
            scaler = gmtpy.ScaleGuru([([5, 15], [52, 58])], axes=(xax, yax))

            par = scaler.get_params()
            lon0 = (par['xmin'] + par['xmax'])/2.
            lat0 = (par['ymin'] + par['ymax'])/2.
            sll = '%g/%g' % (lon0, lat0)
            widget['J'] = '-JM' + sll + '/%(width)gp'

            widget['J'] = '-JM' + sll + '/%(width)gp'
            scaler['B'] = \
                '-B%(xinc)gg%(xinc)g:%(xlabel)s:' \
                '/%(yinc)gg%(yinc)g:%(ylabel)s:WSen'

            aspect = gmtpy.aspect_for_projection(
                version, *(widget.J() + scaler.R()))

            aspect = 1.045
            widget.set_aspect(aspect)

            gmt.pscoast(D='h', W='1p,red', *(widget.JXY() + scaler.R()))
            gmt.psbasemap(*(widget.JXY() + scaler.BR()))

            fname = 'gmtpy_test_basic2.png'
            fpath = self.fpath(fname)
            gmt.save(fpath, resolution=75, bbox=layout.bbox())
Exemplo n.º 7
0
def plot_erroneous_ne_to_latlon():
    import gmtpy
    import random
    import subprocess
    import time

    while True:
        w, h = 20, 15

        gsize = random.uniform(0., 1.) * 4. * 10.**random.uniform(4., 7.)
        north_grid, east_grid = num.meshgrid(
            num.linspace(-gsize / 2., gsize / 2., 11),
            num.linspace(-gsize / 2., gsize / 2., 11))

        north_grid = north_grid.flatten()
        east_grid = east_grid.flatten()

        lat_delta = gsize / earthradius * r2d * 2.
        lon = random.uniform(-180., 180.)
        lat = random.uniform(-90., 90.)

        print(gsize / 1000.)

        lat_grid, lon_grid = orthodrome.ne_to_latlon(lat, lon, north_grid,
                                                     east_grid)
        lat_grid_alt, lon_grid_alt = \
            orthodrome.ne_to_latlon_alternative_method(
                lat, lon, north_grid, east_grid)

        maxerrlat = num.max(num.abs(lat_grid - lat_grid_alt))
        maxerrlon = num.max(num.abs(lon_grid - lon_grid_alt))
        eps = 1.0e-8
        if maxerrlon > eps or maxerrlat > eps:
            print(lat, lon, maxerrlat, maxerrlon)

            gmt = gmtpy.GMT(
                config={
                    'PLOT_DEGREE_FORMAT': 'ddd.xxxF',
                    'PAPER_MEDIA': 'Custom_%ix%i' %
                    (w * gmtpy.cm, h * gmtpy.cm),
                    'GRID_PEN_PRIMARY': 'thinnest/0/50/0'
                })

            south = max(-85., lat - 0.5 * lat_delta)
            north = min(85., lat + 0.5 * lat_delta)

            lon_delta = lat_delta / math.cos(lat * d2r)

            delta = lat_delta / 360. * earthradius * 2. * math.pi
            scale_km = gmtpy.nice_value(delta / 10.) / 1000.

            west = lon - 0.5 * lon_delta
            east = lon + 0.5 * lon_delta

            x, y = (west, east), (south, north)
            xax = gmtpy.Ax(mode='min-max', approx_ticks=4.)
            yax = gmtpy.Ax(mode='min-max', approx_ticks=4.)
            scaler = gmtpy.ScaleGuru(data_tuples=[(x, y)], axes=(xax, yax))
            scaler['R'] = '-Rg'
            layout = gmt.default_layout()
            mw = 2.5 * gmtpy.cm
            layout.set_fixed_margins(mw, mw, mw / gmtpy.golden_ratio,
                                     mw / gmtpy.golden_ratio)
            widget = layout.get_widget()
            # widget['J'] =  ('-JT%g/%g'  % (lon, lat)) + '/%(width)gp'
            widget['J'] = (
                '-JE%g/%g/%g' % (lon, lat, min(lat_delta/2., 180.)))\
                + '/%(width)gp'
            aspect = gmtpy.aspect_for_projection(*(widget.J() + scaler.R()))
            widget.set_aspect(aspect)

            gmt.psbasemap(B='5g5',
                          L=('x%gp/%gp/%g/%g/%gk' %
                             (widget.width() / 2., widget.height() / 7., lon,
                              lat, scale_km)),
                          *(widget.JXY() + scaler.R()))

            gmt.psxy(in_columns=(lon_grid, lat_grid),
                     S='x10p',
                     W='1p/200/0/0',
                     *(widget.JXY() + scaler.R()))
            gmt.psxy(in_columns=(lon_grid_alt, lat_grid_alt),
                     S='c10p',
                     W='1p/0/0/200',
                     *(widget.JXY() + scaler.R()))

            gmt.save('orthodrome.pdf')
            subprocess.call(['xpdf', '-remote', 'ortho', '-reload'])
            time.sleep(2)
        else:
            print('ok', gsize, lat, lon)
Exemplo n.º 8
0
widget = palette_layout.get_widget(0, 0)
spacer = palette_layout.get_widget(1, 0)
palette_widget = palette_layout.get_widget(2, 0)
spacer.set_horizontal(0.5 * gmtpy.cm)
palette_widget.set_horizontal(0.5 * gmtpy.cm)
w, h = gmt.page_size_points()
palette_layout.set_policy((w / gmtpy.golden_ratio, 0.), (0., 0.),
                          aspect=1. / gmtpy.golden_ratio)

xx, yy, zz = to_flat_xyz(x, y, z)

xax = gmtpy.Ax(label='Distance from Yoda')
yax = gmtpy.Ax(label='Height over Yoda')
zax = gmtpy.Ax(snap=True, label='The Force')

guru = gmtpy.ScaleGuru([(xx, yy, zz)], axes=(xax, yax, zax))

grdfile = gmt.tempfilename()
cptfile = gmt.tempfilename()

par = guru.get_params()
inc_interpol = ((par['xmax'] - par['xmin']) /
                (widget.width() / gmtpy.inch * 50.),
                (par['ymax'] - par['ymin']) /
                (widget.height() / gmtpy.inch * 50.))

rxyj = guru.R() + widget.XYJ()

gmt.surface(T=0.3,
            G=grdfile,
            I=inc_interpol,
Exemplo n.º 9
0
            south = max(-85., lat - 0.5 * lat_delta)
            north = min(85., lat + 0.5 * lat_delta)

            lon_delta = lat_delta / math.cos(lat * d2r)

            delta = lat_delta / 360. * config.earthradius * 2. * math.pi
            scale_km = gmtpy.nice_value(delta / 10.) / 1000.

            west = lon - 0.5 * lon_delta
            east = lon + 0.5 * lon_delta

            x, y = (west, east), (south, north)
            xax = gmtpy.Ax(mode='min-max', approx_ticks=4.)
            yax = gmtpy.Ax(mode='min-max', approx_ticks=4.)
            scaler = gmtpy.ScaleGuru(data_tuples=[(x, y)], axes=(xax, yax))
            scaler['R'] = '-Rg'
            layout = gmt.default_layout()
            mw = 2.5 * gmtpy.cm
            layout.set_fixed_margins(mw, mw, mw / gmtpy.golden_ratio,
                                     mw / gmtpy.golden_ratio)
            widget = layout.get_widget()
            # widget['J'] =  ('-JT%g/%g'  % (lon, lat)) + '/%(width)gp'
            widget['J'] = (
                '-JE%g/%g/%g' %
                (lon, lat, min(lat_delta / 2., 180.))) + '/%(width)gp'
            aspect = gmtpy.aspect_for_projection(*(widget.J() + scaler.R()))
            widget.set_aspect(aspect)

            if lat > 0:
                axes_layout = 'WSen'