Repository: RadioAstronomySoftwareGroup/pyuvdata
Pull request #742 (2019-12-30 17:50:36)

fixed uvcalibrate w/ x_orientation update
<!--- Provide a general summary of your changes in the Title above -->
Quick fix for utils.uvcalibrate given new x_orientation attribute

## Description
<!--- Describe your changes in detail -->
uvcalibrate was breaking b/c of non-support of x_orientation, this PR fixes that.

## Motivation and Context
<!--- Why is this change required? What problem does it solve? -->
<!--- If it fixes an open issue, please link to the issue here. If this PR closes an issue, put the word 'closes' before the issue link to auto-close the issue when the PR is merged. -->

## Types of changes
<!--- What types of changes does your code introduce? Put an `x` in all the boxes that apply: -->
- [x] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to change)
- [ ] Documentation change (documentation changes only)
- [ ] Version change
- [ ] Build or continuous integration change


## Checklist:
<!--- You may remove the checklists that don't apply to your change type(s) or just leave them empty -->
<!--- Go over all the following points, and replace the space with an `x` in all the boxes that apply. -->
<!--- If you're unsure about any of these, don't hesitate to ask. We're here to help! -->
- [ ] I have read the [contribution guide](https://github.com/RadioAstronomySoftwareGroup/pyuvdata/blob/master/.github/CONTRIBUTING.md).
- [ ] My code follows the code style of this project.

Bug fix checklist:
- [x] My fix includes a new test that breaks as a result of the bug (if possible).
- [ ] All new and existing tests pass in both python 2 and python 3.
- [x] I have updated the [CHANGELOG](https://github.com/RadioAstronomySoftwareGroup/pyuvdata/blob/master/CHANGELOG.md).

New feature checklist:
- [ ] I have added or updated the docstrings associated with my feature using the [numpy docstring format](https://numpydoc.readthedocs.io/en/latest/format.html).
- [ ] I have updated the tutorial to highlight my new feature (if appropriate).
- [ ] I have added tests to cover my new feature.
- [ ] All new and existing tests pass in both python 2 and python 3.
- [ ] I have updated the [CHANGELOG](https://github.com/RadioAstronomySoftwareGroup/pyuvdata/blob/master/CHANGELOG.md).

Breaking change checklist:  
- [ ] I have updated the docstrings associated with my change using the [numpy docstring format](https://numpydoc.readthedocs.io/en/latest/format.html).
- [ ] I have updated the tutorial to reflect my changes (if appropriate).
- [ ] My change includes backwards compatibility and deprecation warnings (if possible).
- [ ] I have added tests to cover my changes.
- [ ] All new and existing tests pass in both python 2 and python 3.
- [ ] I have updated the [CHANGELOG](https://github.com/RadioAstronomySoftwareGroup/pyuvdata/blob/master/CHANGELOG.md).

Documentation change checklist:
- [ ] Any updated docstrings use the [numpy docstring format](https://numpydoc.readthedocs.io/en/latest/format.html).
- [ ] If this is a significant change to the readme or other docs, I have checked that they are rendered properly on ReadTheDocs. (you may need help to get this branch to build on RTD, just ask!)

Version change checklist:
- [ ] I have updated the [CHANGELOG](https://github.com/RadioAstronomySoftwareGroup/pyuvdata/blob/master/CHANGELOG.md) to put all the unreleased changes under the new version (leaving the unreleased section empty).
- [ ] I have noted any dependency changes since the last version and will update the conda package build accordingly.

Build or continuous integration change checklist:
- [ ] If required or optional dependencies have changed (including version numbers), I have updated the readme to reflect this.
- [ ] If this is a new CI setup, I have added the associated badge to the readme and to references/make_index.py (if appropriate).


codecov[bot]: # [Codecov](https://codecov.io/gh/RadioAstronomySoftwareGroup/pyuvdata/pull/742?src=pr&el=h1) Report
> Merging [#742](https://codecov.io/gh/RadioAstronomySoftwareGroup/pyuvdata/pull/742?src=pr&el=desc) into [master](https://codecov.io/gh/RadioAstronomySoftwareGroup/pyuvdata/commit/3e18b8b4b8fab07067857d6025700df5367334e7?src=pr&el=desc) will **decrease** coverage by `0.23%`.
> The diff coverage is `100%`.

[![Impacted file tree graph](https://codecov.io/gh/RadioAstronomySoftwareGroup/pyuvdata/pull/742/graphs/tree.svg?width=650&token=4QykcCeB1H&height=150&src=pr)](https://codecov.io/gh/RadioAstronomySoftwareGroup/pyuvdata/pull/742?src=pr&el=tree)

```diff
@@            Coverage Diff            @@
##           master    #742      +/-   ##
=========================================
- Coverage   99.03%   98.8%   -0.24%     
=========================================
  Files          21      21              
  Lines        9435    9435              
=========================================
- Hits         9344    9322      -22     
- Misses         91     113      +22
```


| [Impacted Files](https://codecov.io/gh/RadioAstronomySoftwareGroup/pyuvdata/pull/742?src=pr&el=tree) | Coverage Δ | |
|---|---|---|
| [pyuvdata/utils.py](https://codecov.io/gh/RadioAstronomySoftwareGroup/pyuvdata/pull/742/diff?src=pr&el=tree#diff-cHl1dmRhdGEvdXRpbHMucHk=) | `99.11% <100%> (-0.89%)` | :arrow_down: |
| [pyuvdata/version.py](https://codecov.io/gh/RadioAstronomySoftwareGroup/pyuvdata/pull/742/diff?src=pr&el=tree#diff-cHl1dmRhdGEvdmVyc2lvbi5weQ==) | `87.27% <0%> (-12.73%)` | :arrow_down: |
| [pyuvdata/uvh5.py](https://codecov.io/gh/RadioAstronomySoftwareGroup/pyuvdata/pull/742/diff?src=pr&el=tree#diff-cHl1dmRhdGEvdXZoNS5weQ==) | `99.19% <0%> (-0.81%)` | :arrow_down: |
| [pyuvdata/aipy\_extracts.py](https://codecov.io/gh/RadioAstronomySoftwareGroup/pyuvdata/pull/742/diff?src=pr&el=tree#diff-cHl1dmRhdGEvYWlweV9leHRyYWN0cy5weQ==) | `84.9% <0%> (-0.63%)` | :arrow_down: |
| [pyuvdata/uvbase.py](https://codecov.io/gh/RadioAstronomySoftwareGroup/pyuvdata/pull/742/diff?src=pr&el=tree#diff-cHl1dmRhdGEvdXZiYXNlLnB5) | `99.38% <0%> (-0.62%)` | :arrow_down: |
| [pyuvdata/uvdata.py](https://codecov.io/gh/RadioAstronomySoftwareGroup/pyuvdata/pull/742/diff?src=pr&el=tree#diff-cHl1dmRhdGEvdXZkYXRhLnB5) | `99.84% <0%> (-0.16%)` | :arrow_down: |

------

[Continue to review full report at Codecov](https://codecov.io/gh/RadioAstronomySoftwareGroup/pyuvdata/pull/742?src=pr&el=continue).
> **Legend** - [Click here to learn more](https://docs.codecov.io/docs/codecov-delta)
> `Δ = absolute <relative> (impact)`, `ø = not affected`, `? = missing data`
> Powered by [Codecov](https://codecov.io/gh/RadioAstronomySoftwareGroup/pyuvdata/pull/742?src=pr&el=footer). Last update [3e18b8b...c2cd3a5](https://codecov.io/gh/RadioAstronomySoftwareGroup/pyuvdata/pull/742?src=pr&el=lastupdated). Read the [comment docs](https://docs.codecov.io/docs/pull-request-comments).


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e5fdb455..aa10d642 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -13,6 +13,7 @@ All notable changes to this project will be documented in this file.
 - `utils.apply_uvflag` for applying UVFlag objects to UVData objects
 
 ### Fixed
+- Fixed `utils.uvcalibrate` to handle `x_orientation` attribute
 - Arrays of file names can now be passed to `read` (not just lists).
 - run_check is no longer turned off in `read_uvfits` and `read_uvh5` when `read_data` is False.
 - Redundancy finder will now error if any baselines appear in multiple groups.
diff --git a/pyuvdata/utils.py b/pyuvdata/utils.py
index 0424b1a8..4e856f8e 100644
--- a/pyuvdata/utils.py
+++ b/pyuvdata/utils.py
@@ -520,7 +520,7 @@ def uvcalibrate(uvdata, uvcal, inplace=True, prop_flags=True, flag_missing=True,
         for key in uvdata.get_antpairpols():
             # get indices for this key
             blt_inds = uvdata.antpair2ind(key)
-            pol_ind = np.argmin(np.abs(uvdata.polarization_array - polstr2num(key[2])))
+            pol_ind = np.argmin(np.abs(uvdata.polarization_array - polstr2num(key[2], uvdata.x_orientation)))
 
             # try to get gains for each antenna
             ant1 = (key[0], key[2][0])


Test patch:
diff --git a/pyuvdata/tests/test_utils.py b/pyuvdata/tests/test_utils.py
index ddf16a46..8e338b9d 100644
--- a/pyuvdata/tests/test_utils.py
+++ b/pyuvdata/tests/test_utils.py
@@ -955,6 +955,8 @@ def test_uvcalibrate_apply_gains():
     # read data
     uvd = pyuvdata.UVData()
     uvd.read(os.path.join(DATA_PATH, 'zen.2457698.40355.xx.HH.uvcAA'))
+    # give it an x_orientation
+    uvd.x_orientation = 'e'
     uvc = pyuvdata.UVCal()
     uvc.read_calfits(os.path.join(DATA_PATH, 'zen.2457698.40355.xx.gain.calfits'))
     # assign gain scale manually