def test_recurrence_from_catalog(self): # don't test if DISPLAY environment variable undefined if sys.platform != 'win32': try: display = os.environ['DISPLAY'] except KeyError: return ################################################################### # Generate test data ################################################################### fours = numpy.ones(81683) * 4.0 fives = numpy.ones(21683) * 5.0 sixes = numpy.ones(1260) * 6.0 sevens = numpy.ones(98) * 7.0 eights = numpy.ones(7) * 8.0 nines = numpy.ones(1) * 9.0 magnitudes = numpy.concatenate( [fours, fives, sixes, sevens, eights, nines]) latitude = 0.0 longitude = 0.0 time = datetime.datetime(2010, 1, 1, 0, 0, 0) event_list = [] for magnitude in magnitudes: event = EarthquakeEvent(latitude, longitude, magnitude, time) event_list.append(event) # change year of first event to give a range of date event_list[0].time = datetime.datetime(2000, 1, 1, 0, 0, 0) pass event_set = EventSet(event_list) ################################################################### # Expected results (generated manually) ################################################################### b_least_squares_test = -1.0454065177746481 a_least_squares_test = 8.3695720382963614 b_mle_test = 1.8542409163755169 annual_num_eq_test = 10473.2 ################################################################## # Test recurrence calulation #a, b, b_mle, annual_num_eq = calc_recurrence(event_set, min_mag=5.5, interval=0.5) a, b, b_mle, annual_num_eq = calc_recurrence(event_set, interval=1.0, verbose=False) msg = a_least_squares_test, a assert numpy.allclose(a_least_squares_test, a, rtol=1e-15), msg msg = b_least_squares_test, b assert numpy.allclose(b_least_squares_test, b, rtol=1e-15), msg msg = b_mle_test, b_mle assert numpy.allclose(b_mle_test, b_mle, rtol=1e-15), msg msg = annual_num_eq_test, annual_num_eq assert numpy.allclose(annual_num_eq_test, annual_num_eq, rtol=1e-15), msg
def test_recurrence_from_catalog(self): # don't test if DISPLAY environment variable undefined if sys.platform != 'win32': try: display = os.environ['DISPLAY'] except KeyError: return ################################################################### # Generate test data ################################################################### fours=numpy.ones(81683)*4.0 fives=numpy.ones(21683)*5.0 sixes=numpy.ones(1260)*6.0 sevens=numpy.ones(98)*7.0 eights=numpy.ones(7)*8.0 nines=numpy.ones(1)*9.0 magnitudes = numpy.concatenate([fours, fives, sixes, sevens, eights, nines]) latitude = 0.0 longitude = 0.0 time=datetime.datetime(2010,1,1,0,0,0) event_list = [] for magnitude in magnitudes: event = EarthquakeEvent(latitude, longitude, magnitude, time) event_list.append(event) # change year of first event to give a range of date event_list[0].time=datetime.datetime(2000,1,1,0,0,0) pass event_set = EventSet(event_list) ################################################################### # Expected results (generated manually) ################################################################### b_least_squares_test = -1.0454065177746481 a_least_squares_test = 8.3695720382963614 b_mle_test = 1.8542409163755169 annual_num_eq_test = 10473.2 ################################################################## # Test recurrence calulation #a, b, b_mle, annual_num_eq = calc_recurrence(event_set, min_mag=5.5, interval=0.5) a, b, b_mle, annual_num_eq = calc_recurrence(event_set, interval=1.0, verbose = False) msg = a_least_squares_test, a assert numpy.allclose(a_least_squares_test, a, rtol=1e-15), msg msg = b_least_squares_test, b assert numpy.allclose(b_least_squares_test, b, rtol=1e-15), msg msg = b_mle_test, b_mle assert numpy.allclose(b_mle_test, b_mle, rtol=1e-15), msg msg = annual_num_eq_test, annual_num_eq assert numpy.allclose(annual_num_eq_test, annual_num_eq, rtol=1e-15), msg
## end_point = [127.2, 2.6] ## subset_name = 'subset7' ## max_lon = 126.2 ## min_lon = 122.4 ## max_lat = -1.1 ## min_lat = -2.6 ## start_point = [122.4, -1.9] ## end_point = [126.2, -1.9] EventSet.create_subset(subset_name, max_lon = max_lon, min_lon = min_lon, max_lat = max_lat, min_lat = min_lat)#, #min_mag = min_mag, min_depth= min_depth) # Specify line along which to plot cross-section if file_name.endswith('.nordic'): figure_base = file_name[:-7] # Plot cross-section xsection_figurefilename = (figure_base + '_' + str(start_point[0]) + '_' + str(start_point[1]) + '_' + str(end_point[0]) + '_' + str(end_point[0]) + '_' + subset_name + '.png') figure_name = os.path.join(file_path, 'figures', xsection_figurefilename) plot_xsection(EventSet, subset_name, [max_lon, max_lat], [min_lon, min_lat], figurename = figure_name) # Plot recurrence recurrence_figure_name = xsection_figurefilename[:-4] + '_recurrence.png' figure_name = os.path.join(file_path, 'figures', recurrence_figure_name) calc_recurrence(EventSet.catalogue_subset[subset_name], min_mag = 4.5, max_mag_ls = 5.5, figurepath = figure_name)
##end_point = [123.96, 1.01] ##subset_name = 'subset4' ##max_lon = 125.4 ##min_lon = 124.0 ##max_lat = 1.6 ##min_lat = -1.0 ##start_point = [124.98, -0.301] ##end_point = [123.96, 0.5] ##min_depth = 35 ##max_depth = 150 subset_name = 'subset4_shallow' max_lon = 125.4 min_lon = 124.0 max_lat = 1.6 min_lat = -1.0 start_point = [124.98, -0.301] end_point = [123.96, 1.01] min_depth = 150 max_depth = 250 EventSet.create_subset(subset_name, max_lon = max_lon, min_lon = min_lon, max_lat = max_lat, min_lat = min_lat, min_depth = min_depth, max_depth = max_depth) figure_name = in_file[:-7] + '_instraslab_4.png' recurrence_from_catalog.calc_recurrence(EventSet.catalogue_subset[subset_name], min_mag = 4.8, max_mag_ls = 6.0, figurepath = figure_name)