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

using pkg_resources

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