keflavich / cube-line-extractor

4 stars 1 forks source link

FITS header updates and sqrt(mom2) still needed? #25

Closed jmangum closed 2 years ago

jmangum commented 2 years ago

Working through several updates to CubeLineMoment I noted the following comment from @keflavich regarding a "pending" PR:

    # compute various moments & statistics along the spcetral dimension
    peak_velocity = brightest_cube.spectral_axis[brightest_cube.argmax(axis=0)]
    max_map = peak_amplitude = brightest_cube.max(axis=0)
    width_map = brightest_cube.linewidth_sigma() # or vcube.moment2(axis=0)**0.5
    fwhm_map = brightest_cube.linewidth_fwhm() # FOR TESTING
    sqrtmom2_map = brightest_cube.moment2(axis=0)**0.5 # FOR TESTING
    centroid_map = brightest_cube.moment1(axis=0)

    # NOTE: the updating header stuff will be completely redundant after
    # https://github.com/radio-astro-tools/spectral-cube/pull/383 is merged
    if not os.path.exists('moment0'):
        os.mkdir('moment0')
    hdu = width_map.hdu
    hdu.header['OBJECT'] = cube.header['OBJECT']
    hdu.writeto("moment0/{0}_WidthMap.fits".format(target),overwrite=True)
    hdu = centroid_map.hdu
    hdu.header['OBJECT'] = cube.header['OBJECT']
    hdu.writeto("moment0/{0}_CentroidMap.fits".format(target),overwrite=True)
    hdu = peak_amplitude.hdu
    hdu.header['OBJECT'] = cube.header['OBJECT']
    hdu.writeto("moment0/{0}_MaxMap.fits".format(target),overwrite=True)
    hdu = fwhm_map.hdu
    hdu.header['OBJECT'] = cube.header['OBJECT']
    hdu.writeto("moment0/{0}_FWHMMap.fits".format(target),overwrite=True)
    hdu = sqrtmom2_map.hdu
    hdu.header['OBJECT'] = cube.header['OBJECT']
    hdu.writeto("moment0/{0}_SQRTMOM2Map.fits".format(target),overwrite=True)

Can I remove the hdu.header['OBJECT'] calls?

Also, given the runtime warning:

WARNING: VarianceWarning: Note that the second moment returned will be a variance map. To get a linewidth map, use the SpectralCube.linewidth_fwhm() or SpectralCube.linewidth_sigma() methods instead. [spectral_cube.spectral_cube]

perhaps we can remove the sqrtmom2_map calculation and output?

jmangum commented 2 years ago

Looks like https://github.com/radio-astro-tools/spectral-cube/pull/383 was merged in 2017.

keflavich commented 2 years ago

Yes, I think you can remove all the header['OBJECT'] lines.

And yes, you can remove the moment2 lines as well if they're not useful

jmangum commented 2 years ago

Resolved with PR #28