Grids Classes

class starlord.GridGenerator

Manages grids and generates grid interpolators.

You can use create_grid() to make a new grid. Starlord uses the class methods reload_grids() register_grid(), grids(), and get_grid() to manage the grids available to it. These are all optional for the user – you can initialize a GridGenerator directly on a file path. Once you have a GridGenerator ready, you can use build_grid() to make an interpolator in the desired output.

__init__(filename)
Parameters:

filename (str | Path)

build_grid(column, axis_tf={}, value_tf=<function GridGenerator.<lambda>>)

Build the grid into an interpolator of the requested column.

Parameters:
  • column (str) – The output column to interpolate.

  • axis_tf (dict[str, Callable]) – A dictionary mapping input column names to functions to be applied to them before the interpolator is constructed. Note that the transformed axis must still be in strictly-increasing order.

  • value_tf (Callable) – A function that will be applied to the output column.

Returns:

A GridInterpolator of the requested grid and output.

Raises:

AssertionError – if the column is not a grid output, the grid itself is malformed, or if an axis transform un-sorted the axis.

Return type:

GridInterpolator

classmethod create_grid(grid_name, inputs, outputs, derived={}, input_mappings={})

Create a new grid and write it to the Starlord grid directory.

The input, output, and derived names must be unique, valid as Python variable names, and not start with “_”. A fair few validity checks are made to ensure that the grid is valid before the grid is written. Once you make a grid with this function, you can use it in your Starlord models or build interpolators using get_grid() and build_grid().

Parameters:
  • grid_name (str) – A name for your grid, overwrites any existing grid of the same name. If the name does not include a directory, the file will be saved in the Starlord grid storage.

  • inputs (OrderedDict[str, ndarray]) – The grid inputs as an OrderedDict of 1-d, strictly-increasing arrays of floats in the same order as the output axes.

  • outputs (dict[str, ndarray]) – The output variables for the grid, a dict of float arrays with a shape corresponding to the inputs provided.

  • derived (dict[str, str]) – Values that may be computed from the grid (the dict keys) and the code required to compute them (the values). Variables used must be inputs, outputs, or derived keys and enclosed by curly braces.

  • input_mappings (dict[str, str]) – The code to be used for the inputs, by axis (keys must match input keys) if not overridden by the model. If not specified, this defaults to being a model parameter “p.[input_name]”.

Raises:

AssertionError – If any of the validity checks fail – see the error message for further explanation.

Return type:

None

classmethod get_grid(grid_name)

Gets a specific grid from the dict of known grids.

Raises:

KeyError – if grid_name is not registered with Starlord.

Parameters:

grid_name (str)

Return type:

GridGenerator

classmethod grids()

Gets a dict of the grids known to Starlord.

Return type:

dict[str, GridGenerator]

classmethod register_grid(filename)

Add a grid by filename to the GridGenerator tracked list for e.g. get_grid().

The file does not need to be in the Starlord grid directory.

Parameters:

filename (str) – The npz file to load the grid from

Raises:

AssertionError – if the grid is not a proper StarlordGrid from create_grid()

Return type:

None

classmethod reload_grids()

Clear the grids and load them again from the grid directory.

Note that this removes any grids added with register_grid() which are not in that directory.

Return type:

None

static restructure_grid(arr, inputDims, outputDims)

Transforms an array from a list of points to input and output arrays.

Parameters:
  • arr – The array containing the input and output data as specific columns and individual grid points as rows.

  • inputDims – a tuple of the independant variables’ column indicies.

  • outputDims – a tuple of the dependant variables’ column indices.

Returns:

The input axes as a list of 1-d arrays and the output variables as a list of n-d arrays where n is the number of inputs.

summary(full=False, fancy_text=True)

Prints basic information about the grid.

Parameters:
  • full (bool) – if False, only print the first few outputs and derived outputs, otherwise print them all.

  • fancy_text (bool) – whether to style the output with colors and bolding.

Return type:

None

class starlord.GridInterpolator

GridInterpolator(axes, values, tol=1e-6)

An interpolator for gridded data, optimized for use in Cython.

__init__(*args, **kwargs)
__new__(**kwargs)
interp(self, double[:] x) double
bounds
ndim
shape