def create_coverage_dataset(self,name,wms_url,netcdf_url,low_res_url, data_range_from, data_range_to, is_categorical): """ Creates a coverage dataset in the EcoMaps DB @param name: Display name of the dataset @param wms_url: Endpoint for the mapping server @param netcdf_url: URL of the OpenDAP endpoint for this dataset @param low_res_url: URL for accessing the NetCDF file over the HTTP protocol @param data_range_from: Low range for the data @param data_range_to: High range for the data @param is_categorical: Set to true if the data is categorical (not continuous) """ with self.transaction_scope() as session: dataset_type = session.query(DatasetType).filter(DatasetType.type=='Coverage').one() dataset = Dataset() dataset.name = name dataset.dataset_type = dataset_type dataset.netcdf_url = netcdf_url dataset.wms_url = wms_url dataset.low_res_url = low_res_url dataset.data_range_from = data_range_from dataset.data_range_to = data_range_to dataset.is_categorical = is_categorical session.add(dataset)
def registerThreddsDatasets(url, types, session): """Scan over the given url for thredds datasets. Add to the session""" xml = parse(urllib2.urlopen(url)) for dataset in xml.getElementsByTagName("dataset"): if dataset.hasAttribute("urlPath"): # Here we should lookup the sevicename which (contained in this element) # and find out the services base. ds = Dataset() ds.dataset_type = types["GRID"] # Set to GRID type by default # See if a dataType has been defined for this dataset. If so, look # it up dataTypes = dataset.getElementsByTagName("dataType") if dataTypes.length == 1: ds.dataset_type = types[dataTypes[0].firstChild.nodeValue] path = dataset.attributes["urlPath"].value ds.name = dataset.attributes["name"].value ds.wms_url = urljoin(url, "/thredds/wms/" + path + "?service=WMS&version=1.3.0&request=GetCapabilities") ds.netcdf_url = urljoin(url, "/thredds/dodsC/" + path) session.add(ds) # Register the dataset to the session # Group sibling catalogRefs together. If any of these have an aggregation we will scan them # otherwise just scan all of the catalogueRegs catalogRefs = xml.getElementsByTagName("catalogRef") for key, group in groupby(catalogRefs, lambda e: e.parentNode): groupList = list(group) aggregations = filter(lambda x: x.attributes["xlink:title"].value.lower().endswith("aggregation"), groupList) scan = aggregations if len(aggregations) > 0 else groupList # Were there any aggregations? for catRef in scan: # Check if the current catRef node has any sibling datasets which are aggregations. # If it does, ignore this catRef if not hasSiblingAggregationDatasets(catRef): path = urljoin(url, catRef.attributes["xlink:href"].value) registerThreddsDatasets(path, types, session)
def create_point_dataset(self,name,wms_url,netcdf_url): """ Creates a point dataset in the EcoMaps DB @param name: Display name of the dataset @param wms_url: Endpoint for the mapping server @param netcdf_url: URL of the OpenDAP endpoint for this dataset """ with self.transaction_scope() as session: dataset_type = session.query(DatasetType).filter(DatasetType.type=='Point').one() dataset = Dataset() dataset.name = name dataset.dataset_type = dataset_type dataset.netcdf_url = netcdf_url dataset.wms_url = wms_url dataset.low_res_url = None session.add(dataset)
def _populate_session(self): with self._service.transaction_scope() as session: user = User() user.username = "******" user.name = "Test User" user.email = "*****@*****.**" user.access_level = "CEH" session.add(user) pointDst = DatasetType() pointDst.type = "Point" coverDst = DatasetType() coverDst.type = "Coverage" resultDst = DatasetType() resultDst.type = "Result" session.add(pointDst) session.add(coverDst) session.add(resultDst) dataset_a = Dataset() dataset_a.dataset_type = pointDst dataset_a.viewable_by_user_id = self._user_id dataset_a.name = "Dataset1" session.add(dataset_a) dataset_b = Dataset() dataset_b.dataset_type = pointDst dataset_b.name = "Dataset2" session.add(dataset_b) dataset_c = Dataset() dataset_c.dataset_type = pointDst dataset_c.viewable_by_user_id = self._another_user_id dataset_c.name = "Dataset3" session.add(dataset_c) dataset_d = Dataset() dataset_d.dataset_type = resultDst dataset_d.name = "Results Dataset 1" dataset_d.viewable_by_user_id = 1 session.add(dataset_d) analysis_a = Analysis() analysis_a.point_dataset = dataset_a analysis_a.coverage_datasets.append(AnalysisCoverageDataset(dataset_b)) analysis_a.viewable_by = self._user_id analysis_a.result_dataset = dataset_d analysis_a.deleted = False analysis_b = Analysis() analysis_b.point_dataset = dataset_a analysis_b.coverage_datasets.append(AnalysisCoverageDataset(dataset_b)) analysis_b.run_by = self._user_id analysis_b.result_dataset = dataset_d analysis_b.deleted = False analysis_c = Analysis() analysis_c.point_dataset = dataset_a analysis_c.coverage_datasets.append(AnalysisCoverageDataset(dataset_b)) analysis_c.viewable_by = self._another_user_id analysis_c.result_dataset = dataset_d analysis_c.deleted = False session.add(analysis_a) session.add(analysis_b) session.add(analysis_c)