Beispiel #1
0
    def write_db_to_brightway(self):
        for s in pyprind.prog_bar(self.scenarios.items()):
            scenario, year = s

            print('Write new database to Brightway2.')
            wurst.write_brightway2_database(
                self.db, "ecoinvent_" + scenario + "_" + str(year))
Beispiel #2
0
def test_full_import():
    bw.projects.set_current(BW_PROJECT)

    ndb = setup_db()

    ndb.update_electricity()
    ndb.update_cars()
    dbname = "test_carculator_complete"
    if dbname in bw.databases:
        del bw.databases[dbname]
    wurst.write_brightway2_database(ndb.db, dbname)
    del bw.databases[dbname]
Beispiel #3
0
def test_full_import():
    bw.projects.set_current(BW_PROJECT)

    ndb = NewDatabase(
        scenario=scenario,
        year=year,
        source_db='ecoinvent 3.6 cutoff',
        source_version=3.6)

    ndb.update_electricity_to_remind_data()
    ndb.update_cars()
    dbname = "test_carculator_complete"
    if dbname in bw.databases:
        del bw.databases[dbname]
    wurst.write_brightway2_database(ndb.db, dbname)
    del bw.databases[dbname]
Beispiel #4
0
    def write_db_to_brightway(self, name=None):
        """
        Register the new database into an open brightway2 project.
        :param name: to give a custom name to the database
        :type name: str
        """

        if name:
            if not isinstance(name, str):
                raise TypeError("`name` should be a string.")

        print("Write new database(s) to Brightway2.")
        for scenario in self.scenarios:
            wurst.write_brightway2_database(
                scenario["database"],
                name or eidb_label(scenario["model"], scenario["pathway"],
                                   scenario["year"]),
            )
Beispiel #5
0
    def write_superstructure_db_to_brightway(self,
                                             name=f"super_db_{date.today()}",
                                             filepath=None):
        """
        Register a super-structure database, according to https://github.com/dgdekoning/brightway-superstructure
        :return: filepath of the "scenarios difference file"
        """

        self.db = build_superstructure_db(self.db,
                                          self.scenarios,
                                          db_name=name,
                                          fp=filepath)

        print("Done!")

        wurst.write_brightway2_database(
            self.db,
            name,
        )
Beispiel #6
0
    def write_db_to_brightway(self, name=None):
        """
        Register the new database into an open brightway2 project.
        :param name: to give a (list) of custom name(s) to the database.
        Should either be a string if there's only one database to export.
        Or a list of strings if there are several databases.
        :type name: str
        """

        if name:
            if isinstance(name, str):
                name = [name]
            elif isinstance(name, list):
                if not all(isinstance(item, str) for item in name):
                    raise TypeError(
                        "`name` should be a string or a sequence of strings.")
            else:
                raise TypeError(
                    "`name` should be a string or a sequence of strings.")
        else:
            name = [
                eidb_label(s["model"], s["pathway"], s["year"])
                for s in self.scenarios
            ]

        if len(name) != len(self.scenarios):
            raise ValueError(
                "The number of databases does not match the number of `name` given."
            )

        print("Write new database(s) to Brightway2.")
        for s, scenario in enumerate(self.scenarios):

            # we ensure first the absence of duplicate datasets
            scenario["database"] = self.check_for_duplicates(
                scenario["database"])

            wurst.write_brightway2_database(
                scenario["database"],
                name[s],
            )
 def write_db_to_brightway(self):
     print('Write new database to Brightway2.')
     wurst.write_brightway2_database(self.db,
                                     eidb_label(self.scenario, self.year))
Beispiel #8
0
 def write_db_to_brightway(self):
     print('Write new database to Brightway2.')
     wurst.write_brightway2_database(
         self.db, "ecoinvent_" + self.scenario + "_" + str(self.year))