Commit 90f5fb41 authored by Tomas Pettersson's avatar Tomas Pettersson 🏸

using pkg_resources

parent 37f9ecaa
......@@ -5,6 +5,7 @@ import os
import sys
import json
import pickle
import pkg_resources
from traceback import print_exc
from model import Model
from shapely import geometry
......@@ -24,37 +25,35 @@ def storetree():
continue
split = line.split(' ')
section.append([float(split[2]),float(split[1])])
with open('strtree.pickle', 'wb') as handle:
with open('resources/strtree.pickle', 'wb') as handle:
pickle.dump(sections, handle, protocol=pickle.HIGHEST_PROTOCOL)
def run():
try:
strtree = STRtree(pickle.load(pkg_resources.resource_stream(__name__, '/'.join(('resources', 'strtree.pickle')))))
m = Model()()
with open('input.json',"r") as inputfile:
inputfeaturecollection = json.load(inputfile)
output = {}
multipointoutlet = {}
outletproperties = {}
exercisefeature = {}
for inputfeature in inputfeaturecollection['features']:
if ('primary' in inputfeature['properties'] and inputfeature['properties']['primary'] == 'PADM'):
outletproperties = inputfeature['properties']
outletgeom = geometry.shape(inputfeature['geometry'])
multipointoutlet = m.createOutlet(outletgeom)
if ('auxiliary' in inputfeature['properties'] and inputfeature['properties']['auxiliary'] == 'exercise'):
exercisefeature = inputfeature
with open('exercisemodel/strtree.pickle', 'rb') as handle:
strtree = STRtree(pickle.load(handle))
m = Model()()
with open('input.json',"r") as inputfile:
inputfeaturecollection = json.load(inputfile)
output = {}
multipointoutlet = {}
outletproperties = {}
exercisefeature = {}
for inputfeature in inputfeaturecollection['features']:
if ('primary' in inputfeature['properties'] and inputfeature['properties']['primary'] == 'PADM'):
outletproperties = inputfeature['properties']
outletgeom = geometry.shape(inputfeature['geometry'])
multipointoutlet = m.createOutlet(outletgeom)
if ('auxiliary' in inputfeature['properties'] and inputfeature['properties']['auxiliary'] == 'exercise'):
exercisefeature = inputfeature
output = m.createOutput(multipointoutlet,exercisefeature, strtree)
output['properties'] = {}
output['properties']['uuid'] = os.getcwd().split(os.sep)[-1]
output['properties']['status'] = 'COMPLETE'
output['properties']['simulation'] = outletproperties['simulation']
output = m.createOutput(multipointoutlet,exercisefeature, strtree)
output['properties'] = {}
output['properties']['uuid'] = os.getcwd().split(os.sep)[-1]
output['properties']['status'] = 'COMPLETE'
output['properties']['simulation'] = outletproperties['simulation']
with open('output.json',"w") as outputfile:
json.dump(output, outputfile)
with open('output.json',"w") as outputfile:
json.dump(output, outputfile)
sys.exit(0)
except Exception as error:
......
......@@ -8,4 +8,4 @@ setup(name='exercisemodel',
author_email='tomas.pettersson@smhi.se',
license='MIT',
packages=['exercisemodel'],
zip_safe=False)
\ No newline at end of file
zip_safe=True)
\ 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