import numpy as np
import glob
import re

filelist = glob.glob("XrayLuminosity_512*")
filelist.sort(reverse=True)

n=2
outarray=np.empty(shape=[0,3])
for name in filelist:

  redshift=float(re.findall(r"[-+]?\d*\.\d+|\d+",name)[1])
  Xray=np.fromfile(name).reshape(512,512,512)
  Density=np.fromfile('Density_%04i_%4.1f_normal.dat'%(n,redshift)).reshape(512,512,512)

  index = np.argwhere(Xray > 0)
  xmin = index[:][:,0].min()
  xmax = index[:][:,0].max()
  ymin = index[:][:,1].min()
  ymax = index[:][:,1].max()
  zmin = index[:][:,2].min()
  zmax = index[:][:,2].max()

  Density = Density[Xray>0]
  X=Xray[Xray>0]
  z=np.ones_like(X)*redshift
  temp = np.array([z,Density,X])
  outarray=np.append(outarray,temp.T,axis=0)
  print temp.T
  #print outarray
  #Xray=np.zeros([512,512,512])
  #Xray[Density>Density_mean] = Xmean

  #np.savetxt('Density_Xray_%4.2f.dat'%redshift,outarray.T)
  n+=1

np.savetxt('Density_Xray.dat',outarray)

