<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def map_midc_to_pvlib(variable_map, field_name):
 """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. """

    new_field_name = field_name
    for midc_name, pvlib_name in variable_map.items():
        if field_name.startswith(midc_name):
            # extract the instrument and units field and then remove units
            instrument_units = field_name[len(midc_name):]
            units_index = instrument_units.find('[')
            instrument = instrument_units[:units_index - 1]
            new_field_name = pvlib_name + instrument.replace(' ', '_')
            break
    return new_field_name