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

Update wcs interface to use pixel_to_world_values instead of non-values versions. #195

Merged
merged 2 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions romanisim/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -964,8 +964,8 @@ def inject_sources_into_l2(model, cat, x=None, y=None, psf=None, rng=None,
rng = galsim.UniformDeviate(123)

if x is None or y is None:
x, y = model.meta.wcs.numerical_inverse(cat['ra'], cat['dec'],
with_bounding_box=False)
x, y = model.meta.wcs.numerical_inverse(
cat['ra'].value, cat['dec'].value, with_bounding_box=False)

filter_name = model.meta.instrument.optical_element
cat = catalog.table_to_catalog(cat, [filter_name])
Expand Down
4 changes: 2 additions & 2 deletions romanisim/l3.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ def inject_sources_into_l3(model, cat, x=None, y=None, psf=None, rng=None,
rng = galsim.UniformDeviate(seed)

if x is None or y is None:
x, y = model.meta.wcs.numerical_inverse(cat['ra'], cat['dec'],
x, y = model.meta.wcs.numerical_inverse(cat['ra'].value, cat['dec'].value,
with_bounding_box=False)

filter_name = model.meta.basic.optical_element
Expand Down Expand Up @@ -756,7 +756,7 @@ def add_more_metadata(metadata, efftimes, filter_name, wcs, shape, nexposures):
metadata['resample']['pointings'] = nexposures
metadata['resample']['product_exposure_time'] = (
metadata['basic']['max_exposure_time'])
xref, yref = wcs.world_to_pixel(
xref, yref = wcs.world_to_pixel_values(
metadata['wcsinfo']['ra_ref'], metadata['wcsinfo']['dec_ref'])
metadata['wcsinfo']['x_ref'] = xref
metadata['wcsinfo']['y_ref'] = yref
Expand Down
9 changes: 5 additions & 4 deletions romanisim/tests/test_l3.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def test_sim_mosaic():

# Create bounds from the object list
twcs = romanisim.wcs.get_mosaic_wcs(metadata)
allx, ally = twcs.world_to_pixel(cat['ra'], cat['dec'])
allx, ally = twcs.world_to_pixel_values(cat['ra'].value, cat['dec'].value)

# Obtain the sample extremums
xmin = min(allx)
Expand All @@ -170,7 +170,7 @@ def test_sim_mosaic():
ymax = max(ally)

# Obtain WCS center
xcen, ycen = twcs.world_to_pixel(ra_ref, dec_ref)
xcen, ycen = twcs.world_to_pixel_values(ra_ref, dec_ref)

# Determine maximum extremums from WCS center
xdiff = max([math.ceil(xmax - xcen), math.ceil(xcen - xmin)]) + 1
Expand All @@ -191,7 +191,8 @@ def test_sim_mosaic():
assert len(extras['objinfo']) == len(cat)

# Ensure center pixel of bright objects is bright
x_all, y_all = moswcs.world_to_pixel(cat['ra'][:10], cat['dec'][:10])
x_all, y_all = moswcs.world_to_pixel_values(cat['ra'][:10].value,
cat['dec'][:10].value)
for x, y in zip(x_all, y_all):
x = int(x)
y = int(y)
Expand Down Expand Up @@ -581,7 +582,7 @@ def test_scaling():
# pixel scales are different by a factor of two.
fluxes = []
for im, fac in zip((im1, im2, im3), (1, 2, 1)):
pix = im.meta.wcs.world_to_pixel(
pix = im.meta.wcs.world_to_pixel_values(
imdict['tabcatalog']['ra'][0], imdict['tabcatalog']['dec'][0])
pind = [int(x) for x in pix]
margin = 30 * fac
Expand Down
5 changes: 3 additions & 2 deletions romanisim/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,8 +516,9 @@ def update_photom_keywords(im, gain=None):
if 'wcs' in im['meta']:
wcs = im['meta']['wcs']
cenpix = (im.data.shape[0] // 2, im.data.shape[1] // 2)
cc = wcs.pixel_to_world((cenpix[0], cenpix[0], cenpix[0] + 1),
(cenpix[1], cenpix[1] + 1, cenpix[1]))
cc = wcs.pixel_to_world(
(cenpix[0], cenpix[0], cenpix[0] + 1),
(cenpix[1], cenpix[1] + 1, cenpix[1]))
angle = (cc[0].position_angle(cc[1]) -
cc[0].position_angle(cc[2]))
area = (cc[0].separation(cc[1]) * cc[0].separation(cc[2])
Expand Down
2 changes: 1 addition & 1 deletion romanisim/wcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ def coeffs_to_poly(mat, degree):
# convention in the galsim CelestialWCS object, we delete that here.
# Success is defined by
# (GWCS._radec(x, y) ==
# wcs_from_fits_header(GWCS.header.header).pixel_to_world(x, y))
# wcs_from_fits_header(GWCS.header.header).pixel_to_world_values(x, y))

cd = w.wcs.piximg_matrix

Expand Down
Loading