AguaClara / aguaclara_research

a python package containing research tools for AguaClara
MIT License
1 stars 4 forks source link

missing functions #3

Closed monroews closed 6 years ago

monroews commented 6 years ago

The following functions are missing from Environmental_Processes_Analysis Perhaps eliminate the filedialog.askdirectory() since it seems that code doesn't work on Macs. Instead pass the function the directory path.

def aeration_data(DO_column): """ This function extracts the data from folder containing tab delimited files of aeration data. The file must be the original tab delimited file. All text strings below the header must be removed from these files. The file names must be the air flow rates with units of micromoles/s. An example file name would be "300.xls" where 300 is the flowr ate in micromoles/s The function opens a file dialog for the user to select the directory containing the data.

Parameters
----------
DO_column: index of the column that contains the dissolved oxygen concentration data.

Returns
-------
filepaths: list of all file paths in the directory sorted by flow rate
airflows: sorted numpy array of air flow rates with units of micromole/s attached
DO_data: sorted list of numpy arrays. Thus each of the numpy data arrays can have different lengths to accommodate short and long experiments
time_data: sorted list of numpy arrays containing the times with units of seconds. Each
"""

dirpath = filedialog.askdirectory()
#return the list of files in the directory
filenames = os.listdir(dirpath)
#extract the flowrates from the filenames and apply units
airflows=((np.array([i.split('.', 1)[0] for i in filenames])).astype(np.float32))
#sort airflows and filenames so that they are in ascending order of flow rates
idx   = np.argsort(airflows)
airflows = (np.array(airflows)[idx])*u.umole/u.s
filenames = np.array(filenames)[idx]

filepaths = [os.path.join(dirpath, i) for i in filenames]
#DO_data is a list of numpy arrays. Thus each of the numpy data arrays can have different lengths to accommodate short and long experiments
# cycle through all of the files and extract the column of data with oxygen concentrations and the times
DO_data=[Column_of_data(i,0,-1,DO_column,'mg/L') for i in filepaths]
time_data=[(ftime(i,0,-1)).to(u.s) for i in filepaths]
aeration_collection = collections.namedtuple('aeration_results','filepaths airflows DO_data time_data')
aeration_results = aeration_collection(filepaths, airflows, DO_data, time_data)
return aeration_results

def O2_sat(Pressure_air,Temperature): """ This equation is valid for 278 K < T < 318 K

Parameters
----------
Pressure_air: air pressure with appropriate units.
Temperature: water temperature with appropriate units

Returns
-------
Saturated oxygen concentration in mg/L
"""
fraction_O2 = 0.21
Pressure_O2 = Pressure_air *fraction_O2
return (Pressure_O2.to(u.atm).magnitude)*u.mg/u.L*np.exp(1727/Temperature.to(u.K).magnitude - 2.105)

def Gran(data_file_path): """ This function extracts the data from a ProCoDA Gran plot file. The file must be the original tab delimited file.

Parameters
----------
data_file_path : string of the file name or file path.
If the file is in the working directory, then the file name is sufficient.
Example data_file_path = 'Reactor_data.txt'

Returns
-------
V_titrant (mL) as numpy array
ph_data as numpy array (no units)
V_sample (mL) volume of the original sample that was titrated
Normality_titrant (mole/L) normality of the acid used to titrate the sample
V_equivalent (mL) volume of acid required to consume all of the ANC
ANC (mole/L) Acid Neutralizing Capacity of the sample

"""
df = pd.read_csv(data_file_path,delimiter='\t',header=5)
V_t = np.array(pd.to_numeric(df.iloc[0:,0]))*u.mL
pH = np.array(pd.to_numeric(df.iloc[0:,1]))
df = pd.read_csv(data_file_path,delimiter='\t',header=-1,nrows=5)
V_S = pd.to_numeric(df.iloc[0,1])*u.mL
N_t = pd.to_numeric(df.iloc[1,1])*u.mole/u.L
V_eq = pd.to_numeric(df.iloc[2,1])*u.mL
ANC_sample = pd.to_numeric(df.iloc[3,1])*u.mole/u.L
Gran_collection = collections.namedtuple('Gran_results','V_titrant ph_data V_sample Normality_titrant V_equivalent ANC')
Gran = Gran_collection(V_titrant=V_t, ph_data=pH,V_sample=V_S, Normality_titrant=N_t, V_equivalent=V_eq, ANC=ANC_sample )
return Gran;
fletchapin commented 6 years ago

@monroews I'll begin working on adding those in today. We were probably working off an old version of EPA and didn't add the functions in you created once it was copied into aguaclara_research from the 4530 repo

fletchapin commented 6 years ago

These functions have been added to aguaclara_research v1.0.2