def map_midc_to_pvlib(variable_map, field_name):
new_field_name = field_name<EOL>for midc_name, pvlib_name in variable_map.items():<EOL><INDENT>if field_name.startswith(midc_name):<EOL><INDENT>instrument_units = field_name[len(midc_name):]<EOL>units_index = instrument_units.find('<STR_LIT:[>')<EOL>instrument = instrument_units[:units_index - <NUM_LIT:1>]<EOL>new_field_name = pvlib_name + instrument.replace('<STR_LIT:U+0020>', '<STR_LIT:_>')<EOL>break<EOL><DEDENT><DEDENT>return new_field_name<EOL>
A mapper function to rename Dataframe columns to their pvlib counterparts.

    Parameters
    ----------
    variable_map: Dictionary
        A dictionary for mapping MIDC field name to pvlib name. See
        VARIABLE_MAP for default value and description of how to construct
        this argument.
    field_name: string
        The Column to map.

    Returns
    -------
    label: string
        The pvlib variable name associated with the MIDC field or the input if
        a mapping does not exist.

    Notes
    -----
    Will fail if field_name to be mapped matches an entry in VARIABLE_MAP and
    does not contain brackets. This should not be an issue unless MIDC file
    headers are updated.