@@ -346,7 +346,7 @@ def interp_smoothed_array_and_derivatives(
346346 return interps
347347
348348
349- def compare_l2_norm (depth , calc , obs ):
349+ def l2_norm_profiles (depth , calc , obs ):
350350 """
351351 Computes the L2 norm for N profiles at a time (assumed to be linear between points).
352352
@@ -362,12 +362,12 @@ def compare_l2_norm(depth, calc, obs):
362362 """
363363 err = []
364364 for i in range (len (calc )):
365- err .append (l2_norm (depth , calc [i ], obs [i ]))
365+ err .append (l2_norm_profile (depth , calc [i ], obs [i ]))
366366
367367 return err
368368
369369
370- def compare_chisqr_factor (calc , obs ):
370+ def chisqr_profiles (calc , obs ):
371371 """
372372 Computes the chisqr factor for N profiles at a time. Assumes a 1% a priori uncertainty on the seismic model.
373373
@@ -381,12 +381,12 @@ def compare_chisqr_factor(calc, obs):
381381 """
382382 err = []
383383 for i in range (len (calc )):
384- err .append (chisqr_factor (calc [i ], obs [i ]))
384+ err .append (chisqr_profile (calc [i ], obs [i ]))
385385
386- return err
386+ return np . array ( err )
387387
388388
389- def l2_norm (x , funca , funcb ):
389+ def l2_norm_profile (x , funca , funcb ):
390390 """
391391 Computes the L2 norm of the difference between two 1D profiles,
392392 assuming linear interpolation between points.
@@ -407,12 +407,11 @@ def l2_norm(x, funca, funcb):
407407 :return: L2 norm (scalar)
408408 :rtype: float
409409 """
410- diff = np .array (funca - funcb )
411- diff = diff * diff
410+ diff = np .square (funca - funcb )
412411 return np .sqrt (integrate .trapezoid (diff , x ))
413412
414413
415- def chisqr_factor (calc , obs ):
414+ def chisqr_profile (calc , obs , uncertainties = 0.01 ):
416415 """
417416 Computes the :math:`\\ chi^2` factor for a single profile, assuming a 1 %
418417 uncertainty on the reference (observed) values. This provides a normalized
@@ -428,22 +427,20 @@ def chisqr_factor(calc, obs):
428427 where :math:`N` is the number of elements in the profile.
429428
430429 :param calc: Array of calculated values (e.g., from a model).
431- :type calc: array-like of float
430+ :type calc: array
432431
433432 :param obs: Array of reference or observed values.
434- :type obs: array-like of float
433+ :type obs: array
434+
435+ :param uncertainties: Array of uncertainties values.
436+ :type uncertainties: array or float
435437
436438 :return: The :math:`\\ chi^2` factor for the profile.
437439 :rtype: float
438440 """
439441
440- err = np .empty_like (calc )
441- for i in range (len (calc )):
442- err [i ] = pow ((calc [i ] - obs [i ]) / (0.01 * np .mean (obs )), 2.0 )
443-
444- err_tot = np .sum (err ) / len (err )
445-
446- return err_tot
442+ err = np .square ((calc - obs ) / (uncertainties * np .mean (obs )))
443+ return np .sum (err ) / len (err )
447444
448445
449446def independent_row_indices (array ):
0 commit comments