Skip to content

Commit

Permalink
Tiny changes to address gaussian noise parameters in input files
Browse files Browse the repository at this point in the history
  • Loading branch information
thisFreya committed Dec 12, 2021
1 parent cd7a691 commit 6d03b19
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
13 changes: 13 additions & 0 deletions ioSPI/cryoemio.py
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ def fill_parameters_dictionary(
*** miscellaneous ***
- seed [OPTIONAL] : seed for the run. If not present, random.
- signal_to_noise [OPTIONAL] : signal-to-noise ratio for gaussian white noise.
- signal_to_noise_db [OPTIONAL] : signal-to-noise ratio in decibels.
"""
parameters = None
with open(input_params_file, "r") as f:
Expand All @@ -143,6 +145,17 @@ def fill_parameters_dictionary(
except KeyError:
random.seed()
dic["simulation"]["seed"] = random.randint(0, int(1e10))
dic["other"] = {}
try:
dic["other"]["signal_to_noise"] = parameters["miscellaneous"]["signal_to_noise"]
except KeyError:
pass
try:
dic["other"]["signal_to_noise_db"] = parameters["miscellaneous"][
"signal_to_noise_db"
]
except KeyError:
pass
dic["simulation"]["log_file"] = log_file
dic["sample"] = {}
dic["sample"]["diameter"] = parameters["specimen_grid_params"]["hole_diameter_nm"]
Expand Down
13 changes: 11 additions & 2 deletions tests/test_cryoemio.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,11 @@ def test_fill_parameters_dictionary_max():
noise = "no"
detector_q_efficiency = 0.1
mtf_params = [0.1, 0.0, 0.7, 0, 0]
noise_override = 0.1
noise_override = "yes"
log_file = "itslog.log"
seed = 210
snr = 0.6
snr_db = 10
key = particle_mrcout.split(".mrc")[0]

try:
Expand Down Expand Up @@ -109,7 +111,11 @@ def test_fill_parameters_dictionary_max():
"detector_Q_efficiency": detector_q_efficiency,
"MTF_params": mtf_params,
},
"miscellaneous": {"seed": seed},
"miscellaneous": {
"seed": seed,
"signal_to_noise": snr,
"signal_to_noise_db": snr_db,
},
}
contents = yaml.dump(data)
f.write(contents)
Expand Down Expand Up @@ -167,6 +173,9 @@ def test_fill_parameters_dictionary_max():
assert out_dict["detector"]["mtf_alpha"] == mtf_params[3]
assert out_dict["detector"]["mtf_beta"] == mtf_params[4]
assert out_dict["detector"]["image_file_out"] == mrc_file

assert out_dict["other"]["signal_to_noise"] == snr
assert out_dict["other"]["signal_to_noise_db"] == snr_db
finally:
os.unlink(tmp_yml.name)

Expand Down

0 comments on commit 6d03b19

Please sign in to comment.