def pull_values(self, id_coords): #use id_coordinates as center values of new map. ra_cent = float(id_coords.ra.to_string(decimal=True)) dec_cent = float(id_coords.dec.to_string(decimal=True)) ref_head = self.astrometry #make a copy of the reference header, need to change center values. ref_head['CRVAL1'] = ra_cent ref_head['CRVAL2'] = dec_cent #Galactic Coordinate System hp = HEALPix( nside=2048, order='ring', frame='galactic' ) #this is with nside for the Planck Maps for the Planck Maps. #create a grid representing the potential map planck_pix = hp.pixel_resolution.to( u.arcsecond).value #pixel size of the planck parameter maps #the 1.5 factor is to oversize the maps map_deg_x = self.x_size * self.r_pix / (1.5 * 3600 ) #mapsize in degrees. map_deg_y = self.y_size * self.r_pix / (1.5 * 3600) npixxside = ceil( map_deg_x * 3600 / planck_pix) #number of pixels along each axis in reference map npixyside = ceil(map_deg_y * 3600 / planck_pix) #oversized to account for interpolation later ra = np.linspace(ra_cent - map_deg_x, ra_cent + map_deg_x, npixxside) * u.deg dec = np.linspace(dec_cent - map_deg_y, dec_cent + map_deg_y, npixyside) * u.deg ra_grid, dec_grid = np.meshgrid(ra, dec) #commit coordinate grid to a skycoord class coords = SkyCoord(ra=ra_grid.ravel(), dec=dec_grid.ravel(), frame='icrs') #pull in the parameters at these specified coordiantes beta = hp.interpolate_bilinear_skycoord(coords, self.full_params[2]) T = hp.interpolate_bilinear_skycoord(coords, self.full_params[1]) Tau = hp.interpolate_bilinear_skycoord(coords, self.full_params[0]) I = calc_intensity(beta, Tau, T, nu=self.nu) * 1e20 #1e20 for conversion to Mjy #reshape the map to a 2D array as opposed to a 1D array. I_map = np.reshape(I, (npixxside, npixyside)) #interpolate to match the reference astrometry. interped_map, ragrd, decgrd = interp_back_to_ref( I_map, ra_grid, dec_grid, ref_head) #calculate the rms and surface brightness for this realization. rms = np.sqrt(np.mean(interped_map)) return rms
def read_in_fits(filename, center, ref_head, ref_pixsize=8, ref_mapsize=260): ''' Purpose : This function reads in the fits files for the components and parses them so that we are left with data only for our field. Inputs: filename (str) - the singular filename for a component used in the MBB fit center (float array) - center of the field of interest ref_head (Astropy.header) - header for the reference field ref_pixsize - pixel size of the reference map ref_mapsize - mapsize of the reference map Outputs: map (float array) - an array of flux values at the given field pixsize (float) - pixel size of the uninterpolated component maps x_side (int) - the length of the x-axis of the map y_side (int) - the length of the y-axis of the map RA_grid (float array) - grid of the Right Ascension values used to pull out components DEC_grid (float array) - grid of the Declination values used to pull out components ''' hdul = fits.open(filename) head = hdul[1].header if 'Temperature' in filename: data = hdul[1].data.field('TEMP') error = hdul[1].data.field('ERR_TEMP') elif 'Spectral-Index' in filename: data = hdul[1].data.field('BETA') error = hdul[1].data.field('ERR_BETA') elif 'Opacity' in filename: data = hdul[1].data.field('TAU353') error = hdul[1].data.field('ERR_TAU') else: data = hdul[1].data.field(0) nside = head['NSIDE'] order = head['ORDERING'] hdul.close() #Galactic Coordinate System hp = HEALPix(nside=nside, order=order, frame='galactic') #create a pixel grid in terms of the nu=353 grid for GNILC to create our intensity maps pixsize = hp.pixel_resolution.to(u.arcsecond).value #* 2 is for boosting the size of the map so to fix edge effects from interpolation map_arc_x = ref_mapsize[0] * 2 * ref_pixsize #map size in arcseconds map_arc_y = ref_mapsize[1] * 2 * ref_pixsize npixxside = ceil(map_arc_x / pixsize) #convert to map size in pixels for nu = 353 map. npixyside = ceil(map_arc_y / pixsize) #* 2 is for boosting the size of the map so to fix edge effects from interpolation x = np.linspace(0, ref_mapsize[0] * 2, npixxside) y = np.linspace(0, ref_mapsize[1] * 2, npixyside) X, Y = np.meshgrid(x, y) w = world(ref_head) skycoords = pixel_to_skycoord(X.ravel(), Y.ravel(), wcs=w, origin=0) RA_grid = np.asarray(skycoords.ra.to_string(decimal=True), dtype='float') * u.deg DEC_grid = np.asarray(skycoords.dec.to_string(decimal=True), dtype='float') * u.deg # coords = SkyCoord(RA_grid.ravel(), DEC_grid.ravel(), frame='icrs') coords = SkyCoord(ra=RA_grid.ravel(), dec=DEC_grid.ravel(), frame='icrs') gal_coords = coords.galactic map = hp.interpolate_bilinear_skycoord(gal_coords, data) x_side = len(x) y_side = len(y) return map, pixsize, y_side, x_side, RA_grid, DEC_grid