added an option to provide output directory for MCMC results
@@ -323,8 +323,8 @@ def mcmc_negfc_sampling(cube, angs, psfn, ncomp, plsc, initial_state, fwhm=4,
burnin=0.3, rhat_threshold=1.01, rhat_count_threshold=1,
niteration_min=0, niteration_limit=1e2,
niteration_supp=0, check_maxgap=1e4, nproc=1,
- output_file=None, display=False, verbosity=0,
- save=False):
+ output_dir='results/', output_file=None, display=False,
+ verbosity=0, save=False):
r""" Runs an affine invariant mcmc sampling algorithm in order to determine
the position and the flux of the planet using the 'Negative Fake Companion'
technique. The result of this procedure is a chain with the samples from the
@@ -411,6 +411,9 @@ def mcmc_negfc_sampling(cube, angs, psfn, ncomp, plsc, initial_state, fwhm=4,
Maximum number of steps per walker between two Gelman-Rubin test.
nproc: int, optional
The number of processes to use for parallelization.
+ output_dir: str, optional
+ The name of the output directory which contains the output files in the
+ case ``save`` is True.
output_file: str, optional
The name of the output file which contains the MCMC results in the case
``save`` is True.
@@ -448,9 +451,9 @@ def mcmc_negfc_sampling(cube, angs, psfn, ncomp, plsc, initial_state, fwhm=4,
output_file = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
try:
- os.makedirs('results/'+output_file)
+ os.makedirs(output_dir+output_file)
except OSError as exc:
- if exc.errno == 17 and os.path.isdir('results/'+output_file):
+ if exc.errno == 17 and os.path.isdir(output_dir+output_file):
# errno.EEXIST == 17 -> File exists
pass
else:
@@ -551,7 +554,7 @@ def mcmc_negfc_sampling(cube, angs, psfn, ncomp, plsc, initial_state, fwhm=4,
if save:
import pickle
- fname = 'results/{f}/{f}_temp_k{k}'.format(f=output_file, k=k)
+ fname = '{d}{f}/{f}_temp_k{k}'.format(d=output_dir,f=output_file, k=k)
data = {'chain': sampler.chain,
'lnprob': sampler.lnprobability,
'AR': sampler.acceptance_fraction}
@@ -626,11 +629,11 @@ def mcmc_negfc_sampling(cube, angs, psfn, ncomp, plsc, initial_state, fwhm=4,
'AR': sampler.acceptance_fraction,
'lnprobability': sampler.lnprobability}
- with open('results/'+output_file+'/MCMC_results', 'wb') as fileSave:
+ with open(output_dir+output_file+'/MCMC_results', 'wb') as fileSave:
pickle.dump(output, fileSave)
msg = "\nThe file MCMC_results has been stored in the folder {}"
- print(msg.format('results/'+output_file+'/'))
+ print(msg.format(output_dir+output_file+'/'))
if verbosity == 1 or verbosity == 2:
timing(start_time)
