Skip to content

environment_mesh

EnvironmentMesh(bounds, agg_cellboxes, neighbour_graph, config)

a class that defines the environmental mesh structure and contains each cellbox aggregate information

Attributes:

Name Type Description
bounds Boundary

the boundaries of this mesh

agg_cellboxes AggregatedCellBox[]

a list of aggregated cellboxes

neighbour_graph(NeighbourGraph) AggregatedCellBox[]

an object contains each cellbox neighbours information

config dict

conatins the initial config used to build this mesh

Parameters:

Name Type Description Default
bounds Boundary

the boundaries of this mesh

required
agg_cellboxes AggregatedCellBox[]

a list of aggregated cellboxes

required
neighbour_graph NeighbourGraph

an object contains each cellbox neighbours information

required
config dict

conatins the initial config used to build this mesh.

required

add_cellbox(cellbox)

adds the given cellbox to the mesh

cellboxes_to_json()

returns a list of dictionaries containing information about each cellbox in this Mesh. all cellboxes will include id, geometry, cx, cy, dcx, dcy

Returns:

Name Type Description
cellboxes list<dict>

a list of CellBoxes which form the Mesh. CellBoxes are of the form -

{ "id": (string) ...

"geometry": (string) POLYGON(...),

"cx": (float) ...,

"cy": (float) ...,

"dcx": (float) ...,

"dcy": (float) ...,



"value_1": (float) ...,

...,

"value_n": (float) ...

}

fill_ne_neighbour_map(ne_neighbour_map, ne_neighbour_id, north_neighbour_indx, east_neighbour_indx)

fills the north east neighbour map with the given values Args: ne_neighbour_map (dict): the map to be filled ne_neighbour_ID (string): the index of the north east cellbox north_neighbour_index (List): the index of the north neighbours of the parent cellbox east_neighbour_indx (List): the index of the east neighbour of the parent cellbox Returns: ne_neighbour_map (dict): the filled map

fill_nw_neighbour_map(nw_neighbour_map, nw_neighbour_id, north_neighbour_indx, west_neighbour_indx)

fills the north west neighbour map with the given values Args: nw_neighbour_map (dict): the map to be filled nw_neighbour_ID (string): the index of the north west cellbox north_neighbour_index (List): the index of the north neighbours of the parent cellbox west_neighbour_indx (List): the index of the west neighbour of the parent cellbox Returns: nw_neighbour_map (dict): the filled map

fill_se_neighbour_map(se_neighbour_map, se_neighbour_id, south_neighbour_index, east_neighbour_indx)

fills the south east neighbour map with the given values Args: se_neighbour_map (dict): the map to be filled se_neighbour_ID (string): the index of the south east cellbox south_neighbour_index (List): the index of the south neighbours of the parent cellbox east_neighbour_indx (List): the index of the east neighbour of the parent cellbox Returns: se_neighbour_map (dict): the filled map

fill_sw_neighbour_map(sw_neighbour_map, sw_neighbour_id, south_neighbour_index, west_neighbour_indx)

fills the south west neighbour map with the given values Args: sw_neighbour_map (dict): the map to be filled sw_neighbour_ID (string): the index of the south west cellbox south_neighbour_index (List): the index of the south neighbours of the parent cellbox west_neighbour_indx (List): the index of the west neighbour of the parent cellbox Returns: sw_neighbour_map (dict): the filled map

get_cellbox(cellbox_id)

returns the cellbox with the given id

Parameters:

Name Type Description Default
cellbox_id string

the id of the cellbox to be returned

required

Returns: AggregatedCellBox: the cellbox with the given id

get_cellboxes_north_of_bounds(bounds)

returns all cellboxes that are directly north of the given bounds. Only cellboxes which are touching the north edge of the boundary, yet lie entirely outside of the boundary will be returned

Parameters:

Name Type Description Default
bounds Boundary

the bounds encapsulating the cellboxes to be returned

required

Returns: north_cellboxes (AggregatedCellBox[]): a list of cellboxes that are directly north of the given bounds

get_cellboxes_within_bounds(bounds)

returns the cellboxes within the given bounds. Only cellboxes that are completely within the given bounds are returned.

Parameters:

Name Type Description Default
bounds Boundary

the bounds encapsulating the cellboxes to be returned

required

Returns: AggregatedCellBox[]: the cellboxes within the given bounds

get_max_cellbox_id()

returns the maximum cellbox id in the mesh

Returns:

Name Type Description
int

the maximum cellbox id

load_from_json(mesh_json) classmethod

Constructs an Env.Mesh from a given env-mesh json file to be used by other modules (ex.Vessel Performance Modeller).

Parameters:

Name Type Description Default
mesh_json dict

a dictionary loaded from an Env-mesh json file of the following format -

{

"mesh_info": {

    "region": {

        "lat_min": (real),

        "lat_max": (real),

        "long_min": (real),

        "long_max": (real),

        "start_time": (string) 'YYYY-MM-DD',

        "end_time": (string) 'YYYY-MM-DD',

        "cell_width": (real),

        "cell_height" (real),

        "split_depth" (int)

    },

    "data_sources": [

        {

            "loader": (string)

            "params" (dict)

        },

        ...,

        {...}
        ],

    "splitting": {

            "split_depth": (int),

            "minimum_datapoints": (int)

    }

},

"cellboxes": [

    {


    },

    ...,

    {...}


],

"neighbour_graph": [

    {


    },

    ...,

    {...}

]

}

required

Returns:

Name Type Description
EnvironmentMesh

object that contains all the json file mesh information.

merge_mesh(mesh2)

merges the given mesh with this mesh. The given mesh is not modified.

Parameters:

Name Type Description Default
mesh2 EnvironmentMesh

the mesh to be merged with this mesh

required

query_index(point)

Returns a index of the aggregate cellbox that contains the point

Returns: cellbox_index (str) - Cellbox index containing the point

query_inside_mesh(point)

Returns a bool whether the given point is within the cell

Returns: inside_mesh (bool) - Boolean stating if point inside mesh

remove_cellbox(cellbox)

removes the given cellbox from the mesh

Parameters:

Name Type Description Default
cellbox AggregatedCellBox

the cellbox to be removed

required

remove_cellboxes_within_bounds(bounds)

removes the cellboxes within the given bounds. Only cellboxes that are completely within the given bounds are removed.

Parameters:

Name Type Description Default
bounds Boundary

the bounds encapsulating the cellboxes to be removed

required

save(path, format='JSON', format_params=None)

Saves this object to a location in local storage in a specific format.

Parameters:

Name Type Description Default
path String

The file location the mesh will be saved to.

required
format String) (optional

The format the mesh will be saved in. If not format is given, default is JSON. Supported formats are

- JSON

- GEOJSON
'JSON'

sim_split_cellbox(cellbox_id)

splits the cellbox with the given id

Parameters:

Name Type Description Default
cellbox_id string

the id of the cellbox to be split

required

Returns: split_cells (list): a list of the new cellboxes created by the split

split_and_replace(cellbox_id)

splits the cellbox with the given id and replaces it with the new cellboxes

Parameters:

Name Type Description Default
cellbox_id string

the id of the cellbox to be split

required

split_points(points)

Splitting the mesh to maximum split depth around a series of point locations

tie_eastern_cellbox_ng(east_ext_cellboxes, east_int_cellboxes)

Joins the neighbour graphs of sets of cellboxes on the eastern edge of a boundary between two meshes.

Parameters:

Name Type Description Default
east_ext_cellboxes AggregatedCellBox[]

a list of cellboxes that are directly east of the eastern edge of the boundary

required
east_int_cellboxes AggregatedCellBox[]

a list of cellboxes that are directly west of the eastern edge of the boundary

required

tie_northern_cellbox_ng(north_ext_cellboxes, north_int_cellboxes)

Joins the neighbour graphs of sets of cellboxes on the northen edge of a boundary between two meshes.

Parameters:

Name Type Description Default
north_ext_cellboxes AggregatedCellBox[]

a list of cellboxes that are directly north of the northen edge of the boundary

required
north_int_cellboxes AggregatedCellBox[]

a list of cellboxes that are directly south of the northen edge of the boundary

required

tie_southern_cellbox_ng(south_ext_cellboxes, south_int_cellboxes)

Joins the neighbour graphs of sets of cellboxes on the southern edge of a boundary between two meshes.

Parameters:

Name Type Description Default
south_ext_cellboxes AggregatedCellBox[]

a list of cellboxes that are directly south of the southern edge of the boundary

required
south_int_cellboxes AggregatedCellBox[]

a list of cellboxes that are directly north of the southern edge of the boundary

required

tie_western_cellbox_ng(west_ext_cellboxes, west_int_cellboxes)

Joins the neighbour graphs of sets of cellboxes on the western edge of a boundary between two meshes.

Parameters:

Name Type Description Default
west_ext_cellboxes AggregatedCellBox[]

a list of cellboxes that are directly west of the western edge of the boundary

required
west_int_cellboxes AggregatedCellBox[]

a list of cellboxes that are directly east of the western edge of the boundary

required

to_geojson(params_file=None)

Returns the cellboxes of this mesh converted to a geoJSON format.

Returns:

Name Type Description
geojson

The cellboxes of this mesh in a geoJSON format

NOTE

geoJSON format does not contain all the data included in the standard .to_json() format. geoJSON meshes do not contain the configs used to build them, or the neighbour-graph which details how each of the cellboxes are connected together.

to_json()

Returns this Mesh converted to a JSON object.

Returns:

Name Type Description
json

a string representation of the CellGird parseable as a JSON object. The JSON object is of the form -

{

"config": the config used to initialize the Mesh,

"cellboxes": a list of CellBoxes contained within the Mesh,

"neighbour_graph": a graph representing the adjacency of CellBoxes within the Mesh,

"meshiphi_version": the version of MeshiPhi.

}

to_png(params_file, path)

exports a mesh and saves to a png file Args: params_file: A format configuration files as a json object path: The path to save the png file

to_tif(params_file, path)

generates a representation of the mesh in geotif image format.

Parameters:

Name Type Description Default
params_file string) (optional

a path to a file that contains a dict of the folowing export parameters (If not given, default values are used for image export). The file should be of the following format -

{

    "data_name": "elevation",

    "sampling_resolution": [

        150,

        150

     ],

    "projection": "3031",

}

Where data_name (string) is the name of the mesh data that will be included in the tif image (ex. SIC, elevation), if it is a vector data (e.g. fuel) then the vector mean is calculated for each pixel,
sampling_resolution ([int]) is a 2d array that represents the sampling resolution the geotiff will be generated at (how many pixels in the final image),
projection (int) is an int representing the ESPG sampling projection used to create the geotiff image  (default is 4326),
and colour_conf (string) contains the path to color config file, which is a text-based file containing the association between data_name values and colors. It contains 4 columns per line: the data_name value and the corresponding red, green, blue value between 0 and 255, an example format where values range from 0 to 100 is -



        0 240 250 160

        30 230 220 170

        60 220 220 220

        100 250 250 250
required
path string

the path to save the generated tif image.

required

update_cellbox(index, values)

method that adds values to the dict of a cellbox at certain index (to be used by the vessel perf. module to add the perf. metrics to the cellbox)

Parameters:

Name Type Description Default
index int

the index of the cellbox to be updated

required
values dict

a dict contains perf. metrics names and values

required

validate_merge_compatibility(mesh2)

checks if the given mesh is compatible with merging with this mesh

Parameters:

Name Type Description Default
mesh2 EnvironmentMesh

the mesh to be checked for compatibility

required

Returns: bool: True if the given mesh is compatible with merging with this mesh, False otherwise