fourth_day package

Submodules

fourth_day.adamah module

class fourth_day.adamah.Adamah

Bases: object

Constructs the geometry of the system.

Parameters

None

Returns

Return type

None

Raises
  • ValueError – Geometry not recognized

  • ValueError – Dimensions not supported

property exclusion

Returns the exclusion

Parameters

None

Returns

exclusion – The hull of the exclusion zone

Return type

spatial.object

find_intersection(hull: scipy.spatial.qhull.ConvexHull, ray_point: numpy.array) → numpy.array

Finds the closest point on the hull to the ray_point

Parameters
  • hull (spatial.ConvexHull) – Convex hull object defining the volume

  • ray_point (np.array) – The point used to check

Returns

The closest point on the hull

Return type

np.array

property hull

Returns the volume

Parameters

None

Returns

hull – The hull of the world

Return type

spatial.object

point_in_exclusion(point: numpy.ndarray, tolerance=1e-12) → bool

Checks if the point lies inside the exclusion

Parameters

point (np.ndarray:) – Point to check

Returns

Truth or not if inside

Return type

bool

point_in_obs(point: numpy.ndarray, tolerance=1e-12) → bool

Checks if the point lies inside the observed volume

Parameters

point (np.ndarray:) – Point to check

Returns

Truth or not if inside

Return type

bool

point_in_wold(point: numpy.ndarray, tolerance=1e-12) → bool

Checks if the point lies inside the world

Parameters

point (np.ndarray:) – Point to check

Returns

Truth or not if inside

Return type

bool

rectangle(x_length: float, y_length: float, offset=None)

Constructs the rectangle geometry

Parameters
  • x (float) – The x length

  • y (float) – The y length

  • offset (np.array) – The offset of the volume

Returns

Return type

None

property volume

Returns the volume

Parameters

None

Returns

volume – The volume of the world

Return type

float

property x

Returns the max x

Parameters

None

Returns

x – Max x

Return type

float

property y

Returns the max y

Parameters

None

Returns

y – Max y

Return type

float

fourth_day.config module

class fourth_day.config.ConfigClass(*args, **kwargs)

Bases: dict

The configuration class. This is used by the package for all parameter settings. If something goes wrong its usually here.

Parameters

config (dic) – The config dictionary

Returns

Return type

None

from_dict(user_dict: Dict[Any, Any]) → None

Creates a config from dictionary

Parameters

user_dict (dic) – The user dictionary

Returns

Return type

None

from_yaml(yaml_file: str) → None

Update config with yaml file

Parameters

yaml_file (str) – path to yaml file

Returns

Return type

None

fourth_day.current module

Name: state_machine.py Authors: Stephan Meighen-Berger, Golo Wimmer Handles current construction or loading

class fourth_day.current.Current

Bases: object

Constructs and loads the current

Parameters

None

Raises

ValueError – Unsupported water current model

property gradients

Getter function for the current gradients

Parameters
  • x (np.array) – The x coordinates

  • y (np.array) – The y coordinates

Returns

The gradient field

Return type

np.array

property velocities

Getter function for the current velocities

Parameters
  • x (np.array) – The x coordinates

  • y (np.array) – The y coordinates

Returns

The velocity field

Return type

np.array

class fourth_day.current.Current_Loader(savestring: str, num_data_files: int)

Bases: object

Loads the current

Parameters
  • savestring (str) – The location of the data

  • num_data_files (int) – Number of data files

Raises

ValueError – Unsupported water current model

evaluate_data_at_coords(coords: numpy.array, out_nr: int, data_max=1)

Evaluate data at a speficied coordiante array of shape (n, 2), for n coordinates. Optionally also pass a magnitude multiplication factor; defaults to 1. For vector valued data, returns 3 arrays of length n for the velocities (in coordinate directions) and speed at the n coordinates. For scalar valued data, returns one array of the scalar evaluated at the n coordinates.

Parameters
  • coords (np.array) – The coordinates to evaluate at

  • out_nr (int) – The current step

Returns

The velocities or gradients depending on setup

Return type

np.array

class fourth_day.current.Homogeneous_Current(vel_grad_switch: bool)

Bases: object

Homogeneous current

Parameters

vel_grad_switch (bool) – Switches between the two outputs

Raises

ValueError – Unsupported water current model

evaluate_data_at_coords(coords: numpy.array, out_nr: int) → numpy.array

Returns a zero array in the shape of the input

Parameters
  • coords (np.array) – Positional coordinates

  • out_nr (int) – The current step

Returns

Depending on switch the shapes will be different

Return type

np.array

class fourth_day.current.No_Current(vel_grad_switch: bool)

Bases: object

No current

Parameters

vel_grad_switch (bool) – Switches between the two outputs

Raises

ValueError – Unsupported water current model

evaluate_data_at_coords(coords: numpy.array, out_nr: int) → numpy.array

Returns a zero array in the shape of the input

Parameters
  • coords (np.array) – Positional coordinates

  • out_nr (int) – The current step

Returns

Depending on switch the shapes will be different

Return type

np.zeros

class fourth_day.current.Parabolic_Current(vel_grad_switch: bool)

Bases: object

Parabolic current

Parameters

vel_grad_switch (bool) – Switches between the two outputs

Raises

ValueError – Unsupported water current model

evaluate_data_at_coords(coords: numpy.array, out_nr: int) → numpy.array

Returns a zero array in the shape of the input

Parameters
  • coords (np.array) – Positional coordinates

  • out_nr (int) – The current step

Returns

Depending on switch the shapes will be different

Return type

np.array

class fourth_day.current.Potential_Cylinder_Current(vel_grad_switch: bool)

Bases: object

The potential flow arounda cylinder current

Parameters

vel_grad_switch (bool) – Switches between the two outputs

Raises

ValueError – Unsupported exclusion

evaluate_data_at_coords(coords: numpy.array, out_nr: int) → numpy.array

Returns a zero array in the shape of the input

Parameters
  • coords (np.array) – Positional coordinates

  • out_nr (int) – The current step

Returns

Depending on switch the shapes will be different

Return type

np.array

fourth_day.fourth_day module

class fourth_day.fourth_day.Fourth_Day(userconfig=None)

Bases: object

class: Fourth_Day Interace to the FD package. This class stores all methods required to run the simulation of the bioluminescence :param config: Configuration dictionary for the simulation :type config: dic

Returns

Return type

None

property light_yields

Getter function for the light yields. The switch needs to be true

Parameters

None

Returns

light_yields – The light yield of the detector

Return type

np.array

Raises

ValueError – When the correct switches were’t set in the config

property measured

Getter function for the measured light yields. The switch needs to be true

Parameters

None

Returns

light_yields – The light yield of the detector

Return type

np.array

Raises

ValueError – When the correct switches were’t set in the config

sim()

Calculates the light yields depending on input

Parameters

None

Returns

Return type

None

property statistics

Getter functions for the simulation results from the simulation

Parameters

None

Returns

statistics – Stores the results from the simulation

Return type

dic

property t

Getter functions for the simulation time

Parameters

None

Returns

t – The time array

Return type

np.array

property wavelengths

Getter functions for the wavelengths of the emitted light used

Parameters

None

Returns

statistics – Stores the results from the simulation

Return type

dic

fourth_day.functions module

fourth_day.functions.interp2d_pairs(*args, **kwargs)

Same interface as interp2d but the returned interpolant will evaluate its inputs as pairs of values.

fourth_day.functions.normalize(v: numpy.array) → numpy.array

normalizes a vector v

Parameters

v (np.array) – The vector to normalize

Returns

The normalized vector

Return type

np.array

fourth_day.genesis module

class fourth_day.genesis.Genesis

Bases: object

Creates the different organisms and their light pdfs

Parameters

None

Returns

Return type

None

property Evolved

Getter function for the filtered organisms

Parameters

None

Returns

evolved – The evolved organisms

Return type

dict

property Life

Getter function for the organisms

Parameters

None

Returns

life – The organisms

Return type

dict

property Light_pdfs

Getter function for the light pdfs

Parameters

None

Returns

pdfs – The light pdfs

Return type

dict

property Movement

Getter function for the movement profiles

Parameters

None

Returns

movement – The movement profiles

Return type

dict

pulse_emission(organisms: pandas.core.frame.DataFrame) → numpy.array

Emission magnitude depending on how long the organisms have been emitting

Parameters

organisms (pd.DataFrame) – The organisms of interest

Returns

multi_array – The emission fractions for each element in remain_time

Return type

np.array

fourth_day.lucifer module

class fourth_day.lucifer.Lucifer

Bases: object

Contains the methods to propagate the light to the detector

Parameters

None

Returns

Return type

None

light_bringer(statistics: pandas.core.frame.DataFrame, life: fourth_day.genesis.Genesis) → numpy.array

Calculates the light yields for the MC results

Parameters
  • statistics (pd.DataFrame) – The results from the MC simulation

  • life (Genesis instance) – Collection for the light emission pdfs

Returns

arriving – The attenuated photon counts depending on time

Return type

np.array

fourth_day.mc_sim module

class fourth_day.mc_sim.MC_sim(life: fourth_day.genesis.Genesis, world: fourth_day.adamah.Adamah, current: fourth_day.current.Current)

Bases: object

Monte-carlo simulation for the light emissions.

Parameters
  • life (Genesis object) – The organisms

  • world (Adamah) – The world

Returns

Return type

None

Raises

ValueError – Wrong starting distribution

property iterations

Getter functions for the simulation iterations

Parameters

None

Returns

iterations – Number of iterations

Return type

float

property statistics

Getter functions for the simulation results from the simulation

Parameters

None

Returns

statistics – Stores the results from the simulation

Return type

dic

fourth_day.pdfs module

class fourth_day.pdfs.Gamma(mean: Union[float, numpy.ndarray], sd: Union[float, numpy.ndarray], max_val=None)

Bases: fourth_day.pdfs.ScipyPDF

Class for the scaled gamma distribution

Parameters
  • mean (Union[float, np.array]) – The mean value

  • sd (Union[float, np.array]) – The std

Returns

Return type

None

class fourth_day.pdfs.LogNorm(mean: Union[float, numpy.ndarray], sd: Union[float, numpy.ndarray], max_val=inf)

Bases: fourth_day.pdfs.ScipyPDF

Class for the lognormal distribution

Parameters
  • mean (Union[float, np.array]) – The mean value

  • sd (Union[float, np.array]) – The std

Returns

Return type

None

class fourth_day.pdfs.Normal(mean: Union[float, numpy.ndarray], sd: Union[float, numpy.ndarray], max_val=inf)

Bases: fourth_day.pdfs.ScipyPDF

Class for the normal distributon

Parameters
  • mean (Union[float, np.ndarray]) –

  • sd (Union[float, np.ndarray]) –

Returns

Return type

None

class fourth_day.pdfs.PDF

Bases: object

Interface class for the pdfs. One layer inbetween to allow different pdf packages such as scipy and numpy

Parameters

pdf_interface (class) – Interface class to the pdf classes

Returns

Return type

None

abstract classmethod pdf(points: Union[float, numpy.ndarray]) → numpy.ndarray

Calculates the probability of the given points

Parameters

points (np.ndarray) – The points to evaluate

Returns

The probabilities

Return type

np.ndarray

abstract rvs(num: int) → numpy.ndarray

Random variate sampling, filled with the subclasses definition

Parameters

num (int) – Number of samples to draw

Returns

rvs – The drawn samples

Return type

np.ndarray

class fourth_day.pdfs.Probability

Bases: object

Abstract class to interface to the probabilities

Parameters

pdf (object) – The probability distribution class

Returns

Return type

None

class fourth_day.pdfs.ScipyPDF

Bases: fourth_day.pdfs.PDF

Interface class for the scipy pdfs

Parameters
  • None

  • Returns

  • None

pdf(points: Union[float, numpy.ndarray], dtype: Optional[type] = None) → numpy.ndarray

Calculates the probabilities

Parameters
  • points (np.ndarray) – The points to evaluate

  • dtype (optional) – Type of the output

Returns

pdf – The probabilities

Return type

np.ndarray

rvs(num: int, dtype: Optional[type] = None) → numpy.ndarray

Calculates the random variates

Parameters
  • num (int) – The number of samples

  • dtype (optional) – Type of the output

Returns

rvs – The drawn samples

Return type

np.ndarray

fourth_day.pdfs.construct_pdf(conf_dict: Dict[str, Any]) → fourth_day.pdfs.PDF

Convenience function to create a PDF from a config dict

Parameters

conf_dict (Dict[str, Any]) – The dict should contain a class key with the name of the PDF to instantiate. Any further keys will be passed as kwargs

Returns

pdf – The constructed pdf

Return type

PDF

Raises

Keyerror – The pdf class is unknown

fourth_day.providence module

class fourth_day.providence.Providence

Bases: object

Contains the methods to propagate the light to the detector

Parameters

None

Returns

Return type

None

fourth_day.state_machine module

class fourth_day.state_machine.FourthDayStateMachine(initial: pandas.core.frame.DataFrame, life: fourth_day.genesis.Genesis, world: fourth_day.adamah.Adamah, current: fourth_day.current.Current, possible_species: numpy.array, possible_means: numpy.array, possible_sds: numpy.array, possible_pulse_size: numpy.array)

Bases: object

The state of the system and the methods to update it

Parameters
  • initial (pd.DataFrame) – The initial state

  • life (Genesis object) – The constructed organisms

  • world (Adamah object) – The constructed world

  • possible_species (np.array) – List of all species

  • possible_means (np.array) – List of all possible means for pulses

  • possible_sds (np.array) – List of all possible sd for pulses

  • possible_pulse_size (np.array) – List of all possible pulse sizes

update()

Updates the state by making one time step

Parameters

None

Returns

list

populationpd.DataFrame

The current state of the population

breakbool

If simulation is done

Return type

[population, break]

fourth_day.vtu_npy_handlers module

class fourth_day.vtu_npy_handlers.vtu_npy_converter

Bases: object

Class to handle vtu and converted npy data.

load_from_vtu_and_build_npy_arrays(print_array_types=False)

Method to convert vtu file data into numpy array data. Loads the vtu files and saves data in numpy array files. When loading data from pvtu file, it is processed from its parallel components and then saved as a single component npy file. This takes a while, so should only be done once, and then the npy files should be used. :arg print_array_types: print vtu information on arrays contained in vtu files; defaults to False.

class fourth_day.vtu_npy_handlers.vtu_reader(directory, file_name, nr_parallel_runs=1, print_array_types=False)

Bases: object

Class to read vtu data format into numpy arrays. :arg directory: directory in which vtu files are stored :arg file_name: vtu file stem name, for full vtu file name of form ‘file_name_a.vtu’ for output number a, and ‘file_name_a_b.vtu’ for parallel run number b greater than 1. :arg nr_parallel_runs: number of parallel runs, defaults to 1.

load_vtu_data_into_array(output_number, data_index, two_d=True)

Read data from vtu parallel files given the files’ output number and the data index in the vtu file. Returns value data as numpy (n x d) array, as well as corresponding coordinate (n x 3) array, where n is the number of data points, and d is 1 for scalar and 3 for vector data. Note: in 2D, the last column will contain zeros only.

Module contents