Пример #1
0
    def get_dataset(self, identifier):
        """Get the handle for the dataset with given identifier from the data
        store. Returns None if no dataset with the given identifier exists.

        Parameters
        ----------
        identifier : string
            Unique dataset identifier

        Returns
        -------
        vizier.datastore.base.DatasetHandle
        """
        url = self.urls.get_dataset(identifier)
        r = requests.get(url)
        if r.status_code == 404:
            return None
        elif r.status_code != 200:
            r.raise_for_status()
        # The result is the workflow handle
        obj = json.loads(r.text)
        ds = deserialize.DATASET_DESCRIPTOR(obj)
        return RemoteDatasetHandle(
            identifier=ds.identifier,
            columns=ds.columns,
            row_count=ds.row_count,
            rows=[deserialize.DATASET_ROW(row) for row in obj[labels.ROWS]],
            store=self)
Пример #2
0
    def create_dataset(self, 
            columns: List[DatasetColumn], 
            rows: List[DatasetRow], 
            properties: Optional[Dict[str, Any]] = None,
            human_readable_name: str = "Untitled Dataset", 
            backend_options: Optional[List[Tuple[str, str]]] = None, 
            dependencies: Optional[List[str]] = None
        ) -> DatasetDescriptor:
        """Create a new dataset in the project datastore using the API. Expects
        a list of columns and the rows for the dataset. All columns and rows
        should have unique non-negative identifier (although this may not
        be enforced by all backend datastores). Depending on the backend
        datastore the given identifier may change. They are, however, required
        to reference the given properties properly.

        Raises ValueError if the backend datastore rejects the given dataset.

        Parameters
        ----------
        columns: list(vizier.datastore.dataset.DatasetColumn)
            List of columns. It is expected that each column has a unique
            identifier.
        rows: list(vizier.datastore.dataset.DatasetRow)
            List of dataset rows.
        properties: dict, optional
            Properties for dataset components

        Returns
        -------
        vizier.datastore.dataset.DatasetDescriptor
        """
        url = self.urls.create_dataset()
        data:Dict[str, Any] = {
            labels.COLUMNS: [serialize.DATASET_COLUMN(col) for col in columns],
            labels.ROWS: [serialize.DATASET_ROW(row) for row in rows]
        }
        if not properties is None:
            data[labels.PROPERTIES] = properties
        # Send request. Raise exception if status code indicates that the
        # request was not successful.
        r = requests.post(url, json=data)
        r.raise_for_status()
        obj = json.loads(r.text)
        return deserialize.DATASET_DESCRIPTOR(obj)
Пример #3
0
    def create_dataset(self, columns, rows, annotations=None):
        """Create a new dataset in the project datastore using the API. Expects
        a list of columns and the rows for the dataset. All columns and rows
        should have unique non-negative identifier (although this may not
        be enforced by all backend datastores). Depending on the backend
        datastore the given identifier may change. They are, however, required
        to reference the given annotations properly.

        Raises ValueError if the backend datastore rejects the given dataset.

        Parameters
        ----------
        columns: list(vizier.datastore.dataset.DatasetColumn)
            List of columns. It is expected that each column has a unique
            identifier.
        rows: list(vizier.datastore.dataset.DatasetRow)
            List of dataset rows.
        annotations: vizier.datastore.annotation.dataset.DatasetMetadata, optional
            Annotations for dataset components

        Returns
        -------
        vizier.datastore.dataset.DatasetDescriptor
        """
        url = self.urls.create_dataset()
        data = {
            labels.COLUMNS: [serialize.DATASET_COLUMN(col) for col in columns],
            labels.ROWS: [serialize.DATASET_ROW(row) for row in rows]
        }
        if not annotations is None:
            data[labels.ANNOTATIONS] = [
                serialize.ANNOTATION(a) for a in annotations.values
            ]
        # Send request. Raise exception if status code indicates that the
        # request was not successful.
        r = requests.post(url, json=data)
        r.raise_for_status()
        obj = json.loads(r.text)
        return deserialize.DATASET_DESCRIPTOR(obj)
Пример #4
0
    def get_descriptor(self, identifier):
        """Get the descriptor for the dataset with given identifier from the
        data store. Returns None if no dataset with the given identifier exists.

        Parameters
        ----------
        identifier : string
            Unique dataset identifier

        Returns
        -------
        vizier.datastore.base.DatasetDescriptor
        """
        url = self.urls.get_dataset_descriptor(identifier)
        r = requests.get(url)
        if r.status_code == 404:
            return None
        elif r.status_code != 200:
            r.raise_for_status()
        # The result is the workflow handle
        obj = json.loads(r.text)
        return deserialize.DATASET_DESCRIPTOR(obj)