PascalLesage / presamples

Package to write, load, manage and verify numerical arrays, called presamples.
BSD 3-Clause "New" or "Revised" License
14 stars 11 forks source link

Losses override production amounts #54

Closed PascalLesage closed 4 years ago

PascalLesage commented 5 years ago

Because presamples replaces values in the technosphere matrix, losses accounted for as technosphere exchanges (where input == output) that are in a presample package replace amounts that should actually be production minus loss when building the technosphere matrix.

Can't think of a solution for the loader, and hence extra care should be taken when generating these presamples (i.e. presamples should for samples of production - samples of losses).

For now, a warning should be issued when matrix_data is supplied to create_presamples_package with an element where input==output.

PascalLesage commented 5 years ago

For example, this will create correct presamples for technosphere exchanges if there is one or less loss exchanges:

Assume get_samples is a function that generates samples for an exchange expressed as a dict.

iterations = 1000
techno_samples = []
techno_indices = []
for exc in act.technosphere():
    techno_indices.append((exc.input.key, exc.output.key, 'technosphere'))
    if exc.input == exc.output:
        techno_samples.append(
            get_samples(exc.as_dict(), iterations)-np.ones(shape=(iterations,))*act['production amount']
        )
        else:
            techno_samples.append(get_samples(exc.as_dict(), iterations))
techno_samples_concat = np.concatenate([arr.reshape(1, -1) for arr in techno_samples], axis=0)
id_, path = presamples.create_presamples_package(
    matrix_data=[(techno_samples_concat, techno_indices, 'technosphere')]
)