antarctica / PolarRoute

Long-distance maritime polar route planning, taking into account complex changing environmental conditions.
MIT License
15 stars 3 forks source link

Can't initialise RoutePlanner with a global mesh #281

Open hjabbot opened 1 month ago

hjabbot commented 1 month ago

When starting with a global mesh, create_mesh and add_vehicle work fine, however optimise_routes crashes due to the longitude range not being valid. This is caused by the tiny_value added in the following method:

def _mesh_boundary_polygon(mesh):
    '''
    Creates a polygon from the mesh boundary
    '''

    # Defining a tiny value
    tiny_value = 1e-10

    lat_min = mesh['config']['mesh_info']['region']['lat_min']-tiny_value
    lat_max = mesh['config']['mesh_info']['region']['lat_max']+tiny_value
    long_min = mesh['config']['mesh_info']['region']['long_min']-tiny_value
    long_max = mesh['config']['mesh_info']['region']['long_max']+tiny_value

    bounds = Boundary([lat_min, lat_max], [long_min, long_max])

    return bounds.to_polygon()

which sets the longitude range to [-180.0000000001, 180.0000000001]. The bounds=Boundary(...) line crashes as it tries to validate the coordinates given before returning the boundary object, but the long values are invalid. I can't simply wrap the values in the longitude_domain() method in MeshiPhi's utils, as this would stop the mesh from being a global mesh, and also limit the range to (179.9999999999,-179.9999999999), resulting in a polygon that is 0.0000000002 degrees wide.

Furthermore the docstrings don't explain at all why the tiny_value is there. Git history has the commit message as 'Updating so if the waypoint is on the edge of the mesh boundary then the point is still included.'

I would include the mesh as an example but it's quite large and this should be repeatable by just creating a mesh with long_min=-180, long_max=180