def convert(self, nc_file): tif_file = "{}.tif".format(nc_file) nc_transform = nc_convert(os.path.join(self.tmp_dir, nc_file)) cdo_transform = cdo_invert(os.path.join(self.tmp_dir, nc_transform)) band = get_band_count(cdo_transform) gdal_translate(cdo_transform, os.path.join(self.tmp_dir, tif_file), bands=[band], projection='EPSG:4326') return tif_file
def run(self): """ Retrieve and process the latest NetCDF file. """ gzfile = self.download(self.base_url, '{}.nc.gz'.format(self.layer_name)) ncfile = gunzip(os.path.join(self.tmp_dir, gzfile)) cdf_file = self.convert(ncfile) bands = get_band_count(cdf_file) img_list = self.get_mosaic_filenames(self.layer_name) for band in range(1, bands + 1): band_date = re.sub('[\-\.]+', '', self.get_date(band).isoformat()) img_name = '{}_{}T000000000Z.tif'.format(self.layer_name, band_date) if img_name not in img_list: band_tif = self.extract_band(cdf_file, band, img_name) dst_file = self.data_dir.format(gsd=GS_DATA_DIR, ws=self.workspace, layer=self.layer_name, file=img_name) dst_dir = os.path.dirname(dst_file) if not os.path.exists(dst_dir): os.makedirs(dst_dir) if dst_file.endswith('.tif'): shutil.move(os.path.join(self.tmp_dir, band_tif), dst_file) self.post_geoserver(dst_file, self.layer_name) if not style_exists(self.layer_name): with open(os.path.join(script_dir, 'resources/gistemp.sld')) as sld: self.set_default_style(self.layer_name, self.layer_name, sld.read().format(latest_band=bands)) self.update_geonode( self.layer_name, title=self.get_title(bands), description=self.abstract, store=self.layer_name, bounds=('-180.0', '180.0', '-90.0', '90.0', 'EPSG:4326'), extra_keywords=['category:Climatology Meteorology Atmosphere']) self.truncate_gs_cache(self.layer_name) self.cleanup()
def run(self): """ Retrieve and process the latest NetCDF file. """ ncfile = self.download( self.base_url, filename='{}.nc'.format(self.layer_name)) cdf_file = self.convert(os.path.join(self.tmp_dir, ncfile)) bands = get_band_count(cdf_file) img_list = self.get_mosaic_filenames(self.layer_name) for band in range(1, bands + 1): band_date = re.sub('[\-\.]+', '', self.get_date(band).isoformat()) img_name = '{}_{}T000000000Z.tif'.format(self.layer_name, band_date) if img_name not in img_list: band_tif = self.extract_band(cdf_file, band, img_name) dst_file = self.data_dir.format(gsd=GS_DATA_DIR, ws=self.workspace, layer=self.layer_name, file=img_name) dst_dir = os.path.dirname(dst_file) if not os.path.exists(dst_dir): os.makedirs(dst_dir) if dst_file.endswith('.tif'): shutil.move(os.path.join(self.tmp_dir, band_tif), dst_file) self.post_geoserver(dst_file, self.layer_name) if not style_exists(self.layer_name): with open(os.path.join(script_dir, 'resources/cmap.sld')) as sld: self.set_default_style(self.layer_name, self.layer_name, sld.read().format(latest_band=bands)) self.update_geonode(self.layer_name, title=self.get_title(bands), description=self.abstract, store=self.layer_name, bounds=('-178.75', '178.75', '-88.75', '88.75', 'EPSG:4326')) self.truncate_gs_cache(self.layer_name) self.cleanup()