opendrift.models.openoil.adios.models.common.utilities

Tools for helping make our data models.

So far: making dataclasses read/writable as JSON

Module Contents

Classes

JSON_List

just like a list, but with the ability to turn it into JSON

Functions

something(val)

much like python's "Truthy" and Falsey", but we want some values

dataclass_to_json(cls)

class decorator that adds the ability to save a dataclass as JSON

opendrift.models.openoil.adios.models.common.utilities.something(val)[source]

much like python’s “Truthy” and Falsey”, but we want some values to not be false like zero, for instance

opendrift.models.openoil.adios.models.common.utilities.dataclass_to_json(cls)[source]

class decorator that adds the ability to save a dataclass as JSON

All fields must be either JSON-able Python types or have be a type with a _to_json method

class opendrift.models.openoil.adios.models.common.utilities.JSON_List[source]

Bases: list

just like a list, but with the ability to turn it into JSON

A regular list can only be converted to JSON if it has JSON-able objects in it.

Note: must be subclassed, and the item_type attribute set

Initialize self. See help(type(self)) for accurate signature.

item_type
py_json(sparse=True)[source]
classmethod from_py_json(py_json, allow_none=False)[source]

create a JSON_List from json array of objects that may be json-able.

__repr__()[source]

Return repr(self).