From 0c5937f2cb245e944dae7d0a0bbce92a4e6ff7cf Mon Sep 17 00:00:00 2001 From: "Knollmueller, Jakob (kjako)" Date: Thu, 15 Feb 2018 15:26:15 +0100 Subject: [PATCH] plotting routines --- 1d_separation.py | 25 +++++++++++----------- hubble_separation.py | 49 ++++++++++++++++++++++++++++++++++++++++++++ point_separation.py | 27 +++--------------------- rgb_separation.py | 5 +++-- 4 files changed, 68 insertions(+), 38 deletions(-) create mode 100644 hubble_separation.py diff --git a/1d_separation.py b/1d_separation.py index d470c5c..bc73eed 100644 --- a/1d_separation.py +++ b/1d_separation.py @@ -39,45 +39,46 @@ if __name__ == '__main__': energy2 = problem_iteration(energy2) energy3 = problem_iteration(energy3) + size = 15 plt.figure() # plt.plot(data, 'k-') f, (ax0, ax1,ax2) = plt.subplots(3, sharex=True, sharey=True) - plt.suptitle('diffuse components') + plt.suptitle('diffuse components', size=size) ax0.plot(exp(energy1.s).val, 'k-') ax0.yaxis.set_label_position("right") - ax0.set_ylabel(r'$\alpha = 1.25$') + ax0.set_ylabel(r'$\alpha = 1.25$', size=size) ax0.set_ylim(1e-1,1e3) ax0.set_yscale("log") ax1.plot(exp(energy2.s).val, 'k-') ax1.yaxis.set_label_position("right") - ax1.set_ylabel(r'$\alpha = 1.5$') + ax1.set_ylabel(r'$\alpha = 1.5$', size=size) ax2.plot(exp(energy3.s).val, 'k-') ax2.yaxis.set_label_position("right") - ax2.set_ylabel(r'$\alpha = 1.75$') + ax2.set_ylabel(r'$\alpha = 1.75$', size=size) plt.savefig('1d_diffuse.pdf') plt.figure() f, (ax0, ax1,ax2) = plt.subplots(3, sharex=True, sharey=True) - plt.suptitle('point-like components') + plt.suptitle('point-like components', size=size) ax0.plot(exp(energy1.u).val, 'k-') ax0.yaxis.set_label_position("right") - ax0.set_ylabel(r'$\alpha = 1.25$') + ax0.set_ylabel(r'$\alpha = 1.25$', size=size) ax0.set_ylim(1e-1,1e3) ax0.set_yscale("log") ax1.plot(exp(energy2.u).val, 'k-') ax1.yaxis.set_label_position("right") - ax1.set_ylabel(r'$\alpha = 1.5$') + ax1.set_ylabel(r'$\alpha = 1.5$', size=size) ax2.plot(exp(energy3.u).val, 'k-') ax2.yaxis.set_label_position("right") - ax2.set_ylabel(r'$\alpha = 1.75$') + ax2.set_ylabel(r'$\alpha = 1.75$', size=size) ax0.set_yscale("log") @@ -87,21 +88,21 @@ if __name__ == '__main__': plt.savefig('1d_points.pdf') plt.figure() f, (ax0, ax1,ax2) = plt.subplots(3, sharex=True, sharey=True) - plt.suptitle('data and true components') + plt.suptitle('data and true components', size=size) ax0.plot(data, 'k-') ax0.set_yscale("log") ax0.set_ylim(1e-1,1e3) ax0.yaxis.set_label_position("right") - ax0.set_ylabel(r'data') + ax0.set_ylabel(r'data', size=size) ax1.plot(exp(s).val, 'k-') ax1.yaxis.set_label_position("right") - ax1.set_ylabel(r'diffuse') + ax1.set_ylabel(r'diffuse', size=size) ax2.plot(exp(u).val, 'k-') ax2.yaxis.set_label_position("right") - ax2.set_ylabel(r'point-like') + ax2.set_ylabel(r'point-like', size=size) # plt.ylim(1e-0) plt.savefig('1d_data.pdf') diff --git a/hubble_separation.py b/hubble_separation.py new file mode 100644 index 0000000..23eddf9 --- /dev/null +++ b/hubble_separation.py @@ -0,0 +1,49 @@ +from point_separation import build_problem, problem_iteration, load_data +from nifty2go import * +import numpy as np +from matplotlib import rc +rc('font',**{'family':'serif','serif':['Palatino']}) +rc('text', usetex=True) +from matplotlib import pyplot as plt +from matplotlib.colors import LogNorm + + +np.random.seed(42) +if __name__ == '__main__': + path = 'hst_05195_01_wfpc2_f702w_pc_sci.fits' + data = load_data(path) + alpha = 1.3 + + + + myEnergy = build_problem(data, alpha=alpha) + for i in range(10): + myEnergy = problem_iteration(myEnergy) + + size = 15 + vmin = data.min()+0.01 + vmax = 0.1*data.max() + plt.figure() + plt.imshow(np.exp(myEnergy.s.val),norm=LogNorm(vmin=vmin, vmax=vmax)) + cbar = plt.colorbar() + cbar.set_label('flux', size=size) + plt.title('diffuse emission', size=size) + plt.axis('off') + plt.savefig('hubble_diffuse.pdf') + + plt.figure() + plt.imshow(np.exp(myEnergy.u.val), norm=LogNorm(vmin=vmin, vmax=vmax)) + cbar = plt.colorbar() + cbar.set_label('flux', size=size) + plt.title('point-like emission', size=size) + plt.axis('off') + plt.savefig('hubble_point.pdf') + + plt.figure() + plt.imshow(data, norm=LogNorm(vmin=vmin, vmax=vmax)) + cbar = plt.colorbar() + cbar.set_label('flux', size=size) + plt.title('data', size=size) + plt.axis('off') + plt.savefig('hubble_data.pdf') + plt.close() diff --git a/point_separation.py b/point_separation.py index d2dcc66..d68ac84 100644 --- a/point_separation.py +++ b/point_separation.py @@ -40,8 +40,8 @@ def build_problem(data, alpha): separationEnergy = SeparationEnergy(position=initial_x, parameters=parameters) return separationEnergy -def problem_iteration(energy): - controller = GradientNormController(verbose=True, tol_abs_gradnorm=0.00000001, iteration_limit=3) +def problem_iteration(energy, iterations=3): + controller = GradientNormController(verbose=True, tol_abs_gradnorm=0.00000001, iteration_limit=iterations) minimizer = RelaxedNewton(controller=controller) energy, convergence = minimizer(energy) new_position = energy.position @@ -69,28 +69,7 @@ def multi_problem_iteration(energy_list): return new_energy if __name__ == '__main__': - path = 'hst_05195_01_wfpc2_f702w_pc_sci.fits' - data = load_data(path) - alpha = 1.3 - - - myEnergy = build_problem(data, alpha=alpha) - x =np.arange(0,100) - y = np.sin(x/12.) - y **=2 - y[50] = 10 - y[4] = 5 - y[70] = 3 - y += 0.1 - myEnergy = build_problem(y, alpha=alpha) - - for i in range( 100): - - myEnergy = problem_iteration(myEnergy) - # plt.viridis() - # plt.imsave('points0.png',myEnergy.u.val) - # plt.imsave('maps0.png',(myEnergy.s).val) - # plt.imsave('data0.png',myEnergy.d.val) + pass diff --git a/rgb_separation.py b/rgb_separation.py index d58ed86..2eb14e1 100644 --- a/rgb_separation.py +++ b/rgb_separation.py @@ -3,10 +3,11 @@ from matplotlib import pyplot as plt import numpy as np if __name__ == '__main__': - data = plt.imread('eso1242a.jpg') + # data = plt.imread('eso1242a.jpg') + data = plt.imread('10Keso1242a.tif') data = data.astype(float) data = data.clip(0.0001) - energy_list = build_multi_problem(data, 1.35) + energy_list = build_multi_problem(data, 1.2) for i in range(10): energy_list = multi_problem_iteration(energy_list) -- GitLab