Exemple #1
0
def cut_save(filename, position, size):
    #Load image for data and wht, also wcs
    hdu = fits.open(os.getcwd() + '/DATA/' + filename)
    hdr = hdu[0].header
    data = hdu[0].data
    wcs_data = WCS(hdr)

    try:
        #Make the cutout, including the wcs
        cutout_data = Cutout2D(data,
                               position=position,
                               size=size,
                               wcs=wcs_data)
        hdu[0].data = cutout_data

        #Plotting cutout image
        plt.imshow(cutout_data, origin='lower', cmap='v', norm=LogNorm())
        plt.show()

        #Update header with the cutout WCS
        data.header.update(cutout_data.wcs.to_header())

        #Write the cutout to a new FITS file
        cutout_filename = 'cut_' + filename
        hdu.writeto(os.getcwd() + '/DATA/' + cutout_filename, overwrite=True)

    except:
        ima = Image(os.getcwd() + '/DATA/' + filename)
        x_1, x_2 = hdr['CRPIX1'] - size[0], hdr['CRPIX2'] + size[0]
        y_1, y_2 = hdr['CRPIX1'] - size[1], hdr['CRPIX2'] + size[1]
        ima_cut = Image.copy(ima[x_1:x_2, y_1:y_2])
        hdu[0].data = ima_cut.data

        #Plotting cutout image
        plt.imshow(ima_cut.data,
                   origin='lower',
                   cmap='viridis',
                   norm=LogNorm())
        plt.show()

        #Write the cutout to a new FITS file
        cutout_filename = 'cut_' + filename
        hdu.writeto(os.getcwd() + '/DATA/' + cutout_filename, overwrite=True)

    hdu.close()
Exemple #2
0
    if (nargs == nargs_need):
        name = sys.argv[1]
        redshift_input = np.float(sys.argv[2])
        #        fitscube,fitshdr=rfits_cube(filename)
    else:
        print("USE: HIIGaussian_Jim.py NAME_OF_IMAGE REDSHIFT")
        print("There is no such data in " + os.getcwd() + "/DATA/ path!")
        quit()

    start_time = time.time()

    #cube = Cube(filename=DATA_PATH +'flux_elines.{}.cube.fits.gz'.format(name))
    #ima = cube[20, :, :]
    #ima_err = cube[140, :, :]

    ima = Image(filename=DATA_PATH + '{}_calib_rot_rec.fits'.format(name))
    ima_err = 0.12631367914366032 * Image.copy(ima / ima)

    catal, grid, res2, gfitim, gfitim2, chi2_global = xav_explorer(ima,
                                                                   ima_err,
                                                                   name,
                                                                   plot=True)

    #Here will be a time function to calculate the run time y hours, minutes and seconds
    hours = int(time.time() - start_time) / 3600
    minutes = ((time.time() - start_time) - int(time.time() - start_time)) / 60
    seconds = (time.time() - start_time) - int(time.time() - start_time)

    print('My program took {} hours {} minutes {} seconds to run'.format(
        hours, minutes, seconds))