示例#1
0
def import_secondary_context_membership():
    """Add docstring."""
    log.info('Read in secondary context membership')
    SecondaryContextMembership = pd.read_csv(inputpath +
                                             'SecondaryContextMembership.csv')
    return SecondaryContextMembership
示例#2
0
    SecondaryContextMembership = pd.read_csv(inputpath +
                                             'SecondaryContextMembership.csv')
    return SecondaryContextMembership


if __name__ == '__main__':

    flowables = pd.DataFrame()
    flowables_w_primary_contexts = pd.DataFrame()
    primary_contexts = pd.DataFrame()

    # Loop through flow class specific files based on those classes specified in flowlistspecs
    for t in flow_list_specs["flow_classes"]:
        # Handle flowables first
        flowables_for_class = read_in_flowclass_file(t, 'Flowables')
        log.info('Import ' + str(len(flowables_for_class)) +
                 ' flowables for class ' + t)
        # Drop duplicate flowables in list
        flowables_for_class = flowables_for_class.drop_duplicates(
            subset='Flowable')
        # Add Flow Class to columns
        flowables_for_class['Class'] = t
        flowables = pd.concat([flowables, flowables_for_class],
                              ignore_index=True,
                              sort=False)
        class_primary_contexts = read_in_flowclass_file(
            t, 'FlowablePrimaryContexts')
        flowables_for_class = flowables_for_class.drop_duplicates()
        log.info('Import ' + str(len(class_primary_contexts)) +
                 ' flowable primary contexts for class ' + t)
        class_primary_contexts = class_primary_contexts.dropna(axis=0,
                                                               how='all')
示例#3
0
    # Pull in mapping file
    mapping = fedelemflowlist.get_flowmapping(source)
    conversions = fedelemflowlist.get_alt_conversion()
    # merge in conversion factors where source unit = alternate unit
    mapping_w_conversion = pd.merge(
        mapping,
        conversions,
        how='left',
        left_on=['TargetFlowName', 'SourceUnit', 'TargetUnit'],
        right_on=['Flowable', 'AltUnit', 'Unit'])
    # update conversion factor where current conversion is 1 and the updated conversion exists
    converted1 = mapping_w_conversion['InverseConversionFactor'].notnull()
    converted2 = mapping_w_conversion['ConversionFactor'] == 1
    mapping_w_conversion['Convert'] = converted1 & converted2
    mapping_w_conversion.loc[
        (mapping_w_conversion['Convert'] == True),
        'ConversionFactor'] = mapping_w_conversion['InverseConversionFactor']
    converted = mapping_w_conversion['Convert'].sum()
    log.info('added conversion factors for ' + str(converted) + ' flows')
    mapping_w_conversion = mapping_w_conversion.drop(columns=[
        'Flowable', 'Unit', 'AltUnit', 'AltUnitConversionFactor',
        'InverseConversionFactor', 'Convert'
    ])
    flowmapping_order = list(flowmapping_fields.keys())
    mapping_w_conversion = mapping_w_conversion[flowmapping_order]

    for s in pd.unique(mapping_w_conversion['SourceListName']):
        mapping = mapping_w_conversion[mapping_w_conversion['SourceListName']
                                       == s]
        mapping.to_csv(flowmappingpath + s + '.csv', index=False)
        mappings = pd.read_csv(inputpath + base_name + ftype + '.csv')
        return mappings

    flowable_mappings = get_manual_mappings(base_name, 'flowables')
    context_mappings = get_manual_mappings(base_name, 'contexts')

    # Load full flow list to get all the contexts
    flowlist = fedelemflowlist.get_flows()
    flowlist_short = flowlist[['Flowable', 'Context', 'Flow UUID']]
    fl_mapping = pd.merge(flowable_mappings,
                          flowlist_short,
                          left_on=['TargetFlowName'],
                          right_on=['Flowable'])

    len_flowable_matches = len(fl_mapping)
    log.info("Matches of USLCI flowables to flowlist flows: " +
             str(len_flowable_matches))
    fl_mapping = pd.merge(context_mappings,
                          fl_mapping,
                          left_on=['TargetFlowContext'],
                          right_on=['Context'])
    fl_mapping = fl_mapping.drop(columns=['Flowable', 'Context'])
    len_matches = len(fl_mapping)
    log.info("Matches of USLCI flowables and contexts to flowlist flows: " +
             str(len_matches))

    manual_overrides = get_manual_mappings(base_name, 'manual_overrides')
    fl_corresponding = flowlist_short[(
        flowlist_short['Context'].isin(manual_overrides['TargetFlowContext'])
        & flowlist_short['Flowable'].isin(manual_overrides['Target Name']))]
    log.info("Found " + str(len(fl_corresponding)) +
             " flowlist flows in manual overrides.")
def import_secondary_context_membership():
    log.info('Read in secondary context membership')
    SecondaryContextMembership = pd.read_csv(inputpath + 'SecondaryContextMembership.csv')
    return SecondaryContextMembership

if __name__ == '__main__':

    flowables = pd.DataFrame()
    flowables_w_primary_contexts = pd.DataFrame()
    primary_contexts = pd.DataFrame()

    # Loop through flow class specific files based on those classes specified in flowlistspecs
    for t in flow_list_specs["flow_classes"]:
        # Handle flowables first
        flowables_for_class = read_in_flowclass_file(t, 'Flowables')
        log.info('Import ' + str(len(flowables_for_class)) + ' flowables for class ' + t)
        # Drop duplicate flowables in list
        flowables_for_class = flowables_for_class.drop_duplicates(subset='Flowable')
        # Add Flow Class to columns
        flowables_for_class['Class'] = t
        flowables = pd.concat([flowables, flowables_for_class], ignore_index=True, sort=False)
        class_primary_contexts = read_in_flowclass_file(t, 'FlowablePrimaryContexts')
        flowables_for_class = flowables_for_class.drop_duplicates()
        log.info('Import ' + str(len(class_primary_contexts)) + ' flowable primary contexts for class ' + t)
        class_primary_contexts = class_primary_contexts.dropna(axis=0, how='all')

        # merge in flowables and flowable primary contexts
        class_flowables_w_primary_contexts = pd.merge(flowables_for_class, class_primary_contexts)
        # Add in Alt units
        try:
            altunits_for_class = read_in_flowclass_file(t, 'FlowableAltUnits')