本文整理汇总了Python中catalog.Catalog类的典型用法代码示例。如果您正苦于以下问题:Python Catalog类的具体用法?Python Catalog怎么用?Python Catalog使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Catalog类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: analyse_regions
def analyse_regions(self, array_path):
"""
receives a path to an array of quakes object
prints how many quakes there are outside a region that caused shocks on that region
"""
# auxiliary object
catalog = Catalog()
# get earthquake array
quakes = pickle.load(open(array_path, 'rb'))
# analyse kanto
kanto_bounds = catalog.get_kanto_bounds()
self.analyse_region(quakes, kanto_bounds, 'kanto')
# analyse kansai
kansai_bounds = catalog.get_kansai_bounds()
self.analyse_region(quakes, kansai_bounds, 'kansai')
# analyse tohoku
tohoku_bounds = catalog.get_tohoku_bounds()
self.analyse_region(quakes, tohoku_bounds, 'tohoku')
# analyse east_japan
east_japan_bounds = catalog.get_east_japan_bounds()
self.analyse_region(quakes, east_japan_bounds, 'east_japan')
示例2: read_excel
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
示例3: catalog_get_meta
def catalog_get_meta(catalog_id, key=None):
"""
Initialize catalog metadata.
"""
descriptor = registry.lookup(catalog_id)[0]['descriptor']
catalog = Catalog(catalog_factory, descriptor)
return catalog.get_meta(key)
示例4: catalog_init_meta
def catalog_init_meta(catalog_id, role):
"""
Initialize catalog metadata.
"""
descriptor = registry.lookup(catalog_id)[0]['descriptor']
catalog = Catalog(catalog_factory, descriptor)
catalog.init_meta(owner=role)
示例5: catalog_remove_meta
def catalog_remove_meta(catalog_id, key, value=None):
"""
Initialize catalog metadata.
"""
descriptor = registry.lookup(catalog_id)[0]['descriptor']
catalog = Catalog(catalog_factory, descriptor)
catalog.remove_meta(key, value)
示例6: catalog_destroy
def catalog_destroy(catalog_id):
"""
Destroys a catalog.
"""
descriptor = registry.lookup(catalog_id)[0]['descriptor']
catalog = Catalog(catalog_factory, descriptor)
catalog.destroy()
示例7: apply_decluster
def apply_decluster(self):
"""
apply window method to the whole catalog and write mainshocks on file
"""
# get instances of classes we'll need
catalog = Catalog()
window_var = WindowVar()
# from the catalog we want, get earthquakes array on memory
earthquake_array = catalog.get_earthquake_array('../catalogs/new_jma.txt')
# decluster array, separating mainshocks and aftershocks
declustered_array = window_var.decluster(earthquake_array)
# save declustered array using pickle
file_aux1 = open('data_persistence/declustered_array_window_var', 'wb')
pickle.dump(declustered_array, file_aux1)
# open declustered array using another name
file_aux2 = open('data_persistence/declustered_array_window_var', 'rb')
new_declustered_array = pickle.load(file_aux2)
# save declustered array
# record the mainshocks on a catalog
catalog.record_mainshocks(declustered_array, file_write='../results/window_var_method/mainshocks.txt', file_read='../catalogs/jma.txt')
示例8: do_chi_square
def do_chi_square(self, catalog_file, alpha, seconds):
"""
receives a catalog file, a significance level and a number of seconds
do a hyphotesis test to detect whether the catalog is poissonian or not, under the significance level
H0 -> catalog is poissonian
H1 -> catalog is not poissonian
prints the p-value and the significance level
"""
# get observed frequencies
catalog = Catalog()
observed_frequencies = catalog.get_observed_frequencies(catalog_file, seconds)
# print if the observed frequencies are too low
for x in observed_frequencies:
if x < 5:
print("Warning: the number of occurrences appear to be too low!")
break
# get the number of restrictions
restrictions = 1 # 1 restriction, since lambda - rate of occurrence - is estimated from the parameters
# perform chi square test
result = chisquare(observed_frequencies, ddof=restrictions)
# get the p_value
p_value = result[1]
# print results showing the p value and the significance level
print("the p_value was: ", p_value)
print("the significance level was: ", alpha)
示例9: simple_report
def simple_report(self):
"""
plot the number of earthquakes above some magnitudes just to get an idea of the catalog
"""
# get a catalog
catalog = Catalog()
# initially, we have empty lists of magnitude values and number of earthquakes above magnitude
mag_values = []
num_quakes = []
# iterate through an interesting range of magnitudes
mag_limit = 0.0
while mag_limit <= 10.0:
# count how many earthquakes are above that limit
quakes = catalog.count_earthquakes(mag_limit)
# append information on the lists
num_quakes.append(quakes)
mag_values.append(mag_limit)
# increment
mag_limit += 0.1
# plot graph and save result
plt.plot(mag_values, num_quakes, 'ro')
plt.xlabel('Magnitude ')
plt.ylabel('Number of earthquakes')
plt.savefig('../results/earthquakes.jpg')
plt.close()
示例10: read_syracuse
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
示例11: read_seracuse
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
示例12: run
def run(self):
condition=self.condition
path=self.path
end_cb=self.query_end_cb
while(True):
condition.acquire()
try:
while not self.query:
condition.wait()
q=self.query
self.query=""
finally:
condition.release()
def cb(catalog, entry):
return self.catalog_cb(q, catalog, entry)
catalog=Catalog(path)
try:
print "run query: "+q
catalog.query(q, cb)
end_cb(q)
finally:
catalog.close()
示例13: read_syracuse_thermal
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
示例14: Extractor
class Extractor(object):
__metaclass__ = ABCMeta
name = 'Course Extractor'
def __init__(self, spider=None, input_directory='raw_output'):
"""
:param spider: spider
:type spider: CourseSpider
:return:
"""
if spider is None:
self.input_directory = input_directory
self.catalog = Catalog()
self.name = self.input_directory
self.timestamp = date.today()
else:
self.input_directory = spider.get_raw_output()
self.catalog = Catalog()
self.name = spider.get_name()
self.timestamp = spider.get_timestamp()
def set_input_directory(self, directory):
# set the directory of raw html files
self.input_directory = directory
@abstractmethod
def extract_each(self, filename):
"""
:param filename:
:return: extracted catalog
:rtype: Catalog
"""
pass
def extract_all(self):
file_list = [self.input_directory+'/' + f for f in os.listdir(self.input_directory)]
num_files = len(file_list)
print '[INFO] start extracting from %s' % self.name
print '[INFO] total files: %d' % num_files
for each in file_list:
print '[INFO] processing file: %s, %d remaining' % (each, num_files)
self.catalog.append_catalog(self.extract_each(each))
num_files -= 1
print '[SUMMARY] finished extraction'
def to_csv(self):
print '[INFO] saving catalog to file'
self.catalog.to_csv(self.name+'__'+str(self.timestamp), sep=',')
def print_result(self):
print self.catalog
示例15: plot_histograms
def plot_histograms(self, folder):
"""
receives a folder, corresponding to the path of the method we're using
ex: folder = '../results/window_method/'
plot histograms showing how much quakes have occurred on each year
for the regions of kanto, kansai, tohoku and east japan
"""
# auxiliar variable
catalog = Catalog()
# get bounds so to include all the japan
bounds = [0.0, 360.0, 0.0, 360.0]
# plot histogram for all japan, considering only mainshocks
self.show_quakes_by_year(folder + 'classified_quakes.txt', bounds, folder + 'japan_mainshocks.jpg',
'Mainshocks by year on japan region', mainshocks=True)
# plot histogram for japan, considering everything
self.show_quakes_by_year(folder + 'classified_quakes.txt', bounds, folder + 'japan_all.jpg',
'Quakes by year on japan region', mainshocks=False)
# get bounds of kanto
bounds = catalog.get_kanto_bounds()
# plot histogram for kanto, considering only mainshocks
self.show_quakes_by_year(folder + 'classified_quakes.txt', bounds, folder + 'kanto_mainshocks.jpg',
'Mainshocks by year on kanto region', mainshocks=True)
# plot histogram for kanto, considering everything
self.show_quakes_by_year(folder + 'classified_quakes.txt', bounds, folder + 'kanto_all.jpg',
'Quakes by year on kanto region', mainshocks=False)
# get bounds of kansai
bounds = catalog.get_kansai_bounds()
# plot histogram for kansai, considering only mainshocks
self.show_quakes_by_year(folder + 'classified_quakes.txt', bounds, folder + 'kansai_mainshocks.jpg',
'Mainshocks by year on kansai region', mainshocks=True)
# plot histogram for kansai, considering everything
self.show_quakes_by_year(folder + 'classified_quakes.txt', bounds, folder + 'kansai_all.jpg',
'Quakes by year on kansai region', mainshocks=False)
# get bounds of tohoku
bounds = catalog.get_tohoku_bounds()
# plot histogram for tohoku, considering only mainshocks
self.show_quakes_by_year(folder + 'classified_quakes.txt', bounds, folder + 'tohoku_mainshocks.jpg',
'Mainshocks by year on tohoku region', mainshocks=True)
# plot histogram for tohoku, considering everything
self.show_quakes_by_year(folder + 'classified_quakes.txt', bounds, folder + 'tohoku_all.jpg',
'Quakes by year on tohoku region', mainshocks=False)
# get bounds of east_japan
bounds = catalog.get_east_japan_bounds()
# plot histogram for east_japan, considering only mainshocks
self.show_quakes_by_year(folder + 'classified_quakes.txt', bounds, folder + 'east_japan_mainshocks.jpg',
'Mainshocks by year on east_japan region', mainshocks=True)
# plot histogram for east_japan, considering everything
self.show_quakes_by_year(folder + 'classified_quakes.txt', bounds, folder + 'east_japan_all.jpg',
'Quakes by year on east_japan region', mainshocks=False)