@@ -397,7 +397,7 @@ def read_pobs(fname, full_output=False, gz=True, separator_insertion=None):
397
397
398
398
399
399
# this is based on Mattia Bruno's implementation at https://github.com/mbruno46/pyobs/blob/master/pyobs/IO/xml.py
400
- def import_dobs_string (content , noempty = False , full_output = False , separator_insertion = True ):
400
+ def import_dobs_string (content , full_output = False , separator_insertion = True ):
401
401
"""Import a list of Obs from a string in the Zeuthen dobs format.
402
402
403
403
Tags are not written or recovered automatically.
@@ -406,9 +406,6 @@ def import_dobs_string(content, noempty=False, full_output=False, separator_inse
406
406
----------
407
407
content : str
408
408
XML string containing the data
409
- noemtpy : bool
410
- If True, ensembles with no contribution to the Obs are not included.
411
- If False, ensembles are included as written in the file, possibly with vanishing entries.
412
409
full_output : bool
413
410
If True, a dict containing auxiliary information and the data is returned.
414
411
If False, only the data is returned as list.
@@ -457,7 +454,6 @@ def import_dobs_string(content, noempty=False, full_output=False, separator_inse
457
454
_check (dobs [4 ].tag == "ne" )
458
455
ne = int (dobs [4 ].text .strip ())
459
456
_check (dobs [5 ].tag == "nc" )
460
- nc = int (dobs [5 ].text .strip ())
461
457
462
458
idld = {}
463
459
deltad = {}
@@ -507,7 +503,11 @@ def import_dobs_string(content, noempty=False, full_output=False, separator_inse
507
503
508
504
for name in names :
509
505
for i in range (len (deltad [name ])):
510
- deltad [name ][i ] = np .array (deltad [name ][i ]) + mean [i ]
506
+ tmp = np .zeros_like (deltad [name ][i ])
507
+ for j in range (len (deltad [name ][i ])):
508
+ if deltad [name ][i ][j ] != 0. :
509
+ tmp [j ] = deltad [name ][i ][j ] + mean [i ]
510
+ deltad [name ][i ] = tmp
511
511
512
512
res = []
513
513
for i in range (len (mean )):
@@ -516,25 +516,30 @@ def import_dobs_string(content, noempty=False, full_output=False, separator_inse
516
516
obs_names = []
517
517
for name in names :
518
518
h = np .unique (deltad [name ][i ])
519
- if len (h ) == 1 and np .all (h == mean [i ]) and noempty :
519
+ if len (h ) == 1 and np .all (h == mean [i ]):
520
520
continue
521
- deltas .append (deltad [name ][i ])
522
- obs_names .append (name )
523
- idl .append (idld [name ])
521
+ repdeltas = []
522
+ repidl = []
523
+ for j in range (len (deltad [name ][i ])):
524
+ if deltad [name ][i ][j ] != 0. :
525
+ repdeltas .append (deltad [name ][i ][j ])
526
+ repidl .append (idld [name ][j ])
527
+ if len (repdeltas ) > 0 :
528
+ obs_names .append (name )
529
+ deltas .append (repdeltas )
530
+ idl .append (repidl )
531
+
524
532
res .append (Obs (deltas , obs_names , idl = idl ))
525
533
res [- 1 ]._value = mean [i ]
526
534
_check (len (e_names ) == ne )
527
535
528
536
cnames = list (covd .keys ())
529
537
for i in range (len (res )):
530
538
new_covobs = {name : Covobs (0 , covd [name ], name , grad = gradd [name ][i ]) for name in cnames }
531
- if noempty :
532
- for name in cnames :
533
- if np .all (new_covobs [name ].grad == 0 ):
534
- del new_covobs [name ]
535
- cnames_loc = list (new_covobs .keys ())
536
- else :
537
- cnames_loc = cnames
539
+ for name in cnames :
540
+ if np .all (new_covobs [name ].grad == 0 ):
541
+ del new_covobs [name ]
542
+ cnames_loc = list (new_covobs .keys ())
538
543
for name in cnames_loc :
539
544
res [i ].names .append (name )
540
545
res [i ].shape [name ] = 1
@@ -546,8 +551,6 @@ def import_dobs_string(content, noempty=False, full_output=False, separator_inse
546
551
res [i ].tag = symbol [i ]
547
552
if res [i ].tag == 'None' :
548
553
res [i ].tag = None
549
- if not noempty :
550
- _check (len (res [0 ].covobs .keys ()) == nc )
551
554
if full_output :
552
555
retd = {}
553
556
tool = file_origin .get ('tool' , None )
@@ -568,7 +571,7 @@ def import_dobs_string(content, noempty=False, full_output=False, separator_inse
568
571
return res
569
572
570
573
571
- def read_dobs (fname , noempty = False , full_output = False , gz = True , separator_insertion = True ):
574
+ def read_dobs (fname , full_output = False , gz = True , separator_insertion = True ):
572
575
"""Import a list of Obs from an xml.gz file in the Zeuthen dobs format.
573
576
574
577
Tags are not written or recovered automatically.
@@ -577,9 +580,6 @@ def read_dobs(fname, noempty=False, full_output=False, gz=True, separator_insert
577
580
----------
578
581
fname : str
579
582
Filename of the input file.
580
- noemtpy : bool
581
- If True, ensembles with no contribution to the Obs are not included.
582
- If False, ensembles are included as written in the file.
583
583
full_output : bool
584
584
If True, a dict containing auxiliary information and the data is returned.
585
585
If False, only the data is returned as list.
@@ -615,7 +615,7 @@ def read_dobs(fname, noempty=False, full_output=False, gz=True, separator_insert
615
615
with open (fname , 'r' ) as fin :
616
616
content = fin .read ()
617
617
618
- return import_dobs_string (content , noempty , full_output , separator_insertion = separator_insertion )
618
+ return import_dobs_string (content , full_output , separator_insertion = separator_insertion )
619
619
620
620
621
621
def _dobsdict_to_xmlstring (d ):
@@ -782,7 +782,7 @@ def create_dobs_string(obsl, name, spec='dobs v1.0', origin='', symbol=[], who=N
782
782
o = obsl [oi ]
783
783
if repname in o .idl :
784
784
if counters [oi ] < 0 :
785
- num = offsets [ oi ]
785
+ num = 0
786
786
if num == 0 :
787
787
data += '0 '
788
788
else :
@@ -798,7 +798,7 @@ def create_dobs_string(obsl, name, spec='dobs v1.0', origin='', symbol=[], who=N
798
798
if counters [oi ] >= len (o .idl [repname ]):
799
799
counters [oi ] = - 1
800
800
else :
801
- num = offsets [ oi ]
801
+ num = 0
802
802
if num == 0 :
803
803
data += '0 '
804
804
else :
0 commit comments