예제 #1
0
def get_nepal_etas_fc(n_procs=None,
                      cat_len=5. * 365.,
                      p_cat=1.1,
                      q_cat=1.5,
                      t_0=dtm.datetime(1990, 1, 1, tzinfo=tz_utc),
                      t_now=dtm.datetime(2015, 5, 7, tzinfo=tzutc),
                      **pram_updates):
    # emulating the 2015-5-7 forecast issued to NASA...
    #
    np_prams = {key: nepal_ETAS_prams[key] for key in ['lats', 'lons', 'mc']}
    np_prams.update({
        'd_lat': 0.1,
        'd_lon': 0.1,
        'etas_range_factor': 25.0,
        'etas_range_padding': 1.25,
        'etas_fit_factor': 1.5,
        't_0': t_0,
        't_now': t_now,
        'transform_type': 'equal_area',
        'transform_ratio_max': 2.,
        'cat_len': cat_len,
        'calc_etas': True,
        'n_contours': 15,
        'n_processes': n_procs,
        'p_cat': p_cat,
        'q_cat': q_cat
    })
    #
    # ... and any params we've passed along...
    np_prams.update(pram_updates)
    #nepal_etas_fc = gep.ETAS_rtree(**np_prams)
    #
    #return gep.ETAS_rtree(**np_prams)
    return gep.ETAS_mpp_handler_xyz(**np_prams)
def etas_outputs(n_processes=None,
                 output_path='etas_outputs/',
                 kml_file='etas_kml.kml',
                 png_file=None,
                 xyz_file=None,
                 fignum=0,
                 color_map='jet',
                 *args,
                 **kwargs):
    #
    # standard set of output files for ETAS, including kml, .png, and .xyz files.
    #
    if not os.path.isdir(output_path): os.makedirs(output_path)
    #
    n_processes = (n_processes or mpp.cpu_count())
    # get a base string for output files.
    base_path = ((kml_file or png_file) or xyz_file)
    pth, fl = os.path.split(base_path)
    fl_root, ext = os.path.splitext(fl)
    #
    #
    kml_file = (kml_file or fl_root + '_kml.kml')
    png_file = (png_file or fl_root + '_png.png')
    xyz_file = (xyz_file or fl_root + '_xyz.xyz')
    #
    kml_file = os.path.join(output_path, kml_file)
    png_file = os.path.join(output_path, png_file)
    xyz_file = os.path.join(output_path, xyz_file)
    #
    #kml_file = (kml_file or os.path.join(pth, fl_root + '_kml.kml'))
    #png_file = (png_file or os.path.join(pth, fl_root + '_png.png'))
    #xyz_fyle = (xyz_file or os.path.join(pth, fl_root + '_xyz.xyz'))
    print('files: ', kml_file, png_file, xyz_file)
    #
    ETAS = gep.ETAS_mpp_handler_xyz(n_processes=n_processes, *args, **kwargs)
    #
    ETAS.make_etas_contour_map(n_contours=n_contours,
                               fignum=fignum,
                               fig_size=fig_size,
                               contour_fig_file=png_file,
                               contour_kml_file=kml_file,
                               kml_contours_bottom=0.,
                               kml_contours_top=1.0,
                               alpha=.6,
                               alpha_kml=.6,
                               refresh_etas=False,
                               map_resolution='i',
                               map_projection='cyl',
                               map_cmap=color_map)
    #
    plt.figure(fignum)
    plt.title('ETAS: \n%s\n' %
              str(kwargs.get('t_now', dtm.datetime.now(pytz.timezone('UTC')))))
    plt.savefig(png_file)
    #
    ETAS.export_xyz(xyz_file)
    ETAS.export_kml(kml_file)
    #
    return ETAS
예제 #3
0
def get_nepal_etas_test(p_cat=1.1,
                        q_cat=1.5,
                        t_start=dtm.datetime(2015, 5, 7, tzinfo=tzutc),
                        delta_t=120,
                        n_cpu=None,
                        **pram_updates):
    # create a "test" etas set, aka ETAS from the events tha timmediately follow the forecast for a geospatial-etas comparison.
    # this is basically a reboot of the RI/PI method, on crack. note, however, that we nominally want
    # this ETAS to be stationary (aka, omori_p = 0), so we're not weighting any specific time during the forecast test period.
    #
    # pram_updates: any earthquake parameters (aka, np_prams) we might want to specify, like "q"...
    # nepal ETAS after forcast (for comparison with forecast)
    t_now = t_start + dtm.timedelta(days=delta_t)
    #
    np_prams = {key: nepal_ETAS_prams[key] for key in ['lats', 'lons', 'mc']}
    # yoder: set 'cat_len':5*365. parameter to None, but verify default behavior. we can also set cat_len
    np_prams.update({
        'd_lat': 0.1,
        'd_lon': 0.1,
        'etas_range_factor': 25.0,
        'etas_range_padding': 1.25,
        'etas_fit_factor': 1.5,
        't_0': t_start,
        't_now': t_now,
        'transform_type': 'equal_area',
        'transform_ratio_max': 2.,
        'cat_len': None,
        'calc_etas': False,
        'n_contours': 15
    })
    #
    np_prams_test = np_prams
    #
    # configure for a 120 day period after the forecast time.
    # yoder: 31 july 2016 :: we should be able to just pass the p_etas param now, to get the stationary catalog.
    etas = gep.ETAS_mpp_handler_xyz(p_cat=p_cat,
                                    q_cat=q_cat,
                                    p_etas=0.,
                                    n_processes=n_cpu,
                                    **np_prams_test)
    # ... except we want to know (or have evidence) that this is how the map was calculated...
    for j, eq in enumerate(etas.catalog):
        etas.catalog['p'][j] = 0.0
        # ... and sort of a sloppy way to do this as well...
        for key, val in pram_updates.items():
            try:
                etas.catalog[key] = val
            except:
                #print('failed to update parameter: {}:{}'.format(key,val))
                pass
    #
    #etas.make_etas()
    return etas
예제 #4
0
def auto_etas_global_params(lon_center=None, lat_center=None, d_lat_0=.25, d_lon_0=.5, dt_0=10,  mc=2.5, mc_0=4.5, d_lat=.1, d_lon=.1, to_dt=None, fnameroot='etas_auto', catlen=5.0*365.0, doplot=False, kmldir='kml_auto', etas_range_factor=10., etas_range_padding=.5, etas_fit_factor=2.0, transform_type='equal_area',transform_ratio_max=2.5, calc_etas=True, n_contours=15, etas_cat_range=None, etas_xyz_range=None, p_cat=1.1, q_cat=1.5, p_etas=None, Lr_factor=3., **kwargs):
	'''
	# this is probably a major staple of future work in ETAS; when in doubt, start here and point it at a big earthquake.
	#
	# a starter script to auto-select some parameters for an ETAS run. in practice, give this script a center location (probably a mainshock epicenter).
	# the script will find the largest earthquake in that region and scale up an ETAS parameter set accordingly.
		# d_lat_0, d_lon_0, dt_0 are the starting catalog parameters (largest earthquake in d_lat_0 x d_lon_0 x dt_0 cube).
	'''
	#
	#if to_dt == None: to_dt = dtm.datetime.now(pytz.timezone('UTC'))
	to_dt = (to_dt or dtm.datetime.now(pytz.timezone('UTC')))
	mc_0  = (mc_0 or mc)
	#
	if lon_center==None and lat_center==None:
		# let's look for any large earthquake in the world. assume for this, mc
		mc_0=6.0
		lat_center = 0.
		lon_center = 0.
		d_lat_0 = 88.
		d_lon_0 = 180.
	#
	# get a preliminary catalog:
	cat_0 = atp.catfromANSS(lon=[lon_center-d_lon_0, lon_center+d_lon_0], lat=[lat_center - d_lat_0, lat_center+d_lat_0], minMag=mc_0, dates0=[to_dt-dtm.timedelta(days=dt_0), to_dt], fout=None, rec_array=True)
	#
	#biggest_earthquake = filter(lambda x: x['mag']==max(cat_0['mag']), cat_0)[0]
	mainshock = {cat_0.dtype.names[j]:x for j,x in enumerate(list(filter(lambda x: x['mag']==max(cat_0['mag']), cat_0))[0])}
	#
	# now, get new map domain based on rupture length, etc.
	L_r = .5*10.0**(.5*mainshock['mag'] - 1.76)
	delta_lat = Lr_factor*L_r/lon2km
	delta_lon = Lr_factor*L_r/(lon2km*math.cos(deg2rad*mainshock['lat']))
	print("mainshock data: ", mainshock, L_r, delta_lat, delta_lon)
	#
	working_cat = atp.catfromANSS(lon=[mainshock['lon']-delta_lon, mainshock['lon']+delta_lon], lat=[mainshock['lat']-delta_lat, mainshock['lat']+delta_lat], minMag=mc, dates0=[to_dt-dtm.timedelta(days=catlen), to_dt], fout=None, rec_array=True)
	#
	print("biggest event(s): ", [rw for rw in working_cat if rw['mag']==max(working_cat['mag'])])
	#
	# now, do some ETAS:
	# skip working_cat above, but parse lon, lat, etc. parameters similarly. pass those (and other) params to make_etas_fcfiles()
	# looks like this: make_etas_fcfiles(root_prams=nepal_ETAS_prams, **kwargs), and:
	# nepal_ETAS_prams = {'todt':None, 'gridsize':.1, 'contres':5, 'mc':4.5, 'kmldir':kmldir, 'catdir':kmldir, 'fnameroot':'nepal', 'catlen':5.0*365.0, 'doplot':False, 'lons':[nepal_epi_lon-nepal_dlon, nepal_epi_lon+nepal_dlon], 'lats':[nepal_epi_lat-nepal_dlat, nepal_epi_lat+nepal_dlat], 'bigquakes':None, 'bigmag':7.00, 'eqtheta':None, 'eqeps':None, 'fitfactor':5.0, 'cmfnum':0, 'fignum':1, 'contour_intervals':None}
	root_prams = {'t_now':None, 'd_lat':d_lat, 'd_lon':d_lon, 'contres':10, 'mc':mc, 'kmldir':kmldir, 'catdir':kmldir, 'fnameroot':fnameroot, 'catlen':catlen, 'doplot':False, 'lons':[mainshock['lon']-delta_lon, mainshock['lon']+delta_lon], 'lats':[mainshock['lat']-delta_lat, mainshock['lat']+delta_lat], 'etas_range_factor':etas_range_factor, 'etas_range_padding':etas_range_padding, 'etas_fit_factor':etas_fit_factor, 'transform_type':transform_type, 'transform_ratio_max':transform_ratio_max, 'calc_etas':calc_etas, 'n_contours':n_contours, 'etas_cat_range':etas_cat_range, 'etas_xyz_range':etas_xyz_range, 'p_cat':p_cat, 'q_cat':q_cat, 'p_etas':p_etas}
	#
	etas = gep.ETAS_mpp_handler_xyz(**root_prams)
	
	# 'bigquakes':None, 'bigmag':mainshock['mag']-1.5, 'eqtheta':None, 'eqeps':None, 'fitfactor':5.0, 'cmfnum':0, 'fignum':1, 'contour_intervals':None}
	#root_prams = {}
	print("now execute with root_prams: ", root_prams)
	#my_kwargs = {}
	#
	return etas