Skip to content

Commit

Permalink
updates to container.merge_spectra
Browse files Browse the repository at this point in the history
	modified:   hera_pspec/container.py
	modified:   pipelines/pspec_pipeline/pspec_pipe.py
  • Loading branch information
nkern committed Jul 10, 2018
1 parent 30c38cd commit ccff2e4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 10 deletions.
19 changes: 13 additions & 6 deletions hera_pspec/container.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,9 @@ def __del__(self):
pass


def merge_spectra(psc, dset_split_str='_x_', ext_split_str='_', verbose=True):
def merge_spectra(psc, groups=None, dset_split_str='_x_', ext_split_str='_', verbose=True):
"""
Iterate through a PSpecContainer and, within each group,
Iterate through a PSpecContainer and, within each specified group,
merge spectra of similar name but different psname extension.
Power spectra to-be-merged are assumed to follow the naming convention
Expand All @@ -334,8 +334,11 @@ def merge_spectra(psc, dset_split_str='_x_', ext_split_str='_', verbose=True):
feed dset_split_str as '' or None. Example, to merge together: uvp_1, uvp_2, uvp_3
feed dset_split_str=None and ext_split_str='_'.
Parameters:
-----------
Parameters
----------
groups : list
A list of groupnames to operate on. Default is all groups.
dset_split_str : str
The pattern used to split dset1 from dset2 in the psname.
Expand All @@ -350,8 +353,12 @@ def merge_spectra(psc, dset_split_str='_x_', ext_split_str='_', verbose=True):
assert isinstance(psc, PSpecContainer)

# get groups
groups = psc.groups()
assert len(groups) > 0, "no groups exist in this Container object"
_groups = psc.groups()
if groups is None:
groups = _groups
else:
groups = [grp for grp in groups if grp in _groups]
assert len(groups) > 0, "no specified groups exist in this Container object"

# Iterate over groups
for grp in groups:
Expand Down
8 changes: 4 additions & 4 deletions pipelines/pspec_pipeline/pspec_pipe.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@
# change to working dir
os.chdir(work_dir)


#-------------------------------------------------------------------------------
# Run Jacknife Data Difference
#-------------------------------------------------------------------------------
Expand Down Expand Up @@ -149,15 +148,16 @@ def pspec(i, outfile=outfname, dt=data_template, st=std_template, jobs=jobs, pol
hp.utils.log("\nStarting power spectrum file merge: {}\n{}".format(time, '-'*60), f=lf, verbose=verbose)

# Get all groups
psc = hp.PSpecContainer(outfname, 'r')
groups = psc.groups()
del psc

# Define merge function
def merge(i, filename=filename, groups=groups):
def merge(i, groups=groups, filename=outfname):
try:
psc = hp.PSpecContainer(filename, mode='rw')
grp = groups[i]
spectra = [os.path.join(grp, sp) for sp in psc.get_spectra(grp)]
hp.utils.merge_pspec(psc, spectra=spectra)
hp.container.merge_spectra(psc, groups=[grp])
except:
hp.utils.log("\nPSPEC MERGE job {} errored with:".format(i), f=ef, tb=sys.exc_info(), verbose=verbose)
return 1
Expand Down

0 comments on commit ccff2e4

Please sign in to comment.