Example #1
0
def plot_co_spectra(results,):

    filename_base = \
            cloud_results['figure_dir'] + 'diagnostics/' + \
            cloud_results['filename_extension'] + '_co_spectra'

    from astropy.io import fits
    from mycoords import make_velocity_axis
    from myimage_analysis import bin_image
    from myio import check_file

    cloud = cloud_results['cloud']

    co_filename = cloud.co_filename

    if cloud_results['args']['bin_procedure'] in ('all', 'mle'):
        co_filename = co_filename.replace('.fits', '_bin.fits')

    exists = \
        check_file(co_filename, clobber=False)

    if not exists:
        co_data, co_header = fits.getdata(co_filename,
                                                      header=True,
                                                      )
        cloud.co_data, cloud.co_header = \
            bin_image(co_data,
                      binsize=(1, cloud.binsize, cloud.binsize),
                      header=co_header,
                      statistic=np.nanmean)

        fits.writeto(cloud.co_filename.replace('.fits', '_bin.fits'),
                     cloud.co_data,
                     cloud.co_header,
                     )
    else:
        cloud.co_data, cloud.co_header = \
            fits.getdata(co_filename,
                                                      header=True,
                                                      )

    cloud.co_vel_axis = make_velocity_axis(cloud.co_header)

    # Derive relevant region
    hi_mask = cloud.region_mask
    av_data, av_header = fits.getdata(cloud.av_filename_bin, header=True)
    cloud.load_region(cloud.region_filename, header=cloud.av_header)
    cloud._derive_region_mask(av_data=av_data)
    co_mask = cloud.region_mask
    hi_mask = co_mask

    cloudpy.plot_hi_spectrum(cloud,
                      filename=filename_base + '.png',
                      limits=[-50, 30, -10, 70],
                      plot_co=plot_co,
                      hi_mask=hi_mask,
                      co_mask=co_mask,
                      )
Example #2
0
def plot_co_spectra(results, ):

    filename_base = \
            cloud_results['figure_dir'] + 'diagnostics/' + \
            cloud_results['filename_extension'] + '_co_spectra'

    from astropy.io import fits
    from mycoords import make_velocity_axis
    from myimage_analysis import bin_image
    from myio import check_file

    cloud = cloud_results['cloud']

    co_filename = cloud.co_filename

    if cloud_results['args']['bin_procedure'] in ('all', 'mle'):
        co_filename = co_filename.replace('.fits', '_bin.fits')

    exists = \
        check_file(co_filename, clobber=False)

    if not exists:
        co_data, co_header = fits.getdata(
            co_filename,
            header=True,
        )
        cloud.co_data, cloud.co_header = \
            bin_image(co_data,
                      binsize=(1, cloud.binsize, cloud.binsize),
                      header=co_header,
                      statistic=np.nanmean)

        fits.writeto(
            cloud.co_filename.replace('.fits', '_bin.fits'),
            cloud.co_data,
            cloud.co_header,
        )
    else:
        cloud.co_data, cloud.co_header = \
            fits.getdata(co_filename,
                                                      header=True,
                                                      )

    cloud.co_vel_axis = make_velocity_axis(cloud.co_header)

    # Derive relevant region
    hi_mask = cloud.region_mask
    av_data, av_header = fits.getdata(cloud.av_filename_bin, header=True)
    cloud.load_region(cloud.region_filename, header=cloud.av_header)
    cloud._derive_region_mask(av_data=av_data)
    co_mask = cloud.region_mask
    hi_mask = co_mask

    cloudpy.plot_hi_spectrum(
        cloud,
        filename=filename_base + '.png',
        limits=[-50, 30, -10, 70],
        plot_co=plot_co,
        hi_mask=hi_mask,
        co_mask=co_mask,
    )
Example #3
0
def plot_hi_spectrum(cloud_results, plot_co=1):

    filename_base = \
            cloud_results['figure_dir'] + 'diagnostics/' + \
            cloud_results['filename_extension'] + '_hi_spectrum'

    from astropy.io import fits
    from mycoords import make_velocity_axis
    from myimage_analysis import bin_image
    from myio import check_file

    cloud = cloud_results['cloud']

    if plot_co:

        co_filename = cloud.co_filename

        if cloud_results['args']['bin_procedure'] in ('all', 'mle'):
            co_filename = co_filename.replace('.fits', '_bin.fits')

        exists = \
            check_file(co_filename, clobber=False)

        if not exists:
            co_data, co_header = fits.getdata(co_filename,
                                                          header=True,
                                                          )
            cloud.co_data, cloud.co_header = \
                bin_image(co_data,
                          binsize=(1, cloud.binsize, cloud.binsize),
                          header=co_header,
                          statistic=np.nanmean)

            fits.writeto(cloud.co_filename.replace('.fits', '_bin.fits'),
                         cloud.co_data,
                         cloud.co_header,
                         )
        else:
            cloud.co_data, cloud.co_header = \
                fits.getdata(co_filename,
                                                          header=True,
                                                          )

        cloud.co_vel_axis = make_velocity_axis(cloud.co_header)

    # Derive relevant region
    if cloud_results['args']['bin_procedure'] in ('all', 'mle'):
        av_filename = cloud.av_filename_bin
        hi_filename = cloud.hi_filename_bin
    else:
        av_filename = cloud.av_filename
    hi_mask = cloud.region_mask
    av_data, av_header = fits.getdata(av_filename, header=True)
    cloud.hi_data, cloud.hi_header = \
            fits.getdata(hi_filename, header=True)
    cloud.load_region(cloud.region_filename, header=av_header)
    cloud._derive_region_mask(av_data=av_data)
    co_mask = cloud.region_mask
    hi_mask = co_mask

    import matplotlib.pyplot as plt
    plt.close(); plt.clf();
    co = np.copy(cloud.co_data[30,:,:])
    co[co_mask] = np.nan
    plt.imshow(co, origin='lower')
    plt.savefig('/usr/users/ezbc/Desktop/comap_' + cloud.region + '.png')

    assert all((cloud.hi_data.shape, cloud.co_data.shape,
                cloud.region_mask.shape))

    cloudpy.plot_hi_spectrum(cloud,
                      filename=filename_base + '.png',
                      limits=[-50, 30, -10, 70],
                      plot_co=plot_co,
                      hi_mask=hi_mask,
                      co_mask=co_mask,
                      )
Example #4
0
def plot_hi_spectrum(cloud_results, plot_co=1):

    filename_base = \
            cloud_results['figure_dir'] + 'diagnostics/' + \
            cloud_results['filename_extension'] + '_hi_spectrum'

    from astropy.io import fits
    from mycoords import make_velocity_axis
    from myimage_analysis import bin_image
    from myio import check_file

    cloud = cloud_results['cloud']

    if plot_co:

        co_filename = cloud.co_filename

        if cloud_results['args']['bin_procedure'] in ('all', 'mle'):
            co_filename = co_filename.replace('.fits', '_bin.fits')

        exists = \
            check_file(co_filename, clobber=False)

        if not exists:
            co_data, co_header = fits.getdata(
                co_filename,
                header=True,
            )
            cloud.co_data, cloud.co_header = \
                bin_image(co_data,
                          binsize=(1, cloud.binsize, cloud.binsize),
                          header=co_header,
                          statistic=np.nanmean)

            fits.writeto(
                cloud.co_filename.replace('.fits', '_bin.fits'),
                cloud.co_data,
                cloud.co_header,
            )
        else:
            cloud.co_data, cloud.co_header = \
                fits.getdata(co_filename,
                                                          header=True,
                                                          )

        cloud.co_vel_axis = make_velocity_axis(cloud.co_header)

    # Derive relevant region
    if cloud_results['args']['bin_procedure'] in ('all', 'mle'):
        av_filename = cloud.av_filename_bin
        hi_filename = cloud.hi_filename_bin
    else:
        av_filename = cloud.av_filename
    hi_mask = cloud.region_mask
    av_data, av_header = fits.getdata(av_filename, header=True)
    cloud.hi_data, cloud.hi_header = \
            fits.getdata(hi_filename, header=True)
    cloud.load_region(cloud.region_filename, header=av_header)
    cloud._derive_region_mask(av_data=av_data)
    co_mask = cloud.region_mask
    hi_mask = co_mask

    import matplotlib.pyplot as plt
    plt.close()
    plt.clf()
    co = np.copy(cloud.co_data[30, :, :])
    co[co_mask] = np.nan
    plt.imshow(co, origin='lower')
    plt.savefig('/usr/users/ezbc/Desktop/comap_' + cloud.region + '.png')

    assert all(
        (cloud.hi_data.shape, cloud.co_data.shape, cloud.region_mask.shape))

    cloudpy.plot_hi_spectrum(
        cloud,
        filename=filename_base + '.png',
        limits=[-50, 30, -10, 70],
        plot_co=plot_co,
        hi_mask=hi_mask,
        co_mask=co_mask,
    )