Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
stw
wt
exercisemodel
Commits
17806c08
Commit
17806c08
authored
Nov 29, 2017
by
Tomas Pettersson
🏸
Browse files
added particletrack
parent
1685b529
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
exercisemodel/__init__.py
View file @
17806c08
...
...
@@ -8,6 +8,7 @@ import pickle
import
pkg_resources
from
traceback
import
print_exc
from
model
import
Model
from
particletrack
import
Particletrack
from
shapely
import
geometry
from
shapely.geometry
import
LineString
from
shapely.strtree
import
STRtree
...
...
@@ -49,11 +50,21 @@ def write_properties(filepath, props):
for
key
,
value
in
props
.
iteritems
():
f
.
write
(
key
+
"="
+
value
+
"
\n
"
)
def
writeStatus
(
status
):
props
=
read_properties
(
'taskinfo.properties'
)
if
props
.
has_key
(
"status"
):
props
[
'status'
]
=
status
write_properties
(
'taskinfo.properties'
,
props
)
def
run
():
try
:
writeStatus
(
"INITIAL"
)
strtree
=
STRtree
(
pickle
.
load
(
pkg_resources
.
resource_stream
(
__name__
,
'/'
.
join
((
'resources'
,
'strtree.pickle'
)))))
m
=
Model
()()
with
open
(
'input.json'
,
"r"
)
as
inputfile
:
writeStatus
(
"PARTIAL"
)
inputfeaturecollection
=
json
.
load
(
inputfile
)
output
=
{}
multipointoutlet
=
{}
...
...
@@ -67,23 +78,26 @@ def run():
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'
]
outputfeaturecollection
=
m
.
createOutput
(
multipointoutlet
,
exercisefeature
,
strtree
)
outputfeaturecollection
[
'properties'
]
=
{}
outputfeaturecollection
[
'properties'
][
'uuid'
]
=
os
.
getcwd
().
split
(
os
.
sep
)[
-
1
]
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
(
output
,
outputfile
)
props
=
read_properties
(
'taskinfo.properties'
)
if
props
.
has_key
(
"status"
):
props
[
'status'
]
=
"COMPLETE"
write_properties
(
'taskinfo.properties'
,
props
)
json
.
dump
(
outputfeaturecollection
,
outputfile
)
writeStatus
(
"COMPLETE"
)
sys
.
exit
(
0
)
except
Exception
as
error
:
print_exc
()
writeStatus
(
"ERROR"
)
sys
.
exit
(
1
)
'''
To run in terminal call with python __init__.py
...
...
exercisemodel/__init__.pyc
0 → 100644
View file @
17806c08
File added
exercisemodel/model.py
View file @
17806c08
...
...
@@ -192,8 +192,8 @@ class Model(object):
properties
=
{};
properties
[
'nStep'
]
=
step
properties
[
'time'
]
=
time
properties
[
'meanLat'
]
=
centroid
.
x
properties
[
'meanLon'
]
=
centroid
.
y
properties
[
'meanLat'
]
=
centroid
.
y
properties
[
'meanLon'
]
=
centroid
.
x
properties
[
'category'
]
=
category
properties
[
'level'
]
=
level
return
properties
...
...
exercisemodel/model.pyc
0 → 100644
View file @
17806c08
File added
exercisemodel/particletrack.py
0 → 100644
View file @
17806c08
import
json
from
datetime
import
datetime
class
Particletrack
:
@
staticmethod
def
write
(
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'
])
utcdatetime
=
datetime
.
utcfromtimestamp
(
p
[
'time'
]
/
1000
)
timestring
=
utcdatetime
.
strftime
(
'%Y-%m-%d-%H-%M'
)
with
open
(
'particletrack-'
+
step
+
'-'
+
timestring
+
'.dat'
,
"w"
)
as
particlefile
:
particlefile
.
write
(
" "
+
step
+
" "
+
utcdatetime
.
strftime
(
'%Y-%m-%d %H:%M'
)
+
" "
+
str
(
len
(
coords
))
+
" "
+
meanlon
+
" "
+
meanlat
+
" "
+
"0.0000
\n
"
)
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
"
)
'''
To run in terminal call with python particletrack.py
'''
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
exercisemodel/particletrack.pyc
0 → 100644
View file @
17806c08
File added
output.json
View file @
17806c08
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment