Package: randonneur
randonneurKeep moving forward.Randonneur is a library to make changes to life cycle inventory databases. You can use it to re-link your data to the latest version of a background database, to update existing databases with new data, or to perform other data transformations. Randonneur uses JSON files to describe these changes; contrast this withwurst, which can do these manipulations and more, but documents its manipulations in code.Although designed to work withBrightway, this library is not Brightway-specific.UsageBasic patternLoad arandonneurdata migration file.Load an inventory database in thewurstformatDo any necessary data preparation steps, e.g. nomenclature harmonization between migration and database fieldsDecide on what data types you want to apply changes to;exchanges,datasets, or both.Decide on what types of changes you want to apply:create,replace,update,delete, anddisaggregateDecide whether you want to apply the changes in the migration file to all datasets/exchanges or just a subset; builddataset_filterand/orexchange_filterfunctions if necessary.Applymigrate_datasetsormigrate_exchangesWrite the resulting database to diskData formatMigration data is specified in a JSON file as a single dictionary. This filemustinclude the following keys:name: Follows thedata package specificationlicenses: Follows thedata package specification. Must be a list.In addition, the following properties should follow thedata package specificationif provided:versiondescriptionsourceshomepagecontributorscreatedFinally, at least one change type should be included. The change types are:create-datasetscreate-exchangesreplaceupdateudpatedeletedisaggregateSee the directoryexamplesfor real-world implementations.For migrating exchanges: Given a database, iterate through the datasets. If adataset_filteris given, ignore any datasets which don't pass the filter. In each dataset, iterate through the exchanges. If anexchange_filteris given, ignore any exchanges which don't pass the filter. For each exchange, look at the following possible transformations in order:delete,replace,update, anddisaggregate. Only one transformation can be done to an exchange. Each transformation will change or delete the exchange under consideration, and maybe add some new exchanges to the dataset, though this addition will only happen after the original exchanges have been examined. After looking at all the exchanges, apply thecreatetransformation to add more exchanges if provided.For each exchange and transformation, we need to decide if that transformation should be applied. We do this based on the attributes of the dataset and exchange, and the attributes given in the transformation data. We compare the attribute values for a given set of fields, and these attributes must match exactly. The default fields arename,reference product,product,location,unit; you can specify your own fields.Migrating datasets works the same way, except that we operate directly on the datasets instead of the exchanges.Migrating exchangesExchanges are the consumption or production of a good or service. Exchanges link two datasets (two activities, one product and one activity, one activity and one biosphere flow, or even other dataset types). We support the following types of exchange changes:deletereplaceupdatedisaggregatecreateCreateCreates a new exchange in all datasets, or in one specific dataset.Because we are specifying a new exchange, we need to listallinformation needed to define an exchange,includingthe exchangeamount. This is different than the other modification types, whererelativeamounts are given with the keyallocation. We can't give relative amounts here because we have no exchange to refer to, and we don't have a surefire way to identify the reference production exchange (and there might not be one in any case).If you want to add an exchange to all datasets:{"create":[{"targets":[{# All fields needed to define an exchange}]}]}If you only want to create an exchange in one dataset:{"create":[{"targets":[{# All fields needed to define an exchange}],"dataset":{# All fields needed to identify the dataset}}]}datasetmust be adict, not a list; it can only identify one dataset.Note that in thewurstformat,datasetuse the keyreference productwhile exchanges use the keyproduct; these are two different concepts, so have different keys.ReplaceReplacement substitutes an exchange one-to-one; as such, the new exchange must be completely defined.However, theamountshould not be specified; rather, anallocationfactor should be given, and theamountof the original exchange will be multiplied byallocation.Ifallocationis not given, a default value of 1.0 is used.Note:randonneurcurrently does not adjust uncertainty when rescaling.Aside from the quantitative values, no other data from the original exchange is taken over to the new exchange. If you only want to change a few fields, use anupdateinstead. If you don't want the exchange amount re-scaled, use a combination ofdeleteandcreate.The data format forreplacetype is:{"replace":[{"source":{# All fields needed to identify the exchange to be replaced},"target":{# All fields needed to define the new exchange},# `dataset` is optional"dataset":{# All fields needed to identify the dataset to change}}]}Updateupdatediffers fromreplacein that it changes attributes of the original exchange instead of creating a completely new object; otherwise, its behaviour is the same asreplace. The data format is:{"update":[{"source":{# All fields needed to identify the exchange to be modified},"target":{# Some fields which you want to change},# `dataset` is optional"dataset":{# All fields needed to identify the dataset to change}}]}DeleteDelete exchanges. Follows the same patterns asreplaceandupdate:{"delete":[{"source":{# All fields needed to identify the exchange to be deleted},# `dataset` is optional"dataset":{# All fields needed to identify the dataset to change}}]}DisaggregateDisaggregation is splitting one exchange into many. Theallocationfield is used to determine how much of the exchange passes to each new exchange.The new exchanges start ascopiesof the original exchange, and are updating using the additional data provided. In other words, this functions more like anupdatethan areplace. This is because the most common use case for disaggregation is to split one input or output among several regions, where almost all metadata for the child exchanges would be identical.allocationfields do not have to sum to one.The data format includes a list of new exchanges for each matched source:{"disaggregate":[{"source":{# All fields needed to identify the exchange to be disaggregated},"targets":[{# Some fields which you want to change}],# `dataset` is optional"dataset":{# All fields needed to identify the dataset to change}}]}ContributingContributions are very welcome.
To learn more, see theContributor Guide.LicenseDistributed under the terms of theBSD 3 Clause license,randonneuris free and open source software.IssuesIf you encounter any problems,
pleasefile an issuealong with a detailed description.