Esempio n. 1
0
class FoundryDatasets():
    """
    Class to download datasets hosted on Materials Data Facility

    Args:
        no_local_server: (bool), whether or not the server is local. Set to True if running on e.g. Google Colab

        anonymous: (bool), whether to use your MDF user or be anonymous. Some functionality may be disabled if True

        test: (bool), whether to be in test mode. Some functionality may be disabled if True

    Methods:
        download_data: downloads specified data from MDF and saves to current directory
            Args:
                name: (str), name of the dataset to download

                doi: (str), digital object identifier of the dataset to download

                download: (bool), whether or not to download the full dataset

            Returns:
                None
    """

    def __init__(self, no_local_server, anonymous, test):
        self.no_local_server = no_local_server
        self.anonymous = anonymous
        self.test = test
        self.mdf = Forge(no_local_server=self.no_local_server,
                         anonymous=self.anonymous,
                         test=self.test)

    def download_data(self, name=None, doi=None, download=False):
        if name is not None:
            self.mdf.match_source_names(name)
        elif doi is not None:
            self.mdf.match_dois(doi)
        else:
            print('ERROR: please specify either the dataset name or DOI for lookup MDF')
        result = self.mdf.search()
        if len(result) == 1:
            print('Successfully found the desired dataset on MDF')
            print('MDF entry:')
            pprint(result)
            if download == True:
                print('Downloading dataset from MDF')
                self.mdf.globus_download(results=result)
        return
Esempio n. 2
0
def test_forge_match_dois():
    f = Forge(index="mdf")
    # One doi
    f.match_dois("https://dx.doi.org/10.13011/M3B36G")
    res1 = f.search()
    assert res1 != []
    assert check_field(res1, "dc.identifier.identifier",
                       "https://dx.doi.org/10.13011/M3B36G") == 0

    # Multiple dois
    f.match_dois(["https://dx.doi.org/10.13011/M3B36G", "10.18126/M23P9G"])
    res2 = f.search()

    # # res1 is ça subset of res2
    assert len(res2) > len(res1)
    assert all([r1 in res2 for r1 in res1])
    assert check_field(res2, "dc.identifier.identifier",
                       "10.18126/M23P9G") == 2

    # No doi
    assert f.match_dois("") == f