Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Wit, Allard de
grompy
Commits
d104602d
Commit
d104602d
authored
Apr 11, 2021
by
Wit, Allard de
Browse files
Small changes to grompy commandline tools
parent
2a02e4e9
Changes
3
Hide whitespace changes
Inline
Side-by-side
grompy/__main__.py
View file @
d104602d
...
...
@@ -45,4 +45,4 @@ def main():
if
__name__
==
"__main__"
:
cli
()
\ No newline at end of file
cli
()
grompy/init.py
View file @
d104602d
...
...
@@ -13,6 +13,9 @@ def init(input_path=None):
if
input_path
is
None
:
input_path
=
Path
.
cwd
()
else
:
input_path
=
Path
(
input_path
)
input_path
=
input_path
.
absolute
()
yaml_conf
=
yaml_conf
.
format
(
input_path
=
input_path
)
yaml_output_fname
=
Path
.
cwd
()
/
"grompy.yaml"
...
...
grompy/load_data.py
View file @
d104602d
...
...
@@ -7,7 +7,6 @@ from csv import DictReader
import
time
import
multiprocessing
as
mp
import
traceback
import
math
import
sqlalchemy
as
sa
import
sqlalchemy.exc
...
...
@@ -16,7 +15,7 @@ import geopandas as gpd
import
numpy
as
np
import
yaml
from
.util
import
count_lines
,
prepare_db
,
printProgressBar
from
.util
import
prepare_db
,
printProgressBar
dummy_date
=
"19000101"
...
...
@@ -68,6 +67,7 @@ def load_parcel_info(dsn, counts_file, shape_file, table_name):
engine
=
sa
.
create_engine
(
dsn
)
df_out
.
to_sql
(
table_name
,
engine
,
if_exists
=
"replace"
,
index
=
False
)
df_out
=
df
=
df_counts
=
None
def
process_rows
(
rows
):
...
...
@@ -82,7 +82,8 @@ def process_rows(rows):
fieldIDs
=
[]
for
column_name
,
row
in
rows
.
items
():
fieldIDs
.
append
(
int
(
row
.
pop
(
"field_ID"
)))
count
=
row
.
pop
(
"count"
)
if
"count"
in
row
:
count
=
row
.
pop
(
"count"
)
recs
=
[]
for
sdate
,
value
in
row
.
items
():
value
=
float
(
value
)
...
...
@@ -93,10 +94,7 @@ def process_rows(rows):
# We add one dummy record to make sure we can create the dataframe properly
recs
.
append
({
"day"
:
dummy_date
,
"value"
:
None
,
"band"
:
column_name
})
df_tmp
=
pd
.
DataFrame
(
recs
)
try
:
df_tmp
[
"day"
]
=
pd
.
to_datetime
(
df_tmp
.
day
).
dt
.
date
except
:
pass
df_tmp
[
"day"
]
=
pd
.
to_datetime
(
df_tmp
.
day
).
dt
.
date
df
=
pd
.
concat
([
df
,
df_tmp
])
df
=
df
.
pivot
(
index
=
"day"
,
columns
=
"band"
,
values
=
"value"
)
df
.
reset_index
(
inplace
=
True
)
...
...
@@ -232,6 +230,7 @@ def load_data(yaml_file):
grompy_conf
=
yaml
.
safe_load
(
open
(
yaml_file
))
# First load parcel info
print
(
"Start loading parcel information. This will take some time..."
)
parcel_info
=
grompy_conf
.
pop
(
"parcel_info"
)
load_parcel_info
(
**
parcel_info
)
...
...
Write
Preview
Markdown
is supported
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