Skip to content

IO Module

io

Classes:

Name Description
ACY
DGN
DLY
DSL
DWC
OPC
SIT
SOL

ACY

Methods:

Name Description
get_var

Extract variable from the ACY data.

get_var(varname)

Extract variable from the ACY data.

DGN

Methods:

Name Description
get_var

Extract variable from the DGN data.

get_var(varname)

Extract variable from the DGN data.

DLY

Bases: DataFrame

Methods:

Name Description
load

Load data from a DLY file into DataFrame.

save

Save DataFrame into a DLY file.

to_monthly

Save as monthly file

validate

Validate the DataFrame to ensure it contains a continuous range of dates

load(path) classmethod

Load data from a DLY file into DataFrame.

save(path=None)

Save DataFrame into a DLY file.

to_monthly(path=None)

Save as monthly file

validate(start_date, end_date)

Validate the DataFrame to ensure it contains a continuous range of dates between start_date and end_date, without duplicates.

DSL

Methods:

Name Description
get_data

Return stored water data.

get_data()

Return stored water data.

DWC

Methods:

Name Description
get_var

Extract variable from the DWC data.

get_var(varname)

Extract variable from the DWC data.

OPC

Bases: DataFrame

Methods:

Name Description
append

Append another OPC or DataFrame to the current OPC instance.

edit_crop_season

Edit the planting and/or harvest dates for a given year and crop.

edit_fertilizer_rate

Edit the fertilizer rate for a given year.

edit_harvest_date

Edit the harvest date for a given year and crop.

edit_operation_date

Edit the operation date for a given year.

edit_operation_value

Edit the operation value for a given year.

edit_plantation_date

Edit the plantation date for a given year and crop.

get_harvest_date

Retrieve the harvest date(s) for a specific year and/or crop code.

get_plantation_date

Retrieve the plantation date(s) for a specific year and/or crop code.

iter_seasons

Iterate over OPC data, yielding dictionaries containing information for each growing season.

load

Load data from an OPC file into DataFrame.

new

Create a new OPC instance with an empty DataFrame with preset columns, a default header,

remove

Remove operation(s) from the OPC file that match all provided criteria.

save

Save DataFrame into an OPC file.

update

Add or update an operation in the OPC file.

update_phu

Update the OPV1 value with the calculated PHU from the DLY data for all plantation dates.

validate

Validate the OPC data to ensure it contains a continuous range of dates without duplicates.

IAUI property writable

Get the auto-irrigation implement ID from the OPC file header.

Returns:

Name Type Description
bool

True if auto-irrigation is enabled (72), False if disabled (0)

LUN property writable

Get the land use number from the OPC file header.

Returns:

Name Type Description
int

The land use number from the first 4 characters of header line 2

append(second_opc)

Append another OPC or DataFrame to the current OPC instance. Args: second_opc (pd.DataFrame or OPC): The data to append. Returns: OPC: A new OPC instance with combined data. Raises: ValueError: If second_opc is not a pandas DataFrame or OPC instance.

edit_crop_season(new_planting_date=None, new_harvest_date=None, crop_code=None)

Edit the planting and/or harvest dates for a given year and crop.

Parameters: year (int): Year. new_planting_date (datetime, optional): New planting date. If not provided, only harvest date will be updated. new_harvest_date (datetime, optional): New harvest date. If not provided, only planting date will be updated. crop_code (int, optional): Crop code. If not provided, changes the first crop found.

edit_fertilizer_rate(rate, year=2020, month=None, day=None)

Edit the fertilizer rate for a given year.

Parameters: rate (float): Fertilizer rate to be set. year (int, optional): Year for the fertilizer rate application. Defaults to 2020. month (int, optional): Month for the fertilizer rate application. If not provided, the first instance is changed. day (int, optional): Day for the fertilizer rate application. Defaults to None.

edit_harvest_date(date, crop_code)

Edit the harvest date for a given year and crop.

Parameters: date (datetime or str): Date of harvest in datetime object or 'YYYY-MM-DD' string format. crop_code (int): Crop code.

edit_operation_date(code, year, month, day, crop_code=None)

Edit the operation date for a given year.

Parameters: code (str): Operation code. year (int): Year. month (int): Month of operation. day (int): Day of operation. crop_code (int, optional): Crop code.

edit_operation_value(code, year, value, crop_code=None)

Edit the operation value for a given year.

Parameters: code (str): Operation code. year (int): Year. value (float): New operation value. crop_code (int, optional): Crop code.

edit_plantation_date(date, crop_code)

Edit the plantation date for a given year and crop.

Parameters: date (datetime or str): Date of plantation in datetime object or 'YYYY-MM-DD' string format. crop_code (int): Crop code.

get_harvest_date(year=None, crop_code=None)

Retrieve the harvest date(s) for a specific year and/or crop code.

Parameters: year (int, optional): Year. Defaults to None. crop_code (int, optional): Crop code. Defaults to None.

Returns: dict: A dictionary of crop codes and their harvest dates with row indices.

get_plantation_date(year=None, crop_code=None)

Retrieve the plantation date(s) for a specific year and/or crop code.

Parameters: year (int, optional): Year. Defaults to None. crop_code (int, optional): Crop code. Defaults to None.

Returns: dict: A dictionary of crop codes and their plantation dates with row indices.

iter_seasons(start_year=None, end_year=None)

Iterate over OPC data, yielding dictionaries containing information for each growing season.

Parameters: start_year (int, optional): The starting year to consider. Defaults to None. end_year (int, optional): The ending year to consider. Defaults to None.

dict: A dictionary containing: - plantation_date: The date of plantation - harvest_date: The date of harvest - crop_code: The crop code - operations: A subset of OPC rows for this season - plantation_index: The index of the plantation row

load(path, start_year=None) classmethod

Load data from an OPC file into DataFrame.

Parameters: path (str): Path to the OPC file. start_year (int, optional): Start year for the OPC file. If not provided, it will be read from the file header.

Returns: OPC: An instance of the OPC class containing the loaded data.

new(name, start_year) classmethod

Create a new OPC instance with an empty DataFrame with preset columns, a default header, and provided name and start year.

Parameters: name (str): The name for this OPC file/instance. start_year (int): The start year to assign in the OPC instance.

Returns: OPC: An OPC instance with no data but with the required metadata set.

remove(opID=None, date=None, cropID=None, XMTU=None, fertID=None, year=None)

Remove operation(s) from the OPC file that match all provided criteria.

Parameters:

Name Type Description Default
opID int

Operation ID to match

None
date str

Date to match in format 'YYYY-MM-DD'

None
cropID int

Crop ID to match

None
XMTU/LYR/pestID/fertID int

Machine type/layer/pesticide ID/fertilizer ID to match

required
year int

Year to match

None

save(path)

Save DataFrame into an OPC file.

Parameters: path (str): Path to save the OPC file.

update(operation)

Add or update an operation in the OPC file.

Parameters:

Name Type Description Default
operation dict

Dictionary containing operation details with keys: - opID: Operation ID (required) - cropID: Crop ID (required) - date: Operation date as string 'YYYY-MM-DD' (required) - XMTU/LYR/pestID/fertID: Machine type/years/pesticide ID/fertilizer ID (optional, default 0) - OPV1-OPV8: Additional operation values (optional, default 0)

required

update_phu(dly, cropcom)

Update the OPV1 value with the calculated PHU from the DLY data for all plantation dates.

Parameters: dly (DLY): DLY object containing weather data. cropcom (DataFrame): DataFrame containing crop code and TBS values.

validate(duration=None)

Validate the OPC data to ensure it contains a continuous range of dates without duplicates.

Parameters: duration (int, optional): Duration of the simulation in years. If None, uses the maximum Yid.

Returns: bool: True if the data is valid, False otherwise.

SIT

Methods:

Name Description
load

Class method to load the .sit file and return a SiteFile instance.

save

Save the current site information to a .SIT file.

elevation property writable

Get elevation value.

lat property writable

Get latitude value.

lon property writable

Get longitude value.

slope property writable

Get slope steep value.

load(file_path) classmethod

Class method to load the .sit file and return a SiteFile instance.

Parameters: file_path (str): Path to the .sit file.

Returns: SiteFile: An instance of the SiteFile class with loaded data.

save(output_dir)

Save the current site information to a .SIT file.

Parameters: output_dir (str): Directory where the .SIT file will be saved, or the full path including the .SIT extension.

SOL

Methods:

Name Description
from_sda

Create a Soil object from Soil Data Access using a query.

load

Load soil data from a file and return a Soil object.

save

Save the soil data to a file using a template.

from_sda(query) classmethod

Create a Soil object from Soil Data Access using a query.

Parameters:

Name Type Description Default
query int or str

Query string for SoilDataAccess. (mukey or WKT str) ( "POINT(-123.4567 45.6789)" )

required

Returns:

Name Type Description
Soil

A new Soil object populated with data from SDA.

load(filepath) classmethod

Load soil data from a file and return a Soil object.

Parameters:

Name Type Description Default
filepath str

Path to the soil file.

required

Returns:

Name Type Description
Soil

A new Soil object populated with data from the file.

save(filepath, template=None)

Save the soil data to a file using a template.

Parameters:

Name Type Description Default
filepath str

Path to save the soil file.

required
template list

Optional list of template lines.

None

Raises:

Type Description
ValueError

If soil properties DataFrame is empty.

config_parser

Classes:

Name Description
ConfigParser

ConfigParser

Methods:

Name Description
get

Retrieve a value from the configuration.

load

Load data from the YAML file.

save

Save data to the YAML file.

update

Update the current config with new values.

get(key, default=None)

Retrieve a value from the configuration.

load()

Load data from the YAML file.

save()

Save data to the YAML file.

update(updates)

Update the current config with new values.

cropcom

Classes:

Name Description
CropCom

Class for handling CROPCOM.DAT file.

CropCom

Class for handling CROPCOM.DAT file.

Methods:

Name Description
constraints

Returns the constraints (min, max ranges) for the parameters.

edit

Updates the parameters in the DataFrame with new values.

get_vars

Returns the vars DataFrame with an additional column containing current values.

save

Save DataFrame into an OPC file.

set_sensitive

Sets sensitive parameters based on a CSV path or list of parameter names.

current property

Returns the current values of parameters in the DataFrame.

constraints()

Returns the constraints (min, max ranges) for the parameters.

edit(values)

Updates the parameters in the DataFrame with new values.

get_vars()

Returns the vars DataFrame with an additional column containing current values.

save(path)

Save DataFrame into an OPC file.

set_sensitive(parms_input, crop_codes, all=False)

Sets sensitive parameters based on a CSV path or list of parameter names. If all is True, all parameters are considered sensitive.

Parameters:

Name Type Description Default
parms_input str or list

Either a CSV file path or list of parameter names to select

required
crop_codes list

List of crop codes to apply parameters to

required
all bool

If True, all parameters are considered sensitive regardless of input

False

data_logger

Classes:

Name Description
DataLogger

A class to handle logging of data using different backends: Redis, SQL, or LMDB.

LMDBTableWriter

Minimal, efficient row store with auto-increment row_id.

RedisWriter

DataLogger

A class to handle logging of data using different backends: Redis, SQL, or LMDB. It supports logging dictionaries and retrieving logged data.

Attributes:

Name Type Description
output_folder str

Directory where files are stored (if applicable).

delete_on_read bool

Whether to delete the data after retrieving it.

backend str

The backend to use ('redis', 'sql', 'lmdb').

Methods:

Name Description
get

Retrieve logged data using the specified backend.

get_writer

Get the appropriate writer based on the backend.

log_dict

Log a dictionary of results using the specified backend.

get(func_name, keep=False)

Retrieve logged data using the specified backend.

Parameters:

Name Type Description Default
func_name str

The name of the function whose data needs to be retrieved.

required
keep bool

If True, do not delete the table even if delete_on_read is True.

False

Returns:

Type Description

pandas.DataFrame: The DataFrame containing the logged data.

get_writer(func_name)

Get the appropriate writer based on the backend.

Parameters:

Name Type Description Default
func_name str

The name of the function to create a writer for.

required

Returns:

Name Type Description
Writer

An instance of the appropriate writer class.

Raises:

Type Description
ValueError

If an unsupported backend is specified.

log_dict(func_name, result)

Log a dictionary of results using the specified backend.

Parameters:

Name Type Description Default
func_name str

The name of the function to log the data for.

required
result dict

Dictionary of results to log.

required

Raises:

Type Description
ValueError

If the result is not a dictionary.

LMDBTableWriter

Minimal, efficient row store with auto-increment row_id. - write_row(row_id=None, **kwargs) -> returns the row_id (string) - read_row(row_id) -> dict or None - query_rows() -> DataFrame with row_id index - delete_table(), open(), close(), context manager

Methods:

Name Description
query_rows

Return all rows as a DataFrame with numeric-sorted row_id.

write_row

Atomically allocate/increment row ID (if None) and write the row.

query_rows()

Return all rows as a DataFrame with numeric-sorted row_id.

write_row(row_id=None, **kwargs)

Atomically allocate/increment row ID (if None) and write the row.

RedisWriter

Methods:

Name Description
close

Close the connection to Redis (flag only; redis client is pooled).

delete_table

Delete all entries associated with the table name, including the counter.

open

Establish connection to Redis and initialize counter if needed.

query_rows

Retrieve all rows from the Redis hash as a DataFrame with row_id as index.

read_row

Read a row from Redis hash.

write_row

Write a row to Redis hash under the specified table name.

close()

Close the connection to Redis (flag only; redis client is pooled).

delete_table()

Delete all entries associated with the table name, including the counter.

open()

Establish connection to Redis and initialize counter if needed.

query_rows()

Retrieve all rows from the Redis hash as a DataFrame with row_id as index.

read_row(row_id)

Read a row from Redis hash.

write_row(row_id=None, **kwargs)

Write a row to Redis hash under the specified table name.

lmdb_writer

Classes:

Name Description
LMDBTableWriter

Minimal, efficient row store with auto-increment row_id.

LMDBTableWriter

Minimal, efficient row store with auto-increment row_id. - write_row(row_id=None, **kwargs) -> returns the row_id (string) - read_row(row_id) -> dict or None - query_rows() -> DataFrame with row_id index - delete_table(), open(), close(), context manager

Methods:

Name Description
query_rows

Return all rows as a DataFrame with numeric-sorted row_id.

write_row

Atomically allocate/increment row ID (if None) and write the row.

query_rows()

Return all rows as a DataFrame with numeric-sorted row_id.

write_row(row_id=None, **kwargs)

Atomically allocate/increment row ID (if None) and write the row.

main

Classes:

Name Description
DataLogger

A class to handle logging of data using different backends: Redis, SQL, or LMDB.

DataLogger

A class to handle logging of data using different backends: Redis, SQL, or LMDB. It supports logging dictionaries and retrieving logged data.

Attributes:

Name Type Description
output_folder str

Directory where files are stored (if applicable).

delete_on_read bool

Whether to delete the data after retrieving it.

backend str

The backend to use ('redis', 'sql', 'lmdb').

Methods:

Name Description
get

Retrieve logged data using the specified backend.

get_writer

Get the appropriate writer based on the backend.

log_dict

Log a dictionary of results using the specified backend.

get(func_name, keep=False)

Retrieve logged data using the specified backend.

Parameters:

Name Type Description Default
func_name str

The name of the function whose data needs to be retrieved.

required
keep bool

If True, do not delete the table even if delete_on_read is True.

False

Returns:

Type Description

pandas.DataFrame: The DataFrame containing the logged data.

get_writer(func_name)

Get the appropriate writer based on the backend.

Parameters:

Name Type Description Default
func_name str

The name of the function to create a writer for.

required

Returns:

Name Type Description
Writer

An instance of the appropriate writer class.

Raises:

Type Description
ValueError

If an unsupported backend is specified.

log_dict(func_name, result)

Log a dictionary of results using the specified backend.

Parameters:

Name Type Description Default
func_name str

The name of the function to log the data for.

required
result dict

Dictionary of results to log.

required

Raises:

Type Description
ValueError

If the result is not a dictionary.

redis_writer

Classes:

Name Description
RedisWriter
RedisWriter

Methods:

Name Description
close

Close the connection to Redis (flag only; redis client is pooled).

delete_table

Delete all entries associated with the table name, including the counter.

open

Establish connection to Redis and initialize counter if needed.

query_rows

Retrieve all rows from the Redis hash as a DataFrame with row_id as index.

read_row

Read a row from Redis hash.

write_row

Write a row to Redis hash under the specified table name.

close()

Close the connection to Redis (flag only; redis client is pooled).

delete_table()

Delete all entries associated with the table name, including the counter.

open()

Establish connection to Redis and initialize counter if needed.

query_rows()

Retrieve all rows from the Redis hash as a DataFrame with row_id as index.

read_row(row_id)

Read a row from Redis hash.

write_row(row_id=None, **kwargs)

Write a row to Redis hash under the specified table name.

inputs

Classes:

Name Description
DLY
OPC
SIT
SOL

DLY

Bases: DataFrame

Methods:

Name Description
load

Load data from a DLY file into DataFrame.

save

Save DataFrame into a DLY file.

to_monthly

Save as monthly file

validate

Validate the DataFrame to ensure it contains a continuous range of dates

load(path) classmethod

Load data from a DLY file into DataFrame.

save(path=None)

Save DataFrame into a DLY file.

to_monthly(path=None)

Save as monthly file

validate(start_date, end_date)

Validate the DataFrame to ensure it contains a continuous range of dates between start_date and end_date, without duplicates.

OPC

Bases: DataFrame

Methods:

Name Description
append

Append another OPC or DataFrame to the current OPC instance.

edit_crop_season

Edit the planting and/or harvest dates for a given year and crop.

edit_fertilizer_rate

Edit the fertilizer rate for a given year.

edit_harvest_date

Edit the harvest date for a given year and crop.

edit_operation_date

Edit the operation date for a given year.

edit_operation_value

Edit the operation value for a given year.

edit_plantation_date

Edit the plantation date for a given year and crop.

get_harvest_date

Retrieve the harvest date(s) for a specific year and/or crop code.

get_plantation_date

Retrieve the plantation date(s) for a specific year and/or crop code.

iter_seasons

Iterate over OPC data, yielding dictionaries containing information for each growing season.

load

Load data from an OPC file into DataFrame.

new

Create a new OPC instance with an empty DataFrame with preset columns, a default header,

remove

Remove operation(s) from the OPC file that match all provided criteria.

save

Save DataFrame into an OPC file.

update

Add or update an operation in the OPC file.

update_phu

Update the OPV1 value with the calculated PHU from the DLY data for all plantation dates.

validate

Validate the OPC data to ensure it contains a continuous range of dates without duplicates.

IAUI property writable

Get the auto-irrigation implement ID from the OPC file header.

Returns:

Name Type Description
bool

True if auto-irrigation is enabled (72), False if disabled (0)

LUN property writable

Get the land use number from the OPC file header.

Returns:

Name Type Description
int

The land use number from the first 4 characters of header line 2

append(second_opc)

Append another OPC or DataFrame to the current OPC instance. Args: second_opc (pd.DataFrame or OPC): The data to append. Returns: OPC: A new OPC instance with combined data. Raises: ValueError: If second_opc is not a pandas DataFrame or OPC instance.

edit_crop_season(new_planting_date=None, new_harvest_date=None, crop_code=None)

Edit the planting and/or harvest dates for a given year and crop.

Parameters: year (int): Year. new_planting_date (datetime, optional): New planting date. If not provided, only harvest date will be updated. new_harvest_date (datetime, optional): New harvest date. If not provided, only planting date will be updated. crop_code (int, optional): Crop code. If not provided, changes the first crop found.

edit_fertilizer_rate(rate, year=2020, month=None, day=None)

Edit the fertilizer rate for a given year.

Parameters: rate (float): Fertilizer rate to be set. year (int, optional): Year for the fertilizer rate application. Defaults to 2020. month (int, optional): Month for the fertilizer rate application. If not provided, the first instance is changed. day (int, optional): Day for the fertilizer rate application. Defaults to None.

edit_harvest_date(date, crop_code)

Edit the harvest date for a given year and crop.

Parameters: date (datetime or str): Date of harvest in datetime object or 'YYYY-MM-DD' string format. crop_code (int): Crop code.

edit_operation_date(code, year, month, day, crop_code=None)

Edit the operation date for a given year.

Parameters: code (str): Operation code. year (int): Year. month (int): Month of operation. day (int): Day of operation. crop_code (int, optional): Crop code.

edit_operation_value(code, year, value, crop_code=None)

Edit the operation value for a given year.

Parameters: code (str): Operation code. year (int): Year. value (float): New operation value. crop_code (int, optional): Crop code.

edit_plantation_date(date, crop_code)

Edit the plantation date for a given year and crop.

Parameters: date (datetime or str): Date of plantation in datetime object or 'YYYY-MM-DD' string format. crop_code (int): Crop code.

get_harvest_date(year=None, crop_code=None)

Retrieve the harvest date(s) for a specific year and/or crop code.

Parameters: year (int, optional): Year. Defaults to None. crop_code (int, optional): Crop code. Defaults to None.

Returns: dict: A dictionary of crop codes and their harvest dates with row indices.

get_plantation_date(year=None, crop_code=None)

Retrieve the plantation date(s) for a specific year and/or crop code.

Parameters: year (int, optional): Year. Defaults to None. crop_code (int, optional): Crop code. Defaults to None.

Returns: dict: A dictionary of crop codes and their plantation dates with row indices.

iter_seasons(start_year=None, end_year=None)

Iterate over OPC data, yielding dictionaries containing information for each growing season.

Parameters: start_year (int, optional): The starting year to consider. Defaults to None. end_year (int, optional): The ending year to consider. Defaults to None.

dict: A dictionary containing: - plantation_date: The date of plantation - harvest_date: The date of harvest - crop_code: The crop code - operations: A subset of OPC rows for this season - plantation_index: The index of the plantation row

load(path, start_year=None) classmethod

Load data from an OPC file into DataFrame.

Parameters: path (str): Path to the OPC file. start_year (int, optional): Start year for the OPC file. If not provided, it will be read from the file header.

Returns: OPC: An instance of the OPC class containing the loaded data.

new(name, start_year) classmethod

Create a new OPC instance with an empty DataFrame with preset columns, a default header, and provided name and start year.

Parameters: name (str): The name for this OPC file/instance. start_year (int): The start year to assign in the OPC instance.

Returns: OPC: An OPC instance with no data but with the required metadata set.

remove(opID=None, date=None, cropID=None, XMTU=None, fertID=None, year=None)

Remove operation(s) from the OPC file that match all provided criteria.

Parameters:

Name Type Description Default
opID int

Operation ID to match

None
date str

Date to match in format 'YYYY-MM-DD'

None
cropID int

Crop ID to match

None
XMTU/LYR/pestID/fertID int

Machine type/layer/pesticide ID/fertilizer ID to match

required
year int

Year to match

None
save(path)

Save DataFrame into an OPC file.

Parameters: path (str): Path to save the OPC file.

update(operation)

Add or update an operation in the OPC file.

Parameters:

Name Type Description Default
operation dict

Dictionary containing operation details with keys: - opID: Operation ID (required) - cropID: Crop ID (required) - date: Operation date as string 'YYYY-MM-DD' (required) - XMTU/LYR/pestID/fertID: Machine type/years/pesticide ID/fertilizer ID (optional, default 0) - OPV1-OPV8: Additional operation values (optional, default 0)

required
update_phu(dly, cropcom)

Update the OPV1 value with the calculated PHU from the DLY data for all plantation dates.

Parameters: dly (DLY): DLY object containing weather data. cropcom (DataFrame): DataFrame containing crop code and TBS values.

validate(duration=None)

Validate the OPC data to ensure it contains a continuous range of dates without duplicates.

Parameters: duration (int, optional): Duration of the simulation in years. If None, uses the maximum Yid.

Returns: bool: True if the data is valid, False otherwise.

SIT

Methods:

Name Description
load

Class method to load the .sit file and return a SiteFile instance.

save

Save the current site information to a .SIT file.

elevation property writable

Get elevation value.

lat property writable

Get latitude value.

lon property writable

Get longitude value.

slope property writable

Get slope steep value.

load(file_path) classmethod

Class method to load the .sit file and return a SiteFile instance.

Parameters: file_path (str): Path to the .sit file.

Returns: SiteFile: An instance of the SiteFile class with loaded data.

save(output_dir)

Save the current site information to a .SIT file.

Parameters: output_dir (str): Directory where the .SIT file will be saved, or the full path including the .SIT extension.

SOL

Methods:

Name Description
from_sda

Create a Soil object from Soil Data Access using a query.

load

Load soil data from a file and return a Soil object.

save

Save the soil data to a file using a template.

from_sda(query) classmethod

Create a Soil object from Soil Data Access using a query.

Parameters:

Name Type Description Default
query int or str

Query string for SoilDataAccess. (mukey or WKT str) ( "POINT(-123.4567 45.6789)" )

required

Returns:

Name Type Description
Soil

A new Soil object populated with data from SDA.

load(filepath) classmethod

Load soil data from a file and return a Soil object.

Parameters:

Name Type Description Default
filepath str

Path to the soil file.

required

Returns:

Name Type Description
Soil

A new Soil object populated with data from the file.

save(filepath, template=None)

Save the soil data to a file using a template.

Parameters:

Name Type Description Default
filepath str

Path to save the soil file.

required
template list

Optional list of template lines.

None

Raises:

Type Description
ValueError

If soil properties DataFrame is empty.

dly

Classes:

Name Description
DLY
DLY

Bases: DataFrame

Methods:

Name Description
load

Load data from a DLY file into DataFrame.

save

Save DataFrame into a DLY file.

to_monthly

Save as monthly file

validate

Validate the DataFrame to ensure it contains a continuous range of dates

load(path) classmethod

Load data from a DLY file into DataFrame.

save(path=None)

Save DataFrame into a DLY file.

to_monthly(path=None)

Save as monthly file

validate(start_date, end_date)

Validate the DataFrame to ensure it contains a continuous range of dates between start_date and end_date, without duplicates.

opc

Classes:

Name Description
OPC
OPC

Bases: DataFrame

Methods:

Name Description
append

Append another OPC or DataFrame to the current OPC instance.

edit_crop_season

Edit the planting and/or harvest dates for a given year and crop.

edit_fertilizer_rate

Edit the fertilizer rate for a given year.

edit_harvest_date

Edit the harvest date for a given year and crop.

edit_operation_date

Edit the operation date for a given year.

edit_operation_value

Edit the operation value for a given year.

edit_plantation_date

Edit the plantation date for a given year and crop.

get_harvest_date

Retrieve the harvest date(s) for a specific year and/or crop code.

get_plantation_date

Retrieve the plantation date(s) for a specific year and/or crop code.

iter_seasons

Iterate over OPC data, yielding dictionaries containing information for each growing season.

load

Load data from an OPC file into DataFrame.

new

Create a new OPC instance with an empty DataFrame with preset columns, a default header,

remove

Remove operation(s) from the OPC file that match all provided criteria.

save

Save DataFrame into an OPC file.

update

Add or update an operation in the OPC file.

update_phu

Update the OPV1 value with the calculated PHU from the DLY data for all plantation dates.

validate

Validate the OPC data to ensure it contains a continuous range of dates without duplicates.

IAUI property writable

Get the auto-irrigation implement ID from the OPC file header.

Returns:

Name Type Description
bool

True if auto-irrigation is enabled (72), False if disabled (0)

LUN property writable

Get the land use number from the OPC file header.

Returns:

Name Type Description
int

The land use number from the first 4 characters of header line 2

append(second_opc)

Append another OPC or DataFrame to the current OPC instance. Args: second_opc (pd.DataFrame or OPC): The data to append. Returns: OPC: A new OPC instance with combined data. Raises: ValueError: If second_opc is not a pandas DataFrame or OPC instance.

edit_crop_season(new_planting_date=None, new_harvest_date=None, crop_code=None)

Edit the planting and/or harvest dates for a given year and crop.

Parameters: year (int): Year. new_planting_date (datetime, optional): New planting date. If not provided, only harvest date will be updated. new_harvest_date (datetime, optional): New harvest date. If not provided, only planting date will be updated. crop_code (int, optional): Crop code. If not provided, changes the first crop found.

edit_fertilizer_rate(rate, year=2020, month=None, day=None)

Edit the fertilizer rate for a given year.

Parameters: rate (float): Fertilizer rate to be set. year (int, optional): Year for the fertilizer rate application. Defaults to 2020. month (int, optional): Month for the fertilizer rate application. If not provided, the first instance is changed. day (int, optional): Day for the fertilizer rate application. Defaults to None.

edit_harvest_date(date, crop_code)

Edit the harvest date for a given year and crop.

Parameters: date (datetime or str): Date of harvest in datetime object or 'YYYY-MM-DD' string format. crop_code (int): Crop code.

edit_operation_date(code, year, month, day, crop_code=None)

Edit the operation date for a given year.

Parameters: code (str): Operation code. year (int): Year. month (int): Month of operation. day (int): Day of operation. crop_code (int, optional): Crop code.

edit_operation_value(code, year, value, crop_code=None)

Edit the operation value for a given year.

Parameters: code (str): Operation code. year (int): Year. value (float): New operation value. crop_code (int, optional): Crop code.

edit_plantation_date(date, crop_code)

Edit the plantation date for a given year and crop.

Parameters: date (datetime or str): Date of plantation in datetime object or 'YYYY-MM-DD' string format. crop_code (int): Crop code.

get_harvest_date(year=None, crop_code=None)

Retrieve the harvest date(s) for a specific year and/or crop code.

Parameters: year (int, optional): Year. Defaults to None. crop_code (int, optional): Crop code. Defaults to None.

Returns: dict: A dictionary of crop codes and their harvest dates with row indices.

get_plantation_date(year=None, crop_code=None)

Retrieve the plantation date(s) for a specific year and/or crop code.

Parameters: year (int, optional): Year. Defaults to None. crop_code (int, optional): Crop code. Defaults to None.

Returns: dict: A dictionary of crop codes and their plantation dates with row indices.

iter_seasons(start_year=None, end_year=None)

Iterate over OPC data, yielding dictionaries containing information for each growing season.

Parameters: start_year (int, optional): The starting year to consider. Defaults to None. end_year (int, optional): The ending year to consider. Defaults to None.

dict: A dictionary containing: - plantation_date: The date of plantation - harvest_date: The date of harvest - crop_code: The crop code - operations: A subset of OPC rows for this season - plantation_index: The index of the plantation row

load(path, start_year=None) classmethod

Load data from an OPC file into DataFrame.

Parameters: path (str): Path to the OPC file. start_year (int, optional): Start year for the OPC file. If not provided, it will be read from the file header.

Returns: OPC: An instance of the OPC class containing the loaded data.

new(name, start_year) classmethod

Create a new OPC instance with an empty DataFrame with preset columns, a default header, and provided name and start year.

Parameters: name (str): The name for this OPC file/instance. start_year (int): The start year to assign in the OPC instance.

Returns: OPC: An OPC instance with no data but with the required metadata set.

remove(opID=None, date=None, cropID=None, XMTU=None, fertID=None, year=None)

Remove operation(s) from the OPC file that match all provided criteria.

Parameters:

Name Type Description Default
opID int

Operation ID to match

None
date str

Date to match in format 'YYYY-MM-DD'

None
cropID int

Crop ID to match

None
XMTU/LYR/pestID/fertID int

Machine type/layer/pesticide ID/fertilizer ID to match

required
year int

Year to match

None
save(path)

Save DataFrame into an OPC file.

Parameters: path (str): Path to save the OPC file.

update(operation)

Add or update an operation in the OPC file.

Parameters:

Name Type Description Default
operation dict

Dictionary containing operation details with keys: - opID: Operation ID (required) - cropID: Crop ID (required) - date: Operation date as string 'YYYY-MM-DD' (required) - XMTU/LYR/pestID/fertID: Machine type/years/pesticide ID/fertilizer ID (optional, default 0) - OPV1-OPV8: Additional operation values (optional, default 0)

required
update_phu(dly, cropcom)

Update the OPV1 value with the calculated PHU from the DLY data for all plantation dates.

Parameters: dly (DLY): DLY object containing weather data. cropcom (DataFrame): DataFrame containing crop code and TBS values.

validate(duration=None)

Validate the OPC data to ensure it contains a continuous range of dates without duplicates.

Parameters: duration (int, optional): Duration of the simulation in years. If None, uses the maximum Yid.

Returns: bool: True if the data is valid, False otherwise.

sit

Classes:

Name Description
SIT
SIT

Methods:

Name Description
load

Class method to load the .sit file and return a SiteFile instance.

save

Save the current site information to a .SIT file.

elevation property writable

Get elevation value.

lat property writable

Get latitude value.

lon property writable

Get longitude value.

slope property writable

Get slope steep value.

load(file_path) classmethod

Class method to load the .sit file and return a SiteFile instance.

Parameters: file_path (str): Path to the .sit file.

Returns: SiteFile: An instance of the SiteFile class with loaded data.

save(output_dir)

Save the current site information to a .SIT file.

Parameters: output_dir (str): Directory where the .SIT file will be saved, or the full path including the .SIT extension.

sol

Classes:

Name Description
SOL
SOL

Methods:

Name Description
from_sda

Create a Soil object from Soil Data Access using a query.

load

Load soil data from a file and return a Soil object.

save

Save the soil data to a file using a template.

from_sda(query) classmethod

Create a Soil object from Soil Data Access using a query.

Parameters:

Name Type Description Default
query int or str

Query string for SoilDataAccess. (mukey or WKT str) ( "POINT(-123.4567 45.6789)" )

required

Returns:

Name Type Description
Soil

A new Soil object populated with data from SDA.

load(filepath) classmethod

Load soil data from a file and return a Soil object.

Parameters:

Name Type Description Default
filepath str

Path to the soil file.

required

Returns:

Name Type Description
Soil

A new Soil object populated with data from the file.

save(filepath, template=None)

Save the soil data to a file using a template.

Parameters:

Name Type Description Default
filepath str

Path to save the soil file.

required
template list

Optional list of template lines.

None

Raises:

Type Description
ValueError

If soil properties DataFrame is empty.

outputs

Classes:

Name Description
ACY
DGN
DSL
DWC

ACY

Methods:

Name Description
get_var

Extract variable from the ACY data.

get_var(varname)

Extract variable from the ACY data.

DGN

Methods:

Name Description
get_var

Extract variable from the DGN data.

get_var(varname)

Extract variable from the DGN data.

DSL

Methods:

Name Description
get_data

Return stored water data.

get_data()

Return stored water data.

DWC

Methods:

Name Description
get_var

Extract variable from the DWC data.

get_var(varname)

Extract variable from the DWC data.

all

Classes:

Name Description
ACY
DGN
DWC
ACY

Methods:

Name Description
get_var

Extract variable from the ACY data.

get_var(varname)

Extract variable from the ACY data.

DGN

Methods:

Name Description
get_var

Extract variable from the DGN data.

get_var(varname)

Extract variable from the DGN data.

DWC

Methods:

Name Description
get_var

Extract variable from the DWC data.

get_var(varname)

Extract variable from the DWC data.

sw

Classes:

Name Description
DSL
DSL

Methods:

Name Description
get_data

Return stored water data.

get_data()

Return stored water data.

parm

Classes:

Name Description
Parm

Parm

Methods:

Name Description
constraints

Returns the constraints (min, max ranges) for the parameters.

edit

Updates the parameters in the DataFrame with new values.

get_vars

Returns the vars DataFrame with an additional column containing current values.

read_parm

Reads and constructs a DataFrame from a .DAT file.

save

Saves the current DataFrame to a .DAT file.

set_sensitive

Sets sensitive parameters based on a CSV path or list of parameter names.

current property

Returns the current values of parameters in the DataFrame.

constraints()

Returns the constraints (min, max ranges) for the parameters.

edit(values)

Updates the parameters in the DataFrame with new values.

get_vars()

Returns the vars DataFrame with an additional column containing current values.

read_parm(file_name)

Reads and constructs a DataFrame from a .DAT file.

save(path)

Saves the current DataFrame to a .DAT file.

set_sensitive(parms_input, all=False)

Sets sensitive parameters based on a CSV path or list of parameter names. If all is True, all parameters are considered sensitive.

Parameters:

Name Type Description Default
parms_input str or list

Either a CSV file path or list of parameter names to select

required
all bool

If True, all parameters are considered sensitive regardless of input

False