IO & Data Management (API)¶
Measurement Data¶
pyadm1ode_calibration.io.loaders.measurement_data.MeasurementData(data, metadata=None)
¶
Container for biogas plant measurement data.
This class manages time-series data from biogas plants, providing methods for loading, validation, cleaning (outlier removal), and pre-processing (gap filling, resampling).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
DataFrame containing measurements. If a 'timestamp' column exists, it will be converted to datetime and used as the index. |
required |
metadata
|
Optional[Dict[str, Any]]
|
Optional dictionary containing contextual information (e.g., plant ID, location). |
None
|
Source code in pyadm1ode_calibration/io/loaders/measurement_data.py
Functions¶
fill_gaps(columns=None, method='interpolate', **kwargs)
¶
Fill missing values (NaNs) in the data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
columns
|
Optional[List[str]]
|
Columns to fill. |
None
|
method
|
str
|
Fill method ('interpolate', 'forward', 'backward', 'mean', 'median'). |
'interpolate'
|
**kwargs
|
Any
|
Additional arguments for filling (e.g., 'limit'). |
{}
|
Source code in pyadm1ode_calibration/io/loaders/measurement_data.py
from_csv(filepath, timestamp_column='timestamp', sep=',', parse_dates=True, resample=None, **kwargs)
classmethod
¶
Load measurement data from a CSV file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str
|
Path to the CSV file. |
required |
timestamp_column
|
str
|
Name of the column containing time information. |
'timestamp'
|
sep
|
str
|
CSV delimiter. Defaults to ','. |
','
|
parse_dates
|
bool
|
Whether to parse dates. Defaults to True. |
True
|
resample
|
Optional[str]
|
Frequency string to resample to (e.g., '1h'). |
None
|
**kwargs
|
Any
|
Additional arguments passed to pd.read_csv. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
MeasurementData |
MeasurementData
|
A new instance with the loaded data. |
Source code in pyadm1ode_calibration/io/loaders/measurement_data.py
get_measurement(column, start_time=None, end_time=None)
¶
Get a specific measurement series, optionally windowed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
column
|
str
|
Name of the measurement column. |
required |
start_time
|
Optional[datetime]
|
Start of window. |
None
|
end_time
|
Optional[datetime]
|
End of window. |
None
|
Returns:
| Type | Description |
|---|---|
Series
|
pd.Series: The requested time series. |
Source code in pyadm1ode_calibration/io/loaders/measurement_data.py
get_substrate_feeds(substrate_columns=None)
¶
Extract substrate feed rates as a 2D numpy array.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
substrate_columns
|
Optional[List[str]]
|
Column names for substrates. |
None
|
Returns:
| Type | Description |
|---|---|
ndarray
|
np.ndarray: Matrix of feed rates. |
Source code in pyadm1ode_calibration/io/loaders/measurement_data.py
get_time_window(start_time, end_time)
¶
Create a new MeasurementData instance for a specific time window.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
start_time
|
Union[str, datetime]
|
Start timestamp. |
required |
end_time
|
Union[str, datetime]
|
End timestamp. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
MeasurementData |
MeasurementData
|
A subset of the data. |
Source code in pyadm1ode_calibration/io/loaders/measurement_data.py
remove_outliers(columns=None, method='zscore', threshold=3.0, **kwargs)
¶
Detect and remove outliers from specified columns.
Outliers are replaced with NaN.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
columns
|
Optional[List[str]]
|
Columns to check. Defaults to all numeric. |
None
|
method
|
str
|
Detection method ('zscore', 'iqr', 'moving_window'). |
'zscore'
|
threshold
|
float
|
Threshold for outlier detection. |
3.0
|
**kwargs
|
Any
|
Additional arguments for the detection method. |
{}
|
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
Total number of outliers removed. |
Source code in pyadm1ode_calibration/io/loaders/measurement_data.py
resample(freq, aggregation='mean')
¶
Resample the time series data to a new frequency.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
freq
|
str
|
Frequency string (e.g., '1h', '1d'). |
required |
aggregation
|
str
|
Aggregation function ('mean', 'sum', 'first', 'last'). |
'mean'
|
Source code in pyadm1ode_calibration/io/loaders/measurement_data.py
summary()
¶
Get a statistical summary of all measurement columns.
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: Descriptive statistics. |
to_csv(filepath, **kwargs)
¶
Save the current data to a CSV file.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str
|
Destination path. |
required |
**kwargs
|
Any
|
Passed to pd.DataFrame.to_csv. |
{}
|
Source code in pyadm1ode_calibration/io/loaders/measurement_data.py
validate(required_columns=None, expected_ranges=None)
¶
Validate measurement data against schema and range expectations.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
required_columns
|
Optional[List[str]]
|
Columns that must be present. |
None
|
expected_ranges
|
Optional[Dict[str, Tuple[float, float]]]
|
Mapping of column names to (min, max) range tuples. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
ValidationResult |
ValidationResult
|
Result of the validation checks. |
Source code in pyadm1ode_calibration/io/loaders/measurement_data.py
CSV Handler¶
pyadm1ode_calibration.io.loaders.csv_handler.CSVHandler(decimal_separator='.', thousands_separator=',')
¶
Handler for CSV file operations in PyADM1.
Supports reading and writing various CSV formats used in biogas plant operation and laboratory analysis.
Example
handler = CSVHandler() data = handler.load_substrate_lab_data("lab_results.csv")
Initialize CSV handler.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
decimal_separator
|
str
|
Decimal separator ("." or ",") |
'.'
|
thousands_separator
|
str
|
Thousands separator ("," or "." or "") |
','
|
Source code in pyadm1ode_calibration/io/loaders/csv_handler.py
Functions¶
create_template_substrate_csv(filepath, format_type='horizontal')
¶
Create template CSV file for substrate data entry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str
|
Output file path |
required |
format_type
|
str
|
"horizontal" or "vertical" |
'horizontal'
|
Example
handler.create_template_substrate_csv("template.csv")
Source code in pyadm1ode_calibration/io/loaders/csv_handler.py
694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 | |
export_measurement_data(data, filepath, sep=',', encoding='utf-8', include_index=True)
¶
Export measurement data to CSV.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
DataFrame with measurements |
required |
filepath
|
str
|
Output file path |
required |
sep
|
str
|
Column separator |
','
|
encoding
|
str
|
File encoding |
'utf-8'
|
include_index
|
bool
|
Include index (timestamp) in output |
True
|
Example
handler.export_measurement_data(measurements, "export.csv")
Source code in pyadm1ode_calibration/io/loaders/csv_handler.py
export_parameter_table(data, filepath, sep=',', encoding='utf-8')
¶
Export parameter table to CSV.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
DataFrame with parameters |
required |
filepath
|
str
|
Output file path |
required |
sep
|
str
|
Column separator |
','
|
encoding
|
str
|
File encoding |
'utf-8'
|
Example
handler.export_parameter_table(params_df, "parameters.csv")
Source code in pyadm1ode_calibration/io/loaders/csv_handler.py
export_simulation_results(results, filepath, sep=',', encoding='utf-8', flatten_components=True)
¶
Export simulation results to CSV.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
results
|
List[Dict[str, Any]]
|
List of result dicts from plant.simulate() |
required |
filepath
|
str
|
Output file path |
required |
sep
|
str
|
Column separator |
','
|
encoding
|
str
|
File encoding |
'utf-8'
|
flatten_components
|
bool
|
Flatten component results into columns |
True
|
Example
results = plant.simulate(duration=30, dt=1/24) handler.export_simulation_results(results, "simulation.csv")
Source code in pyadm1ode_calibration/io/loaders/csv_handler.py
export_substrate_data(data, filepath, sep=',', encoding='utf-8')
¶
Export substrate data to CSV.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
Union[Dict[str, Any], DataFrame]
|
Dict or DataFrame with substrate data |
required |
filepath
|
str
|
Output file path |
required |
sep
|
str
|
Column separator |
','
|
encoding
|
str
|
File encoding |
'utf-8'
|
Example
handler.export_substrate_data(substrate_data, "export.csv")
Source code in pyadm1ode_calibration/io/loaders/csv_handler.py
load_measurement_data(filepath, timestamp_column='timestamp', sep=',', encoding='utf-8', parse_dates=True, resample=None)
¶
Load time series measurement data from CSV.
Expected columns: - timestamp (or Zeit, Zeitstempel) - Q_sub_* (substrate feeds) - pH, VFA, TAC, FOS_TAC - T_digester - Q_gas, Q_ch4, Q_co2, CH4_content, P_gas - P_el, P_th
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str
|
Path to CSV file |
required |
timestamp_column
|
str
|
Name of timestamp column |
'timestamp'
|
sep
|
str
|
Column separator |
','
|
encoding
|
str
|
File encoding |
'utf-8'
|
parse_dates
|
bool
|
Parse timestamp column |
True
|
resample
|
Optional[str]
|
Resample frequency (e.g., "1h", "1d") |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with measurements |
Example
handler = CSVHandler() data = handler.load_measurement_data( ... "plant_data.csv", ... resample="1h" ... )
Source code in pyadm1ode_calibration/io/loaders/csv_handler.py
load_multiple_substrate_samples(filepath, sep=',', encoding='utf-8', date_column='sample_date', name_column='substrate_name')
¶
Load multiple substrate samples from CSV.
Expected format: Each row is one sample with columns for all parameters.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str
|
Path to CSV file |
required |
sep
|
str
|
Column separator |
','
|
encoding
|
str
|
File encoding |
'utf-8'
|
date_column
|
str
|
Name of date column |
'sample_date'
|
name_column
|
str
|
Name of substrate name column |
'substrate_name'
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with substrate data |
Example
handler = CSVHandler() samples = handler.load_multiple_substrate_samples( ... "substrate_database.csv" ... ) print(samples.head())
Source code in pyadm1ode_calibration/io/loaders/csv_handler.py
load_parameter_table(filepath, sep=',', encoding='utf-8', index_col=None)
¶
Load parameter table from CSV.
Expected format: - Rows: Parameters - Columns: Different scenarios/substrates
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str
|
Path to CSV file |
required |
sep
|
str
|
Column separator |
','
|
encoding
|
str
|
File encoding |
'utf-8'
|
index_col
|
Optional[str]
|
Column to use as index (usually parameter name) |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
DataFrame with parameters |
Example
params = handler.load_parameter_table("parameters.csv")
Source code in pyadm1ode_calibration/io/loaders/csv_handler.py
load_simulation_results(filepath, sep=',', encoding='utf-8')
¶
Load simulation results from CSV.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str
|
Path to CSV file |
required |
sep
|
str
|
Column separator |
','
|
encoding
|
str
|
File encoding |
'utf-8'
|
Returns:
| Type | Description |
|---|---|
List[Dict[str, Any]]
|
List of result dicts |
Example
results = handler.load_simulation_results("simulation.csv")
Source code in pyadm1ode_calibration/io/loaders/csv_handler.py
load_substrate_lab_data(filepath, substrate_name=None, substrate_type=None, sample_date=None, sep=',', encoding='utf-8', validate=True)
¶
Load substrate characterization data from laboratory CSV.
Expected columns (German or English): - Trockensubstanzgehalt (TS) [% FM] - Organische Trockensubstanz (VS) [% TS] - Fermentierbare organische Trockensubstanz (foTS) [% TS] - Rohprotein (RP) [% TS] - Rohfett (RL) [% TS] - Rohfaser (RF) [% TS] - NDF, ADF, ADL [% TS] - pH-Wert (pH) - Ammoniumstickstoff (NH4-N) [g/L or mg/L] - Alkalinität (TAC) [mmol/L] - Biochemisches Methanpotential (BMP) [L CH4/kg oTS] - CSB des Filtrats (COD_S) [g/L]
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
filepath
|
str
|
Path to CSV file |
required |
substrate_name
|
Optional[str]
|
Substrate name (if not in file) |
None
|
substrate_type
|
Optional[str]
|
Substrate type (maize, manure, grass, etc.) |
None
|
sample_date
|
Optional[Union[str, datetime]]
|
Sample date (if not in file) |
None
|
sep
|
str
|
Column separator |
','
|
encoding
|
str
|
File encoding |
'utf-8'
|
validate
|
bool
|
Validate data ranges |
True
|
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dict with substrate data |
Example
handler = CSVHandler() data = handler.load_substrate_lab_data( ... "maize_analysis.csv", ... substrate_name="Maize silage batch 23", ... substrate_type="maize", ... sample_date="2024-01-15" ... ) print(f"TS: {data['TS']:.1f}% FM")
Source code in pyadm1ode_calibration/io/loaders/csv_handler.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 | |
Database¶
pyadm1ode_calibration.io.persistence.database.Database(connection_string=None, config=None)
¶
PostgreSQL database interface for PyADM1.
Handles connection pooling, session management, and CRUD operations for all calibration-related entities.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
connection_string
|
Optional[str]
|
Database URL. |
None
|
config
|
Optional[DatabaseConfig]
|
Database configuration object. |
None
|
Source code in pyadm1ode_calibration/io/persistence/database.py
Functions¶
close()
¶
create_all_tables()
¶
create_plant(plant_id, name, location=None, operator=None, V_liq=None, V_gas=None, T_ad=None, P_el_nom=None, configuration=None)
¶
Register a new biogas plant in the database.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plant_id
|
str
|
Unique identifier. |
required |
name
|
str
|
Human-readable name. |
required |
location
|
Optional[str]
|
Geographic location. |
None
|
operator
|
Optional[str]
|
Entity operating the plant. |
None
|
V_liq
|
Optional[float]
|
Liquid volume in m3. |
None
|
V_gas
|
Optional[float]
|
Gas volume in m3. |
None
|
T_ad
|
Optional[float]
|
Operating temperature in K. |
None
|
P_el_nom
|
Optional[float]
|
Nominal electrical power in kW. |
None
|
configuration
|
Optional[Dict]
|
Additional technical configuration. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Plant |
Plant
|
The created plant instance. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If plant_id already exists. |
Source code in pyadm1ode_calibration/io/persistence/database.py
drop_all_tables()
¶
execute_query(query, params=None)
¶
Execute a custom read-only SQL query.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
query
|
str
|
SQL query string. |
required |
params
|
Optional[Dict[str, Any]]
|
Query parameters. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: Query results. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If dangerous keywords are detected. |
Source code in pyadm1ode_calibration/io/persistence/database.py
from_env(prefix='DB')
classmethod
¶
Create a database instance from environment variables.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prefix
|
str
|
Prefix for environment variables (e.g., 'DB' -> 'DB_HOST'). |
'DB'
|
Returns:
| Name | Type | Description |
|---|---|---|
Database |
Database
|
A configured database instance. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If required variables are missing. |
Source code in pyadm1ode_calibration/io/persistence/database.py
get_latest_calibration(plant_id)
¶
Get the most recent calibration for a plant.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plant_id
|
str
|
Plant ID. |
required |
Returns:
| Type | Description |
|---|---|
Optional[Dict[str, Any]]
|
Optional[Dict[str, Any]]: Latest calibration record. |
Source code in pyadm1ode_calibration/io/persistence/database.py
get_plant(plant_id)
¶
Retrieve a plant by its ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plant_id
|
str
|
The plant identifier. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
Plant |
Plant
|
The plant instance. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If plant is not found. |
DatabaseError
|
On SQL failure. |
Source code in pyadm1ode_calibration/io/persistence/database.py
get_session()
¶
Context manager for SQLAlchemy database sessions.
Yields:
| Name | Type | Description |
|---|---|---|
Session |
Session
|
An active database session. |
Source code in pyadm1ode_calibration/io/persistence/database.py
get_statistics(plant_id)
¶
Get database usage statistics for a specific plant.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plant_id
|
str
|
Plant ID. |
required |
Returns:
| Type | Description |
|---|---|
Dict[str, Any]
|
Dict[str, Any]: Counts and time ranges of stored data. |
Source code in pyadm1ode_calibration/io/persistence/database.py
list_plants()
¶
List all registered plants.
Returns:
| Type | Description |
|---|---|
List[Dict[str, Any]]
|
List[Dict[str, Any]]: List of plant summary dictionaries. |
Source code in pyadm1ode_calibration/io/persistence/database.py
list_simulations(plant_id=None, scenario=None)
¶
List simulations matching specific criteria.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plant_id
|
Optional[str]
|
Filter by plant. |
None
|
scenario
|
Optional[str]
|
Filter by scenario. |
None
|
Returns:
| Type | Description |
|---|---|
List[Dict[str, Any]]
|
List[Dict[str, Any]]: List of simulation summaries. |
Source code in pyadm1ode_calibration/io/persistence/database.py
load_calibrations(plant_id, calibration_type=None, limit=10)
¶
Load past calibrations for a plant.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plant_id
|
str
|
Plant ID. |
required |
calibration_type
|
Optional[str]
|
Filter by type. |
None
|
limit
|
int
|
Max records to return. |
10
|
Returns:
| Type | Description |
|---|---|
List[Dict[str, Any]]
|
List[Dict[str, Any]]: List of calibration records. |
Source code in pyadm1ode_calibration/io/persistence/database.py
load_measurements(plant_id, start_time=None, end_time=None, columns=None, source=None)
¶
Load measurements as a pandas DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plant_id
|
str
|
Plant ID. |
required |
start_time
|
Optional[datetime]
|
Start of window. |
None
|
end_time
|
Optional[datetime]
|
End of window. |
None
|
columns
|
Optional[List[str]]
|
Specific columns to load. |
None
|
source
|
Optional[str]
|
Filter by data source. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: Measurements indexed by timestamp. |
Source code in pyadm1ode_calibration/io/persistence/database.py
load_simulation(simulation_id)
¶
Load simulation metadata and its full time series.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
simulation_id
|
str
|
ID of the simulation. |
required |
Returns:
| Type | Description |
|---|---|
Optional[Dict[str, Any]]
|
Optional[Dict[str, Any]]: Dictionary containing metadata and 'time_series' DataFrame. |
Source code in pyadm1ode_calibration/io/persistence/database.py
load_substrates(plant_id, substrate_type=None, start_date=None, end_date=None)
¶
Load substrate data as a DataFrame.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plant_id
|
str
|
Plant ID. |
required |
substrate_type
|
Optional[str]
|
Filter by type. |
None
|
start_date
|
Optional[datetime]
|
Start date. |
None
|
end_date
|
Optional[datetime]
|
End date. |
None
|
Returns:
| Type | Description |
|---|---|
DataFrame
|
pd.DataFrame: Table of substrate analyses. |
Source code in pyadm1ode_calibration/io/persistence/database.py
store_calibration(plant_id, calibration_type, method, parameters, objective_value, objectives, validation_metrics=None, data_start=None, data_end=None, success=True, message=None)
¶
Store a calibration result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plant_id
|
str
|
Plant ID. |
required |
calibration_type
|
str
|
'initial' or 'online'. |
required |
method
|
str
|
Optimization method. |
required |
parameters
|
Dict[str, float]
|
Calibrated values. |
required |
objective_value
|
float
|
Final cost value. |
required |
objectives
|
List[str]
|
Variables used in objective. |
required |
validation_metrics
|
Optional[Dict[str, float]]
|
RMSE, R2 etc. |
None
|
data_start
|
Optional[datetime]
|
Start of data window. |
None
|
data_end
|
Optional[datetime]
|
End of data window. |
None
|
success
|
bool
|
Whether calibration converged. |
True
|
message
|
Optional[str]
|
Status message. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Calibration |
Calibration
|
Stored record. |
Source code in pyadm1ode_calibration/io/persistence/database.py
store_measurements(plant_id, data, source='SCADA', validate=True)
¶
Bulk store measurement data for a plant.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plant_id
|
str
|
ID of the plant. |
required |
data
|
DataFrame
|
Measurements with 'timestamp' column. |
required |
source
|
str
|
Data source name. Defaults to 'SCADA'. |
'SCADA'
|
validate
|
bool
|
Whether to run quality checks before storing. |
True
|
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
Number of records stored. |
Source code in pyadm1ode_calibration/io/persistence/database.py
store_simulation(simulation_id, plant_id, results, name=None, description=None, duration=None, parameters=None, scenario='baseline')
¶
Store simulation metadata and time series.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
simulation_id
|
str
|
Unique ID for the simulation. |
required |
plant_id
|
str
|
Associated plant ID. |
required |
results
|
List[Dict[str, Any]]
|
Time-series results from simulation. |
required |
name
|
Optional[str]
|
Simulation name. |
None
|
description
|
Optional[str]
|
Optional description. |
None
|
duration
|
Optional[float]
|
Duration in days. |
None
|
parameters
|
Optional[Dict]
|
Parameters used in this run. |
None
|
scenario
|
str
|
Scenario label. Defaults to 'baseline'. |
'baseline'
|
Returns:
| Name | Type | Description |
|---|---|---|
Simulation |
Simulation
|
Stored simulation record. |
Source code in pyadm1ode_calibration/io/persistence/database.py
store_substrate(plant_id, substrate_name, substrate_type, sample_date, lab_data, sample_id=None, lab_name=None, notes=None)
¶
Store substrate laboratory analysis data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
plant_id
|
str
|
Associated plant ID. |
required |
substrate_name
|
str
|
Name (e.g., 'Maize Silage'). |
required |
substrate_type
|
str
|
Category. |
required |
sample_date
|
datetime
|
Date of sampling. |
required |
lab_data
|
Dict[str, float]
|
Chemical properties (TS, VS, oTS, etc.). |
required |
sample_id
|
Optional[str]
|
Lab internal ID. |
None
|
lab_name
|
Optional[str]
|
Lab name. |
None
|
notes
|
Optional[str]
|
Additional comments. |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
Substrate |
Substrate
|
Stored record. |
Source code in pyadm1ode_calibration/io/persistence/database.py
Validation¶
pyadm1ode_calibration.io.validation.validators.DataValidator
¶
Validates measurement data quality and consistency.
Functions¶
validate(data, required_columns=None, expected_ranges=None)
staticmethod
¶
Perform comprehensive data validation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
DataFrame
|
DataFrame to validate |
required |
required_columns
|
Optional[List[str]]
|
Columns that must be present |
None
|
expected_ranges
|
Optional[Dict[str, Tuple[float, float]]]
|
Mapping of column names to (min, max) |
None
|
Returns:
| Type | Description |
|---|---|
ValidationResult
|
ValidationResult object |