Skip to content

Commit 33e2276

Browse files
authored
Merge branch 'main' into feature/app-setting-secret
2 parents db3e8aa + 264d9fb commit 33e2276

24 files changed

Lines changed: 193 additions & 25 deletions

.env

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
SOURCE_FILE=./resources/samples/input1_LatLon.pickle
1+
SOURCE_FILE=./resources/samples/input4_LatLon.pickle
22
# development settings
33
CONFIGURATION_FILE=./app-configuration.json
44
PRINT_CONFIGURATION=yes

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@
77

88
# User-specific stuff
99
.idea/**/workspace.xml
10+
.idea/**/misc.xml
11+
.idea/**/*.iml
1012
.idea/**/tasks.xml
1113
.idea/**/usage.statistics.xml
12-
.idea/**/misc.xml
1314
.idea/**/dictionaries
1415
.idea/**/shelf
1516

.idea/python-sdk.iml

Lines changed: 0 additions & 8 deletions
This file was deleted.

CHANGELOG_SDK.md

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,17 @@
44

55
- introduce app-setting-type `SECRET`
66

7+
## 2024-xx
8+
9+
- addition of examples in app.py of importing functions from other .py files, creating artifacts, translating result back to a TrajectoryCollection
10+
11+
## 2024-09 `v2.2.1`
12+
13+
- exchange samples: generated by next MoveApps move2 to movingpandas translator app
14+
715
## 2024-09 `v2.2.1`
816

9-
- switch to [miniforge](https://github.com/conda-forge/miniforge)
17+
- switch build from `micromamba` to [miniforge](https://github.com/conda-forge/miniforge)
1018

1119
## 2024-03 `v2.1.0`
1220

Dockerfile_smoketest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,4 @@ COPY --chown=$UID:$GID . $PROJECT_DIR
3131
RUN conda env create --prefix $ENV_PREFIX --file $PROJECT_DIR/environment.yml && \
3232
conda clean --all --yes
3333

34-
ENTRYPOINT [ "conda", "run", "--prefix", "${ENV_PREFIX}", "python3", "sdk.py" ]
34+
ENTRYPOINT [ "conda", "run", "--no-capture-output", "--prefix", "${ENV_PREFIX}", "python3", "sdk.py" ]

Dockerfile_unittest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,4 @@ COPY app/ ./app/
1515
RUN conda env create --prefix ${ENV_PREFIX} --file environment.yml && \
1616
conda clean --all --yes
1717

18-
RUN conda run --prefix ${ENV_PREFIX} python3 -m unittest
18+
RUN conda run --no-capture-output --prefix ${ENV_PREFIX} python3 -m unittest

app-configuration.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"app-name": "MoveApps Python SDK"
2+
"app-name": "MoveApps Python SDK",
3+
"year": 2014
34
}

app/app.py

Lines changed: 37 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22
from sdk.moveapps_io import MoveAppsIo
33
from movingpandas import TrajectoryCollection
44
import logging
5+
import matplotlib.pyplot as plt
6+
7+
# showcase for importing functions from another .py file (in this case from "./app/getGeoDataFrame.py")
8+
from app.getGeoDataFrame import get_GDF
59

610

711
class App(object):
@@ -11,12 +15,42 @@ def __init__(self, moveapps_io):
1115

1216
@hook_impl
1317
def execute(self, data: TrajectoryCollection, config: dict) -> TrajectoryCollection:
14-
"""Your app code goes here"""
18+
1519
logging.info(f'Welcome to the {config}')
1620

21+
"""Your app code goes here"""
22+
23+
# showcase injecting App settings (parameter `year`)
24+
data_gdf = get_GDF(data) # translate the TrajectoryCollection to a GeoDataFrame
25+
logging.info(f'Subsetting data for {config["year"]}')
26+
# subset the data to only contain the specified year
27+
if config["year"] in data_gdf.index.year:
28+
result = data_gdf[data_gdf.index.year == config["year"]]
29+
else:
30+
result = None
31+
32+
# showcase creating an artifact
33+
if result is not None:
34+
result.plot(column=data.get_traj_id_col(), alpha=0.5)
35+
plot_file = self.moveapps_io.create_artifacts_file("plot.png")
36+
plt.savefig(plot_file)
37+
logging.info(f'saved plot to {plot_file}')
38+
else:
39+
logging.warning("Nothing to plot")
40+
41+
# showcase accessing auxiliary files
1742
auxiliary_file_a = MoveAppsIo.get_auxiliary_file_path("auxiliary-file-a")
1843
with open(auxiliary_file_a, 'r') as f:
1944
logging.info(f.read())
2045

21-
# return some useful data for next apps in the workflow
22-
return data
46+
# Translate the result back to a TrajectoryCollection
47+
if result is not None:
48+
result = TrajectoryCollection(
49+
result,
50+
traj_id_col=data.get_traj_id_col(),
51+
t=data.to_point_gdf().index.name,
52+
crs=data.get_crs()
53+
)
54+
55+
# return the resulting data for next Apps in the Workflow
56+
return result

app/getGeoDataFrame.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# showcase for defining functions in a file other than ./app/app.py
2+
3+
import logging
4+
from movingpandas import TrajectoryCollection
5+
from geopandas.geodataframe import GeoDataFrame
6+
7+
def get_GDF(data: TrajectoryCollection) -> GeoDataFrame:
8+
9+
logging.info("Translating to GeoDataFrame")
10+
11+
# Transfer the data to a GeoDataFrame
12+
data_gdf = data.to_point_gdf()
13+
14+
# Return the data
15+
return data_gdf

appspec.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@
88
"default": "Python SDK",
99
"type": "STRING"
1010
},
11+
{
12+
"id": "year",
13+
"name": "The year",
14+
"description": "Enter the year for which you want to keep the data",
15+
"defaultValue": 1960,
16+
"type": "INTEGER"
17+
},
1118
{
1219
"id": "auxiliary-file-a",
1320
"name": "Your message",

0 commit comments

Comments
 (0)