@@ -369,6 +369,14 @@ def save_reconstruction_csv(
369369 One file is written per mapper: ``source_plane_reconstruction_{i}.csv``,
370370 with columns ``y``, ``x``, ``reconstruction``, ``noise_map``.
371371
372+ The reconstruction noise map inverts the curvature regularization matrix, which is
373+ singular for rank-deficient inversions (e.g. the reduced-iteration searches used by
374+ test profiles). The column schema is fixed, because consumers index the CSV by
375+ column name, so in that case the ``noise_map`` column is written as ``nan`` (with a
376+ logged warning) rather than omitted, and the file is still written: the
377+ reconstruction is a science product in its own right and must not be lost, nor may
378+ a failure here abort the enclosing model-fit.
379+
372380 Parameters
373381 ----------
374382 inversion
@@ -383,10 +391,20 @@ def save_reconstruction_csv(
383391 y = mapper .source_plane_mesh_grid [:, 0 ]
384392 x = mapper .source_plane_mesh_grid [:, 1 ]
385393 reconstruction = inversion .reconstruction_dict [mapper ]
386- noise_map = inversion .reconstruction_noise_map_dict [mapper ]
394+
395+ try :
396+ noise_map = inversion .reconstruction_noise_map_dict [mapper ]
397+ except np .linalg .LinAlgError :
398+ logger .warning (
399+ f"save_reconstruction_csv: could not compute the reconstruction noise map for "
400+ f"mapper { i } (singular curvature_reg_matrix); writing the noise_map column of "
401+ f"source_plane_reconstruction_{ i } .csv as nan."
402+ )
403+ noise_map = None
387404
388405 with open (output_path / f"source_plane_reconstruction_{ i } .csv" , mode = "w" , newline = "" ) as f :
389406 writer = csv .writer (f )
390407 writer .writerow (["y" , "x" , "reconstruction" , "noise_map" ])
391408 for j in range (len (x )):
392- writer .writerow ([float (y [j ]), float (x [j ]), float (reconstruction [j ]), float (noise_map [j ])])
409+ noise_value = float ("nan" ) if noise_map is None else float (noise_map [j ])
410+ writer .writerow ([float (y [j ]), float (x [j ]), float (reconstruction [j ]), noise_value ])
0 commit comments