Network-structured error flattening for power grids and other real-world networks