Skip to content

Commit

Permalink
Revert changes to pixel_to_world, keep for world_to_pixel.
Browse files Browse the repository at this point in the history
  • Loading branch information
schlafly committed Jan 8, 2025
1 parent 768ac0e commit 2d6eafd
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 12 deletions.
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
8 changes: 4 additions & 4 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 @@ -740,8 +740,8 @@ def add_more_metadata(metadata, efftimes, filter_name, wcs, shape, nexposures):
metadata['photometry']['conversion_megajanskys'] = 1

cenx, ceny = ((shape[1] - 1) / 2, (shape[0] - 1) / 2)
c1 = wcs.pixel_to_world_values(cenx, ceny)
c2 = wcs.pixel_to_world_values(cenx + 1, ceny)
c1 = wcs.pixel_to_world(cenx, ceny)
c2 = wcs.pixel_to_world(cenx + 1, ceny)
pscale = c1.separation(c2)

metadata['photometry']['pixelarea_steradians'] = (pscale ** 2).to(u.sr)
Expand Down Expand Up @@ -769,7 +769,7 @@ def add_more_metadata(metadata, efftimes, filter_name, wcs, shape, nexposures):
metadata['wcsinfo']['dec_center'] = c1.dec.to(u.degree).value
xcorn, ycorn = [[0, shape[1] - 1, shape[1] - 1, 0],
[0, 0, shape[0] - 1, shape[0] - 1]]
ccorn = wcs.pixel_to_world_values(xcorn, ycorn)
ccorn = wcs.pixel_to_world(xcorn, ycorn)
for i, corn in enumerate(ccorn):
metadata['wcsinfo']['ra_corn{i+1}'] = corn.ra.to(u.degree).value
metadata['wcsinfo']['dec_corn{i+1}'] = corn.dec.to(u.degree).value
Expand Down
5 changes: 3 additions & 2 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_values(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 Down Expand Up @@ -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_values(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
6 changes: 3 additions & 3 deletions romanisim/tests/test_wcs.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ def test_wcs_from_fits_header():
wcs2 = wcs.wcs_from_fits_header(wcs1.header.header)
xg, yg = np.meshgrid(np.linspace(0, 4088, 100), np.linspace(0, 4088, 100))
rd1 = np.degrees(wcs1._radec(xg.copy(), yg.copy()))
rd2 = wcs2.pixel_to_world_values(xg.copy(), yg.copy())
rd2 = wcs2.pixel_to_world(xg.copy(), yg.copy())
rd1 = SkyCoord(ra=rd1[0] * u.deg, dec=rd1[1] * u.deg, frame=rd2.frame)
sep = rd1.separation(rd2).to(u.arcsec).value

Expand Down Expand Up @@ -168,7 +168,7 @@ def test_scale_factor():
# Create the wcs and generate results
distortion = make_fake_distortion_function()
gwcs = wcs.make_wcs(cc, distortion, scale_factor=scale_factor)
sky = gwcs.pixel_to_world_values(grid, grid)
sky = gwcs.pixel_to_world(grid, grid)

assert all(truth.separation(sky).to(u.arcsec).value < 1e-3)

Expand All @@ -190,6 +190,6 @@ def test_scale_factor_negative():
# Create the wcs and generate results
distortion = make_fake_distortion_function()
gwcs = wcs.make_wcs(cc, distortion, scale_factor=scale_factor)
sky = gwcs.pixel_to_world_values(grid, grid)
sky = gwcs.pixel_to_world(grid, grid)

assert all(truth.separation(sky).to(u.arcsec).value < 1e-3)
2 changes: 1 addition & 1 deletion romanisim/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -516,7 +516,7 @@ 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_values(
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]) -
Expand Down

0 comments on commit 2d6eafd

Please sign in to comment.