def locateAndSave(initloc,raw_pts,t): aggregated_pts = aggregate.aggregate(raw_pts,args.utmspan) result = locate_dyfi.locate(initloc,aggregated_pts) # Copy solution grid and ipe line to leaflet output webtddir = 'leaflet/data/timedependent/' + evid; os.makedirs(webtddir,exist_ok=True) webgridfile = webtddir + '/grid.' + str(t) + '.geojson' copyfile(tmpgridfile,webgridfile) webgridfile = webtddir + '/ipeline.' + str(t) + '.geojson' copyfile(tmpipefile,webgridfile) # Now aggregated_pts should have additional data (distance, mag, etc.) # from the locate function # Save responses (with results) and copy to leaflet output responsesfilename = 'output/responses.' + evid + '.geojson' print('Writing to ' + responsesfilename) responsesgeojson = geojson.FeatureCollection(aggregated_pts) with open(responsesfilename, 'w') as outfile: geojson.dump(responsesgeojson, outfile) webfilename = 'leaflet/data/aggregated.' + evid + '.geojson' copyfile(responsesfilename,webfilename) webfilename = webtddir + '/responses.' + str(t) + '.geojson' copyfile(responsesfilename,webfilename) # Save this solution result['properties']['t'] = t result['properties']['npts'] = len(raw_pts) solutions.append(result) print('Result: ',result) # Overwrite the solutions output file at each step. It should be # usable even if processing is interrupted. allgeojson = { 'type': 'FeatureCollection', 'features' : solutions } print('Writing to ' + outfilename) with open(outfilename, 'w') as outfile: geojson.dump(allgeojson, outfile) webfilename = 'leaflet/data/out.' + evid + '.geojson' copyfile(outfilename,webfilename)
lastrun_npts = 0 # Number of points of last run iterations = 0 # Number of iterations of locator algorithm t = 0 # Now computing location for first t seconds of event allresults = [] while (lastrun_npts < npts and (args.maxtime == 0 or t < args.maxtime)): t += args.interval # Create a new datapts that only has the entries in the time window this_pts = [pt for pt in allpts if pt['properties']['t'] <= t] this_npts = len(this_pts) if this_npts <= lastrun_npts + args.ptdiff: continue this_pts = aggregate.aggregate(this_pts, args.utmspan) iterations += 1 best_result = False print('%i: Running otime + %i mins (%i entries in %i locations)...' % (iterations, t / 60, this_npts, len(this_pts))) result = locate_dyfi.locate(this_pts) # Copy solution grid to leaflet output webgriddir = 'leaflet/data/grids/' + evid os.makedirs(webgriddir, exist_ok=True) webgridfile = webgriddir + '/grid.' + str(t) + '.geojson' copyfile(tmpgridfile, webgridfile) # TODO: Use GeoJSON property methods for this
# DONE INITIAL SETUP allpts = data['features'] # Extract epicenter data # TODO: If evdata doesn't exist, handle it # TODO: Epicenter should have evid; right now, infer from input filename for i in range(0,len(allpts)): if 'is_epicenter' in allpts[i]['properties']: break evdata = allpts.pop(i) npts = len(allpts) print('Finished loading, got %i pts.' % npts) this_pts = aggregate.aggregate(allpts,args.utmspan) allgeojson = { 'type': 'FeatureCollection', 'features' : this_pts } print('Writing to ' + outfilename) with open(outfilename, 'w') as outfile: geojson.dump(allgeojson, outfile) # Copy aggregated grid to leaflet output webfilename = 'leaflet/data/aggregated.' + evid + '.geojson' copyfile(outfilename,webfilename) print('Done.')