def loadin_central_fits(haloID,zl,bsz,nnn,band='ACS_F606_NEW.res'): GroupFirstSub = il.groupcat.loadHalos(basePath,135,fields=['GroupFirstSub']) sub_galnrs = GroupFirstSub[haloID] my_api = "9dc591936258a12cb7192ebf79450272" # Input your own api for Illustris database dl_base = 'http://www.illustris-project.org' cmd = 'wget --content-disposition --header="API-Key: '+my_api+'" "'+dl_base+ \ '/api/Illustris-1/snapshots/135/subhalos/'+str(sub_galnrs)+ \ '/stellar_mocks/broadband.fits"' if( not (os.path.isfile("./broadband_"+str(sub_galnrs)+".fits")) ): os.system(cmd) filename = "./broadband_"+str(sub_galnrs)+".fits" hdulist = pyfits.open(filename) nx1 = hdulist[3].header['NAXIS1'] nx2 = hdulist[3].header['NAXIS2'] Dcmr_zl0 = mm.cosmocalc(0.01, H0=70.4, WM=0.2726, WV=0.7274)['DL_Mpc'] Dcmr_zl1 = mm.cosmocalc(zl, H0=70.4, WM=0.2726, WV=0.7274)['DL_Mpc'] bsz_init = np.rad2deg(hdulist[3].header['FOV'])*3600.0*Dcmr_zl0/Dcmr_zl1 # arcsec dsx_init = bsz_init/nx1 hdulist.close() return_image = sunpy__load.load_broadband_image(filename,band) nnx1 = int(bsz/dsx_init) nnx2 = int(bsz/dsx_init) return_image_new = np.zeros((nnx1,nnx2)) if bsz >= bsz_init: return_image_new[nnx1/2-nx1/2:nnx1/2+nx1/2,nnx2/2-nx2/2:nnx2/2+nx2/2] = return_image else: return_image_new = return_image[nx1/2-nnx1/2:nx1/2+nnx1/2,nx2/2-nnx2/2:nx2/2+nnx2/2] return_image_new = ssi.congrid(return_image_new,(nnn,nnn)) return return_image_new
def return_johnson_uvk_img(filename, camera=0, scale_min=0.1, scale_max=50, size_scale=1.0): if not os.path.exists(filename): print("file not found:", filename) sys.exit() b_effective_wavelength = sunpy__load.load_broadband_effective_wavelengths( filename, band="U_Johnson.res") g_effective_wavelength = sunpy__load.load_broadband_effective_wavelengths( filename, band="V_Johnson.res") r_effective_wavelength = sunpy__load.load_broadband_effective_wavelengths( filename, band="K_Johnson.res") b_image = (sunpy__load.load_broadband_image( filename, band="U_Johnson.res", camera=camera) * b_effective_wavelength / g_effective_wavelength * 2.5) g_image = (sunpy__load.load_broadband_image( filename, band="V_Johnson.res", camera=camera) * g_effective_wavelength / g_effective_wavelength) r_image = (sunpy__load.load_broadband_image( filename, band="K_Johnson.res", camera=camera) * r_effective_wavelength / g_effective_wavelength * 1.5) n_pixels img = np.zeros((n_pixels, n_pixels, 3), dtype=float) img[:, :, 0] = asinh(r_image, scale_min=scale_min, scale_max=scale_max, non_linear=0.5) img[:, :, 1] = asinh(g_image, scale_min=scale_min, scale_max=scale_max, non_linear=0.5) img[:, :, 2] = asinh(b_image, scale_min=scale_min, scale_max=scale_max, non_linear=0.5) img[img < 0] = 0 return img
def return_johnson_uvk_img(filename,camera=0,scale_min=0.1,scale_max=50,size_scale=1.0): if (not os.path.exists(filename)): print "file not found:", filename sys.exit() b_effective_wavelength = sunpy__load.load_broadband_effective_wavelengths(filename,band="U_Johnson.res") g_effective_wavelength = sunpy__load.load_broadband_effective_wavelengths(filename,band="V_Johnson.res") r_effective_wavelength = sunpy__load.load_broadband_effective_wavelengths(filename,band="K_Johnson.res") b_image = sunpy__load.load_broadband_image(filename,band='U_Johnson.res',camera=camera) * b_effective_wavelength / g_effective_wavelength * 2.5 g_image = sunpy__load.load_broadband_image(filename,band='V_Johnson.res',camera=camera) * g_effective_wavelength / g_effective_wavelength r_image = sunpy__load.load_broadband_image(filename,band='K_Johnson.res',camera=camera) * r_effective_wavelength / g_effective_wavelength * 1.5 n_pixels img = np.zeros((n_pixels, n_pixels, 3), dtype=float) img[:,:,0] = asinh(r_image, scale_min=scale_min, scale_max=scale_max,non_linear=0.5) img[:,:,1] = asinh(g_image, scale_min=scale_min, scale_max=scale_max,non_linear=0.5) img[:,:,2] = asinh(b_image, scale_min=scale_min, scale_max=scale_max,non_linear=0.5) img[img<0] = 0 return img
def return_h_band_img(filename,camera=0,scale_min=0.1,scale_max=50,size_scale=1.0): if (not os.path.exists(filename)): print "file not found:", filename sys.exit() image = sunpy__load.load_broadband_image(filename,band='H_Johnson.res', camera=camera) n_pixels = image.shape[0] img = np.zeros((n_pixels, n_pixels), dtype=float) img[:,:] = asinh(image, scale_min=scale_min, scale_max=scale_max,non_linear=0.5) img[img<0] = 0 return img
def return_sdss_gri_img(filename,camera=0,scale_min=0.1,scale_max=50,size_scale=1.0, non_linear=0.5): if (not os.path.exists(filename)): print "file not found:", filename sys.exit() b_image = sunpy__load.load_broadband_image(filename,band='g_SDSS.res',camera=camera) * 0.7 g_image = sunpy__load.load_broadband_image(filename,band='r_SDSS.res',camera=camera) * 1.0 r_image = sunpy__load.load_broadband_image(filename,band='i_SDSS.res',camera=camera) * 1.4 n_pixels = r_image.shape[0] img = np.zeros((n_pixels, n_pixels, 3), dtype=float) img[:,:,0] = asinh(r_image, scale_min=scale_min, scale_max=scale_max,non_linear=non_linear) img[:,:,1] = asinh(g_image, scale_min=scale_min, scale_max=scale_max,non_linear=non_linear) img[:,:,2] = asinh(b_image, scale_min=scale_min, scale_max=scale_max,non_linear=non_linear) img[img<0] = 0 del b_image, g_image, r_image gc.collect() return img
def return_sdss_gri_img(filename, camera=0, scale_min=0.1, scale_max=50, size_scale=1.0, non_linear=0.5): if not os.path.exists(filename): print("file not found:", filename) sys.exit() b_image = (sunpy__load.load_broadband_image( filename, band="g_SDSS.res", camera=camera) * 0.7) g_image = (sunpy__load.load_broadband_image( filename, band="r_SDSS.res", camera=camera) * 1.0) r_image = (sunpy__load.load_broadband_image( filename, band="i_SDSS.res", camera=camera) * 1.4) n_pixels = r_image.shape[0] img = np.zeros((n_pixels, n_pixels, 3), dtype=float) img[:, :, 0] = asinh(r_image, scale_min=scale_min, scale_max=scale_max, non_linear=non_linear) img[:, :, 1] = asinh(g_image, scale_min=scale_min, scale_max=scale_max, non_linear=non_linear) img[:, :, 2] = asinh(b_image, scale_min=scale_min, scale_max=scale_max, non_linear=non_linear) img[img < 0] = 0 del b_image, g_image, r_image gc.collect() return img
def return_h_band_img(filename, camera=0, scale_min=0.1, scale_max=50, size_scale=1.0): if not os.path.exists(filename): print("file not found:", filename) sys.exit() image = sunpy__load.load_broadband_image(filename, band="H_Johnson.res", camera=camera) n_pixels = image.shape[0] img = np.zeros((n_pixels, n_pixels), dtype=float) img[:, :] = asinh(image, scale_min=scale_min, scale_max=scale_max, non_linear=0.5) img[img < 0] = 0 return img
'formats': ('S3', 'i10', 'f8') }) except TypeError: catalog = np.loadtxt('directory_catalog_135.txt', dtype={ 'names': ('subdirs', 'galaxy_numbers', 'galaxy_masses'), 'formats': ('S3', 'i8', 'f8') }) all_subdirs = catalog['subdirs'] all_galnrs = catalog['galaxy_numbers'] for index, galnr in enumerate(all_galnrs[:1]): cmd = 'wget --content-disposition --header="API-Key: '+my_api+'" "'+dl_base+ \ '/api/Illustris-1/snapshots/135/subhalos/'+str(galnr)+ \ '/stellar_mocks/broadband.fits"' if (not (os.path.isfile("./broadband_" + str(galnr) + ".fits"))): os.system(cmd) filename = "./broadband_" + str(galnr) + ".fits" # retrieve the image. Could be used for non-parametric fitting, plotting, etc. image = sunpy__load.load_broadband_image(filename, band='B_Johnson.res') # plot an SDSS gri band idealized image sunpy__plot.plot_sdss_gri(filename, savefile='./sdss_gri_' + str(galnr) + '.png') os.remove("./" + filename)
def loadin_fits(sub_galnrs, zl, bsz, nnn, band='ACS_F606_NEW.res'): my_api = "9dc591936258a12cb7192ebf79450272" dl_base = 'http://www.illustris-project.org' #try: #catalog = np.loadtxt('directory_catalog_135.txt', #dtype={'names' : ('subdirs', 'galaxy_numbers', 'galaxy_masses'), #'formats': ('S3', 'i8', 'f8')}) #except: #os.system("wget "+dl_base+"/files/directory_catalog_135.txt") #catalog = np.loadtxt('directory_catalog_135.txt', #dtype={'names' : ('subdirs', 'galaxy_numbers', 'galaxy_masses'), #'formats': ('S3', 'i8','f8')}) #1 rad2 = 3282.8 deg2 = 4.25 x 10^10 arcsec2 #all_subdirs = catalog['subdirs'] #all_galnrs = catalog['galaxy_numbers'] #int_all_subdirs = all_subdirs.astype('int') #sub_galnrs = 127228 #sub_galnrs = 326247 #sub_galnrs = 1030 #sub_galnrs = 19 cmd = 'wget --content-disposition --header="API-Key: '+my_api+'" "'+dl_base+ \ '/api/Illustris-1/snapshots/135/subhalos/'+str(sub_galnrs)+ \ '/stellar_mocks/broadband.fits"' if (not (os.path.isfile("./broadband_" + str(sub_galnrs) + ".fits"))): os.system(cmd) filename = "./broadband_" + str(sub_galnrs) + ".fits" hdulist = pyfits.open(filename) nx1 = hdulist[3].header['NAXIS1'] nx2 = hdulist[3].header['NAXIS2'] bsz_init = np.rad2deg( hdulist[3].header['FOV']) * 3600.0 * mm.Dc(0.01) / mm.Dc(zl) # arcsec dsx_init = bsz_init / nx1 hdulist.close() return_image = sunpy__load.load_broadband_image(filename, band) nnx1 = int(bsz / dsx_init) nnx2 = int(bsz / dsx_init) return_image_new = np.zeros((nnx1, nnx2)) if bsz >= bsz_init: return_image_new[nnx1 / 2 - nx1 / 2:nnx1 / 2 + nx1 / 2, nnx2 / 2 - nx2 / 2:nnx2 / 2 + nx2 / 2] = return_image else: return_image_new = return_image[nx1 / 2 - nnx1 / 2:nx1 / 2 + nnx1 / 2, nx2 / 2 - nnx2 / 2:nx2 / 2 + nnx2 / 2] #print nx1/2-int(bsz/2.0/dsx_init),nx1/2+int(bsz/2.0/dsx_init),nx2/2-int(bsz/2.0/dsx_init),nx2/2+int(bsz/2.0/dsx_init) #return_image_new = return_image return_image_new = ssi.congrid(return_image_new, (nnn, nnn)) #pl.figure() #pl.contourf(np.log10(return_image_new)) #pl.colorbar() return return_image_new
catalog = np.loadtxt('directory_catalog_135.txt', dtype={'names' : ('subdirs', 'galaxy_numbers', 'galaxy_masses'), 'formats': ('S3', 'i10', 'f8')}) except: os.system("wget "+dl_base+"/files/directory_catalog_135.txt") catalog = np.loadtxt('directory_catalog_135.txt', dtype={'names' : ('subdirs', 'galaxy_numbers', 'galaxy_masses'), 'formats': ('S3', 'i10','f8')}) all_subdirs = catalog['subdirs'] all_galnrs = catalog['galaxy_numbers'] for index,galnr in enumerate(all_galnrs[:1]): cmd = 'wget --content-disposition --header="API-Key: '+my_api+'" "'+dl_base+ \ '/api/Illustris-1/snapshots/135/subhalos/'+str(galnr)+ \ '/stellar_mocks/broadband.fits"' if( not (os.path.isfile("./broadband_"+str(galnr)+".fits")) ): os.system(cmd) filename = "./broadband_"+str(galnr)+".fits" # retrieve the image. Could be used for non-parametric fitting, plotting, etc. image = sunpy__load.load_broadband_image(filename,band='B_Johnson.res') # plot an SDSS gri band idealized image sunpy__plot.plot_sdss_gri(filename, savefile='./sdss_gri_'+str(galnr)+'.png') os.remove("./"+filename)