demo.py 2.14 KB
Newer Older
Martin Reinecke's avatar
Martin Reinecke committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#
# Copyright(C) 2017-2018 Max-Planck-Society
# Author: Jakob Knollmueller
#
# Starblade is being developed at the Max-Planck-Institut fuer Astrophysik

Jakob Knollmueller's avatar
Jakob Knollmueller committed
19
import numpy as np
Jakob Knollmueller's avatar
Jakob Knollmueller committed
20
from astropy.io import fits
Jakob Knollmueller's avatar
Jakob Knollmueller committed
21
from matplotlib import pyplot as plt
Jakob Knollmueller's avatar
Jakob Knollmueller committed
22

Martin Reinecke's avatar
Martin Reinecke committed
23
import starblade as sb
Jakob Knollmueller's avatar
Jakob Knollmueller committed
24 25 26

if __name__ == '__main__':
    #specifying location of the input file:
Jakob Knollmueller's avatar
cleanup  
Jakob Knollmueller committed
27
    path = 'data/hst_05195_01_wfpc2_f702w_pc_sci.fits'
Jakob Knollmueller's avatar
Jakob Knollmueller committed
28 29 30 31 32 33 34 35 36
    path = 'data/frame-i-004874-3-0692.fits'

    # data = fits.open(path)[1].data
    data = fits.open(path)[0].data[1000:15000,1250:1750]
    data -= data.min() - 0.001
    # data = 1.-plt.imread('data/sdss.png').T[0]
    # data = fits.open(path)[1].data

    data = data.clip(min=0.0001)
Jakob Knollmueller's avatar
Jakob Knollmueller committed
37 38 39


    data = np.ndarray.astype(data, float)
Jakob Knollmueller's avatar
Jakob Knollmueller committed
40
    vmin = np.log(data.min()+0.2)
Jakob Knollmueller's avatar
Jakob Knollmueller committed
41
    vmax = np.log(data.max())
Jakob Knollmueller's avatar
Jakob Knollmueller committed
42
    plt.imsave('data.png', np.log(data),vmin=vmin,vmax=vmax)
Jakob Knollmueller's avatar
Jakob Knollmueller committed
43 44

    alpha = 1.25
Martin Reinecke's avatar
Martin Reinecke committed
45
    Starblade = sb.build_starblade(data, alpha=alpha)
Jakob Knollmueller's avatar
Jakob Knollmueller committed
46
    for i in range(10):
Jakob Knollmueller's avatar
Jakob Knollmueller committed
47
        Starblade = sb.starblade_iteration(Starblade, samples=i)
Jakob Knollmueller's avatar
Jakob Knollmueller committed
48 49 50

        #plotting on logarithmic scale
        plt.imsave('diffuse_component.png', Starblade.s.val, vmin=vmin, vmax=vmax)
Martin Reinecke's avatar
Martin Reinecke committed
51
        plt.imsave('pointlike_component.png', Starblade.u.val, vmin=vmin, vmax=vmax)
Jakob Knollmueller's avatar
Jakob Knollmueller committed
52 53 54 55 56 57 58
        plt.figure()
        k_lenghts = Starblade.power_spectrum.domain[0].k_lengths
        plt.plot(k_lenghts, Starblade.power_spectrum.val)
        plt.title('power spectrum')
        plt.yscale('log')
        plt.xscale('log')
        plt.ylabel('power')
Jakob Knollmueller's avatar
Jakob Knollmueller committed
59
        plt.xlabel('harmonic mode')
Jakob Knollmueller's avatar
Jakob Knollmueller committed
60
        plt.savefig('power_spectrum.png')