def create_layers(self): data_range = RASTER_METEROLOGICAL_DATA_RANGE[self.map_class] # get a list with geo codes and city names from available states for geocode, city_name in get_cities().items(): raster_name = None raster_date = None # check the last raster file available by city raster_dir_path = os.path.join( RASTER_PATH, 'meteorological', 'city', self.map_class, str(geocode), ) search_path = os.path.join(raster_dir_path, '*') for raster_file_path in glob(search_path, recursive=True): # filter by tiff format if not raster_file_path[-3:] == 'tif': continue _raster_name = raster_file_path.split(os.sep)[-1] _raster_date = datetime.strptime(_raster_name, '%Y%m%d.tif') if raster_date is None or raster_date < _raster_date: raster_name = _raster_name raster_date = _raster_date # skip if no file found if raster_name is None: continue # layer configuration definition layer_name = city_name.upper().replace(' ', '_') layer_title = city_name.title() vmin, vmax = data_range layer_conf = { # general information 'map_class': self.map_class, 'geocode': geocode, 'name': layer_name, 'rgb': '#FF9900', 'title': layer_title, 'date_time': str(datetime.now()), # projection and data range 'wms_srs': self.map_config['wms_srs'], 'crs_proj': self.map_config['crs_proj'], 'vmin': vmin, 'vmax': vmax, # path 'file_name': '%s.map' % geocode, 'data_name': '%s.tif' % raster_date.strftime('%Y%m%d'), 'dir_path': os.path.join( self.path['local_mapfile_dir'], 'layers', self.map_class ), } self.create_layer(layer_conf)
def test_get_cities(self): """ :return: """ cities = dbdata.get_cities() assert cities[3304557] == 'Rio de Janeiro'
def create_layers(self): data_range = RASTER_METEROLOGICAL_DATA_RANGE[self.map_class] # get a list with geo codes and city names from available states for geocode, city_name in get_cities().items(): raster_name = None raster_date = None # check the last raster file available by city raster_dir_path = os.path.join( RASTER_PATH, 'meteorological', 'city', self.map_class, str(geocode), ) search_path = os.path.join( raster_dir_path, '*' ) for raster_file_path in glob(search_path, recursive=True): # filter by tiff format if not raster_file_path[-3:] == 'tif': continue _raster_name = raster_file_path.split(os.sep)[-1] _raster_date = datetime.strptime(_raster_name, '%Y%m%d.tif') if raster_date is None or raster_date < _raster_date: raster_name = _raster_name raster_date = _raster_date # skip if no file found if raster_name is None: continue # layer configuration definition layer_name = city_name.upper().replace(' ', '_') layer_title = city_name.title() vmin, vmax = data_range layer_conf = { # general information 'map_class': self.map_class, 'geocode': geocode, 'name': layer_name, 'rgb': '#FF9900', 'title': layer_title, 'date_time': str(datetime.now()), # projection and data range 'wms_srs': self.map_config['wms_srs'], 'crs_proj': self.map_config['crs_proj'], 'vmin': vmin, 'vmax': vmax, # path 'file_name': '%s.map' % geocode, 'data_name': '%s.tif' % raster_date.strftime('%Y%m%d'), 'dir_path': os.path.join( self.path['local_mapfile_dir'], 'layers', self.map_class ) } self.create_layer(layer_conf)
def generate_raster_cities( raster_class: str, date_start: datetime=None ): """ Create raster images by city using as mask a shapefile and background a raster file of the whole country. Each city can have raster file for datetime regards the datetime from the original file (whole country). :param raster_class: :param date_start: :return: """ path_search = os.path.join( RASTER_PATH, 'meteorological', 'country', raster_class, '*' ) cities = get_cities().items() n_processes = mp.cpu_count() for raster_input_file_path in glob(path_search, recursive=True): raster_name = raster_input_file_path.split(os.sep)[-1] # filter by tiff format if not raster_name[-3:] == 'tif': continue # filter by date raster_date = get_date_from_file_name(raster_name) if date_start is not None and raster_date < date_start: continue # processing p = mp.Pool(n_processes) p.map( MeteorologicalRasterProcess( raster_class, raster_date, raster_input_file_path ), cities ) p.close() p.join()
def generate_raster_cities(raster_class: str, date_start: datetime = None): """ Create raster images by city using as mask a shapefile and background a raster file of the whole country. Each city can have raster file for datetime regards the datetime from the original file (whole country). :param raster_class: :param date_start: :return: """ path_search = os.path.join( RASTER_PATH, 'meteorological', 'country', raster_class, '*' ) cities = get_cities().items() n_processes = mp.cpu_count() for raster_input_file_path in glob(path_search, recursive=True): raster_name = raster_input_file_path.split(os.sep)[-1] # filter by tiff format if not raster_name[-3:] == 'tif': continue # filter by date raster_date = get_date_from_file_name(raster_name) if date_start is not None and raster_date < date_start: continue # processing p = mp.Pool(n_processes) p.map( MeteorologicalRasterProcess( raster_class, raster_date, raster_input_file_path ), cities, ) p.close() p.join()