Exemplo n.º 1
0
    se_red = np.genfromtxt(taffy_extdir + 'rawspectra_for_paperplot/se_red.dat', dtype=None, names=['wav','flux'])

    # bridge west region 
    bw_blue = np.genfromtxt(taffy_extdir + 'rawspectra_for_paperplot/bw_new_blue.dat', dtype=None, names=['wav','flux'])
    bw_red = np.genfromtxt(taffy_extdir + 'rawspectra_for_paperplot/bw_new_red.dat', dtype=None, names=['wav','flux'])

    # bridge east region
    be_blue = np.genfromtxt(taffy_extdir + 'rawspectra_for_paperplot/be_new_blue.dat', dtype=None, names=['wav','flux'])
    be_red = np.genfromtxt(taffy_extdir + 'rawspectra_for_paperplot/be_new_red.dat', dtype=None, names=['wav','flux'])

    # Make figure
    # read in i band SDSS image
    sdss_i, wcs_sdss = vcm.get_sdss('i')

    # read in lzifu output file
    lzifu_hdulist, wcs_lzifu = vcm.get_lzifu_products()

    # create figure and plot
    # the sdss image is plotted according the the function in the 
    # vel_channel_map code it is slightly modified here to work with gridspec.
    fig = plt.figure(figsize=(9,9))  # figsize=(width, height)

    # modify rc Params
    mpl.rcParams["font.family"] = "serif"
    mpl.rcParams["font.sans-serif"] = ["Computer Modern Sans"]
    #mpl.rcParams["text.usetex"] = True
    # I've kept this above commented out line here as a reminder. 
    # This line will stop any bold text from appearing anywhere 
    # on your figure. Didn't realize this for a couple hours lol...
    # Also, this single line increases the run time for this code
    # from ~6 seconds to ~20 seconds.
Exemplo n.º 2
0
home = os.getenv('HOME')  # Does not have a trailing slash at the end
taffy_dir = home + '/Desktop/ipac/taffy/'
taffy_extdir = '/Volumes/Bhavins_backup/ipac/TAFFY/'
savedir = '/Volumes/Bhavins_backup/ipac/TAFFY/baj_gauss_fits_to_lzifu_linefits/'

sys.path.append(taffy_dir + 'codes/')
import bpt_plots as bpt
import vel_channel_map as vcm

if __name__ == '__main__':
	
    # Start time
    start = time.time()
    dt = datetime.datetime
    print "Starting at --", dt.now()

    # constants:
    lightspeed = 299792.458  # km/s

    # read in i band SDSS image
    sdss_i, wcs_sdss = vcm.get_sdss('i')

    # read in lzifu output file
    h, wcs_lzifu = vcm.get_lzifu_products()
    del h 
    h = fits.open(savedir + 'stitched_cube.fits')

    # put fit in arr
    r_line_total = 

	sys.exit(0)
Exemplo n.º 3
0
def make_diff_map():

    # read in indices file
    h = fits.open(savedir + 'all_cases_indices.fits')

    comp1_inv_idx = h['COMP1_INV'].data
    comp2_inv_idx = h['COMP2_INV'].data
    single_idx = h['SINGLE_IDX'].data
    diffmean_idx = h['DIFFMEAN_IDX'].data
    diffstd_idx = h['DIFFSTD_IDX'].data
    diffboth_idx = h['DIFFBOTH_IDX'].data

    intg_flux_comp1_hdu = fits.open(savedir + 'intg_flux_cube_comp1.fits')
    intg_flux_comp2_hdu = fits.open(savedir + 'intg_flux_cube_comp2.fits')

    intg_flux_comp1 = intg_flux_comp1_hdu[0].data
    intg_flux_comp2 = intg_flux_comp2_hdu[0].data

    diffmap = intg_flux_comp2 - intg_flux_comp1

    # NaN out some spaxels that don't seem right
    # ds9 coords [x,y]
    nan_list = [[20, 47], [20, 48], [20, 49]]

    for coord_to_nan in nan_list:
        i = coord_to_nan[1] - 1
        j = coord_to_nan[0] - 1
        print "DS9 coords:", coord_to_nan, "   Array coords:", i, j
        diffmap[i, j] = np.nan

    # Plotting
    # read in i band SDSS image
    sdss_i, wcs_sdss = vcm.get_sdss('i')

    # read in lzifu output file
    lzifu_hdulist, wcs_lzifu = vcm.get_lzifu_products()

    # Save as fits file
    hdr = lzifu_hdulist['B_LINE'].header
    # Create file
    hdu = fits.PrimaryHDU(diffmap, header=hdr)
    # write
    hdu.writeto(taffy_extdir + 'intg_flux_diff_map.fits', overwrite=True)

    # ------------ also save indices file with proper header ------------ #
    indices_hdu = fits.PrimaryHDU()
    indices_hdul = fits.HDUList(indices_hdu)

    hdr['EXTNAME'] = 'COMP1_INV'
    indices_hdul.append(fits.ImageHDU(data=comp1_inv_idx, header=hdr))

    hdr['EXTNAME'] = 'COMP2_INV'
    indices_hdul.append(fits.ImageHDU(data=comp2_inv_idx, header=hdr))

    hdr['EXTNAME'] = 'SINGLE_IDX'
    indices_hdul.append(fits.ImageHDU(data=single_idx, header=hdr))

    hdr['EXTNAME'] = 'DIFFMEAN_IDX'
    indices_hdul.append(fits.ImageHDU(data=diffmean_idx, header=hdr))

    hdr['EXTNAME'] = 'DIFFSTD_IDX'
    indices_hdul.append(fits.ImageHDU(data=diffstd_idx, header=hdr))

    hdr['EXTNAME'] = 'DIFFBOTH_IDX'
    indices_hdul.append(fits.ImageHDU(data=diffboth_idx, header=hdr))
    indices_hdul.writeto(taffy_extdir + 'all_cases_indices_with_wcs.fits',
                         overwrite=True)

    sys.exit(0)

    # plot sdss image
    fig, ax = vcm.plot_sdss_image(sdss_i, wcs_sdss)

    # draw contours
    x = np.arange(58)
    y = np.arange(58)
    X, Y = np.meshgrid(x, y)

    # get colormap
    colorbrewer_cm = vcm.get_colorbrewer_cm('coolwarm')

    kernel = Gaussian2DKernel(stddev=0.9)
    diffmap = convolve(diffmap, kernel, boundary='extend')

    c = ax.contour(X, Y, diffmap, transform=ax.get_transform(wcs_lzifu),\
     cmap=colorbrewer_cm, linewidths=2.0, interpolation='None')
    ax.clabel(c,
              inline=True,
              inline_spacing=2,
              fontsize=8,
              fmt='%1.1f',
              lw=4,
              ls='-')

    # add colorbar inside figure
    cbaxes = inset_axes(ax,
                        width='30%',
                        height='3%',
                        loc=8,
                        bbox_to_anchor=[0.02, 0.08, 1, 1],
                        bbox_transform=ax.transAxes)
    #cb = plt.colorbar(c, cax=cbaxes, ticks=[min(levels), max(levels)], orientation='horizontal')
    #cb.ax.get_children()[0].set_linewidths(10.0)
    #cb.ax.set_xlabel(r'$\mathrm{Integrated\ flux [erg\, s^{-1}\, cm^{-2}\, \AA^{-1} * km\, s^{-1}]}$', fontsize=12)

    plt.show()

    return None
Exemplo n.º 4
0
def plot_map(ew_map, ew_map_north, ew_map_south):

    # NaN out small EW
    nan_idx = np.where(ew_map < 0.1)
    ew_map[nan_idx] = np.nan

    # combine masks and plot
    comb_mask = (north_mask == 1) & (south_mask == 1)

    ew_map = ma.array(ew_map, mask=comb_mask)

    # modify rc Params
    mpl.rcParams["font.family"] = "serif"
    mpl.rcParams["font.sans-serif"] = ["Computer Modern Sans"]
    mpl.rcParams["text.usetex"] = False
    mpl.rcParams["text.latex.preamble"] = r"\usepackage{cmbright}"

    # make figure
    fig = plt.figure()
    lzifu_hdulist, wcs_lzifu = vcm.get_lzifu_products()
    ax = fig.add_subplot(111, projection=wcs_lzifu)

    cax = ax.imshow(ew_map,
                    vmin=2.0,
                    vmax=15.0,
                    cmap='inferno',
                    origin='lower',
                    interpolation='None')
    cbar = fig.colorbar(cax)
    cbar.ax.set_ylabel(r'$\mathrm{H \beta\ EW\, [\AA]}$', fontsize=14)

    #ax.set_autoscale_on(False)  # to stop matplotlib from changing zoom level and able actually overplot the image and contours

    lon = ax.coords[0]
    lat = ax.coords[1]

    lon.set_ticks_visible(True)
    lon.set_ticklabel_visible(True)
    lat.set_ticks_visible(True)
    lat.set_ticklabel_visible(True)

    lon.display_minor_ticks(True)
    lat.display_minor_ticks(True)

    lon.set_major_formatter('hh:mm:ss.s')
    lat.set_major_formatter('dd:mm:ss.s')

    lon.set_axislabel('Right Ascension (J2000)', fontsize=14)
    lat.set_axislabel('Declination (J2000)', fontsize=14)

    ax.coords.frame.set_color('k')
    ax.grid(color='gray', ls='dashed', lw=0.7)

    # Add text for figure panel
    f = FontProperties()
    f.set_weight('bold')
    ax.text(0.05, 0.97, '(b)', verticalalignment='top', horizontalalignment='left', \
        transform=ax.transAxes, color='k', fontproperties=f, size=18)

    fig.savefig(taffy_extdir + 'figures_stitched_cube/hbeta_ew_map.png', \
        dpi=300, bbox_inches='tight')
    # DO NOT save this as pdf. Save as png and convert to pdf with preview.
    # For some reason, the underlying EW map loses resolution when saving as pdf.

    return None
Exemplo n.º 5
0
def main():
    """
    The purpose of this code is to compare the Vs+V1+V1n map
    (this is currently the top middle panel in Fig 7) with the
    Vs+V2+V1n map. This is one of the plots the referee wanted 
    to see. I think they think that this will display the rotation
    better. I'm not entirely sure.

    This code is completely based on the codes --
    1. stitche_vel_vdisp_cube.py and 2. contours_from_linefits.py.
    """

    # Generate the Vs + V2 + V1n map
    #genmap()

    # Read in the new map and make contours
    map_vel_comp2_hdu = fits.open(gaussfits_dir + 'vel_cube_comp2.fits')
    map_vel_comp2_new_hdu = fits.open(gaussfits_dir + 'vel_cube_vs_v2_v1n.fits')

    map_vel_comp2 = map_vel_comp2_hdu[0].data
    map_vel_comp2_new = map_vel_comp2_new_hdu[0].data

    # Diagnostic figures
    # Do not delete this code block. Useful for checking.
    """
    fig = plt.figure()
    ax1 = fig.add_subplot(121)
    ax2 = fig.add_subplot(122)

    ax1.imshow(map_vel_comp2, origin='lower', vmin=-350, vmax=350)
    ax2.imshow(map_vel_comp2_new, origin='lower', vmin=-350, vmax=350)

    plt.show()
    """

    # ------- Contours --------- # 
    # Plotting
    # Change MPL RC params first to stop using TeX for all text
    # becasue I can't use bold text with TeX.
    mpl.rcParams['text.usetex'] = False
    # Bold text
    f = FontProperties()
    f.set_weight('bold')

    # read in i band SDSS image
    sdss_i, wcs_sdss = vcm.get_sdss('i')

    # read in lzifu output file
    lzifu_hdulist, wcs_lzifu = vcm.get_lzifu_products()

    # plot sdss image
    fig, ax = vcm.plot_sdss_image(sdss_i, wcs_sdss)

    # draw contours
    x = np.arange(58)
    y = np.arange(58)
    X, Y = np.meshgrid(x,y)

    # get colormap
    colorbrewer_cm = vcm.get_colorbrewer_cm('blue2yellow')

    # select contour map to plot and set the variables 
    # set the variables, levels, and limits below
    con_map = map_vel_comp2_new

    # apply min and max limits
    minlim = -500
    maxlim = 500
    minidx = np.where(con_map < minlim)
    maxidx = np.where(con_map > maxlim)
    con_map[minidx] = np.nan
    con_map[maxidx] = np.nan

    levels = np.array([-350, -250, -200, -150, -100, 0, 100, 150, 200, 250, 350])  # vel both comp

    # try smoothing the map to get smoother contours
    # define kernel
    kernel = Gaussian2DKernel(stddev=0.9)
    con_map = convolve(con_map, kernel, boundary='extend')

    c = ax.contour(X, Y, con_map, transform=ax.get_transform(wcs_lzifu),\
     levels=levels, cmap=colorbrewer_cm, linewidths=2.0, interpolation='None')

    # add colorbar inside figure
    cbaxes = inset_axes(ax, width='30%', height='3%', loc=8, bbox_to_anchor=[0.02, 0.08, 1, 1], bbox_transform=ax.transAxes)
    cb = plt.colorbar(c, cax=cbaxes, ticks=[min(levels), max(levels)], orientation='horizontal')
    cb.ax.get_children()[0].set_linewidths(16.0)
    cb.ax.set_xlabel(r'$\mathrm{Radial\ Velocity\ [km\, s^{-1}]}$', fontsize=15)

    plt.show()

    return None
Exemplo n.º 6
0
def main():

    # ------------------------- Read in data ------------------------- #
    # Read in HI data from Condon et al. 1993
    hi_cube_hdu = fits.open(home +
                            '/Dropbox/Taffy/HI_Condon_et_al/taffy_HIcube.fits')
    hi_cube = hi_cube_hdu[0].data

    # Now read in optical IFU data
    # Only need red channel for Halpha
    obs_r_hdu = fits.open(taffy_data + 'Taffy_R.fits')
    obs_r = obs_r_hdu[0].data

    # Using my own line fits instead of lzifu
    r_line_total = np.load(taffy_extdir + 'halpha_profile_mylinefits.npy')

    # ------------------------- Other preliminaries ------------------------- #
    # create wavelength array
    # I read these data from the corresponding headers
    # red wav arr
    delt_r = 0.3  # i.e. the wav axis is sampled at 0.3A
    red_wav_start = 6165.0
    total_red_res_elem = 2350

    red_wav_arr = [
        red_wav_start + delt_r * i for i in range(total_red_res_elem)
    ]
    red_wav_arr = np.asarray(red_wav_arr)

    # get mask of all possible not NaN pixels
    all_mask = vcm.get_region_mask('all_possibly_notnan_pixels_new')

    # Make sure that rest wavelength is Halpha wavelength in air!! the IFU data was taken on the ground
    # find line index in wavelength array
    redshift = 0.0145  # average z
    sys_vel = redshift * speed_of_light  # avg systemic velocity is z*c = 4350 km/s
    halpha_air_wav = 6562.80
    halpha_wav = halpha_air_wav * (1 + redshift)
    halpha_idx = np.argmin(abs(red_wav_arr - halpha_wav))

    # ------------------------- Plotting ------------------------- #
    # read in i band SDSS image
    sdss_i, wcs_sdss = vcm.get_sdss('i')

    # read in lzifu output file
    lzifu_hdulist, wcs_lzifu = vcm.get_lzifu_products()

    # plot sdss image
    fig, ax = vcm.plot_sdss_image(sdss_i, wcs_sdss)

    # Now read in regions file and convert to polygons
    #with fl as open():

    regstr = 'polygon(52.75971,52.679517,55.559628,52.679492,55.559611,55.479493,52.759775,55.479517) # color=red width=2'
    regstr = regstr.split('(')[1].split(')')[0]
    regstr = regstr.split(',')
    reglist = list(
        regstr)  # this is now a list of floats represented as strings

    reg_pn_list = []
    for k in range(0, 8, 2):
        reg_pn_list.append([float(reglist[k]), float(reglist[k + 1])])

    reg_pn = pg.Polygon(reg_pn_list)

    extract_spec(reg_pn, hi_cube)
    #extract_spec(reg_pn, obs_r)

    #plt.show()

    return None