smp_utils
PEST-style site sample (smp) file support utilities
dataframe_to_smp(dataframe, smp_filename, name_col='name', datetime_col='datetime', value_col='value', datetime_format='dd/mm/yyyy', value_format='{0:15.6E}', max_name_len=12)
write a dataframe as an smp file
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
dataframe
|
`pandas.DataFrame`
|
the dataframe to write to an SMP file. This dataframe should be in "long" form - columns for site name, datetime, and value. |
required |
smp_filename
|
`str`
|
smp file to write |
required |
name_col
|
`str`,optional
|
the name of the dataframe column that contains the site name. Default is "name" |
'name'
|
datetime_col
|
`str`
|
the column in the dataframe that the datetime values. Default is "datetime". |
'datetime'
|
value_col
|
`str`
|
the column in the dataframe that is the values |
'value'
|
datetime_format
|
`str`
|
The format to write the datetimes in the smp file. Can be either 'dd/mm/yyyy' or 'mm/dd/yyy'. Default is 'dd/mm/yyyy'. |
'dd/mm/yyyy'
|
value_format
|
`str`
|
a python float-compatible format. Default is "{0:15.6E}". |
'{0:15.6E}'
|
Example::
pyemu.smp_utils.dataframe_to_smp(df,"my.smp")
smp_to_dataframe(smp_filename, datetime_format=None)
load an smp file into a pandas dataframe
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
smp_filename
|
`str`
|
path and name of existing smp filename to load |
required |
datetime_format
|
`str`
|
The format of the datetime strings in the smp file. Can be either "%m/%d/%Y %H:%M:%S" or "%d/%m/%Y %H:%M:%S" If None, then we will try to deduce the format for you, which always dangerous. |
None
|
Returns:
| Type | Description |
|---|---|
|
|
|
|
site names. Missing values are set to NaN. |
Example::
df = smp_to_dataframe("my.smp")
smp_to_ins(smp_filename, ins_filename=None, use_generic_names=False, gwutils_compliant=False, datetime_format=None, prefix='')
create an instruction file for an smp file
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
smp_filename
|
`str`
|
path and name of an existing smp file |
required |
ins_filename
|
`str`
|
the name of the instruction
file to create. If None, |
None
|
use_generic_names
|
`bool`
|
flag to force observations names
to use a generic |
False
|
gwutils_compliant
|
`bool`
|
flag to use instruction set that is compliant with the PEST gw utils (fixed format instructions). If false, use free format (with whitespace) instruction set. Default is False |
False
|
datetime_format
|
`str`
|
string to pass to datetime.strptime in
the |
None
|
prefix
|
`str`
|
a prefix to add to the front of the derived observation names. Default is '' |
''
|
Returns:
| Type | Description |
|---|---|
|
|
|
|
information with the observation names and |
|
|
instruction lines as additional columns. |
Example::
df = pyemu.smp_utils.smp_to_ins("my.smp")