Skip to content

Commit

Permalink
[dd_test] a few fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
m-weigand committed Oct 20, 2020
1 parent 61e0c33 commit b4dfc6d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 69 deletions.
66 changes: 5 additions & 61 deletions lib/lib_dd/decomposition/ccd_single_stateless.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,14 @@ def fit_one_spectrum(fit_data):
# run the inversion
ND.run_inversion()

# extract the (only) iteration
# extract the last iteration
final_iteration = ND.iterations[-1]

# renormalize data (we deal only with one spectrum here)
# WARNING/NOTE: Renormalization MUST occur before either rms values
# (iteration.rms_values) or integrated parameters (iteration.stat_pars) are
# accessed/computed, as these parameters are sensitive to the normalized
# parameters/values.
if fit_data['inv_opts']['norm_factors'] is not None:
norm_factors = fit_data['inv_opts']['norm_factors']

Expand All @@ -173,12 +177,6 @@ def fit_one_spectrum(fit_data):
# parameterization !)
iteration.m[0] -= np.log10(norm_factors)
iteration.f = iteration.Model.f(iteration.m)
# note that we use .stat_pars as a parameter. This is a property
# which triggers the initial aggregation/computation of the
# parameters. Only then can we modify them.
# iteration.statpars = renormalize_statpars(
# iteration.stat_pars, norm_factors
# )

# data
# note: the normalization factor can be applied either to the
Expand All @@ -195,60 +193,6 @@ def fit_one_spectrum(fit_data):
return ND


def renormalize_statpars(stat_pars_dict, norm_factors):
"""Given normalization factors for each spectrum, renormalize relevant stat
pars. Return the modified dictionary.
Parameters
----------
stat_pars_dict : dict
dictionary containing the stat pars of an iteration
(iteration.stat_pars)
norm_factors : numpy.ndarray
Normalization factors for the spectra
Returns
-------
stat_pars_dict : dict
dictionary containing the stat pars of an iteration
(iteration.stat_pars)
"""
if norm_factors is None:
return stat_pars_dict

# renormalize all parameters containing rho0
# Note: When the conductivity model is used, the normalisation factors
# refer to the data in conductivities, and correspondingly, sigma_0. As we
# apply the normalisation to a resistivity (rho_0) parameter, we have to
# invert the normalisations, which manifests as a sign change in the log
# operations
# if key == 'rho0' and norm_factors is not None):
# rho0 is log10
if int(os.environ.get('DD_COND', 0)) == 1:
stat_pars_dict['rho0'] += np.log10(norm_factors).squeeze()
else:
stat_pars_dict['rho0'] -= np.log10(norm_factors).squeeze()

# if(key == 'sigma0' and norm_factors is not None):
# # sigma0 is log10
# # renormalize
# values -= np.log10(norm_factors).squeeze()

# if key == 'sigma_infty' and norm_factors is not None:
# # sigma0 is log10
# # renormalize
# values -= np.log10(norm_factors).squeeze()

# if(key == 'm_tot_n' and norm_factors is not None):
# # renormalize
# if int(os.environ.get('DD_COND', 0)) == 1:
# values -= np.log10(norm_factors).squeeze()
# else:
# values += np.log10(norm_factors).squeeze()
return stat_pars_dict


def call_fit_functions(fit_data, ND):
# only proceed if one of the plot functions will be called. This makes sure
# that we can run without an existing output directory, and only fail if we
Expand Down
5 changes: 0 additions & 5 deletions lib/lib_dd/io/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,7 @@ def save_f(fid, final_iterations, norm_factors):
extra_dim = 1
f_data = f_data.T

# import pdb
# pdb.set_trace()
f_data = f_data.reshape(extra_dim, base_dim)
if norm_factors is not None:
print('normalising')
f_data /= norm_factors[index]
np.savetxt(fid, f_data)

open('f_format.dat', 'w').write(itd[0].Data.obj.data_format)
6 changes: 3 additions & 3 deletions src/dd_test/dd_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ def write_pc_infos(fid):
'git log -1 | grep commit',
shell=True
)
git_branch = subprocess.check_output('git branch | grep "\*"', shell=True)
git_branch = subprocess.check_output(r'git branch | grep "\*"', shell=True)
uname = subprocess.check_output('uname -a', shell=True)
cpu = subprocess.check_output(
'cat /proc/cpuinfo | grep "model name" | head -1', shell=True)
Expand All @@ -107,7 +107,7 @@ def write_pc_infos(fid):


def _get_data_files_for_binary(options):
return available_binaries[options.binary + '.py']['data_files'].values()
return list(available_binaries[options.binary]['data_files'].values())


def initialize_new_test_dir(options):
Expand Down Expand Up @@ -136,7 +136,7 @@ def initialize_new_test_dir(options):
# now write default dd_single.py call
default_N = 20
default_nr_cores = 1
fid.write(options.binary + '.py\n')
fid.write(options.binary + '\n')
fid.write('-n {0}\n-c {1}\n--silent\n'.format(
default_N, default_nr_cores))

Expand Down

0 comments on commit b4dfc6d

Please sign in to comment.