Skip to content

Commit

Permalink
Merge branch 'main' of github.com:52North/WeatherRoutingTool
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinPontius committed Jun 11, 2024
2 parents a7580f3 + c538e2e commit 08ae033
Show file tree
Hide file tree
Showing 4 changed files with 188 additions and 52 deletions.
2 changes: 1 addition & 1 deletion WeatherRoutingTool/ship/shipparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ def get_element(self, idx):
raise ValueError(
'Index ' + str(idx) + ' is not available for array with length ' + str(self.speed.shape[0]))
return (fuel_rate, power, rpm, speed, r_wind, r_calm, r_waves, r_shallow, r_roughness, wave_height,
wave_direction, wave_period, u_currents, v_currents, u_wind_speed, v_wind_speed, v_wind_speed, pressure,
wave_direction, wave_period, u_currents, v_currents, u_wind_speed, v_wind_speed, pressure,
air_temperature, salinity, water_temperature, status, message)

def get_single_object(self, idx):
Expand Down
69 changes: 38 additions & 31 deletions tests/test_continuous_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,15 +163,18 @@ def test_set_map_bbox(self):
test_bbox = box(2, 1, 7, 5)

map_bbx = Map(lat1, lon1, lat2, lon2)
continuouscheck_obj = ContinuousCheck(db_engine=engine)
with engine.connect() as conn:
continuouscheck_obj = ContinuousCheck(db_engine=conn.connection)
continuous_bbox_wkt = continuouscheck_obj.set_map_bbox(map_bbx)

assert continuous_bbox_wkt == test_bbox.wkt

def test_query_nodes(self):
seamark_obj = basic_test_func.create_dummy_SeamarkCrossing_object(db_engine=engine)
gdf = seamark_obj.query_nodes(engine,
"SELECT *,geometry as geom FROM nodes")
with engine.connect() as conn:
seamark_obj = basic_test_func.create_dummy_SeamarkCrossing_object(
db_engine=conn.connection)
gdf = seamark_obj.query_nodes(conn.connection,
"SELECT *,geometry as geom FROM nodes")

point = {"col1": ["name1", "name2"],
"geometry": [Point(1, 2), Point(2, 1)]}
Expand All @@ -186,9 +189,11 @@ def test_query_nodes(self):
print("point type checked")

def test_query_ways(self):
seamark_obj = basic_test_func.create_dummy_SeamarkCrossing_object(db_engine=engine)
gdf = seamark_obj.query_ways(engine,
"SELECT *, geometry AS geom FROM ways")
with engine.connect() as conn:
seamark_obj = basic_test_func.create_dummy_SeamarkCrossing_object(
db_engine=conn.connection)
gdf = seamark_obj.query_ways(conn.connection,
"SELECT *, geometry AS geom FROM ways")

line = {"col1": ["name1", "name2"],
"geometry": [LineString([(1, 2), (3, 4)]), LineString([(2, 1), (5, 6)])]}
Expand All @@ -206,15 +211,12 @@ def test_concat_nodes_ways(self):
"""
Test for checking if table with ways and nodes includes geometries (Point, LineString)
"""
seamark_obj = basic_test_func.create_dummy_SeamarkCrossing_object(
db_engine=engine)
concat_all = seamark_obj.concat_nodes_ways(
db_engine=engine,
query=[
"SELECT *, geometry as geom FROM nodes",
"SELECT *, geometry AS geom FROM ways"
]
)
with engine.connect() as conn:
seamark_obj = basic_test_func.create_dummy_SeamarkCrossing_object(
db_engine=conn.connection)
concat_all = seamark_obj.concat_nodes_ways(db_engine=conn.connection,
query=["SELECT *, geometry as geom FROM nodes",
"SELECT *, geometry AS geom FROM ways"])

# Create points and linestrings dummy data

Expand All @@ -238,11 +240,12 @@ def test_concat_nodes_ways(self):
assert set(type_list).intersection([Point, LineString]), "Geometry type error"

def test_set_STRETree(self):
seamark_obj = basic_test_func.create_dummy_SeamarkCrossing_object(
db_engine=engine)
test_query = ["SELECT *, geometry as geom FROM nodes",
"SELECT *, geometry AS geom FROM ways"]
concat_tree = seamark_obj.set_STRTree(db_engine=engine, query=test_query)
with engine.connect() as conn:
seamark_obj = basic_test_func.create_dummy_SeamarkCrossing_object(
db_engine=conn.connection)
test_query = ["SELECT *, geometry as geom FROM nodes",
"SELECT *, geometry AS geom FROM ways"]
concat_tree = seamark_obj.set_STRTree(db_engine=conn.connection, query=test_query)

# Create points and linestrings dummy data
point1 = {
Expand Down Expand Up @@ -274,11 +277,12 @@ def test_check_crossing(self):

test_crossing_list = [True, True, True, True, False]

seamark_obj = basic_test_func.create_dummy_SeamarkCrossing_object(db_engine=engine)
test_query = ["SELECT *, geometry as geom FROM nodes",
"SELECT *, geometry AS geom FROM ways"
]
concat_tree = seamark_obj.set_STRTree(db_engine=engine, query=test_query)
with engine.connect() as conn:
seamark_obj = basic_test_func.create_dummy_SeamarkCrossing_object(db_engine=conn.connection)
test_query = ["SELECT *, geometry as geom FROM nodes",
"SELECT *, geometry AS geom FROM ways"]

concat_tree = seamark_obj.set_STRTree(db_engine=conn.connection, query=test_query)
seamark_obj.concat_tree = concat_tree

# returns a list of tuples(shapelySTRTree, predicate, result_array, bool type)
Expand All @@ -291,9 +295,11 @@ def test_check_crossing(self):
assert test_crossing_list == check_list

def test_set_landpolygon_STRTree(self):
landpolygoncrossing_obj = basic_test_func.create_dummy_landpolygonsCrossing_object(engine)
test_query = "SELECT *,geometry as geom from land_polygons"
landpolygon_tree = landpolygoncrossing_obj.set_landpolygon_STRTree(db_engine=engine, query=test_query)
with engine.connect() as conn:
landpolygoncrossing_obj = basic_test_func.create_dummy_landpolygonsCrossing_object(conn.connection)
test_query = "SELECT *,geometry as geom from land_polygons"
landpolygon_tree = landpolygoncrossing_obj.set_landpolygon_STRTree(
db_engine=conn.connection, query=test_query)

test_land_polygons_gdf = gpd.GeoDataFrame(
geometry=[box(0, 1, 3, 5)])
Expand All @@ -310,8 +316,9 @@ def test_check_land_crossing(self):
lon_end = np.array((4.5, 7.5, 10, 10, 5))
test_list = [True, True, True, False, True]

landpolygoncrossing_obj = basic_test_func.create_dummy_landpolygonsCrossing_object(
engine)
with engine.connect() as conn:
landpolygoncrossing_obj = basic_test_func.create_dummy_landpolygonsCrossing_object(
conn.connection)
landpolygoncrossing_obj.land_polygon_STRTree = STRtree(test_land_polygons_gdf["geometry"])
check_list = landpolygoncrossing_obj.check_crossing(
lat_start=lat_start, lon_start=lon_start, lat_end=lat_end, lon_end=lon_end
Expand Down
6 changes: 4 additions & 2 deletions tests/test_route_postprocessing.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,8 @@ def generate_test_route_postprocessing_obj(self):
)
boat = basic_test_func.create_dummy_Tanker_object()
boat.set_boat_speed(6)
postprocessed_route = RoutePostprocessing(rp, boat, db_engine=engine)
with engine.connect() as conn:
postprocessed_route = RoutePostprocessing(rp, boat, db_engine=conn.connection)
return postprocessed_route

def test_create_route_segments(self):
Expand Down Expand Up @@ -158,7 +159,8 @@ def test_get_route_box(self):
def test_query_data(self):
test_query = "SELECT *, geometry as geom From seamark"
rpp = self.generate_test_route_postprocessing_obj()
gdf_seamark = rpp.query_data(test_query, engine=engine)
with engine.connect() as conn:
gdf_seamark = rpp.query_data(test_query, engine=conn.connection)
assert isinstance(gdf_seamark, type(test_seamark_gdf))
type_list = [type(geometry) for geometry in gdf_seamark["geom"]]
assert set(type_list).intersection([LineString]), "Geometry type error"
Expand Down
Loading

0 comments on commit 08ae033

Please sign in to comment.