Open fjuniorr opened 7 months ago
I don't think we need a general strategy for now - we can hard code the unit conversions we need for the real data we have. There aren't that many:
[
{
'source': {'unit': 'Bq'},
'target': {'unit': 'kBq'},
'conversion_factor': 1e-3
},
{
'source': {'unit': 'ton'},
'target': {'unit': 'kg'},
'conversion_factor': 1e-3
},
{
'source': {'unit': 'g'},
'target': {'unit': 'kg'},
'conversion_factor': 1e3
},
{
'source': {'unit': 'mg'},
'target': {'unit': 'kg'},
'conversion_factor': 1e-6
},
]
I'm working on this in #42 by creating a new get_conversion_factor
that hardcodes the conversion factors that we have so far.
For the current matching flows in agribalyse-3.1.1-biosphere
and industry-2.0-biosphere
we are failing to generate conversions factors for:
SourceUnit | TargetUnit | SourceFlowName | TargetFlowName | ConversionFactor |
---|---|---|---|---|
kg | kBq | Lead-210/kg | Lead-210 | ? |
kg | kBq | Radium-226/kg | Radium-226 | ? |
kg | kBq | Radium-228/kg | Radium-228 | ? |
kg | kBq | Ruthenium | Ruthenium-103 | ? |
kg | m3 | Gas, mine, off-gas, process, coal mining/kg | Gas, mine, off-gas, process, coal mining | ? |
m2a | m2*year | Occupation, * | Occupation, * | 1 |
m3y | m3*year | Volume occupied, reservoir | Volume occupied, reservoir | 1 |
ton | m3 | Water | Water | 1 |
g | m3 | Water | Water | 0,000001 |
kg | m3 | Water | Water | 0,001 |
l | m3 | Water, * | Water, * | 0,001 |
@cmutel should we add these as well? Could you help me fill this table and check the values?
I will try, but the conversion factors aren't easily found. I will ask my network.
After https://github.com/fjuniorr/flowmapper/pull/51 I removed the following conversions factors across dimensions:
if s.name == 'Ammonia, as N' and t.name == 'Ammonia':
result = 17 / 14
elif s.name.startswith('Water') and t.name.startswith('Water') and s.unit == 'ton' and t.unit == 'm3':
result = 1.0
elif s.name.startswith('Water') and t.name.startswith('Water') and s.unit == 'g' and t.unit == 'm3':
result = 1e-6
elif s.name.startswith('Water') and t.name.startswith('Water') and s.unit == 'kg' and t.unit == 'm3':
result = 1e-3
elif s.name.startswith('Water') and t.name.startswith('Water') and s.unit == 'l' and t.unit == 'm3':
I've not read the docs carefully but the pint
package used for https://github.com/fjuniorr/flowmapper/issues/55 has support for conversions across dimensions using contexts.
This question appears to be useful python - How to use transformations in pint package correctly? - Stack Overflow
@cmutel now it's clearer to me that conversion_factor
should be a method of Flow
, not Unit
. With this change we can properly use information from the flows to handle both conversions across dimensions and others (such as in https://github.com/fjuniorr/flowmapper-ci/issues/13 when to be modelled as pure elements the content of one substance in terms of other is not 1).
See https://github.com/fjuniorr/flowmapper/issues/24#issuecomment-1833224902