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

generate cubes in a different coordinate system than the one observed #2

Open
SpandanCh opened this issue Jan 27, 2022 · 1 comment

Comments

@SpandanCh
Copy link

Hi,

I did the observations in galactic co-ordinates, but would like to generate the cubes in equatorial coordinates. Is there a way to specify the desired coordinates while running the gbtgridder?

I tried to use the --clonecube option with a sample cube with header in RA-Dec, but the output is still given in galactic coordinates.

@astrofle
Copy link

astrofle commented Jan 10, 2024

Dear Spandan,
Sorry for the late reply.
The gbtgridder does not handle coordinate transformations. dysh will provide the functionality to change between coordinate systems.
To change the coordinates of your data you can use the following as a guide (be warned, that this example will overwrite the data since it uses flush):

from astropy.io import fits
from astropy import units as u
from astropy.coordinates import SkyCoord


def eq2gal(table):
    """
    Transform the coordinates in `table` from Equatorial to Galactic.

    Parameters
    ----------
    table : `~astropy.FITS_rec`
        SDFITS table with the data and coordinates.

    Returns
    -------
    table : `~astropy.FITS_rec`
        SDFITS table with all Equatorial coordinates
        changed to Galactic.
    """

    mask = (table["CTYPE2"] == "RA  ") & (table["CTYPE3"] == "DEC ")
    coo = SkyCoord(table["CRVAL2"][mask]*u.deg, table["CRVAL3"][mask]*u.deg, frame="fk5")

    glon = coo.galactic.l.deg
    glat = coo.galactic.b.deg

    table["CTYPE2"][mask] = "GLON"
    table["CRVAL2"][mask] = glon

    table["CTYPE3"][mask] = "GLAT"
    table["CRVAL3"][mask] = glat

    return table


myfile = "/home/scratch/psalas/file.fits"
hdu = fits.open(myfile, mode="update")
table = hdu[1].data
table = eq2gal(table)
hdu[1].data = table
hdu.flush()

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

No branches or pull requests

2 participants