Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add optional near-field corrections to the phasing function #1482

Open
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

baron-de-montblanc
Copy link

Description

Included code to perform near-field corrections through keyword arguments passed to the phase() function.

I added two new keys to the phase_dict dictionary (cat_dist_units and cat_near_field), allowing the user to specify the units associated with the cat_dist key, and whether or not to apply near-field corrections (boolean value). As a result, a lot of tests are breaking because these extra keys didn't exist when they were written. I'm having trouble tracking down every instance of phase_dict to patch this.

It also still isn't clear whether or not an unproject_near_field() function is necessary, so I have left in some commented-out lines of code while I work on figuring this out (to be removed or uncommented when this is resolved).

Motivation and Context

This feature allows users to specify the RA, DEC, and distance to a near-field source, and "focus" on that source (it will then appear in focus in an image, for example). This is done in practice by calculating the geometric near-field w values for each visibility, updating those in the uvw_array, computing the resulting phase differences, and updating the phase directly for each visibility. This feature is turned off by default (i.e. the default behavior for the phase() function is just to perform the traditional far-field phasing).

Types of changes

  • 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:

New feature checklist:

  • I have added or updated the docstrings associated with my feature using the numpy docstring format.
  • 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.
  • I have updated the CHANGELOG.

@bhazelton
Copy link
Member

Rather than adding new phase_center_dict keys, let's use a new cat type for near-field phased objects, maybe `"near_field"? Then encourage and support passing a Quantity for distance, but if a scalar is passed interpret it as in meters for near field and parsecs for ephem cat types. Update the docs to be very clear about this.

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: ba8783f Previous: bca6cf0 Ratio
tests/utils/test_bls.py::test_ants_to_bls[min=4259840-len=10] 215140.27267544658 iter/sec (stddev: 0.000005969824238735253) 434661.1807555354 iter/sec (stddev: 0.0000013012435924847232) 2.02

This comment was automatically generated by workflow using github-action-benchmark.

Copy link

codecov bot commented Jan 10, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 99.93%. Comparing base (c62e1e2) to head (87b64e4).

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #1482   +/-   ##
=======================================
  Coverage   99.93%   99.93%           
=======================================
  Files          63       63           
  Lines       21852    21943   +91     
=======================================
+ Hits        21837    21928   +91     
  Misses         15       15           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

…iriad and ms file formats on windows devices
Copy link
Member

@bhazelton bhazelton left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is looking really good! Just a few small comments.

Return the x,y,z coordinates of the focal point.

The focal point corresponds to the location of
the NEAR-FIELD object of interest in the MWA-centred
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't specific to MWA, maybe "in the telescope centered ENU frame"?

Comment on lines +2609 to +2612
# The centre of the ENU frame should be located at the MEDIAN position of the array
loc = uvd.telescope.location.itrs.cartesian.xyz.value
antpos = uvd.telescope.antenna_positions + loc
x, y, z = np.median(antpos, axis=0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is interesting and not what I expected from the docstring. From the docstring I'd assumed you were using the nominal telescope location (uvd.telescope.location) for the center of the ENU frame. I think this makes sense, but it'd be good to update the docstring to say that it's centered at the median position of the antennas.

antpos = uvd.telescope.antenna_positions + loc
x, y, z = np.median(antpos, axis=0)

# Initialize EarthLocation object centred on MWA
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

again, not MWA specific

# Initialize EarthLocation object centred on MWA
mwa = EarthLocation(x, y, z, unit=units.m)

# Convert sky object to an AltAz frame centred on the MWA
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here again

Comment on lines +2653 to +2656
# Antenna positions in ENU frame
antpos = uvd.telescope.get_enu_antpos() - np.median(
uvd.telescope.get_enu_antpos(), axis=0
)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ENU frame is different than the one you used in _get_focus_xyz because it's centered on the telescope location not on the median antenna position. Is that what you want?

Comment on lines -4626 to -4628
elif not ((phase_dict[key] is None) or isinstance(phase_dict[key], str)):
phase_dict[key] = float(phase_dict[key])

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you remove these lines?

Comment on lines +587 to +618
# @pytest.mark.filterwarnings("ignore:The uvw_array does not match the expected values")
# @pytest.mark.parametrize(
# "cat_type",
# ["sidereal", "near_field"]
# )
# def test_readwriteread_phase(tmp_path, casa_uvfits, cat_type):
# """
# CASA tutorial uvfits loopback test including phasing corrections.
# """
# uv_in = casa_uvfits

# uv_out = UVData()
# write_file = str(tmp_path / "outtest_casa_phased.uvfits")

# uv_in.phase(cat_name='foo', cat_type=cat_type, ra=0.8, dec=-0.4, dist=10000)

# uv_in.write_uvfits(write_file)
# file_read = write_file
# uv_out.read(file_read)

# assert uv_in.telescope._location.frame == uv_out.telescope._location.frame
# assert uv_in.telescope._location.ellipsoid == uv_out.telescope._location.ellipsoid

# uv_in.filename = uv_out.filename
# uv_out._consolidate_phase_center_catalogs(
# reference_catalog=uv_in.phase_center_catalog,
# )

# assert uv_in == uv_out
# return


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove this. If there's a good reason we might need it in the future it can go into an issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants