# http://pyrocko.org - GPLv3 # # The Pyrocko Developers, 21st Century # ---|P------/S----------~Lg----------
citation=None, region=None):
# dataset geometry (including overlap/endpoints)
# tile geometry (including overlap)
else:
if self.region is None: return True
a = self.region b = self.positive_region(region) return (( (a[0] <= b[0] and b[1] <= b[1]) or (a[0] <= b[0]+360. and b[1]+360 <= a[1])) and a[2] <= b[2] and b[3] <= a[3])
d = 360. / (self.nx - 1) return self.covers(region) and dmin <= d <= dmax
util.download_file( url, fpath, username, password, status_callback=get_download_callback( 'Downloading %s topography...' % self.__class__.__name__))
return self.xmin + num.arange(self.nx) * self.dx
return self.ymin + num.arange(self.ny) * self.dy
xmax += 360.
xmin += 360. xmax += 360.
xmin, xmax, ymin, ymax = self.positive_region(region) itxmin = int(math.floor((xmin - self.xmin) / self.stx)) itxmax = int(math.ceil((xmax - self.xmin) / self.stx)) if itxmin == itxmax: itxmax += 1 itymin = int(math.floor((ymin - self.ymin) / self.sty)) itymax = int(math.ceil((ymax - self.ymin) / self.sty)) if itymin == itymax: if itymax != self.ntilesy: itymax += 1 else: itymin -= 1
indices = [] for ity in range(itymin, itymax): for itx in range(itxmin, itxmax): indices.append((itx % self.ntilesx, ity))
return indices
return None
if len(region) == 2: x, y = region t = self.get((x, x, y, y)) if t is not None: return t.get(x, y) else: return None
indices = self.tile_indices(region) tiles = [] for itx, ity in indices: t = self.get_tile(itx, ity) if t: tiles.append(t)
return tile.combine(tiles, region)
xmin, xmax, ymin, ymax = region ymin2 = max(-90., ymin) ymax2 = min(90., ymax) region2 = xmin, xmax, ymin2, ymax2 t = self.get(region2) if t is not None and region2 != region: t.yextend_with_repeat(ymin, ymax)
return t
data_dir = op.join(base.data_dir, 'decimated_%i' % ndeci)
data_dir=data_dir, citation=base.citation, region=base.region)
nh = self.ndeci // 2 xmin = self.xmin + itx*self.stx - self.base.dx * nh xmax = self.xmin + (itx+1)*self.stx + self.base.dx * nh ymin = self.ymin + ity*self.sty - self.base.dy * nh ymax = self.ymin + (ity+1)*self.sty + self.base.dy * nh
t = self.base.get_with_repeat((xmin, xmax, ymin, ymax)) if t is not None: t.decimate(self.ndeci)
util.ensuredirs(fpath) with open(fpath, 'w') as f: if t is not None: t.data.tofile(f)
assert 0 <= itx < self.ntilesx assert 0 <= ity < self.ntilesy
fn = '%02i.%02i.bin' % (ity, itx) fpath = op.join(self.data_dir, fn) if not op.exists(fpath): logger.info('making decimated tile: %s (%s)' % (fn, self.name)) self.make_tile(itx, ity, fpath)
assert 0 <= itx < self.ntilesx assert 0 <= ity < self.ntilesy
self.make_if_needed(itx, ity)
fn = '%02i.%02i.bin' % (ity, itx) fpath = op.join(self.data_dir, fn) with open(fpath, 'r') as f: data = num.fromfile(f, dtype=self.dtype)
if data.size == 0: return None
assert data.size == self.ntx*self.nty data = data.reshape((self.ntx, self.nty))
return tile.Tile( self.xmin + itx*self.stx, self.ymin + ity*self.sty, self.dx, self.dx, data)
for ity in range(self.ntilesy): for itx in range(self.ntilesx): self.make_if_needed(itx, ity) |