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
e6ba8756
Commit
e6ba8756
authored
Nov 29, 2017
by
Tomas Pettersson
🏸
Browse files
now writes cloudtrack and particletrack files
parent
17806c08
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
exercisemodel/__init__.py
View file @
e6ba8756
...
...
@@ -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
)
...
...
exercisemodel/__init__.pyc
deleted
100644 → 0
View file @
17806c08
File deleted
exercisemodel/model.py
View file @
e6ba8756
...
...
@@ -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
):
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
...
...
exercisemodel/model.pyc
deleted
100644 → 0
View file @
17806c08
File deleted
exercisemodel/
particletrack
.py
→
exercisemodel/
output
.py
View file @
e6ba8756
...
...
@@ -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
write
feature
(
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
exercisemodel/particletrack.pyc
deleted
100644 → 0
View file @
17806c08
File deleted
output.json
View file @
e6ba8756
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