def _render(t, store): """ Renders a tile, sending output to a temporary directory and puts the result(s) in the store. """ with tmpdir.tmpdir() as d: t.render(d) store.upload_all(d)
def _render(self, rehydrated_jobs, sources): with tmpdir.tmpdir() as d: mock_sources = [] for s in sources: src = self._find_source_by_name(s['source']) vrts = _download_local_vrts(d, self.source_store, s['vrts']) if vrts: mock_sources.append(MockSource(src, vrts)) for rehydrated in rehydrated_jobs: rehydrated.set_sources(mock_sources) _render(rehydrated, self.store)
def unpack(self, store, tmp): img = self.img_name() with store.upload_dir() as target: target_dir = os.path.join(target, self.base_dir) mkdir_p(target_dir) with tmpdir.tmpdir() as d: with zipfile.ZipFile(tmp.name, 'r') as zfile: zfile.extract(img, d) output_file = os.path.join(target, self.output_file()) mask.negative(os.path.join(d, img), "HFA", output_file)
def unpack(self, store, tmp): img = self.img_name() with store.upload_dir() as target: target_dir = os.path.join(target, self.base_dir) mkdir_p(target_dir) with tmpdir.tmpdir() as d: with zipfile.ZipFile(tmp.name, 'r') as zfile: zfile.extract(img, d) output_file = os.path.join(target, self.output_file()) mask.negative(os.path.join(d, img), "HFA", output_file)
def unpack(self, store, tmp): # the file inside the TAR is named like this - we're only interested # in the GeoTIFF file, as it already contains all the information # that we need. tif_file = self._tif_file() shift = GREAT_LAKES[self.lake]['datum'] with tmpdir.tmpdir() as tmp_dir: with tarfile.open(tmp.name, mode='r:gz') as tar: tar.extract(tif_file, tmp_dir) tif_path = os.path.join(tmp_dir, tif_file) assert os.path.exists(tif_path), "Didn't extract TIF" with store.upload_dir() as target: mkdir_p(os.path.join(target, self.base_dir)) output_file = os.path.join(target, self.output_file()) mask.datum_shift(tif_path, 'GTiff', output_file, shift)
def unpack(self, store, data_zip, mask_zip=None): with store.upload_dir() as target: target_dir = os.path.join(target, self.base_dir) mkdir_p(target_dir) # if there's no mask, then just extract the SRTM as-is. if mask_zip is None: self._unpack_hgt(data_zip.name, target_dir) return # otherwise, make a temporary directory to keep the SRTM and # mask in while compositing them. with tmpdir.tmpdir() as d: self._unpack_hgt(data_zip.name, d) mask_name = self.fname.replace(".hgt", ".raw") with zipfile.ZipFile(mask_zip.name, 'r') as zfile: zfile.extract(mask_name, d) mask_file = os.path.join(d, mask_name) # mask off the water using the mask raster raw file output_file = os.path.join(target, self.output_file()) mask.raw(os.path.join(d, self.fname), mask_file, 255, "SRTMHGT", output_file)
def unpack(self, store, data_zip, mask_zip=None): with store.upload_dir() as target: target_dir = os.path.join(target, self.base_dir) mkdir_p(target_dir) # if there's no mask, then just extract the SRTM as-is. if mask_zip is None: self._unpack_hgt(data_zip.name, target_dir) return # otherwise, make a temporary directory to keep the SRTM and # mask in while compositing them. with tmpdir.tmpdir() as d: self._unpack_hgt(data_zip.name, d) mask_name = self.fname.replace(".hgt", ".raw") with zipfile.ZipFile(mask_zip.name, 'r') as zfile: zfile.extract(mask_name, d) mask_file = os.path.join(d, mask_name) # mask off the water using the mask raster raw file output_file = os.path.join(target, self.output_file()) mask.raw(os.path.join(d, self.fname), mask_file, 255, "SRTMHGT", output_file)
def upload_dir(self): with tmpdir() as t: yield t self.upload_all(t)
def upload_dir(self): with tmpdir() as t: yield t self.upload_all(t)