Bugfixes in dobs

This commit is contained in:
Simon Kuberski 2022-06-19 02:03:29 +02:00
parent c9789a34e6
commit 061ba6ecfa

View file

@ -575,17 +575,13 @@ def read_dobs(fname, noempty=False, full_output=False, gz=True, separator_insert
if not fname.endswith('.gz'):
fname += '.gz'
with gzip.open(fname, 'r') as fin:
content = fin.read().decode('utf-8')
content = fin.read()
else:
if fname.endswith('.gz'):
warnings.warn("Trying to read from %s without unzipping!" % fname, UserWarning)
with open(fname, 'r', encoding='utf-8') as fin:
with open(fname, 'r') as fin:
content = fin.read()
# open and read gzipped xml file
infile = gzip.open(fname)
content = infile.read()
return import_dobs_string(content, noempty, full_output, separator_insertion=separator_insertion)
@ -779,31 +775,31 @@ def create_dobs_string(obsl, name, spec='dobs v1.0', origin='', symbol=[], who=N
allcov = {}
for o in obsl:
for name in o.cov_names:
if name in allcov:
if not np.array_equal(allcov[name], o.covobs[name].cov):
raise Exception('Inconsistent covariance matrices for %s!' % (name))
for cname in o.cov_names:
if cname in allcov:
if not np.array_equal(allcov[cname], o.covobs[cname].cov):
raise Exception('Inconsistent covariance matrices for %s!' % (cname))
else:
allcov[name] = o.covobs[name].cov
allcov[cname] = o.covobs[cname].cov
pd['cdata'] = []
for name in cov_names:
for cname in cov_names:
cd = {}
cd['id'] = name
cd['id'] = cname
covd = {'id': 'cov'}
if allcov[name].shape == ():
if allcov[cname].shape == ():
ncov = 1
covd['layout'] = '1 1 f'
covd['#data'] = '%1.14e' % (allcov[name])
covd['#data'] = '%1.14e' % (allcov[cname])
else:
shape = allcov[name].shape
shape = allcov[cname].shape
assert (shape[0] == shape[1])
ncov = shape[0]
covd['layout'] = '%d %d f' % (ncov, ncov)
ds = ''
for i in range(ncov):
for j in range(ncov):
val = allcov[name][i][j]
val = allcov[cname][i][j]
if val == 0:
ds += '0 '
else:
@ -816,8 +812,8 @@ def create_dobs_string(obsl, name, spec='dobs v1.0', origin='', symbol=[], who=N
ds = ''
for i in range(ncov):
for o in obsl:
if name in o.covobs:
val = o.covobs[name].grad[i]
if cname in o.covobs:
val = o.covobs[cname].grad[i]
if val != 0:
ds += '%1.14e ' % (val)
else: