Skip to content

Commit

Permalink
Merge pull request #195 from HERA-Team/uvpspec_backwards_compat
Browse files Browse the repository at this point in the history
Fix backwards compatibility bugs with UVPSpec data files
  • Loading branch information
philbull committed Mar 27, 2019
2 parents 0bee9d2 + ae0307e commit 0de985e
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,18 @@ install:
- conda info -a

# create environment and install dependencies
- conda create -q -n test-environment python=$TRAVIS_PYTHON_VERSION numpy scipy nose pip matplotlib coverage
- conda create -q -n test-environment python=$TRAVIS_PYTHON_VERSION numpy>=1.15.0 scipy nose pip matplotlib coverage
- source activate test-environment
- conda install -c conda-forge healpy aipy scikit-learn
- conda install -c conda-forge healpy aipy
- pip install coveralls
- pip install h5py
- pip install scikit-learn
- pip install git+https://github.com/HERA-Team/pyuvdata.git$PYUVDATA_VERSION
- pip install git+https://github.com/HERA-Team/omnical.git
- pip install git+https://github.com/HERA-Team/linsolve.git
- pip install git+https://github.com/HERA-Team/hera_qm.git
- pip install git+https://github.com/HERA-Team/uvtools.git
- pip install git+https://github.com/HERA-Team/hera_cal.git
- pip install scikit-learn
- pip install pyyaml
- pip install multiprocess
- python setup.py install
Expand Down
25 changes: 20 additions & 5 deletions hera_pspec/uvpspec.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
from pyuvdata import uvutils as uvutils
import h5py
import operator
import warnings


class UVPSpec(object):
Expand Down Expand Up @@ -128,7 +129,7 @@ def __init__(self):
"nsample_array", "cov_array"]
self._dicts_of_dicts = ["stats_array"]

# define which attributes are considred meta data. Large attrs should
# define which attributes are considered meta data. Large attrs should
# be constructed as datasets
self._meta_dsets = ["lst_1_array", "lst_2_array", "time_1_array",
"time_2_array", "blpair_array", "bl_vecs",
Expand Down Expand Up @@ -1139,20 +1140,34 @@ def read_from_group(self, grp, just_meta=False, spws=None, bls=None,
"""
# Make sure the group is a UVPSpec object
assert 'pspec_type' in grp.attrs, "This object is not a UVPSpec object"
assert grp.attrs['pspec_type'] == 'UVPSpec', \
"This object is not a UVPSpec object"
pstype = grp.attrs['pspec_type']
pstype = pstype.decode() if isinstance(pstype, bytes) else pstype
assert pstype == 'UVPSpec', "This object is not a UVPSpec object"

# Clear all data in the current object
self._clear()

# Load-in meta data
for k in grp.attrs:
if k in self._meta_attrs:
setattr(self, k, grp.attrs[k])
val = grp.attrs[k]
if isinstance(val, bytes): val = val.decode() # bytes -> str
setattr(self, k, val)
for k in grp:
if k in self._meta_dsets:
setattr(self, k, grp[k][:])


# Backwards compatibility: pol_array exists (not polpair_array)
if 'pol_array' in grp.attrs:
warnings.warn("Stored UVPSpec contains pol_array attr, which has "
"been superseded by polpair_array. Converting "
"automatically.", UserWarning)
pol_arr = grp.attrs['pol_array']

# Convert to polpair array
polpair_arr = [uvputils.polpair_tuple2int((p,p)) for p in pol_arr]
setattr(self, 'polpair_array', np.array(polpair_arr))

# Use _select() to pick out only the requested baselines/spws
if just_meta:
uvputils._select(self, spws=spws, bls=bls, lsts=lsts,
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def package_files(package_dir, subdirectory):
'packages': ['hera_pspec'],
'package_dir': {'hera_pspec': 'hera_pspec'},
'package_data': {'hera_pspec': data_files},
'install_requires': ['numpy>=1.14', 'scipy','matplotlib>=2.2'],
'install_requires': ['numpy>=1.15', 'scipy','matplotlib>=2.2'],
'include_package_data': True,
'scripts': ['scripts/pspec_run.py', 'scripts/pspec_red.py',
'scripts/bootstrap_run.py'],
Expand Down

0 comments on commit 0de985e

Please sign in to comment.