Skip to content

Commit

Permalink
added distance units and boolean near-field flag to the phase_dict ob…
Browse files Browse the repository at this point in the history
…ject
  • Loading branch information
[email protected] committed Oct 8, 2024
1 parent 98043a5 commit 87f6fb3
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 37 deletions.
10 changes: 10 additions & 0 deletions src/pyuvdata/utils/phase_center_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ def look_in_catalog(
cat_pm_dec=None,
cat_dist=None,
cat_vrad=None,
cat_dist_units="pc",
cat_near_field=False,
ignore_name=False,
target_cat_id=None,
phase_dict=None,
Expand Down Expand Up @@ -83,6 +85,10 @@ def look_in_catalog(
Radial velocity of the source, in units of km/s. Only used for sidereal and
ephem phase centers. Expected to be a float for sidereal and driftscan phase
centers, and an ndarray of floats of shape (Npts,) for ephem phase centers.
cat_dist_units : str
Units to interpret the cat_dist parameter in. Defaults to parsecs.
cat_near_field : bool
Whether or not near-field corrections have been applied. Defaults to False.
ignore_name : bool
Nominally, this method will only look at entries where `cat_name`
matches the name of an entry in the catalog. However, by setting this to
Expand Down Expand Up @@ -146,6 +152,8 @@ def look_in_catalog(
"cat_pm_dec": cat_pm_dec,
"cat_dist": cat_dist,
"cat_vrad": cat_vrad,
"cat_dist_units": cat_dist_units,
"cat_near_field": cat_near_field,
}

tol_dict = {
Expand All @@ -159,6 +167,8 @@ def look_in_catalog(
"cat_pm_dec": default_tols,
"cat_dist": default_tols,
"cat_vrad": default_tols,
"cat_dist_units": None,
"cat_near_field": None,
}

if target_cat_id is not None:
Expand Down
76 changes: 39 additions & 37 deletions src/pyuvdata/uvdata/uvdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -4320,6 +4320,36 @@ def _apply_w_proj(self, *, new_w_vals, old_w_vals, select_mask=None):
(-1j * 2 * np.pi) * delta_w_lambda[:, :, None]
)

def unproject_near_field(self, flipconj=False):
"""
Undo near-field phasing.

Works by near-field projecting to a distance of infinity.

Parameters
----------
flipconj : bool
Is the conjugation scheme "flipped" compared to
what pyuvdata expects? (Default False)

Returns
-------
None (performs operations inplace)
"""
# Keep the far-field Ra and Dec
key = list(self.phase_center_catalog.keys())[-1]
ra = self.phase_center_catalog[key]["cat_lon"]
dec = self.phase_center_catalog[key]["cat_lat"]

self._apply_near_field_corrections(
focus=1e19 * units.km, # TODO: Is there a better way to do this?
ra=ra,
dec=dec,
flipconj=flipconj,
)

return

def unproject_phase(
self, *, use_ant_pos=True, select_mask=None, cat_name="unprojected"
):
Expand All @@ -4345,7 +4375,7 @@ def unproject_phase(
If the object is alread unprojected.
"""
# Start by undoing the near-field phasing
self.unproject_near_field()
# self.unproject_near_field()

# select_mask_use is length Nblts, True means should be unprojected
# only select blts that are actually phased.
Expand Down Expand Up @@ -4605,10 +4635,11 @@ def _phase_dict_helper(
elif (key == "cat_id") and (phase_dict[key] is not None):
# If this is the cat_id, make it an int
phase_dict[key] = int(phase_dict[key])
elif not ((phase_dict[key] is None) or isinstance(phase_dict[key], str)):
# cat_dist_units should be str and cat_near_field should be bool
if (key != "cat_dist_units") and (key != "cat_near_field"):
phase_dict[key] = float(phase_dict[key])
elif phase_dict[key] not in (None, str) and key not in (
"cat_dist_units",
"cat_near_field",
):
phase_dict[key] = float(phase_dict[key])

return phase_dict

Expand Down Expand Up @@ -4667,41 +4698,12 @@ def _apply_near_field_corrections(self, focus, ra, dec, flipconj=False):

# Set data at each polarization (Npols = 4 usually)
for pol in self.polarization_array:

# For some reason the data need an extra axis?
prev = np.reshape(self.get_data(pol), (self.Nblts, self.Nfreqs, 1))
corr = np.reshape(phase_corrections, (self.Nblts, self.Nfreqs, 1))

self.set_data(corr * prev, pol)

def unproject_near_field(self, flipconj=False):
"""
Undo near-field phasing.

Works by near-field projecting to a distance of infinity.

Parameters
----------
flipconj : bool
Is the conjugation scheme "flipped" compared to
what pyuvdata expects? (Default False)

Returns
-------
None (performs operations inplace)
"""
# Keep the far-field Ra and Dec
key = list(self.phase_center_catalog.keys())[-1]
ra = self.phase_center_catalog[key]["cat_lon"]
dec = self.phase_center_catalog[key]["cat_lat"]

self._apply_near_field_corrections(
focus=1e19 * units.km, # TODO: Is there a better way to do this?
ra=ra,
dec=dec,
flipconj=flipconj,
)

def phase(
self,
*,
Expand Down Expand Up @@ -4808,9 +4810,9 @@ def phase(
If the `cat_name` is None.

"""
key = list(self.phase_center_catalog.keys())[-1]
if self.phase_center_catalog[key]["cat_name"] != "":
self.unproject_near_field()
# key = list(self.phase_center_catalog.keys())[-1]
# if self.phase_center_catalog[key]["cat_name"] != "":
# self.unproject_near_field()

if cat_type != "unprojected":
if lon is None:
Expand Down
3 changes: 3 additions & 0 deletions tests/uvdata/test_uvdata.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,8 @@ def dummy_phase_dict():
"cat_vrad": 0.0,
"info_source": "user",
"cat_id": None,
"cat_dist_units": "pc",
"cat_near_field": False,
}

return dummy_dict
Expand Down Expand Up @@ -10359,6 +10361,7 @@ def test_phase_dict_helper_sidereal_lookup(sma_mir, dummy_phase_dict):
lookup_name=True,
time_array=None,
)
print(sma_mir.phase_center_catalog)
assert (
phase_dict.pop("cat_id")
== utils.phase_center_catalog.look_for_name(
Expand Down

0 comments on commit 87f6fb3

Please sign in to comment.