Example #1
0
def test_exists():
    d = Datasource(name="testing")
    d.save()

    exists = Datasource.exists(datasource_id=d.uuid())

    assert exists == True
Example #2
0
def assign_data(gas_data, lookup_results, overwrite):
    """ Create or get an existing Datasource for each gas in the file

        Args:
            gas_data (dict): Dictionary containing data and metadata for species
        Returns:
            dict: Dictionary of UUIDs of Datasources data has been assigned to keyed by species name
    """
    from HUGS.Modules import Datasource

    uuids = {}
    # Add in copying of attributes, or add attributes to the metadata at an earlier state.
    for species in gas_data:
        metadata = gas_data[species]["metadata"]
        data = gas_data[species]["data"]
        name = lookup_results[species]["name"]
        uuid = lookup_results[species]["uuid"]

        # If we have a UUID for this Datasource load the existing object
        # from the object store
        if uuid:
            datasource = Datasource.load(uuid=uuid)
        else:
            datasource = Datasource(name=name)

        # Add the dataframe to the datasource
        datasource.add_data(metadata=metadata, data=data, overwrite=overwrite)
        # Save Datasource to object store
        datasource.save()

        uuids[name] = datasource.uuid()

    return uuids
Example #3
0
    def assign_data(self,
                    lookup_results,
                    source_name,
                    data,
                    metadata,
                    overwrite=False):
        """ Assign data to a new or existing Datasource

            Args:
                lookup_results (dict): Results of Datasource lookup
                source_name (str): Name of data source
                data (xarray.Dataset): Data
                metadata (dict): Dictionary of metadata
                overwrite (bool, default=False): Should exisiting data be overwritten
            Returns:
                list: List of Datasource UUIDs
        """
        from HUGS.Modules import Datasource

        uuids = {}
        for key in lookup_results:
            uuid = lookup_results[key]["uuid"]
            name = metadata["name"]

            if uuid:
                datasource = Datasource.load(uuid=uuid)
            else:
                datasource = Datasource(name=name)

            datasource.add_data(metadata=metadata,
                                data=data,
                                data_type="footprint")
            datasource.save()

            uuids[name] = datasource.uuid()

        return uuids