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

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('taskinfo.properties', props)
print(status)
def run():
try:
......@@ -84,14 +86,9 @@ def run():
outputfeaturecollection['properties']['status'] = 'COMPLETE'
outputfeaturecollection['properties']['simulation'] = outletproperties['simulation']
for outputfeature in outputfeaturecollection['features']:
Particletrack.write(outputfeature)
with open('output.json',"w") as outputfile:
json.dump(outputfeaturecollection, outputfile)
Cloudtrack.write(outputfeaturecollection)
Particletrack.write(outputfeaturecollection)
Output.write(outputfeaturecollection)
writeStatus("COMPLETE")
sys.exit(0)
......
......@@ -111,7 +111,7 @@ class Model(object):
if (lvl > 100):
break
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:
@staticmethod
def write(featurecollection):
with open('output.json',"w") as outputfile:
json.dump(featurecollection, outputfile)
class Particletrack:
@staticmethod
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")
@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:
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
Particletrack.writefeature(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