hydroponics package

Submodules

hydroponics.Basic_functions module

This file contains the most basic functions used in the project. In particular, the file contains functions to: - Import user data from an Excel file - Calculate the molar mass of a salt - Get the solubility product constant (Ksp) and solubility product (Q) of a salt - Convert salt concentrations to ion concentrations - Make a solution given the ion concentration wanted

hydroponics.Basic_functions.get_Ksp(salt_name: str) float[source]
Access the solubility product constant (Ksp) of a salt based on its name.

Uses a salt2nbIons dictionary to find the number of ions in a salt.

Parameters:

salt_name (str) – The formula of the salt. Use standard notation for the formula, e.g. “Ca(NO3)2”, “H2O”, etc.

Returns:

The solubility product constant (Ksp) of the salt.

Return type:

float

hydroponics.Basic_functions.get_Q_solubility(salt_name: str, ions_in_solution: dict) float[source]

Returns the solubility product of a salt

Parameters:
  • salt_name (str) – name of the salt

  • ions_in_solution (dict) – dictionary with keys as ions and values as the concentration in mol/L

Returns:

solubility product Q

Return type:

float

hydroponics.Basic_functions.get_atom_mass(atom_name: str) float[source]

Gets the atomic mass of the atom from a CVS file

Parameters:

atom_name (str) – Name of the atom, i.e. ‘H’, ‘O’, ‘C’, etc.

Returns:

atomic mass of the atom in g/mol

Return type:

float

hydroponics.Basic_functions.get_molar_mass(salt: str) float[source]

Calculate the molar mass of a salt in g/mol.

Parameters:

salt (str) – The chemical formula of the salt. Handles chemical formulas of the following types: - “Ca(NO3)2” - “Ca(2+)(NO3-)2” - “Ca2(NO3)2” - “Ca(NO3)2(2+)” Please do not use spaces in the formula and avoid putting brackets inside brackets.

Returns:

The molar mass of the salt in g/mol.

Return type:

float

hydroponics.Basic_functions.import_plant_data(plant_name: str) dict[source]

Import user data from sheet “My Plant” from the Excel file “UserData.xlsx” and returns it as a dictionary.

Parameters:

plant (str) – name of the column where the data is located

Returns:

dictionary containing the needs of the plant for each ion [g] for a full growth cycle

Return type:

dict

hydroponics.Basic_functions.import_solution_data(solution_name: str) dict[source]

Import user data from the Excel file “UserData.xlsx” and returns it as a dictionary.

Parameters:

solution_name (str) – Name of the column in the Excel file.

Returns:

Dictionary containing the concentration of the ions [g/L] in the solution.

Return type:

dict

hydroponics.Basic_functions.load_from_data(file_name)[source]
hydroponics.Basic_functions.make_solution(ions_in_solution: dict, forbidden_ions: list, volume: float) dict[source]

Returns how much of each salt [g] to add to a solution of certain volume [L] to obtain a certain concentration of ions [g/L]

Parameters:
  • ions_in_solution (dict) – dictionary with keys as ions and values as the concentration in g/L.

  • forbidden_ions (list) – list of ions that cannot be in the solution.

  • volume (float) – volume of the final solution in L.

Returns:

dictionary with keys as salt names and values as the amount of salt needed in g.

Return type:

dict

hydroponics.Basic_functions.predefined_solutions(plant: str, concentration: str = 'g') dict[source]

Import user data from the Excel file “UserData.xlsx” and returns it as a dictionary.

Parameters:
  • plant (str) – Name of the plant. Can either be ‘Eggplant’, ‘Tomato’ or ‘Cucumber’.

  • concentration (str) – Unit of concentration. Can either be ‘g’ or ‘mol’.

Returns:

Dictionary containing the concentration of the ions [g or mol/L] in the solution.

Return type:

dict

hydroponics.Basic_functions.salt2ions(solution: dict, volume: float = 1, unit: str = 'g') dict[source]
Convert salts to ions based on their concentrations and volume. Concentrations are in g/L by default

but can also be given in mol/L by specifying ‘unit’ as ‘mol’. A ‘dict_salts_trad’ dictionary is used to convert salt names to ions. Make sure the salts are in the ‘dict_salts_trad’ dictionary.

Parameters:
  • solution (dict) – A dictionary containing salt names as keys and concentrations as values.

  • volume (float, optional) – Volume of the solution. Defaults to 1.

  • unit (str, optional) – Unit of concentration. Defaults to “g”. Options are “g” or “mol”.

Returns:

A dictionary containing ions and their concentrations [g/L] in the solution (volume =1), their quantity [g] if volume > 1

Return type:

dict

Raises:

ValueError – If the volume is non-positive.

hydroponics.Generate_Report module

This file contains the functions needed in order to generate an automatic report.

hydroponics.Generate_Report.generate_report(plant_name: str, required_nutriments: dict, growth_time: float, ions_of_interest: list, solution_composition: dict, solution_volume: float, forbidden_ions: list = []) None[source]

Generates a simulation report in PDF format based on the provided parameters.

Parameters:
  • plant_name (str) – The name of the plant for which the hydroponic solution simulation is conducted.

  • required_nutriments (dict) – A dictionary containing the required nutriments (ions) for the specified plant for a full growth [g].

  • solution_composition (dict) – A dictionary representing the composition of the hydroponic solution [g/L] for each ion.

  • solution_volume (float) – The volume of the hydroponic solution [L].

  • ions_of_interest (list) – A list of ions for which the concentration is of interest.

  • growth_time (float) – The duration of the growth of the plant [days].

  • forbidden_ions (list, default) – A list of ions that are forbidden in the solution.

Returns:

a pdf is created in the folder of this file

Return type:

None

hydroponics.Generate_Report.merge_dicts(dict1, dict2, ions_of_interest='all')[source]

hydroponics.PH_Approximation_0 module

hydroponics.PH_Approximation_0.find_acid(ions_concentration: dict, acids_pKa: dict, highest_existing_charge_of_compounds: dict) tuple[source]

Identify acids or their deprotonated forms, and return two dictionaries. One where the keys are the identified ions/acids and attribute to them the pKas of the acid they’re associated, the second with the same keys but values being the number of protons the acid would have to lost to reach the form of the ion.

Parameters: ions_concentration (dict): A dictionary with ion names as keys and their concentrations as values. acids_pKa (dict): A dictionary with acid names as keys and their pKa values as lists.

Returns: tuple with three dictionaries 1.Dictionary with identified ions being the key and their corresponding values being the number of protons it lost compared to its non-deprotonated form. 2.Dictionary where ions are the key and the values are the pkas of the acid 3.Dictionary where ions are the key and the values are the highest charge of the compound when it is undissociated

hydroponics.PH_Approximation_0.pH_approximation(concentration_of_ions_in_solution: dict, temperature: float) float[source]

This function calculates the pH of a solution given the concentrations of ions in the solution and the temperature of the solution.

Parameters: concentration_of_ions_in_solution (dict): A dictionary containing the ions(str) as keys and their concentrations(float) in the solution as values. temperature (float): The temperature of the solution in degrees Celsius.

Returns: pH (float): The pH of the solution. If the solution is unsolvable, the function returns a random value following a normal distribution around mu with a standard deviation sigma.

hydroponics.Refill_0 module

hydroponics.Refill_0.Refill_of_container(concentration_of_ions: dict[str, float], optimal_ion_concentrations: dict[str, float], *args: float) dict[str, float][source]

Refill the container with ions that are below the optimal concentration.

This function optionally checks if the concentration of ions in the solution is within an acceptable range of the optimal concentration. If specified, it skips ions that are within the acceptable deviation and refills only those that are below the optimal concentration.

Parameters:
  • concentration_of_ions (dict[str, float]) – A dictionary containing the concentration of ions in the solution.

  • optimal_ion_concentrations (dict[str, float]) – A dictionary containing the optimal concentration of ions in the solution.

  • *args (float) – A list of acceptable maximum percentage deviations from the optimal concentration of ions in the solution.

Returns:

A dictionary containing the ions and the quantities to add to the solution.

Return type:

dict[str, float]

hydroponics.Solutions_Solubility module

This file contains the more advanced functions on solutions and solubility used in the project. In particular, the file contains functions to: - Check the solubility of a solution - Analyse the nutriments in the solution - Update the solution after 1 day of growth - Plot the evolution of the solution

hydroponics.Solutions_Solubility.analyse_nutriments(solution: dict, plant: dict, growth_time: float, volume: float, input_type_solution: str = 'salt') list[source]

Returns the number of days a plant can grow with the given solution.

Parameters:
  • solution (dict) – A dictionary containing salts or ions and their concentrations in the solution.

  • input_type (str) – Type of input data, either “salt” or “ion”.

  • plant (dict) – A dictionary containing ions and their required quantity for plant growth.

  • growth_time (float) – Expected growth time of the plant [days].

  • volume (float) – Volume of the solution [L].

  • *Note – the unit of solution and plant must be the same. (either mol/L or g/L)

Returns:

A list containing three elements:
  • bool: True if the solution contains enough nutriments for the plant, False otherwise.

  • int: Minimum days of growth achievable with the given solution.

  • str: Ion that limits the plant growth.

Return type:

list

Raises:

ValueError – If the volume or growth time is non-positive.

hydroponics.Solutions_Solubility.check_solubility(salts_dict: dict, input_type: str = 'salt', output_type: str = 'bool') bool[source]

Check if the salts mixture is soluble.

Parameters:
  • salts_dict (dict) – Dictionary with keys as salt names and values as concentrations [g/L].

  • input_type (str) – Type of input data, either “salt” or “ion”.

  • output_type (str) – Type of output data, either “bool”, “analysis”, or “update”.

Returns:

True if salts are soluble (if output_type is “bool”).

Analysis of precipitated salts or indication of solubility (if output_type is “analysis”).

Return type:

bool or str

hydroponics.Solutions_Solubility.check_supply_elements(ions_solution, plant) bool[source]
hydroponics.Solutions_Solubility.data4graph(solution: dict, volume: float, plant: dict, growth_time: float) list[source]

Creates a dictionary with the data needed to plot the graph

Parameters:
  • solution (dict) – Initial concentration [g/L] of the ions in the solution.

  • volume (float) – Volume of the solution [L].

  • plant (dict) – Dictionary containing required amount of ions for the plant growth.

  • growth_time (float) – Expected growth time of the plant [days].

Returns:

A list containing two elements:
  • list: A list of days. [0,1,2,3,4,5,6,…]

  • list: A list of dictionaries with the concentration of ions in the solution for each day.

Return type:

list

hydroponics.Solutions_Solubility.plot_graph(solution: dict, input_type: str, plant: dict, growth_time: float, volume: float = 1, ions_of_interest: list = 'all')[source]

Creates graph of salts in hydroponic solution

Parameters:
  • salts (dict) – Initial concentration [g/L] of the ions in the solution.

  • input_type (str) – Type of input data, either “salt” or “ion”.

  • plant (dict) – the plant requirements to fully grow [g].

  • growth_time (float) – Expected growth time of the plant [days].

  • volume (float, optional) – Volume of the solution [L]. Defaults to 1.

  • ions_of_interest (list, optional) – list of ions to plot. Defaults to “all”. Elements must be part of the keys of solution.

Returns:

None, saves the graph as a .png file in the download folder.

hydroponics.Solutions_Solubility.update_sol(ions_solution: dict, plant: dict, volume: float) dict[source]

updates the salts in solutions after 1 day of growth and checks the solubility of the new solution

Parameters:
  • ions_solution – dictionary with keys as ions and values as the amount of ions in the solution [g/L]

  • plant – dictionary with keys as ions and values as the amount of ions needed for 1 day for the plant [g]

Returns:

updated ions_solution after 1 day of growth and checking the solubility

Return type:

dictionary

hydroponics.pH_graph_0 module

hydroponics.pH_graph_0.generation_of_pH_list(concentrations_list: list, temperature: float, plant: str) tuple[source]

Generate pH values and identifies days where pH exceeded limits.

Parameters:
  • concentrations_list (list) – list of dictionaries of concentrations throughout days, with the index of the

  • derived. (dictionary in the list being the day where the concentrations were)

  • temperature (float) – Temperature of the solution in degrees celcius.

  • plant (str) – Name of the plant.

Returns:

pH values for each concentration dictionary. list: Indices of days where pH exceeded limits.

Return type:

list

hydroponics.pH_graph_0.pH_graph(pH_values: list, Days_where_pH_was_exceeded: list, plant: str) None[source]

” Generates a graph of pH values over time, with marked points where pH exceeded limits and a table of points of excess pH levels. The two figures are saved as png files. :param pH_values: :type pH_values: tuple of lists of pH values over time :param Days_where_pH_was_exceeded: :type Days_where_pH_was_exceeded: list :param plant: :type plant: str

Returns:

None

hydroponics.pH_graph_0.pH_part_of_report_generation(concentrations_list: list, temperature: float, plant: str) None[source]

” Generates a pH graph and a table of points of excess pH levels by calling the generation_of_pH _list function followed by the pH_graph function, the latter saving the figures as png files. :param concentrations_list: :type concentrations_list: dict :param temperature: :type temperature: float :param plant: :type plant: str

Returns:

None

Module contents

Simulation of hydroponic farming.