Commit c6081027 authored by Maude Le Jeune's avatar Maude Le Jeune
Browse files

more io dmc

parent 6cd89441
......@@ -280,3 +280,31 @@ def read_cl(file,field=1,hdu=1):
cl = hdulist[hdu].data.field(field)
return cl
def vec2mat (V):
""" Convert vector to symmetric matrix.
"""
ncross = size(V)
dim = int(floor(sqrt(ncross*2)))
M = zeros((dim, dim))
c = 0
for i in range(dim):
for j in range(i+1):
M[i,j] = V[c]
M[j,i] = M[i,j]
c = c+1
return M
def mat2vec (M):
""" Convert symmetric matrix to vector.
"""
dim = shape(M)[0]
ncross = dim*(dim+1)/2
V = zeros((ncross, 1))
c = 0
for i in range(dim):
for j in range(i+1):
V[c] = M[i,j]
c = c+1
return squeeze(V)
......@@ -296,14 +296,25 @@ def write_covmat(file, cov, nbmodes=None):
"""
if __piolib(file):
try:
nFreqs = np.shape(cov)[0]
ncross = nFreqs*(nFreqs+1)/2
Q = np.shape(cov)[2]
R = np.zeros((Q,ncross))
for q in range(Q):
R[q,:] = sp.mat2vec(cov[:,:,q])
grpname = pio.GetGrpName(file)
checkgroup (grpname, "TAB2D")
checkgroup (grpname, "TAB2D", str(ncross+1))
grp = pio.OpenTAB2DGrp(grpname, "w")
val = pio.CreateTAB2DObject(file,'PIODOUBLE')
nr = shape(R)[0]
nc = shape(R)[1]+1
val = pio.WriteTAB2DObject(w,file, 'PIO'+precision,"tab=0:0,0:"+str(nr-1) , grp)
val = pio.WriteTAB2DObject(R,file, 'PIO'+precision,"tab=1:"+str(nc-1)+",0:"+str(nr-1) , grp)
nr = np.shape(R)[0]
nc = np.shape(R)[1]+1
if nbmodes is None:
w = np.zeros((Q))
else:
w = np.squeeze(nbmodes)
val = pio.WriteTAB2DObject(w,file, 'PIODOUBLE',"tab=0:0,0:%d"%(nr-1), grp)
val = pio.WriteTAB2DObject(R,file, 'PIODOUBLE',"tab=1:%d,0:%d"%((nc-1),(nr-1)) , grp)
val = pio.CloseTAB2DGrp(grp)
pio.CloseTAB2DGrp(grp)
except pio.pioError,val:
......@@ -323,13 +334,14 @@ def write_table(file, tab):
"""
if __piolib(file):
try:
nr = np.shape(tab)[0]
nc = np.shape(tab)[1]
grpname = pio.GetGrpName(file)
checkgroup (grpname, "TAB2D")
checkgroup (grpname, "TAB2D", str(nc))
grp = pio.OpenTAB2DGrp(grpname, "w")
val = pio.CreateTAB2DObject(file,'PIODOUBLE')
nr = shape(tab)[0]
nc = shape(tab)[1]
val = pio.WriteTAB2DObject(tab,file, 'PIO'+precision,"tab=0:%d,0:%d"%((nc-1),(nr-1)) , grp)
val = pio.WriteTAB2DObject(tab,file, 'PIODOUBLE',"tab=0:%d,0:%d"%((n
c-1),(nr-1)) , grp)
pio.CloseTAB2DGrp(grp)
except pio.pioError,val:
return str(val)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment