Beispiel #1
0
def read_excel(file='slab++.xlsx'):
    wb = open_workbook(file)
    sheet = wb.sheets()[0]
    number_of_rows = sheet.nrows
    number_of_columns = sheet.ncols
        
    items = []
    
    rows = []
    slabs= Catalog()
    for row in range(4, number_of_rows):
        slab= Slab()
        values = []
        for col in range(number_of_columns):
            par=str(sheet.cell(3,col).value)
            if par:
                print(par)
            value  = sheet.cell(row,col).value
            print(par,value)
            try:
                slab.params[par]= float(value)
            except:
                slab.params[par] = str(value)
                
        # save temperature at 600 km using thermal parameter
        phi = slab.params['thermalPar']
        z = 6.0
        Ta = 1338.0
        Tz = Ta * (1.0 - ( (2.0/np.pi)*np.exp(-1.0*( (np.power(np.pi,2.0)*z)/ (np.power(2.32,2.0) * phi) )) ) )
        slab.params['Temp600'] = Tz
        print(Tz)
        print(slab.params)
        slabs.append(slab)
    return slabs
Beispiel #2
0
def read_slabdata(slabcat=None):
	'''
	Creates slab objects for the slabs identified by Fukao & Obayashi (2013)
	'''

	slabs = {}

	#This dictionary contains information about the boundaries of the slabs mentioned in the 
	#Fukao and Obayashi paper

	#The coordinates are entered as follows:
	#[minlon,minlat,maxlon,maxlat]

	slabs['Honshu'] = {'Bounds' : [109,35,159,45]}
	slabs['Bonin'] = {'Bounds' : [109,23,159,35]}
	slabs['Mariana'] = {'Bounds' : [120,8.3,152,25]}
	slabs['Java'] = {'Bounds' : [89,-10,129,19]}
	slabs['Phillippine'] = {'Bounds' : [114,5,128,18]}
	slabs['Tonga'] = {'Bounds' : [157,-26,190,-10]}
	slabs['Kermadec'] = {'Bounds' : [157,-37,190,-26]}
	slabs['Peruvian'] = {'Bounds' : [270,-15,307,6.7]}
	slabs['Chilean'] = {'Bounds' : [270,-45,307,-15]}
	slabs['Central_American'] = {'Bounds' : [249,4.5,282,33]}

	#For these two regions, we need an oblique box. The coodinates are entered as follows
	#[upper left,lower left,lower right,upper right]

	slabs['Kurile_N'] = {'Bounds' : [134.5,65.5,130.5,61.5,158.5,43,162.5,47]}
	slabs['Kurile_S'] = {'Bounds' : [127.5,58.5,123.5,54.5,151.5,36,155.5,40]}

	if slabcat:
		FukaoSlabs = slabcat
	else:
		FukaoSlabs = Catalog()

	for slabname in slabs:

		newslab = Slab(slabname)

		#add directory to the slabs
		newslab.add_Fukao_slab_details(slabs[slabname])
		FukaoSlabs.append(newslab)

	return FukaoSlabs
Beispiel #3
0
def run_game():
    """  入口程序 """
    pygame.init()
    myset = Mysetting()
    screen = pygame.display.set_mode((myset.screen_w, myset.screen_h))
    pygame.display.set_caption('play slab')

    stats = SlabballStats(myset)
    slab = Slab(myset, screen)

    balls = Group()
    sbf.create_ball(balls, screen, myset)

    while True:
        sbf.check_events(slab)
        if stats.game_active:
            sbf.slap_ball_update(slab, balls, screen, myset)
            sbf.update_balls(myset, balls, screen, stats)
        sbf.update_screen(myset, screen, balls, slab)
def test_slab():
    from itertools import product
    comm = MPI.COMM_WORLD
    sizes = (7, 8, 9, 16, 17, 24)
    types = 'fdgFDG'
    atol = dict(f=1e-6, d=1e-14, g=1e-15)
    for typecode in types:
        for M, N, P in product(sizes, sizes, sizes):
            if P % 2: continue
            fft = Slab(comm, (M, N, P), typecode)
            shape = fft.forward_input_array.shape
            dtype = fft.forward_input_array.dtype
            U = np.random.random(shape).astype(dtype)
            F = fft.forward(U)
            V = fft.backward(F)
            fft.destroy()
            assert np.allclose(U, V, atol=atol[typecode.lower()], rtol=0)
Beispiel #5
0
def read_syracuse_thermal(sub='d80'):
    file = open('data/syracuseetal_parameters_'+sub+'.txt','r')
    slabs=Catalog() # Initialize Catalog object
    for line in file.readlines():
        val = line.split()
        if val[0]!= '#':# skip comments at top of file
            name = val[0]
            savei=0
            for i in range(1,4): # Read in slab names that are more than one string in lenght
                try:
                    float(val[i])
                    break
                except:
                    savei=i
                    name = name + ' ' +val[i]

            slab=Slab(name) # Initialize slab object
            slab.params['transition_depth'] = float(val[savei+1])
            slab.params['transition_T'] = float(val[savei+2])
            slab.params['slab_T'] = float(val[savei+3])
            slab.params['moho_T'] = float(val[savei+4])
            slab.params['max_mantle_T'] = float(val[savei+5])
            slab.params['max_mantle_T_depth'] = float(val[savei+6])
            slab.params['transition_offset'] = float(val[savei+7])
            slab.params['slab_surface_T_30km']= float(val[savei+8])
            slab.params['slab_surface_T_240km'] = float(val[savei+9])
            slab.params['min_slab_T_240km'] = float(val[savei+10])
            slabs.append(slab) # Add slab object to catalot
    return slabs
Beispiel #6
0
def read_syracuse():
    file = open('data/syracuseetal_table1.txt','r')
    
    
    slabs=Catalog() # Initialize Catalog object
    for line in file.readlines():
        val = line.split()
        if val[0]!= '#':# skip comments at top of file
            name = val[0]
            savei=0
            for i in range(1,4): # Read in slab names that are more than one string in lenght
                try:
                    float(val[i])
                    break
                except:
                    savei=i
                    name = name + ' ' +val[i]
            print(val,savei)
            slab=Slab(name) # Initialize slab object
            slab.params['lon']= float(val[savei+1])
            slab.params['lat'] = float(val[savei+2])
            slab.params['H'] = float(val[savei+3])
            slab.params['arc_trench_distance'] = float(val[savei+4])
            slab.params['slab_dip'] = float(val[savei+5])
            slab.params['Vc'] = float(val[savei+6])
            slab.params['age'] = float(val[savei+7])
            slab.params['decent_rate'] = float(val[savei+8])
            slab.params['thermal_parameter'] = float(val[savei+9])
            slab.params['sediment_thickness'] = float(val[savei+10])
            slab.params['subducted_sediment_thickness'] = float(val[savei+11])
            slab.params['upper_plate_type'] = val[savei+12]
            #slab.upper_plate_thickness = float(val[savei+12])
            #slab.upper_plate_age = float(val[savei+13])
            slabs.append(slab) # Add slab object to catalot
    return slabs
Beispiel #7
0
# Example usage
import numpy as np
import matplotlib.pyplot as plt
from slab import Slab

slab_dirichlet = Slab(Bi=np.inf, L=0.02, D=9e-7, c_L=2., c_inf=0., num_eigv=30)
slab_noflux = Slab(Bi=0., L=0.02, D=9e-7, c_L=2., c_inf=0., num_eigv=30)
x = np.linspace(0, 0.02, 1000)
for t in np.logspace(-2, 3, 100):
    plt.plot(x, slab_dirichlet.evaluate(x, t), 'b')
    plt.plot(x, slab_noflux.evaluate(x, t), 'r')

plt.show()
Beispiel #8
0
def read_slabdata(slabcat=None):
	'''
	Read in the slab1.0 data as a catalog of slabs object. The argument options allows one to 
	append these slabs to an existing catalog
	'''

	slabdir='data/slab1.0/'

	#Names given to the slab 1.0 slabs
	slabbounds = {}
	slabbounds['Alaska'] = {'Filename' : 'alu_slab1.0_clip.grd'}
	slabbounds['Cascadia'] = {'Filename' :'cas_slab1.0_clip.grd'}
	slabbounds['Izu-Bonin'] = {'Filename' : 'izu_slab1.0_clip.grd'}
	slabbounds['Mexico'] = {'Filename' : 'mex_slab1.0_clip.grd'}
	slabbounds['Tonga'] = {'Filename' : 'ker_slab1.0_clip.grd'}
	slabbounds['Japan'] = {'Filename' : 'kur_slab1.0_clip.grd'}
	slabbounds['Philippines'] = {'Filename' : 'phi_slab1.0_clip.grd'}
	slabbounds['Ryukyu'] = {'Filename' : 'ryu_slab1.0_clip.grd'}
	slabbounds['Vanautu'] = {'Filename' : 'van_slab1.0_clip.grd'}
	slabbounds['Scotia'] = {'Filename' : 'sco_slab1.0_clip.grd'}
	slabbounds['Solomon'] = {'Filename' : 'sol_slab1.0_clip.grd'}
	slabbounds['South_America'] = {'Filename' : 'sam_slab1.0_clip.grd'}
	slabbounds['Sumatra'] = {'Filename' : 'sum_slab1.0_clip.grd'}

	#try:
	#	os.chdir(slabdir)
	#except:
	#	print('Data directory %s does not exist!' %slabdir)

	slab_ncs = glob.glob(slabdir+'*.grd')

	#Create a catalog object for the slab1.0 slabs
	if slabcat:
		Slabs = slabcat
	else:
		Slabs=Catalog()

	for slab in slab_ncs:

		infile = netcdf.netcdf_file(slab, 'r')

		filevariables = infile.variables.keys()

		lats = infile.variables[filevariables[0]][:]
		lons = infile.variables[filevariables[1]][:]

		#This is a lat x lon array
		depths = infile.variables[filevariables[2]][:]
		infile.close()

		minlat = min(lats)
		maxlat = max(lats)
		minlon = min(lons)
		maxlon = max(lons)

		boundingbox = [minlon,maxlon,minlat,maxlat]

		for name in slabbounds:

			if slabbounds[name]['Filename'] == slab.split('/')[-1].strip():

				#create a Slab object 
				newslab = Slab(name)
				slabbounds[name]['Lat_array'] = lats
				slabbounds[name]['Lon_array'] = lons
				slabbounds[name]['Depth_array'] = depths
				slabbounds[name]['Bounding_box'] = boundingbox

				#Add sub-dicionary to the slab object
				newslab.add_slab1_details(slabbounds[name])
				Slabs.append(newslab)
				break

	return Slabs,slabbounds
Beispiel #9
0
def read_seracuse():
    file = open('data/syracuseetal_parameters.txt','r')


    slabs=Catalog()
    for line in file.readlines():
        val = line.split()
        name = val[0]
        savei=0
        for i in range(1,4):
            try:
                float(val[i])
                break
            except:
                savei=i
                name = name + ' ' +val[i]

        slab=Slab(name)
        slab.transition_depth = float(val[savei+1])
        slab.transition_T = float(val[savei+2])
        slab.slab_T = float(val[savei+3])
        slab.moho_T = float(val[savei+4])
        slab.max_mantle_T = float(val[savei+5])
        slab.max_mantle_T_depth = float(val[savei+6])
        slab.transition_offset = float(val[savei+7])
        slab.slab_surface_T_30km = float(val[savei+8])
        slab.slab_surface_T_240km = float(val[savei+9])
        slab.min_slab_T_240km = float(val[savei+10])
        slabs.append(slab)
    return slabs
Beispiel #10
0
# Example usage
import numpy as np
import matplotlib.pyplot as plt
from slab import Slab

slab_dirichlet = Slab(Bi=np.inf, L=0.02, D=9e-7, c_L=2.0, c_inf=0.0, num_eigv=30)
slab_noflux = Slab(Bi=0.0, L=0.02, D=9e-7, c_L=2.0, c_inf=0.0, num_eigv=30)
x = np.linspace(0, 0.02, 1000)
for t in np.logspace(-2, 3, 100):
    plt.plot(x, slab_dirichlet.evaluate(x, t), "b")
    plt.plot(x, slab_noflux.evaluate(x, t), "r")

plt.show()
Beispiel #11
0
V = 1000000.
A = 0.001

Bi  = 1e-12
L   = 1.
D   = 1e-5
c_L = 1.
c_inf = 0.

maxt = 100000
dt = 1000

num_elements = 200

times, numeric_uptake, _ = dogbone(V,A,1.,c_L,D,L,num_elements,maxt,dt)

x = np.linspace(0.,L,num_elements)

analytic_uptake = []
for t in times:
    analytic = Slab(Bi,L,D,c_L,c_inf)
    analytic_c = analytic.evaluate(x,t)
    analytic_uptake.append(np.trapz(analytic_c,x))

print A*np.array(analytic_uptake)
print numeric_uptake
plt.plot(times,A*np.array(analytic_uptake),'-')
plt.plot(times,np.array(numeric_uptake),'.')
plt.show()