Skip to content

Instantly share code, notes, and snippets.

@cjbayesian
Created October 13, 2012 21:54
Show Gist options
  • Save cjbayesian/3886283 to your computer and use it in GitHub Desktop.
Save cjbayesian/3886283 to your computer and use it in GitHub Desktop.
Observing Dark Worlds visualization
################## Plot training skies ###################
##
## [email protected]
##
##########################################################
## calculate a vector given
## x,y,e1,e2
gal_line<-function(g,scale=100)
{
# e1 is stretch along 0degrees (+1)
# or along 90degrees (-1)
# e2 is stretch along 45 (+1)
# or along 135 (-1)
#e1
if(g$e1<=0)
{
x<-0
y<-scale*g$e1
}
if(g$e1>=0)
{
x<-scale*g$e1
y<-0
}
#e2
x<-x+scale*g$e2*cos(pi/4)
y<-y+scale*g$e2*sin(pi/4)
#start and end points
l_seg<-rbind(c(g$x+x,g$y+y),c(g$x-x,g$y-y))
return(l_seg)
}
add_halo<-function(dm,n_rings=20,max_ringsize=2000)
{
d<-seq(0.1,1,length.out=n_rings)
radii<-1/d
radii<-radii/max(radii) * max_ringsize
for(i in 1:dm$numberHalos)
{
centre<-c(dm[1,2*(i-1)+5],dm[1,2*(i-1)+6])
for(r in radii)
{
x=r*cos(seq(0,2*pi,length.out=100)) + centre[1]
y=r*sin(seq(0,2*pi,length.out=100)) + centre[2]
polygon(x,y,col=rgb(0,0,1,0.05),border=NA)
}
}
}
plt_sky<-function(sky,dm,...)
{
## Plot the galaxies
par(bg='black',col='white',col.main='white')
plot(sky$x,sky$y,col='black',...)
## Add the Dark Matter
add_halo(dm)
for(i in 1:nrow(sky))
{
gl<-gal_line(sky[i,])
lines(gl,col='white')
#print(dist(gl))
}
points(sky$x,sky$y,col='grey',pch=20,cex=0.5)
}
##########################################################################
tr_halos<-read.csv('Training_halos.csv')
tr_folder<-'Train_Skies/'
tr_files<-paste(tr_folder,list.files(tr_folder),sep='')
## Extract sky number from file naming convention
index_sky<-1:length(tr_files)
for(i in 1:length(tr_files))
{
m <- regexpr('[0-9]+', tr_files[i])
index_sky[i]<-as.integer(regmatches(tr_files[i], m))
}
tr_files<-tr_files[order(index_sky)]
####
pdf('plots/training_skies.pdf')
for(i in 1:length(tr_files))
{
sky<-read.csv(tr_files[i])
dm<-tr_halos[i,]
plt_sky(sky,dm,main=paste('Sky',i))
print(paste('plotting sky',i))
}
dev.off()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment