Commit e6ba8756 authored by Tomas Pettersson's avatar Tomas Pettersson 🏸

now writes cloudtrack and particletrack files

parent 17806c08
...@@ -8,7 +8,9 @@ import pickle ...@@ -8,7 +8,9 @@ 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 output import Output
from output import Particletrack
from output import Cloudtrack
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
...@@ -56,7 +58,7 @@ def writeStatus(status): ...@@ -56,7 +58,7 @@ def writeStatus(status):
if props.has_key("status"): if props.has_key("status"):
props['status'] = status props['status'] = status
write_properties('taskinfo.properties', props) write_properties('taskinfo.properties', props)
print(status)
def run(): def run():
try: try:
...@@ -84,14 +86,9 @@ def run(): ...@@ -84,14 +86,9 @@ def run():
outputfeaturecollection['properties']['status'] = 'COMPLETE' outputfeaturecollection['properties']['status'] = 'COMPLETE'
outputfeaturecollection['properties']['simulation'] = outletproperties['simulation'] outputfeaturecollection['properties']['simulation'] = outletproperties['simulation']
for outputfeature in outputfeaturecollection['features']: Cloudtrack.write(outputfeaturecollection)
Particletrack.write(outputfeature) Particletrack.write(outputfeaturecollection)
Output.write(outputfeaturecollection)
with open('output.json',"w") as outputfile:
json.dump(outputfeaturecollection, outputfile)
writeStatus("COMPLETE") writeStatus("COMPLETE")
sys.exit(0) sys.exit(0)
......
...@@ -33,7 +33,7 @@ class Model(object): ...@@ -33,7 +33,7 @@ class Model(object):
center = [centroid.x,centroid.y] center = [centroid.x,centroid.y]
for point in points: for point in points:
latlng = [point.x, point.y] latlng = [point.x, point.y]
centered.append(self.centerPoint(newLatLng, center, latlng)) centered.append(self.centerPoint(newLatLng, center, latlng))
return centered return centered
def centerPoint(self, newCenter, oldCenter, latlng): def centerPoint(self, newCenter, oldCenter, latlng):
...@@ -111,7 +111,7 @@ class Model(object): ...@@ -111,7 +111,7 @@ class Model(object):
if (lvl > 100): if (lvl > 100):
break break
print counter print("Outlet particles count: "+str(counter))
return geometry.MultiPoint(points) return geometry.MultiPoint(points)
...@@ -131,7 +131,7 @@ class Model(object): ...@@ -131,7 +131,7 @@ class Model(object):
def onlandPoints(self, points, strtree): def onlandPoints(self, points, strtree):
result = list(points) result = list(points)
print("On land calculated")
return result return result
......
...@@ -2,17 +2,27 @@ ...@@ -2,17 +2,27 @@
import json import json
from datetime import datetime from datetime import datetime
class Output:
@staticmethod
def write(featurecollection):
with open('output.json',"w") as outputfile:
json.dump(featurecollection, outputfile)
class Particletrack: class Particletrack:
@staticmethod @staticmethod
def write(feature): def writefeature(feature):
p = feature['properties'] p = feature['properties']
category = p['category'] category = p['category']
level = p['level'] level = p['level']
coords = feature['geometry']['coordinates'] coords = feature['geometry']['coordinates']
step = str(p['nStep']) step = str(p['nStep'])
meanlon = str(p['meanLon']) meanlon = "{:10.4f}".format(p['meanLon'])
meanlat = str(p['meanLat']) meanlat = "{:10.4f}".format(p['meanLat'])
utcdatetime = datetime.utcfromtimestamp(p['time']/1000) utcdatetime = datetime.utcfromtimestamp(p['time']/1000)
timestring = utcdatetime.strftime('%Y-%m-%d-%H-%M') timestring = utcdatetime.strftime('%Y-%m-%d-%H-%M')
with open('particletrack-'+step+'-'+timestring+'.dat',"w") as particlefile: with open('particletrack-'+step+'-'+timestring+'.dat',"w") as particlefile:
...@@ -20,6 +30,26 @@ class Particletrack: ...@@ -20,6 +30,26 @@ class Particletrack:
for key,coord in enumerate(coords): 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") 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")
@staticmethod
def write(featurecollection):
for outputfeature in featurecollection['features']:
Particletrack.writefeature(outputfeature)
class Cloudtrack:
@staticmethod
def write(featurecollection):
features = featurecollection['features']
with open('cloudtrack.dat',"w") as cloudfile:
for feature in features:
p = feature['properties']
meanlon = "{:10.4f}".format(p['meanLon'])
meanlat = "{:10.4f}".format(p['meanLat'])
utcdatetime = datetime.utcfromtimestamp(p['time']/1000)
cloudfile.write(utcdatetime.strftime('%Y-%m-%d %H:%M')+" "+meanlon+" "+meanlat+" "+"0.0000\n")
''' '''
...@@ -28,4 +58,4 @@ class Particletrack: ...@@ -28,4 +58,4 @@ class Particletrack:
if __name__ == "__main__": if __name__ == "__main__":
with open('../output.json',"r") as outputfile: with open('../output.json',"r") as outputfile:
outputfeaturecollection = json.load(outputfile) outputfeaturecollection = json.load(outputfile)
Particletrack.write(outputfeaturecollection['features'][0]) Particletrack.writefeature(outputfeaturecollection['features'][0])
\ No newline at end of file \ 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