NutMEG package

Subpackages

Submodules

NutMEG.ecosystem module

class NutMEG.ecosystem.ecosystem(r, c, loggerlevel='INFO', dbpath='/Users/pete/github2/NutMEG/NutMEG/util/../../NutMEG_db')

Bases: object

Module to manage a unique ecosystem, containing a culture of organisms and their local environment (reactor)

r

Environment information and calculations

Type

reactor like

c

Organism information and calculations

Type

culture

backup_r

duplicate of the initial r

Type

reactor like

stoppingdict

Dictionary to tell ecosystem when to stop. See setup_stoppingdict for details

Type

dict

SimID

Simluation identifier for use in data stroage

Type

str

dbh

Helper attribute for datbase management.

Type

ecosystem_dbhelper

c = None
check_stopper(stopper_name, orglst)

Check if stoppingdict’s requirements are met and we should stop the simulation. Returns True if we should, False if we shouldn’t.

Parameters
  • stopper_name (str) – Which stoppper to check (which key in stoppingdict)

  • orglst (list) – List of the relevant parameters for each horde/colony in c.

output_step_data(step, dicti)

Print out key results.

Parameters
  • step (int) – Which step of the simulation we are at.

  • dicti (dict) – Dictionary of results to show.

predict_growth(tmax=1e+17, dt=None, factorup=1.01, staticdt=False, quiet=False)

Predict how a single culture will evolve in a single environment.

Simulate the culture growing at a self-determined timestep (unless otherwise specified up until either a limiter of stoppingdict is reached, tmax is exceeded, or all of the organisms become inactive.

Parameters
  • tmax (float, optional) – Maximum time in s to simulate. Default is 1e17 (3 billion years…)

  • dt (float, optional) – If you want to specify the timestep, pass it as dt in s. If dt is not passed, one will be selected automatically

  • factorup (float, optional) – The factor with which you’d like the culture to grow by when automaticall selecting the timestep. Default 1.01

  • staticdt (bool, optional) – Pass as True if you don’t want the timestep to be dynamically updated every 10000 steps (may result in code running very slow for long simulations). Default False.

  • quiet (bool, optional) – By default current parameters are printed out to the terminal every 100 steps. To stop this, pass quiet as True. Default False.

r = None
setup_stoppingdict()

Initialise the default stoppingdict to be used to tell ecosystem when to stop. Each entry has another dict as a value with keys ‘Max’, ‘Min, ‘Consistency’, ‘Count’. ‘Max’ and ‘Min’ are the maximum and minimum values of some parameter, ‘Consistency’ is ho many time steps in a row the ecosystem must be outside this limits to stop, and ‘Counter’ is the a rolling count of that number.

Returns

  • The default stoppingdict. Can be edited by updating

  • ecosystem.stoppingdict

NutMEG.ecosystem_dbhelper module

class NutMEG.ecosystem_dbhelper.db_helper(e, dbpath)

Bases: object

Class for managing the NutMEG database and its contents regarding ecosystem and simulations.

This class remains a mess while I decide whether we’ll need the unique_params again or not. For now that is all commented out.

e

The ecosystem object performing simulations to save.

Type

ecosystem

dbpath

path to the SQL database. If not passed it will be set to the default (NutMEG_db in your working directory). The default can be changed in NutMEG/utils/NuMEGparams.

Type

str

OrgNames

tuple of organism names to determine table names

Type

tuple

OrgIDs

tuple of OrgIDs

Type

tuple

OrgNums

tuple of the populations of each organism type.

Type

tuple

addcolumn(Table, NameType)

Add a column to a table if it doesn’t exist.

buildresultsdict()

Return the basic entries to the results dictionary, it will be updated in the organsim and reactor db helpers.

check_summary(notrace=True)

Check to see if the simulation you have set up has been performed before.

If it has, a False value and the ID of that simulaiton will be returned. If not, a True value and a Tester ID of a new entry in Summary will be returned.

Parameters

notrace (bool, optional) – If True, delete the entry after checking. Default is True

static create_major_tables(replace=False, dbpath='/Users/pete/github2/NutMEG/NutMEG/util/../../NutMEG_db')

Create the major tables in the ecosystem database inside the file passsed. If replace is True, any tables of the same name will be deleted.

createtable()

Create a table for this simulation.

If the culture and reactor combination has already been performed, return False and the SimID of that simulation. If not, add a row to the Summary table for this simulation, and create a FullResults_Sim_ table for the full output.

Please make sure that the OrgIDs and LocIDs are up-to-date before working out the SimID.

dict_to_db(dicti, end=False, finonly=False)

Save all info in dicti to the FullResults table for this simulation, and return the refreshed (emptied) dictionary.

Parameters
  • dicti (dict) – dictionary to update FullResults and/or Summary with.

  • end (bool, optional) – True if this is the final dict to be saved, then Summary is updated too. Default False

  • finonly (bool, optional) – If True, only add in the last entry of dicti. Default False

static extract_param_db_OrgLoc(OrgIDs, LocID, OrgNums, param, dbpath='/Users/pete/github2/NutMEG/NutMEG/util/../../NutMEG_db')

Fetch a specific parameter from a simulation, using the relevant OrgID and LocIDs as passed. If the param is a Summary variable, this returns the final value from that simulation., if its one of the others, this returns the full list of results

TODO: add in support for organism-specific parameters

Parameters
  • OrgIDs (tuple) – OrgIDs included in the simulation, in the correct order

  • LocID (str) – LocID to extract.

  • OrgNums (tuple) – Initial number of organism, in the correct order.

  • param (str) – Parameter name to extract. Should match database column name, equivalent to parameters found in horde_output, culture_output etc.

  • dbpath (str, optional) – path to database. Default is NutMEG_db

static extract_param_db_Sim(SimID, param, OrgID='', dbpath='/Users/pete/github2/NutMEG/NutMEG/util/../../NutMEG_db')

Fetch a specific parameter from a simulation, using its ID as passed. If the param is a Summary variable this returns the final value from that simulation, if its one of the others, return the full list of results.

Parameters
  • SimID (str) – Simulation ID to use as identifier in Summay or FullResults tables.

  • param (str) – Parameter name to extract. Should match database column name, equivalent to parameters found in horde_output, culture_output etc.

  • OrgID (str, optional) – Some parameters are organism specific and so require the OrgID to extract. If this is the case, pass the OrgID. Default ‘’

  • dbpath (str, optional) – path to database. Default is NutMEG_db

static findOrgIDsLocID(SimID, dbpath='/Users/pete/github2/NutMEG/NutMEG/util/../../NutMEG_db')

Return the OrgIDs and LocID from the simualation that had SimID

static findSimID(OrgIDs, LocID, OrgNums, dbpath='/Users/pete/github2/NutMEG/NutMEG/util/../../NutMEG_db')

Look in the Summary table to see if a simulation has been done with these organisms and environments. If it has, return the SimID.

Parameters
  • OrgIDs (tuple) – OrgIDs included in the simulation, in the correct order

  • LocID (str) – LocID to extract.

  • OrgNums (tuple) – Initial number of organism, in the correct order.

  • dbpath (str, optional) – path to database. Default is NutMEG_db

getOrgdetails()

Update initial details of the culture

get_table_as_dataframe(dbpath='/Users/pete/github2/NutMEG/NutMEG/util/../../NutMEG_db')

Get a table in the database as a pandas dataframe

static guess_name_from_ID(ID)

Try to guess an object’s name from its ID

static print_major_tables(dbpath='/Users/pete/github2/NutMEG/NutMEG/util/../../NutMEG_db', FullResults=None)

Print out the major databases (e.g. all without the sims).

If you also want to pring out a FullResults table, pass FullResults as the SimID.

static print_table(tabname, dbpath='/Users/pete/github2/NutMEG/NutMEG/util/../../NutMEG_db')

print out table tabname using pandas

static removesimdata(SimID, dbpath='/Users/pete/github2/NutMEG/NutMEG/util/../../NutMEG_db')

Delete data from a simulation

uniqueOrgs = ['Methanogen']
uniqueReas = ['EnceladusVessel']
update_summary(dicti)

At the end of the simulation, update the Summary table using the final entry in dicti.

Module contents