def reproject_car_to_hpx(input_data, coord_system_out, nside, order=1, nested=False): import healpy as hp from reproject.wcs_utils import convert_world_coordinates from reproject.healpix.utils import parse_coord_system data, wcs_in = input_data npix = hp.nside2npix(nside) theta, phi = hp.pix2ang(nside, np.arange(npix), nested) lon_out = np.degrees(phi) lat_out = 90.0 - np.degrees(theta) # Convert between celestial coordinates coord_system_out = parse_coord_system(coord_system_out) with np.errstate(invalid="ignore"): lon_in, lat_in = convert_world_coordinates( lon_out, lat_out, (coord_system_out, u.deg, u.deg), wcs_in) # Look up pixels in input system yinds, xinds = wcs_in.wcs_world2pix(lon_in, lat_in, 0) # Interpolate data = np.pad(data, 3, mode="wrap") healpix_data = map_coordinates(data, [xinds + 3, yinds + 3], order=order, mode="wrap", cval=np.nan) return healpix_data, (~np.isnan(healpix_data)).astype(float)
def reproject_car_to_hpx(input_data, coord_system_out, nside, order=1, nested=False): import healpy as hp from reproject.wcs_utils import convert_world_coordinates from reproject.healpix.utils import parse_coord_system data, wcs_in = input_data npix = hp.nside2npix(nside) theta, phi = hp.pix2ang(nside, np.arange(npix), nested) lon_out = np.degrees(phi) lat_out = 90.0 - np.degrees(theta) # Convert between celestial coordinates coord_system_out = parse_coord_system(coord_system_out) with np.errstate(invalid="ignore"): lon_in, lat_in = convert_world_coordinates( lon_out, lat_out, (coord_system_out, u.deg, u.deg), wcs_in ) # Look up pixels in input system yinds, xinds = wcs_in.wcs_world2pix(lon_in, lat_in, 0) # Interpolate data = np.pad(data, 3, mode="wrap") healpix_data = map_coordinates( data, [xinds + 3, yinds + 3], order=order, mode="wrap", cval=np.nan ) return healpix_data, (~np.isnan(healpix_data)).astype(float)
def test_parse_coord_system(): frame = parse_coord_system(Galactic()) assert isinstance(frame, Galactic) frame = parse_coord_system('fk5') assert isinstance(frame, FK5) with pytest.raises(ValueError) as exc: frame = parse_coord_system('e') assert exc.value.args[0] == "Ecliptic coordinate frame not yet supported" frame = parse_coord_system('g') assert isinstance(frame, Galactic) with pytest.raises(ValueError) as exc: frame = parse_coord_system('spam') assert exc.value.args[0] == "Could not determine frame for system=spam"