def _get_coverage(self): """ Returns the coverage to be used for the importer """ gdal_dataset = GDALGmlUtil.open_gdal_dataset_from_any_file(self.session.get_files()) crs = gdal_dataset.get_crs() general_recipe = GeneralRecipe(self.session) global_metadata_fields = general_recipe._global_metadata_fields() local_metadata_fields = general_recipe._local_metadata_fields() sentence_evaluator = SentenceEvaluator(ExpressionEvaluatorFactory()) gdal_coverage_converter = GdalToCoverageConverter(self.resumer, self.session.get_default_null_values(), self.recipe_type, sentence_evaluator, self.session.get_coverage_id(), None, self.session.get_files(), crs, None, None, global_metadata_fields, local_metadata_fields, None, None, general_recipe._metadata_type(), None, None) coverage_slices = self._get_coverage_slices(crs, gdal_coverage_converter) fields = GdalRangeFieldsGenerator(gdal_dataset, self.options['band_names']).get_range_fields() global_metadata = None if len(coverage_slices) > 0: global_metadata = gdal_coverage_converter._generate_global_metadata(coverage_slices[0], self.evaluator_slice) coverage = Coverage(self.session.get_coverage_id(), coverage_slices, fields, gdal_dataset.get_crs(), gdal_dataset.get_band_gdal_type(), self.options['tiling'], global_metadata) return coverage
def _get_coverages(self): """ Returns the list of coverages to be used for the importer """ gdal_dataset = GDALGmlUtil.open_gdal_dataset_from_any_file( self.session.get_files()) crs = CRSUtil.get_compound_crs( [self.options['time_crs'], gdal_dataset.get_crs()]) general_recipe = GeneralRecipe(self.session) global_metadata_fields = general_recipe._global_metadata_fields() local_metadata_fields = general_recipe._local_metadata_fields() sentence_evaluator = SentenceEvaluator(ExpressionEvaluatorFactory()) gdal_coverage_converter = GdalToCoverageConverter( self.resumer, self.session.get_default_null_values(), self.recipe_type, sentence_evaluator, self.session.get_coverage_id(), None, self.session.get_files(), crs, None, None, global_metadata_fields, local_metadata_fields, None, None, general_recipe._metadata_type(), None, None, self.session) coverage_slices_dict = self._get_coverage_slices( crs, gdal_coverage_converter) fields = GdalRangeFieldsGenerator( gdal_dataset, self.options['band_names']).get_range_fields() global_metadata = None if len(coverage_slices_dict["base"]) > 0: global_metadata = gdal_coverage_converter._generate_global_metadata( coverage_slices_dict["base"][0], self.evaluator_slice) results = [] base_coverage_id = self.session.get_coverage_id() for key, value in coverage_slices_dict.items(): if key == "base": # base coverage coverage = Coverage(base_coverage_id, coverage_slices_dict[key], fields, crs, gdal_dataset.get_band_gdal_type(), self.options['tiling'], global_metadata) else: # overview coverage (key = overview_index) coverage_id = create_coverage_id_for_overview( base_coverage_id, key) coverage = Coverage(coverage_id, coverage_slices_dict[key], fields, crs, gdal_dataset.get_band_gdal_type(), self.options['tiling'], global_metadata, base_coverage_id, key) results.append(coverage) return results
def _get_gdal_coverages(self, recipe_type): """ Returns a list of coverage that uses the gdal slicer :param string: recipe_type the type of recipe :rtype: master.importer.coverage.Coverage """ crs = self._resolve_crs(self.options['coverage']['crs']) sentence_evaluator = SentenceEvaluator(ExpressionEvaluatorFactory()) input_files = self.session.get_files() user_axes = self._read_axes(crs) DEFAULT_NUMBER_GDAL_DIMENSIONS = 2 self.__validate_data_bound_axes(user_axes, DEFAULT_NUMBER_GDAL_DIMENSIONS) coverages = GdalToCoverageConverter(self.resumer, self.session.default_null_values, recipe_type, sentence_evaluator, self.session.get_coverage_id(), self._read_bands(), input_files, crs, user_axes, self.options['tiling'], self._global_metadata_fields(), self._local_metadata_fields(), self._bands_metadata_fields(), self._axes_metadata_fields(), self._metadata_type(), self.options['coverage']['grid_coverage'], self.options['import_order'], self.session).to_coverages() return coverages
def _create_convertor(self, convertors, cov_id, crs_code, level, res): recipe_type = GdalToCoverageConverter.RECIPE_TYPE sentence_evaluator = SentenceEvaluator(ExpressionEvaluatorFactory()) files = [] crs = self._get_crs(crs_code) bands_metadata_fields = {} axis_metadata_fields = {} default_null_values = [self.DEFAULT_NULL_VALUE] return GdalToCoverageConverter(self.resumer, default_null_values, recipe_type, sentence_evaluator, cov_id, self.BANDS[level][res], files, crs, self._read_axes(crs), self.options['tiling'], self._global_metadata_fields(), self._local_metadata_fields(), bands_metadata_fields, axis_metadata_fields, self._metadata_type(), self.grid_cov, self.import_order, self.session)
def _global_metadata_fields(self): """ Returns the global metadata fields :rtype: dict """ if "coverage" in self.options and "metadata" in self.options['coverage']: for file_path in self.session.get_files(): try: if "global" in self.options['coverage']['metadata']: global_metadata = self.options['coverage']['metadata']['global'] # global_metadata is manually defined with { ... some values } if type(global_metadata) is dict: metadata_dict = self.options['coverage']['metadata']['global'] else: # global metadata is defined with "a string" if global_metadata != "auto": raise RuntimeException("No valid global metadata attribute for gdal slicer could be found, " "given: " + global_metadata) else: # global metadata is defined with auto, then parse the metadata from the first file to a dict if self.options['coverage']['slicer']['type'] == "gdal": metadata_dict = GdalToCoverageConverter.parse_gdal_global_metadata(file_path) elif self.options['coverage']['slicer']['type'] == "netcdf": metadata_dict = NetcdfToCoverageConverter.parse_netcdf_global_metadata(file_path) else: # global is not specified in ingredient file, it is considered as "global": "auto" if self.options['coverage']['slicer']['type'] == "gdal": metadata_dict = GdalToCoverageConverter.parse_gdal_global_metadata(file_path) elif self.options['coverage']['slicer']['type'] == "netcdf": metadata_dict = NetcdfToCoverageConverter.parse_netcdf_global_metadata(file_path) self.__add_color_palette_table_to_global_metadata(metadata_dict, file_path) result = escape_metadata_dict(metadata_dict) return result except Exception as e: if ConfigManager.skip == True: # Error with opening the first file, then try with another file as skip is true pass else: raise e return {}
def _get_gdal_coverage(self, recipe_type): """ Returns a coverage that uses the gdal slicer :param string: recipe_type the type of recipe :rtype: master.importer.coverage.Coverage """ crs = self._resolve_crs(self.options['coverage']['crs']) sentence_evaluator = SentenceEvaluator(ExpressionEvaluatorFactory()) coverage = GdalToCoverageConverter(recipe_type, sentence_evaluator, self.session.get_coverage_id(), self._read_bands(), self.session.get_files(), crs, self._read_axes(crs), self.options['tiling'], self._global_metadata_fields(), self._local_metadata_fields(), self._bands_metadata_fields(), self._axes_metadata_fields(), self._metadata_type(), self.options['coverage']['grid_coverage']).to_coverage() return coverage
def _create_convertor(self, cov_id): recipe_type = GdalToCoverageConverter.RECIPE_TYPE sentence_evaluator = SentenceEvaluator(ExpressionEvaluatorFactory()) files = [] bands_metadata_fields = {} axis_metadata_fields = {} default_null_values = [] if self.product == self.DEFAULT_PRODUCT: default_null_values = [self.DEFAULT_NULL_VALUE] return GdalToCoverageConverter( self.resumer, default_null_values, recipe_type, sentence_evaluator, cov_id, [self.BAND], files, self.crs, self._read_axes(self.crs), self.options['tiling'], self._global_metadata_fields(), self._local_metadata_fields(), bands_metadata_fields, axis_metadata_fields, self._metadata_type(), self.grid_cov, self.import_order)