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

now writes cloudtrack and particletrack files

parent 17806c08
......@@ -8,7 +8,9 @@ import pickle
import pkg_resources
from traceback import print_exc
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.geometry import LineString
from shapely.strtree import STRtree
......@@ -56,7 +58,7 @@ def writeStatus(status):
if props.has_key("status"):
props['status'] = status
write_properties('', props)
def run():
......@@ -84,14 +86,9 @@ def run():
outputfeaturecollection['properties']['status'] = 'COMPLETE'
outputfeaturecollection['properties']['simulation'] = outletproperties['simulation']
for outputfeature in outputfeaturecollection['features']:
with open('output.json',"w") as outputfile:
json.dump(outputfeaturecollection, outputfile)
......@@ -33,7 +33,7 @@ class Model(object):
center = [centroid.x,centroid.y]
for point in points:
latlng = [point.x, point.y]
centered.append(self.centerPoint(newLatLng, center, latlng))
centered.append(self.centerPoint(newLatLng, center, latlng))
return centered
def centerPoint(self, newCenter, oldCenter, latlng):
......@@ -111,7 +111,7 @@ class Model(object):
if (lvl > 100):
print counter
print("Outlet particles count: "+str(counter))
return geometry.MultiPoint(points)
......@@ -131,7 +131,7 @@ class Model(object):
def onlandPoints(self, points, strtree):
result = list(points)
print("On land calculated")
return result
......@@ -2,17 +2,27 @@
import json
from datetime import datetime
class Output:
def write(featurecollection):
with open('output.json',"w") as outputfile:
json.dump(featurecollection, outputfile)
class Particletrack:
def write(feature):
def writefeature(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'])
meanlon = "{:10.4f}".format(p['meanLon'])
meanlat = "{:10.4f}".format(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:
......@@ -20,6 +30,26 @@ class Particletrack:
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")
def write(featurecollection):
for outputfeature in featurecollection['features']:
class Cloudtrack:
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:
if __name__ == "__main__":
with open('../output.json',"r") as outputfile:
outputfeaturecollection = json.load(outputfile)
\ No newline at end of file
\ No newline at end of file
This diff is collapsed.
Supports Markdown
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