示例#1
0
plt.colorbar()
plt.savefig('chisq_map',fmt='png')

for i in range(0,NX):
	for j in range(0,NY):
		chisq_min = chisq[i,j]
		if chisq[i,j] > 1.0:
			for ii in range(0,NX):
				for jj in range(0,NY):
					res = cube1[i,j]-cube2[ii,jj]
					res = res*res
					chisq_loc = np.sum(res[0]) + np.sum(res[3])
					chisq_loc /= 1001 * 1E25
					if chisq_loc < chisq_min:
						chisq_min = chisq_loc
						nodes[:,i,j] = np.copy(nodes[:,ii,jj])
						cube2[i,j] = np.copy(cube2[ii,jj])
						
		chisq[i,j] = chisq_min
	print 'i = ',i,'done'

chi_hist = chisq.reshape(NX*NY)
plt.cla()
plt.clf()
plt.hist(chi_hist,bins=50)
plt.savefig('chisq_hist_new',fmt='png')
pyana.fzwrite('inverted_spectra_purified.f0',cube2,0,'placeholder')
pyana.fzwrite('nodes_purified.f0',nodes,0,'placeholder')


示例#2
0
By = temp_input[0].data

for i in range(0, NX):
    for j in range(0, NY):
        spinor_cube[7, i, j, :] = np.sqrt(Bx[i, :, j]**2.0 + By[i, :, j]**2.0 +
                                          Bz[i, :, j]**2.0)
        spinor_cube[10, i,
                    j, :] = np.arccos(Bz[i, :, j] / spinor_cube[7, i, j, :])
        spinor_cube[11, i, j, :] = np.arctan(By[i, :, j] / Bx[i, :, j])

d = 66
plt.clf()
plt.cla()
plt.subplot(221)
plt.imshow(spinor_cube[2, :, :, d])
plt.colorbar()
plt.subplot(222)
plt.imshow(spinor_cube[7, :, :, d])
plt.colorbar()
plt.subplot(223)
plt.imshow(spinor_cube[10, :, :, d])
plt.colorbar()
plt.subplot(224)
plt.imshow(spinor_cube[9, :, :, d] / 1e5)
plt.colorbar()
plt.savefig('test_0.png', fmt='png')

#finally we need to flip it and write it down:
spinor_cube = spinor_cube[:, :, :, ::-1]
pyana.fzwrite(output_filename, spinor_cube, 0, 'placeholder')
示例#3
0
import numpy as np
import pyana
import sys

file_in = sys.argv[1] + '.dat'

spectrum = np.loadtxt(file_in, unpack=True)

NS = 4
NL = spectrum.shape[1]

print 'Number of wavelengths = ', NL

cube = np.zeros([1, 1, NS, NL])

cube[0, 0] = np.copy(spectrum[1:5])
#for s in range(1,4):
#	cube[0,0,s] /= cube[0,0,0]

pyana.fzwrite(sys.argv[1] + '.f0', cube, 0, 'placeholder')
示例#4
0
file_in = sys.argv[1]
file_out = sys.argv[2]
to_normalize = int(sys.argv[3])

temp = pyana.fzread(file_in)
stokes_cube = temp["data"]

dims = stokes_cube.shape
NX = dims[0]
NY = dims[1]
NL = dims[3]

print NX, NY, NL

noise_level = 3E-4
I_c_mean = np.mean(stokes_cube[:, :, 0, 0])
noise_level *= I_c_mean

for i in range(0, NX):
    for j in range(0, NY):
        loc_noise = noise_level * np.sqrt(stokes_cube[i, j, 0, 0] / I_c_mean)
        for s in range(0, 4):
            random_sample = np.random.normal(0, 1.0, NL)
            stokes_cube[i, j, s] += random_sample * loc_noise

if (to_normalize):
    for s in range(1, 4):
        stokes_cube[:, :, s, :] /= stokes_cube[:, :, 0, :]

pyana.fzwrite(file_out, stokes_cube, 0, 'placeholder')
示例#5
0
if (NB):
    B_v = an[start:end + 1] * np.cos(an[-1])
    B_h = an[start:end + 1] * np.sin(an[-1])

for i in range(0, B_start):
    an_conv[i] = flt.medfilt(an[i], 11)
    if (sigma):
        an_conv[i] = filters.gaussian_filter(an_conv[i], sigma)

if (NB):
    for i in range(B_start, B_end + 1):
        if (sigma):
            B_v[i - B_start] = filters.gaussian_filter(B_v[i - B_start], sigma)
            B_h[i - B_start] = filters.gaussian_filter(B_h[i - B_start], sigma)
        an_conv[i] = np.sqrt(B_v[i - B_start]**2.0 + B_h[i - B_start]**2.0)

if (NB):
    an_conv[-1] = np.cos(an_conv[-1])
    an_conv[-1] = filters.gaussian_filter(an_conv[-1], sigma)
    an_conv[-1] = np.clip(an_conv[-1], -0.99, 0.99)
    an_conv[-1] = np.arccos(an_conv[-1])

for i in range(0, 0):
    plt.clf()
    plt.cla()
    plt.imshow(an_conv[i])
    plt.colorbar()
    plt.savefig('node_' + str(i) + '.png', fmt='png')

pyana.fzwrite(file_out, an_conv, 0, 'bla')
示例#6
0
spectrum_mean[3] += spectrum_mean[1]+spectrum_mean[2]
spectrum_mean[1] -= spectrum_mean[1]
spectrum_mean[2] -= spectrum_mean[2]

#but also for the whole cube:
for s in range (1,4):
	cube[:,:,s,:] -= cube[:,:,0,:] * zero_level[s]/zero_level[0]

cube[:,:,3,:] += cube[:,:,1,:]+cube[:,:,2,:]
cube[:,:,1,:] = cube[:,:,2,:] = 0

for s in range (1,4):
	cube[:,:,s,:] /= cube[:,:,0,:]

wherenan = np.isnan(cube)
cube[wherenan] = 0.0

spectrum_to_plot=spectrum_mean
plt.subplot(221)
plt.plot(spectrum_to_plot[0])
plt.subplot(222)
plt.plot(spectrum_to_plot[1])
plt.subplot(223)
plt.plot(spectrum_to_plot[2])
plt.subplot(224)
plt.plot(spectrum_to_plot[3])
plt.tight_layout()
plt.savefig('mean_spectrum.png',fmt='png')

pyana.fzwrite(file_out,cube,0,'bla')
示例#7
0
	#regularize
	cH[:,:] = 0.0
	cV[:,:] = 0.0
	cD[:,:] = 0.0
	#cA[47:57,:] = 0.0

	#reconstruct
	reconstructed = pywt.idwt2(coeffs,'db8')

	plt.clf()
	plt.cla()
	plt.subplot(311)
	plt.imshow(nodes[p])
	plt.colorbar()
	plt.subplot(312)
	plt.imshow(reconstructed)
	plt.colorbar()
	plt.subplot(313)
	plt.imshow(nodes[p]-reconstructed)
	plt.colorbar()
	plt.tight_layout()
	plt.savefig('test'+str(p),fmt='png',bbox_inches='tight')
	plt.close('all')

	nodes[p] = reconstructed

pyana.fzwrite(sys.argv[3],nodes,0,'placeholder')



示例#8
0
		vt = f(vt_nodes)
		nodes[index:index+N_vt,i,j] = vt
		index+=N_vt
		f = interpol.interp1d(atmos[i,j,0],atmos[i,j,9])
		v = f(v_nodes)
		nodes[index:index+N_v,i,j] = v
		index+=N_v
		f = interpol.interp1d(atmos[i,j,0],atmos[i,j,7])
		B = f(B_nodes)
		nodes[index:index+N_B,i,j] = B
		index+=N_B
		f = interpol.interp1d(atmos[i,j,0],atmos[i,j,10])
		theta = f(theta_nodes)
		nodes[index:index+N_theta,i,j] = theta
		index+=N_theta
		f = interpol.interp1d(atmos[i,j,0],atmos[i,j,11])
		phi = f(phi_nodes)
		nodes[index:index+N_phi,i,j] = phi

#additional polishing - hardcode
#nodes[4,:,:] = 2E4

nodes = np.transpose(nodes,(0,2,1))
print nodes.shape
#write down nodes in the file:
output_file = sys.argv[2]
pyana.fzwrite(output_file,nodes,0,'placeholder')