Commit 17806c08 authored by Tomas Pettersson's avatar Tomas Pettersson 🏸

added particletrack

parent 1685b529
...@@ -8,6 +8,7 @@ import pickle ...@@ -8,6 +8,7 @@ import pickle
import pkg_resources import pkg_resources
from traceback import print_exc from traceback import print_exc
from model import Model from model import Model
from particletrack import Particletrack
from shapely import geometry from shapely import geometry
from shapely.geometry import LineString from shapely.geometry import LineString
from shapely.strtree import STRtree from shapely.strtree import STRtree
...@@ -49,11 +50,21 @@ def write_properties(filepath, props): ...@@ -49,11 +50,21 @@ def write_properties(filepath, props):
for key, value in props.iteritems(): for key, value in props.iteritems():
f.write(key+"="+value+"\n") f.write(key+"="+value+"\n")
def writeStatus(status):
props = read_properties('taskinfo.properties')
if props.has_key("status"):
props['status'] = status
write_properties('taskinfo.properties', props)
def run(): def run():
try: try:
writeStatus("INITIAL")
strtree = STRtree(pickle.load(pkg_resources.resource_stream(__name__, '/'.join(('resources', 'strtree.pickle'))))) strtree = STRtree(pickle.load(pkg_resources.resource_stream(__name__, '/'.join(('resources', 'strtree.pickle')))))
m = Model()() m = Model()()
with open('input.json',"r") as inputfile: with open('input.json',"r") as inputfile:
writeStatus("PARTIAL")
inputfeaturecollection = json.load(inputfile) inputfeaturecollection = json.load(inputfile)
output = {} output = {}
multipointoutlet = {} multipointoutlet = {}
...@@ -67,23 +78,26 @@ def run(): ...@@ -67,23 +78,26 @@ def run():
if ('auxiliary' in inputfeature['properties'] and inputfeature['properties']['auxiliary'] == 'exercise'): if ('auxiliary' in inputfeature['properties'] and inputfeature['properties']['auxiliary'] == 'exercise'):
exercisefeature = inputfeature exercisefeature = inputfeature
output = m.createOutput(multipointoutlet,exercisefeature, strtree) outputfeaturecollection = m.createOutput(multipointoutlet,exercisefeature, strtree)
output['properties'] = {} outputfeaturecollection['properties'] = {}
output['properties']['uuid'] = os.getcwd().split(os.sep)[-1] outputfeaturecollection['properties']['uuid'] = os.getcwd().split(os.sep)[-1]
output['properties']['status'] = 'COMPLETE' outputfeaturecollection['properties']['status'] = 'COMPLETE'
output['properties']['simulation'] = outletproperties['simulation'] outputfeaturecollection['properties']['simulation'] = outletproperties['simulation']
for outputfeature in outputfeaturecollection['features']:
Particletrack.write(outputfeature)
with open('output.json',"w") as outputfile: with open('output.json',"w") as outputfile:
json.dump(output, outputfile) json.dump(outputfeaturecollection, outputfile)
props = read_properties('taskinfo.properties')
if props.has_key("status"):
props['status'] = "COMPLETE" writeStatus("COMPLETE")
write_properties('taskinfo.properties', props)
sys.exit(0) sys.exit(0)
except Exception as error: except Exception as error:
print_exc() print_exc()
writeStatus("ERROR")
sys.exit(1) sys.exit(1)
''' '''
To run in terminal call with python __init__.py To run in terminal call with python __init__.py
......
...@@ -192,8 +192,8 @@ class Model(object): ...@@ -192,8 +192,8 @@ class Model(object):
properties = {}; properties = {};
properties['nStep'] = step properties['nStep'] = step
properties['time'] = time properties['time'] = time
properties['meanLat'] = centroid.x properties['meanLat'] = centroid.y
properties['meanLon'] = centroid.y properties['meanLon'] = centroid.x
properties['category'] = category properties['category'] = category
properties['level'] = level properties['level'] = level
return properties return properties
......
import json
from datetime import datetime
class Particletrack:
@staticmethod
def write(feature):
p = feature['properties']
category = p['category']
level = p['level']
coords = feature['geometry']['coordinates']
step = str(p['nStep'])
meanlon = str(p['meanLon'])
meanlat = str(p['meanLat'])
utcdatetime = datetime.utcfromtimestamp(p['time']/1000)
timestring = utcdatetime.strftime('%Y-%m-%d-%H-%M')
with open('particletrack-'+step+'-'+timestring+'.dat',"w") as particlefile:
particlefile.write(" "+step+" "+utcdatetime.strftime('%Y-%m-%d %H:%M')+" "+str(len(coords))+" "+meanlon+" "+meanlat+" "+"0.0000\n")
for key,coord in enumerate(coords):
particlefile.write(" "+"{:10.4f}".format(coord[0])+" "+"{:10.4f}".format(coord[1])+" "+"{:1.1f}".format(level[key])+" T T F "+str(category[key])+" 0.000 0.000 0.000\n")
'''
To run in terminal call with python particletrack.py
'''
if __name__ == "__main__":
with open('../output.json',"r") as outputfile:
outputfeaturecollection = json.load(outputfile)
Particletrack.write(outputfeaturecollection['features'][0])
\ No newline at end of file
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment