Skip to content

Commit

Permalink
Fixed a bug in analysis.py
Browse files Browse the repository at this point in the history
added quiet-functions in analysis.py and starformation.py
changed print-statement to print function in analysis.py and
starformation.py
adapted plot.py for usage with 130402 data
adapted execute.py to changes in the other files
  • Loading branch information
healther committed Apr 4, 2013
1 parent ec40b9d commit 548fead
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 37 deletions.
18 changes: 13 additions & 5 deletions analysis.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,21 @@
import numpy as np
import os
from decimal import Decimal
from __future__ import print_function


def main(folder):
def main(folder, quiet=0):
'''This script gives the number of "observed" stars from the sampled datafiles in "folder"/
according to the selection criteria from Yusef-Zadeh et al
'''

if QUIET:
def print(*args):
pass



color1 = "I4" #filter system for first color of CMD
color2 = "M1" #filter system for second color of CMD
min_mag = 8. #minimal observation limit
Expand All @@ -22,9 +29,10 @@ def main(folder):

for fil in files:
#ignoring the settingsfiles and eventual existing former analysis files
if not ('settings' in fil.encode("ascii") or fil.startswith('__')):
if not ('settings' in fil.encode("ascii") or fil.startswith('__') or fil.startswith('.')):
print ("%s/%s" % (folder,fil.encode("ascii")))
f = open("%s/%s" % (folder,fil.encode("ascii")), 'r')
headers = f.readline().split(',')
headers = f.readline().strip().split(',')
data = np.loadtxt(f)
f.close()

Expand All @@ -37,7 +45,7 @@ def main(folder):
y = -2.5*(np.log10(data[:,c2]/7140))


# efficiency?
# efficiency? accuracy?
n=0
#selecting "observed" stars
for i in range(len(x)):
Expand All @@ -53,4 +61,4 @@ def main(folder):
np.savetxt(f, out)
f.close()

print ("Analysed %s files and saved output to %s" % (len(fil),'%s/__expected_number' % folder))
10 changes: 5 additions & 5 deletions execute.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,17 @@ def main():
k = 0.
parameters = []
for av in np.linspace(5.0, 50.0, 10):
for apera in np.linspace(15000, 50000, 8):
for age in np.linspace(500000, 2000000, 12):
starformation.main(av, .001, apera, age, "%s_%s_%s" % (av,apera,age))
print av, apera, age, k/10./8./12.
for apera in np.linspace(15000, 50000, 11):
for age in np.linspace(500000, 2000000, 11):
starformation.main(av, .001, apera, age, "%s_%s_%s" % (av,apera,age), True)
print av, apera, age, k/10./11./11.
k = k+1
parameters.append([av,apera,age])
head = ['AV', 'Aperature_size', 'Age']
f = open('out/__head', 'w')
f.write( ','.join(head)+'\n' )
np.savetxt(f, parameters)
f.close()
analysis.main('out')
analysis.main('out', True)


38 changes: 24 additions & 14 deletions plot.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,42 @@
import matplotlib.pyplot as plt
import numpy as np

f = open('oldout/__expected_number', 'r')
aperature = 3
visual_ex = 1


f = open('out/__expected_number', 'r')
headers = f.readline().strip().split(',')[1:]
data = np.loadtxt(f)
f.close()


fig = plt.figure()
ax = fig.gca(projection='3d')
avs = np.linspace(10.625, 38.75, 6)
aperas = np.linspace(15000, 50000, 7)
ages = np.linspace(500000, 2000000, 5)
numbers = data[:,3].reshape(6, 7, 5)
numbers = np.roll(numbers,2,2)
avs = np.linspace(5.0, 50.0, 10)
aperas = np.linspace(15000, 50000, 11)
ages = np.linspace(500000, 2000000, 11)
numbers = data[:,3].reshape(10, 11, 11)
numbers = np.roll(numbers,4,2)


X, Y = np.meshgrid(avs, ages)
Z = np.transpose(numbers[:,3,:])/559.
Z = np.transpose(numbers[:,aperature,:])/559.
surf = ax.plot_surface(X, Y, Z, rstride=1, cstride=1, cmap=cm.coolwarm)
#ax.zaxis.set_major_locator(LinearLocator(10))
#ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))
#fig.colorbar(surf, shrink=0.5, aspect=5)
fig.colorbar(surf)


x = data[:,0].reshape(6, 7, 5)[:,3,:].reshape(30)
y = data[:,2].reshape(6, 7, 5)[:,3,:].reshape(30)
z = data[:,3].reshape(6, 7, 5)[:,3,:].reshape(30)/559.
x = X.reshape(110)
y = Y.reshape(110)
z = Z.reshape(110)


#x = data[:,0].reshape(10, 11, 11)[:,aperature,:].reshape(110)
#y = data[:,2].reshape(10, 11, 11)[:,aperature,:].reshape(110)
#z = data[:,3].reshape(10, 11, 11)[:,aperature,:].reshape(110)/559.
ax.scatter(x,y,z)
ax.set_xlabel('av')
ax.set_ylabel('age')
Expand All @@ -45,17 +55,17 @@


X2, Y2 = np.meshgrid(ages, aperas)
Z2 = numbers[0,:,:]/559.
Z2 = numbers[visual_ex,:,:]/559.
surf2 = ax2.plot_surface(X2, Y2, Z2, rstride=1, cstride=1, cmap=cm.coolwarm)
#ax.zaxis.set_major_locator(LinearLocator(10))
#ax.zaxis.set_major_formatter(FormatStrFormatter('%.02f'))
#fig.colorbar(surf, shrink=0.5, aspect=5)
fig2.colorbar(surf2)


x2 = data[:,2].reshape(6, 7, 5)[0,:,:].reshape(35)
y2 = data[:,1].reshape(6, 7, 5)[0,:,:].reshape(35)
z2 = data[:,3].reshape(6, 7, 5)[0,:,:].reshape(35)/559.
x2 = data[:,2].reshape(10, 11, 11)[visual_ex,:,:].reshape(121)
y2 = data[:,1].reshape(10, 11, 11)[visual_ex,:,:].reshape(121)
z2 = data[:,3].reshape(10, 11, 11)[visual_ex,:,:].reshape(121)/559.
ax2.scatter(x2,y2,z2)
ax2.set_xlabel('age')
ax2.set_ylabel('apera')
Expand Down
33 changes: 20 additions & 13 deletions starformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,10 @@
import matplotlib.pyplot as plt
import scipy.spatial
from astropy.io import fits
from __future__ import print_function

def main(A_v = 10.0, sfr = .001, apera = 24000, maxage = 2000000., appendix='default'):

def main(A_v = 10.0, sfr = .001, apera = 24000, maxage = 2000000., appendix='default', quiet=0):
'''Creates a sample of stars
input:
Expand All @@ -20,6 +22,11 @@ def main(A_v = 10.0, sfr = .001, apera = 24000, maxage = 2000000., appendix='def
A_v, sfr, apera, maxage, number of sampled stars, their cumulated mass and
the expected mass
'''

if QUIET:
def print(*args):
pass

t0 = time()
if appendix=='default': # making sure not to overwrite former output
appendix=t0 # by using the starting time as an unique id
Expand Down Expand Up @@ -66,8 +73,8 @@ def g(x):
mass, age = mf.sample(1)[0], sf.sample(1)[0]
cumass = cumass + mass
stars.append([n, age, mass])
# if n % 10000 == 0:
# print n, cumass #reporting progress
if n % 10000 == 0:
print (n, cumass) #reporting progress
n = n+1


Expand Down Expand Up @@ -164,14 +171,14 @@ def g(x):

# timing possibility for optimization efforts

# print 'starting script at %f' %(t0)
# print 'initializing %f' %(t1-t0)
# print "sampleing %f" %(t2-t1)
# print "model data load %f" %(t3-t2)
# print "matching model %f" %(t4-t3)
# print "extracting fluxes %f" %(t5-t4)
# print "saving %f" %(t6-t5)
# print "________________________"
# print "total runtime %f" %(t6-t0)
# print "finishing script %f" %t6
print( 'starting script at %f' %(t0))
print( 'initializing %f' %(t1-t0))
print( "sampleing %f" %(t2-t1))
print( "model data load %f" %(t3-t2))
print( "matching model %f" %(t4-t3))
print( "extracting fluxes %f" %(t5-t4))
print( "saving %f" %(t6-t5))
print( "________________________")
print( "total runtime %f" %(t6-t0))
print( "finishing script %f" %t6)

0 comments on commit 548fead

Please sign in to comment.