def test_grid_data(self): x = num.linspace(0., 2. * math.pi, 100) y = num.linspace(0., 2. * math.pi, 100) x2 = num.tile(x, y.size) y2 = num.repeat(y, x.size) z2 = num.sin(x2) * num.sin(y2) xf, yf, zf = gmtpy.griddata_auto(x2, y2, z2) assert (xf.size, yf.size, zf.size) == (100, 100, 100 * 100) x3, y3, z3 = gmtpy.tabledata(xf, yf, zf) assert_allclose(x3, x2, atol=1e-7) assert_allclose(y3, y2, atol=1e-7) assert_allclose(z3, z2, atol=1e-7) xf2, yf2, zf2 = gmtpy.doublegrid(xf, yf, zf) assert (xf2.size, yf2.size, zf2.size) == (199, 199, 199 * 199) fn = self.fpath('grid.nc') for naming in ['xy', 'lonlat']: gmtpy.savegrd(xf, yf, zf, fn, naming=naming, title='mygrid') xf3, yf3, zf3 = gmtpy.loadgrd(fn) assert_allclose(xf3, xf) assert_allclose(yf3, yf) assert_allclose(zf3, zf)
def _prep_topo(self, k): gmt = self._gmt t, demname = self._get_topo_tile(k) if demname not in self._prep_topo_have: grdfile = gmt.tempfilename() gmtpy.savegrd(t.x(), t.y(), t.data, filename=grdfile, naming='lonlat') if self.illuminate: if k == 'ocean': factor = self.illuminate_factor_ocean else: factor = self.illuminate_factor_land ilumfn = gmt.tempfilename() gmt.grdgradient(grdfile, N='e%g' % factor, A=-45, G=ilumfn, out_discard=True) ilumargs = ['-I%s' % ilumfn] else: ilumargs = [] if self.replace_topo_color_only: t2 = self.replace_topo_color_only grdfile2 = gmt.tempfilename() gmtpy.savegrd(t2.x(), t2.y(), t2.data, filename=grdfile2, naming='lonlat') gmt.grdsample(grdfile2, G=grdfile, Q='l', I='%g/%g' % (t.dx, t.dy), R=grdfile, out_discard=True) gmt.grdmath(grdfile, '0.0', 'AND', '=', grdfile2, out_discard=True) grdfile = grdfile2 self._prep_topo_have[demname] = grdfile, ilumargs return self._prep_topo_have[demname]
def _prep_topo(self, k): gmt = self._gmt t, demname = self._get_topo_tile(k) if demname not in self._prep_topo_have: grdfile = gmt.tempfilename() gmtpy.savegrd( t.x(), t.y(), t.data, filename=grdfile, naming='lonlat') if self.illuminate: if k == 'ocean': factor = self.illuminate_factor_ocean else: factor = self.illuminate_factor_land ilumfn = gmt.tempfilename() gmt.grdgradient( grdfile, N='e%g' % factor, A=-45, G=ilumfn, out_discard=True) ilumargs = ['-I%s' % ilumfn] else: ilumargs = [] if self.replace_topo_color_only: t2 = self.replace_topo_color_only grdfile2 = gmt.tempfilename() gmtpy.savegrd( t2.x(), t2.y(), t2.data, filename=grdfile2, naming='lonlat') gmt.grdsample( grdfile2, G=grdfile, Q='l', I='%g/%g' % (t.dx, t.dy), R=grdfile, out_discard=True) gmt.grdmath( grdfile, '0.0', 'AND', '=', grdfile2, out_discard=True) grdfile = grdfile2 self._prep_topo_have[demname] = grdfile, ilumargs return self._prep_topo_have[demname]
def _prep_topo(self, k): gmt = self._gmt t, demname = self._get_topo_tile(k) if demname not in self._prep_topo_have: grdfile = gmt.tempfilename() gmtpy.savegrd(t.x(), t.y(), t.data, filename=grdfile, naming="lonlat") if self.illuminate: if k == "ocean": factor = self.illuminate_factor_ocean else: factor = self.illuminate_factor_land ilumfn = gmt.tempfilename() gmt.grdgradient(grdfile, N="e%g" % factor, A=-45, G=ilumfn, out_discard=True) ilumargs = ["-I%s" % ilumfn] else: ilumargs = [] if self.replace_topo_color_only: t2 = self.replace_topo_color_only grdfile2 = gmt.tempfilename() gmtpy.savegrd(t2.x(), t2.y(), t2.data, filename=grdfile2, naming="lonlat") gmt.grdsample(grdfile2, G=grdfile, Q="l", I="%g/%g" % (t.dx, t.dy), R=grdfile, out_discard=True) gmt.grdmath(grdfile, "0.0", "AND", "=", grdfile2, out_discard=True) grdfile = grdfile2 self._prep_topo_have[demname] = grdfile, ilumargs return self._prep_topo_have[demname]