Skip to content
Snippets Groups Projects
Commit 165f9722 authored by Yngve Levinsen's avatar Yngve Levinsen
Browse files

added a simple code to read&save fieldmaps

this might not work in all cases just yet
parent be2fb42d
No related branches found
No related tags found
No related merge requests found
......@@ -934,3 +934,43 @@ class partran(dict):
for i in xrange(len(self.columns)):
self[self.columns[i]]=self.data[:,i]
class field_map:
'''
Class to read in the field map structures
WARNING: Work in progress!!
'''
def __init__(self, filename):
self._filename=filename
self._load_data(filename)
def _load_data(self,filename):
import os,numpy
if not os.path.isfile(filename):
raise ValueError("Cannot find file {}".format(filename))
fin = file(filename,'r')
l=fin.readline().split()
self.size=[]
numindexes=[]
while len(l)==2:
numindexes.append(int(l[0])+1)
self.size.append(float(l[1]))
l=fin.readline().split()
self.norm=float(l[0])
self.map=numpy.loadtxt(fin).reshape(numindexes)
print self.map.shape
def savemap(self, filename):
fout=file(filename,'w')
for n,s in zip(self.map.shape,self.size):
fout.write('{} {}\n'.format(n-1,s))
fout.write('{}\n'.format(self.norm))
l=1
for i in self.map.shape:
l*=i
data=self.map.reshape(l)
for j in data:
fout.write('{}\n'.format(j))
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment