def __init__(self, ref, version='Unspecified', internal=False, data_dir=None, model=None, **kwargs):
        """
        :param ref:
        :param version:
        :param internal:
        :param kwargs: quiet, upstream
        """
        super(EcoinventSpreadsheet, self).__init__(ref, **kwargs)
        self.version = version
        self.internal = internal

        self._serialize_dict['version'] = version
        self._serialize_dict['internal'] = internal

        # these things are query-only, for foreground use
        self._data_dir = data_dir
        self._model = model
        self.fg = None
        self.bg = None
        self.lcia = None
        if self._data_dir is not None:
            if model == 'undefined':
                self.fg = EcospoldV2Archive(self._fg_filename, prefix='datasets - public')
            else:
                self.fg = EcospoldV2Archive(self._fg_filename, prefix='datasets')
                if os.path.exists(self._bg_filename):
                    print('BG: Accessing LCI from %s' % self._bg_filename)
                self.bg = LcArchive(self._lci_cache)
                if os.path.exists(self._lci_cache):
                    self.bg.load_json(from_json(self._lci_cache))
                if os.path.exists(self._lcia_validate_filename):
                    self.lcia = EcospoldV2Archive(self._lcia_validate_filename, prefix='datasets')
Example #2
0
def archive_from_json(fname, **archive_kwargs):
    """
    :param fname: JSON filename
    :return: an ArchiveInterface
    """
    j = from_json(fname)
    archive_kwargs["quiet"] = True

    if "prefix" in j.keys():
        archive_kwargs["prefix"] = j["prefix"]

    if "nsUuid" in j.keys():
        archive_kwargs["ns_uuid"] = j["nsUuid"]

    if j["dataSourceType"] == "EcoinventSpreadsheet":
        archive_kwargs["internal"] = bool(j["internal"])
        archive_kwargs["version"] = j["version"]

    try:
        a = archive_factory(j["dataSourceReference"], j["dataSourceType"], **archive_kwargs)
    except KeyError:
        raise ValueError("Unknown dataSourceType %s" % j["dataSourceType"])

    if "catalogNames" in j:
        a.catalog_names = j["catalogNames"]

    if "upstreamReference" in j:
        print("**Upstream reference encountered: %s\n" % j["upstreamReference"])
        a._serialize_dict["upstreamReference"] = j["upstreamReference"]

    a.load_json(j)
    return a