IO Module
io
Classes:
Name | Description |
---|---|
ACM |
|
ACY |
|
DCS |
|
DGN |
|
DLY |
|
DSL |
|
DTP |
|
DWC |
|
OPC |
|
SIT |
|
SOL |
|
ACM
Methods:
Name | Description |
---|---|
get_var |
Extract variable from the ACM data. |
get_var(varname)
Extract variable from the ACM data.
ACY
Methods:
Name | Description |
---|---|
get_var |
Extract variable from the ACY data. |
get_var(varname)
Extract variable from the ACY data.
DCS
Methods:
Name | Description |
---|---|
get_var |
Extract variable from the DCS data. |
get_var(varname)
Extract variable from the DCS 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
DTP
Methods:
Name | Description |
---|---|
get_var |
Extract variable from the DTP data. |
get_var(varname)
Extract variable from the DTP 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. |
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. |
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. |
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(year, month, day, crop_code)
Edit the harvest date for a given year.
Parameters: year (int): Year. month (int): Month of harvest. day (int): Day of harvest. crop_code (int, optional): 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(year, month, day, crop_code)
Edit the plantation date for a given year and crop.
Parameters: year (int): Year. month (int): Month of plantation. day (int): Day of plantation. 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.
remove(opID=None, date=None, cropID=None, XMTU=None, fertID=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 |
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.
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. |
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) |
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. |
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.
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 |
---|---|
CSVWriter |
|
DataLogger |
A class to handle logging of data using different backends: Redis, CSV, or SQL. |
RedisWriter |
|
CSVWriter
Methods:
Name | Description |
---|---|
close |
Close the CSV file and release lock. |
delete_table |
Delete the CSV file. |
open |
Open the CSV file in the specified mode and lock it for exclusive access. |
query_rows |
Retrieve all rows from the CSV file. |
write_row |
Write a row to the CSV file. |
close()
Close the CSV file and release lock.
delete_table()
Delete the CSV file.
open(mode=None)
Open the CSV file in the specified mode and lock it for exclusive access.
query_rows()
Retrieve all rows from the CSV file.
Returns:
Type | Description |
---|---|
pandas.DataFrame: The DataFrame containing all rows. |
write_row(*args, **kwargs)
Write a row to the CSV file.
DataLogger
A class to handle logging of data using different backends: Redis, CSV, or SQL. 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', 'csv', 'sql'). |
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)
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 |
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. |
RedisWriter
Methods:
Name | Description |
---|---|
close |
Close the connection to Redis. |
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. |
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.
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.
Returns:
Type | Description |
---|---|
pandas.DataFrame: A DataFrame containing all rows, including row_ids. |
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.
csv_writer
Classes:
Name | Description |
---|---|
CSVWriter |
|
CSVWriter
Methods:
Name | Description |
---|---|
close |
Close the CSV file and release lock. |
delete_table |
Delete the CSV file. |
open |
Open the CSV file in the specified mode and lock it for exclusive access. |
query_rows |
Retrieve all rows from the CSV file. |
write_row |
Write a row to the CSV file. |
close()
Close the CSV file and release lock.
delete_table()
Delete the CSV file.
open(mode=None)
Open the CSV file in the specified mode and lock it for exclusive access.
query_rows()
Retrieve all rows from the CSV file.
Returns:
Type | Description |
---|---|
pandas.DataFrame: The DataFrame containing all rows. |
write_row(*args, **kwargs)
Write a row to the CSV file.
main
Classes:
Name | Description |
---|---|
DataLogger |
A class to handle logging of data using different backends: Redis, CSV, or SQL. |
DataLogger
A class to handle logging of data using different backends: Redis, CSV, or SQL. 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', 'csv', 'sql'). |
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)
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 |
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. |
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. |
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.
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.
Returns:
Type | Description |
---|---|
pandas.DataFrame: A DataFrame containing all rows, including row_ids. |
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. |
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. |
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. |
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(year, month, day, crop_code)
Edit the harvest date for a given year.
Parameters: year (int): Year. month (int): Month of harvest. day (int): Day of harvest. crop_code (int, optional): 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(year, month, day, crop_code)
Edit the plantation date for a given year and crop.
Parameters: year (int): Year. month (int): Month of plantation. day (int): Day of plantation. 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.
remove(opID=None, date=None, cropID=None, XMTU=None, fertID=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 |
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.
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. |
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) |
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. |
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. |
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. |
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(year, month, day, crop_code)
Edit the harvest date for a given year.
Parameters: year (int): Year. month (int): Month of harvest. day (int): Day of harvest. crop_code (int, optional): 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(year, month, day, crop_code)
Edit the plantation date for a given year and crop.
Parameters: year (int): Year. month (int): Month of plantation. day (int): Day of plantation. 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.
remove(opID=None, date=None, cropID=None, XMTU=None, fertID=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 |
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.
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. |
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) |
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 |
---|---|
ACM |
|
ACY |
|
DCS |
|
DGN |
|
DSL |
|
DTP |
|
DWC |
|
ACM
Methods:
Name | Description |
---|---|
get_var |
Extract variable from the ACM data. |
get_var(varname)
Extract variable from the ACM data.
ACY
Methods:
Name | Description |
---|---|
get_var |
Extract variable from the ACY data. |
get_var(varname)
Extract variable from the ACY data.
DCS
Methods:
Name | Description |
---|---|
get_var |
Extract variable from the DCS data. |
get_var(varname)
Extract variable from the DCS data.
DGN
Methods:
Name | Description |
---|---|
get_var |
Extract variable from the DGN data. |
get_var(varname)
Extract variable from the DGN data.
DSL
DTP
Methods:
Name | Description |
---|---|
get_var |
Extract variable from the DTP data. |
get_var(varname)
Extract variable from the DTP 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 |
---|---|
ACM |
|
ACY |
|
DCS |
|
DGN |
|
DTP |
|
DWC |
|
ACM
Methods:
Name | Description |
---|---|
get_var |
Extract variable from the ACM data. |
get_var(varname)
Extract variable from the ACM data.
ACY
Methods:
Name | Description |
---|---|
get_var |
Extract variable from the ACY data. |
get_var(varname)
Extract variable from the ACY data.
DCS
Methods:
Name | Description |
---|---|
get_var |
Extract variable from the DCS data. |
get_var(varname)
Extract variable from the DCS data.
DGN
Methods:
Name | Description |
---|---|
get_var |
Extract variable from the DGN data. |
get_var(varname)
Extract variable from the DGN data.
DTP
Methods:
Name | Description |
---|---|
get_var |
Extract variable from the DTP data. |
get_var(varname)
Extract variable from the DTP data.
DWC
Methods:
Name | Description |
---|---|
get_var |
Extract variable from the DWC data. |
get_var(varname)
Extract variable from the DWC 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. |
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.
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
|