Skip to content

Commit ecc5a47

Browse files
committed
bugfix in averages.py
Wrong handling of datadir for spectra
1 parent 74fcaed commit ecc5a47

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

python/magic/averages.py

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class AvgField:
102102
"""
103103

104104
def __init__(self, tag=None, tstart=None, model=default_model,
105-
datadir='.', std=False, write=True):
105+
datadir='.', std=False, write=True, tinit_file='tInitAvg'):
106106
"""
107107
:param tag: if you specify an input tag (generic regExp pattern),
108108
the averaging process will only happen on the time series
@@ -121,13 +121,15 @@ def __init__(self, tag=None, tstart=None, model=default_model,
121121
python attributes wich is defined in MagicTs, MagicSpectrum
122122
or MagicRadial.
123123
:type model: str
124+
:param tinit_file: name of the file which contains the start time
125+
:type tinit_file: str
124126
"""
125127

126128
if not os.path.exists(datadir):
127129
print('Directory "{}" has not been found'.format(datadir))
128130
return
129131

130-
tInitFile = os.path.join(datadir, 'tInitAvg')
132+
tInitFile = os.path.join(datadir, tinit_file)
131133
if os.path.exists(tInitFile) and tstart is None:
132134
with open(tInitFile, 'r') as f:
133135
st = f.readline().strip('\n')
@@ -210,9 +212,8 @@ def __init__(self, tag=None, tstart=None, model=default_model,
210212
self.lut['time_series'][field+'_sd'] = -1
211213
setattr(self, field+'_sd', -1)
212214

213-
214215
# Get tags involved in averaging for spectra and radial profiles
215-
tags = self.get_tags(tstart)
216+
tags = self.get_tags(datadir, tstart)
216217

217218
# Handle spectra
218219
self.lut['spectra'] = {}
@@ -371,21 +372,24 @@ def __str__(self):
371372

372373
return st
373374

374-
def get_tags(self, tstart):
375+
def get_tags(self, datadir, tstart):
375376
"""
376377
This routine returns a list of tags which have been generated after tstart
377378
379+
:param datadir: working directory
380+
:type datadir: str
378381
:param tstart: starting averaging time
379382
:type tstart: float
380383
:returns: a list of tags
381384
:rtype: list
382385
"""
383-
logFiles = scanDir('log.*')
386+
logFiles = scanDir(os.path.join(datadir, 'log.*'))
384387
tags = []
385388
for lg in logFiles:
386389
nml = MagicSetup(nml=lg, quiet=True)
387-
if nml.start_time > tstart:
388-
tags.append(nml.tag)
390+
if hasattr(nml, 'start_time'):
391+
if nml.start_time > tstart:
392+
tags.append(nml.tag)
389393

390394
return tags
391395

0 commit comments

Comments
 (0)