def get_coverage(cls, root_path, dataset_id): ''' Memoization (LRU) of _get_coverage ''' if root_path is None or dataset_id is None: return None try: result, ts = cls._coverages.pop(dataset_id) if (time.time() - ts) > cls.CACHE_EXPIRATION: result.close() raise KeyError(dataset_id) except KeyError: if dataset_id is None: return None result = AbstractCoverage.load(root_path, dataset_id,mode='r') result.value_caching = False ts = time.time() if result is None: return None if len(cls._coverages) >= cls.CACHE_LIMIT: key, value = cls._coverages.popitem(0) coverage, ts = value coverage.close(timeout=5) cls._coverages[dataset_id] = result, ts return result
def get_coverage(cls, root_path, dataset_id): ''' Memoization (LRU) of _get_coverage ''' if root_path is None or dataset_id is None: return None try: result, ts = cls._coverages.pop(dataset_id) if (time.time() - ts) > cls.CACHE_EXPIRATION: result.close() raise KeyError(dataset_id) except KeyError: if dataset_id is None: return None result = AbstractCoverage.load(root_path, dataset_id, mode='r') result.value_caching = False ts = time.time() if result is None: return None if len(cls._coverages) >= cls.CACHE_LIMIT: key, value = cls._coverages.popitem(0) coverage, ts = value coverage.close(timeout=5) cls._coverages[dataset_id] = result, ts return result
def parse_constraints(self, environ): base = os.path.split(self.filepath) coverage = AbstractCoverage.load(base[0], base[1],mode='r') last_modified = formatdate(time.mktime(time.localtime(os.stat(self.filepath)[ST_MTIME]))) environ['pydap.headers'].append(('Last-modified', last_modified)) atts = {} atts['title'] = coverage.name dataset = DatasetType(coverage.name) #, attributes=atts) fields, queries = environ['pydap.ce'] response = environ['pydap.response'] queries = filter(bool, queries) # fix for older version of pydap all_vars = coverage.list_parameters() fill_index = -1 if response == "dods": time_context = coverage.get_parameter_context(coverage.temporal_parameter_name) time_fill_value = time_context.fill_value time_data = coverage.get_parameter_values(coverage.temporal_parameter_name) try: fill_index = np.where(time_data == time_fill_value)[0][0] except IndexError: pass # If no fields have been explicitly requested, of if the sequence # has been requested directly, return all variables. if not fields: fields = [[(name, ())] for name in all_vars] dataset = self.get_dataset(coverage, fields, fill_index, dataset, response) return dataset
def __init__(self, coverage_id, base_dir, spans=None, view_criteria=None, viewable_parameters=None, order_by=None): from coverage_model.coverage import AbstractCoverage # wrap a read only abstract coverage so we can access values in a common method self._cov = AbstractCoverage.load(base_dir, persistence_guid=coverage_id, mode='r') self.spans = spans self.view_criteria = view_criteria self.viewable_parameters = [] self.order_by = [] self.np_array_dict = {} if viewable_parameters is not None: if isinstance(viewable_parameters, basestring): viewable_parameters = [viewable_parameters] if not isinstance(viewable_parameters, collections.Iterable): raise TypeError(''.join(['Unable to create view for view_parameter type: ', str(type(viewable_parameters))])) for val in viewable_parameters: if isinstance(val, basestring): self.viewable_parameters.append(val) else: raise TypeError(''.join(['Unable to create view for view_parameter member type: ', str(type(val)), ' from view_parameters: ', str(viewable_parameters)])) if order_by is not None: if isinstance(order_by, basestring): order_by = [order_by] if not isinstance(order_by, collections.Iterable): raise TypeError(''.join(['Unable to order by type: ', str(type(order_by))])) for val in order_by: if isinstance(val, basestring): self.order_by.append(val) else: raise TypeError(''.join(['Unable to order by order_by member type: ', str(type(val)), ' from order_by: ', str(order_by)])) self._extract_parameter_data()
def evaluate(self, pval_callback, time_segment, fill_value=-9999, stride_length=None): self._import_func() from coverage_model.coverage import AbstractCoverage cov = AbstractCoverage.resurrect(self.param_map[self.external_name], mode='r') return self._callable(pval_callback, cov, self.external_name, time_segment)
def get_coverage(self, dataset_id,mode='w'): file_root = FileSystem.get_url(FS.CACHE,'datasets') coverage = AbstractCoverage.load(file_root, dataset_id, mode=mode) return coverage
def get_coverage(self, dataset_id, mode='w'): file_root = FileSystem.get_url(FS.CACHE, 'datasets') coverage = AbstractCoverage.load(file_root, dataset_id, mode=mode) return coverage
def append_reference_coverage(self, path, extents=None, **kwargs): super(ComplexCoverage, self).append_reference_coverage(path, **kwargs) rcov = AbstractCoverage.load(path) self.set_reference_coverage_extents(rcov.persistence_guid, extents, append=True)
def append_parameter(self, parameter_context): # Dad doesn't store it so go to granddad AbstractCoverage.append_parameter(self, parameter_context)
def find(coverage_id, persistence_dir, db_name=None, limit=-1): db = DBFactory.get_db(db_name) rows = db.get(coverage_id) if len(rows) > 1: return AbstractCoverage.load(persistence_dir, persistence_guid=coverage_id, mode='r') return None