def write_stewicombo_metadata(file_name, metadata_dict, category=''):
    """Write metadata JSON for combined inventory to local directory.

    :param file_name: str used as name of combined inventory
    :param metadata_dict: dictionary of metadata to save
    :param category: str, optional to save within a subfolder
    """
    meta = set_stewicombo_meta(file_name, category=category)
    meta.tool_meta = metadata_dict
    write_metadata_to_file(paths, meta)
Beispiel #2
0
def store_method(df, method_id):
    """Prints the method as a dataframe to parquet file"""
    meta = set_lcia_method_meta(method_id)
    method_path = outputpath + '/' + meta.category
    if meta.name_data == "":
        meta.name_data = df['Method'][0]
    meta.tool_meta = compile_metadata(method_id)
    try:
        log.info('saving ' + meta.name_data + ' to ' + method_path)
        write_df_to_file(df, paths, meta)
        write_metadata_to_file(paths, meta)
    except:
        log.error('Failed to save method')
Beispiel #3
0
def write_metadata(source_name, config, fb_meta, category, **kwargs):
    """
    Write the metadata and output as a JSON in a local directory
    :param source_name: string, source name for either a FBA or FBS dataset
    :param config: dictionary, configuration file
    :param fb_meta: object, metadata
    :param category: string, 'FlowBySector' or 'FlowByActivity'
    :param kwargs: additional parameters, if running for FBA, define "year" of data
    :return: object, metadata that includes methodology for FBAs
    """

    fb_meta.tool_meta = return_fb_meta_data(source_name, config, category,
                                            **kwargs)
    write_metadata_to_file(paths, fb_meta)
def write_metadata(file_name,
                   metadata_dict,
                   category='',
                   datatype="inventory"):
    """Write JSON metadata specific to inventory to local directory.

    :param file_name: str in the form of inventory_year
    :param metadata_dict: dictionary of metadata to save
    :param category: str of a stewi format type e.g. 'flowbyfacility'
        or source category e.g. 'TRI Data Files'
    :param datatype: 'inventory' when saving StEWI output files, 'source'
        when downloading and processing source data, 'validation' for saving
        validation metadata
    """
    if (datatype == "inventory") or (datatype == "source"):
        meta = set_stewi_meta(file_name, stewiformat=category)
        meta.tool_meta = metadata_dict
        write_metadata_to_file(paths, meta)
    elif datatype == "validation":
        with open(
                paths.local_path + '/validation/' + file_name +
                '_validationset_metadata.json', 'w') as file:
            file.write(json.dumps(metadata_dict, indent=4))
def write_fm_metadata(file_name, metadata_dict, category=''):
    """Generate and store metadata for facility matcher file."""
    meta = set_facilitymatcher_meta(file_name, category=category)
    meta.tool_meta = metadata_dict
    write_metadata_to_file(paths, meta)