Skip to content

mesh_builder

In this section we will discuss the usage of the MeshBuilder functionality of meshiphi.

Example

An example of how to run this code can be executed by running the following in an ipython/Jupyter Notebook::

from meshiphi.mesh_generation.mesh_builder import MeshBuilder

import json
with open('./config.json', 'r') as f:
    config = json.load(f)['config']

mesh_builder = MeshBuilder(config)
mesh_builder.build_environmental_mesh()

MeshBuilder(config)

A class resposible for building an environment mesh based on a provided config file.

Constructs a Mesh from a given config file.

Parameters:

Name Type Description Default
config dict

config file which defines the attributes of the Mesh to be constructed. config is of the form:

{

"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)

    }

}

NOTE: In the case of constructing a global mesh, the longtitude range should be -180:180.

"j_grid" (bool): True if the Mesh to be constructed should be of the same format as the original Java CellGrid, to be used for regression testing.

required

add_dataloader(Dataloader, params, bounds=None, name='myDataLoader', min_dp=5)

Adds a dataloader to a pre-existing mesh by adding to the metadata

Parameters:

Name Type Description Default
Dataloader ScalarDataLoader or VectorDataLoader

Dataloader object to add to metadata

required
params dict

Parameters to initialise dataloader with

required
bounds Boundary
None
name str

Name of the dataloader used in config

'myDataLoader'

Returns:

Name Type Description
MeshBuilder

Original MeshBuilder object (self) with added metadata for new dataloader

build_environmental_mesh()

splits the mesh then goes through the mesh cellboxes and builds an evironmental mesh that contains the cellboxes aggregated data

Returns:

Name Type Description
EnvironmentMesh

an object that represents the constructed nonunifrom mesh and contains the aggregated cellboxs and neighbour graph

check_global_mesh(bounds, cellboxes, grid_width)

Checks if the mesh is a global one and connects the cellboxes at the minimum longtitude and max longtitude accordingly

Parameters:

Name Type Description Default
bounds Boundary

an object represents the bounds of the mesh

required
cellboxes list<Cellbox>

a list that contains the mesh initial cellboxes (before any splitting)

required
grid_width int

an int represents the width of the mesh ( the number of cellboxes it contains horizontally)

required

Returns: is_global_mesh (bool): a boolean indicates if the mesh is a global one

fill_ne_map(north_east_indx, north_neighbour_indx, east_neighbour_indx, ne_neighbour_map)

method that fills the North east neighbours

fill_nw_map(north_west_indx, north_neighbour_indx, west_neighbour_indx, nw_neighbour_map)

method that fills the North west neighbours

fill_se_map(south_east_indx, south_neighbour_indx, east_neighbour_indx, se_neighbour_map)

method that fills the South east neighbours

fill_sw_neighbour_map(south_west_indx, south_neighbour_indx, west_neighbour_indx, sw_neighbour_map)

method that fills the South west neighbours

get_config()

returns the config

initialize_meta_data(bounds, min_datapoints)

Creates a metadata object which holds information about the data sources within a cellbox.

Parameters:

Name Type Description Default
bounds Boundary

Outer boundary of the mesh being created

required
min_datapoints int

Minimum number of datapoints each dataloader is allowed to aggregate

required

Returns: list(Metadata): Array of metadata objects; one for each data source

initialize_meta_data_subsets(bounds, meta_data_list)

Updates cellbox metadata objects to include data subsets which contain datapoints from only within the cellbox boundaries (as opposed to the entire mesh's boundary)

Parameters:

Name Type Description Default
bounds Boundary

Outer boundary of the cellbox

required
meta_data_list list(Metadata)

Cellbox's metadata that needs to be updated with data subsets

required

Returns:

Name Type Description
list Metadata

Array of metadata objects; one for each data source. Includes data_subsets

split_and_replace(cellbox)

Replaces a cellbox given by parameter 'cellbox' in this grid with 4 smaller cellboxes representing the four corners of the given cellbox. A neighbours map is then created for each of the 4 new cellboxes and the neighbours map for all surrounding cell boxes is updated.

Parameters:

Name Type Description Default
cellbox CellBox

the CellBox within this Mesh to be split into 4 smaller CellBox objects.

required

split_to_depth(split_depth)

splits all cellboxes in this grid until a maximum split depth is reached, or all cellboxes are homogeneous.

Parameters:

Name Type Description Default
split_depth int

The maximum split depth reached by any CellBox within this Mesh after splitting.

required

to_json()

Returns this Mesh converted to a JSON object.

Returns:

Name Type Description
json 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 }