22from sdk .moveapps_io import MoveAppsIo
33from movingpandas import TrajectoryCollection
44import 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
711class 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
0 commit comments