From 548fead621275caa3826addec6d462e6276e9f1f Mon Sep 17 00:00:00 2001 From: healther Date: Thu, 4 Apr 2013 10:27:32 +0200 Subject: [PATCH] Fixed a bug in analysis.py 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 --- analysis.py | 18 +++++++++++++----- execute.py | 10 +++++----- plot.py | 38 ++++++++++++++++++++++++-------------- starformation.py | 33 ++++++++++++++++++++------------- 4 files changed, 62 insertions(+), 37 deletions(-) diff --git a/analysis.py b/analysis.py index 8f27210..f5c9a0d 100755 --- a/analysis.py +++ b/analysis.py @@ -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 @@ -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() @@ -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)): @@ -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)) diff --git a/execute.py b/execute.py index f51c919..35a0a8c 100644 --- a/execute.py +++ b/execute.py @@ -17,10 +17,10 @@ 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'] @@ -28,6 +28,6 @@ def main(): f.write( ','.join(head)+'\n' ) np.savetxt(f, parameters) f.close() - analysis.main('out') + analysis.main('out', True) diff --git a/plot.py b/plot.py index abdc707..5ce5b11 100644 --- a/plot.py +++ b/plot.py @@ -7,7 +7,11 @@ 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() @@ -15,14 +19,15 @@ 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')) @@ -30,9 +35,14 @@ 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') @@ -45,7 +55,7 @@ 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')) @@ -53,9 +63,9 @@ 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') diff --git a/starformation.py b/starformation.py index 5531e84..aa683ae 100755 --- a/starformation.py +++ b/starformation.py @@ -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: @@ -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 @@ -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 @@ -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)