import json


def read_micromanager_stage_positions(filename):
    """ read a list of micromanager stage positions, store these as a list """
    with open(filename, 'r') as stage_positions:
        pos = json.load(stage_positions)

    positions = []

    # iterate over each position in the list, grab the devices and positions
    for p in pos['map']['StagePositions']['array']:
        devs = p['DevicePositions']['array']
        sp = {d['Device']['scalar']: d['Position_um']['array'] for d in devs}
        positions.append(sp)

    return positions