diff --git a/SDG_FORLOOP_WITHTRYCATCH_TEMPLATE.PY b/SDG_FORLOOP_WITHTRYCATCH_TEMPLATE.PY index 707c4ec..f93659d 100644 --- a/SDG_FORLOOP_WITHTRYCATCH_TEMPLATE.PY +++ b/SDG_FORLOOP_WITHTRYCATCH_TEMPLATE.PY @@ -1,3 +1,5 @@ +from testing import outputDF, externalLabData + for x in range(len(outputDF['waterSampleID'])): # print(x) # FOR DEMO @@ -29,3 +31,4 @@ for x in range(len(outputDF['waterSampleID'])): except Exception: pass + diff --git a/format_sdg.py b/format_sdg.py index ffb0b25..fc14344 100644 --- a/format_sdg.py +++ b/format_sdg.py @@ -92,32 +92,6 @@ def def_format_sdg(data_dir = os.getcwd() + '/NEON_dissolved-gases-surfacewater. print("Found: " + outputDF.columns[k]) outputDF.iloc[:,k] = fieldDataProc.loc[:,fieldDataProc.columns == outputDF.columns[k]] - # outputDF.values[k, :] = 0 - #fieldDataProc.values[fieldDataProc.columns == outputDF.columns[k]] - #outputDF.columns[k] = fieldDataProc[fieldDataProc.columns == outputDF.columns[k]] - #print(outputDF.columns[k]) - # shared_columns_fdp = fieldDataProc.columns[k] - # values_fdp = fieldDataProc.values - # print(shared_columns_fdp) - # print(values_fdp) - - #shared_columns_odf = outputDF.columns[k] - #values_odf = outputDF.values - - #outputDF.values[k] = fieldDataProc.values[fieldDataProc.columns[k] == outputDF.columns[k]] - # print(fieldDataProc.columns) - # print(fieldDataProc.values[k]) - # print(len(outputDF)) - #print(fieldDataProc.columns[k]) - #print(fieldDataProc.values[k]) - - - #fieldDataProc.loc[outputDF.columns[k]] - #print(fieldDataProc.values[fieldDataProc.columns == outputDF.columns[k]]) - #outputDF[k] = fieldDataProc[fieldDataProc.columns == outputDF.columns[k]] - - - outputDF['headspaceTemp'] = fieldDataProc['storageWaterTemp'] outputDF['barometricPressure'] = fieldDataProc['ptBarometricPressure'] @@ -129,39 +103,37 @@ def def_format_sdg(data_dir = os.getcwd() + '/NEON_dissolved-gases-surfacewater. #externalLabData = np.array(outputDF) #Populate the output file with external lab data - for x in range(len(outputDF['waterSampleID'])): + for l in range(len(outputDF['waterSampleID'])): + try: + outputDF.loc[outputDF.index[[l]], 'concentrationCO2Air'] = externalLabData.loc[externalLabData.loc[:, 'sampleID'] == outputDF.loc[outputDF.index[[l]], 'referenceAirSampleID'].item(), 'concentrationCO2'].item() + outputDF.loc[outputDF.index[[l]], 'concentrationCO2Gas'] = externalLabData.loc[externalLabData.loc[:, 'sampleID'] == outputDF.loc[outputDF.index[[l]], 'equilibratedAirSampleID'].item(), 'concentrationCO2'].item() + + except Exception: + pass + try: + outputDF.loc[outputDF.index[[l]], 'concentrationCH4Air'] = externalLabData.loc[externalLabData.loc[:, 'sampleID'] == outputDF.loc[outputDF.index[[l]], 'referenceAirSampleID'].item(), 'concentrationCH4'].item() + outputDF.loc[outputDF.index[[x]], 'concentrationCH4Gas'] = externalLabData.loc[ externalLabData.loc[:, 'sampleID'] == outputDF.loc[outputDF.index[[l]], 'equilibratedAirSampleID'].item(), 'concentrationCH4'].item() + + except Exception: + pass + try: - # working code - #outputDF.loc[outputDF.index[[x]], 'concentrationCO2Air'] = externalLabData.loc[:, 'concentrationCO2'] - #fieldDataProc.loc[:, fieldDataProc.columns == outputDF.columns[k]] - outputDF.loc[outputDF.index[[x]], 'concentrationCO2Air'] = externalLabData.loc[[externalLabData['sampleID'] == outputDF.loc[outputDF.index[[x]], 'referenceAirSampleID']], 'concentrationCO2'] - #outputDF['concentrationCO2Gas'].loc[:,(x)] = 0 - #outputDF['concentrationCO2Air'][x] = externalLabData[:, 'concentrationCO2'][externalLabData['sampleID'] == outputDF['referenceAirSampleID'][x]] - #outputDF['concentrationCO2Gas'][x] = externalLabData[:, 'concentrationCO2'][externalLabData['sampleID'] == outputDF['equilibratedAirSampleID'][x]] - except NameError: + outputDF.loc[outputDF.index[[l]], 'concentrationN2OAir'] = externalLabData.loc[externalLabData.loc[:, 'sampleID'] == outputDF.loc[outputDF.index[[l]], 'referenceAirSampleID'].item(), 'concentrationN2O'].item() + outputDF.loc[outputDF.index[[l]], 'concentrationN2OGas'] = externalLabData.loc[externalLabData.loc[:, 'sampleID'] == outputDF.loc[outputDF.index[[l]], 'equilibratedAirSampleID'].item(), 'concentrationN2O'].item() + except Exception: pass - # try: - # outputDF['concentrationCH4Air'][x] = externalLabData['concentrationCH4'][externalLabData['sampleID'] == outputDF['referenceAirSampleID'][x]] - # outputDF['concentrationCH4Gas'][x] = externalLabData['concentrationCH4'][externalLabData['sampleID'] == outputDF['equilibratedAirSampleID'][x]] - # except NameError: - # pass - - # try: - # outputDF['concentrationN2OAir'][x] = externalLabData['concentrationN2O'][externalLabData['sampleID'] == outputDF['referenceAirSampleID'][x]] - # outputDF['concentrationN2OGas'][x] = externalLabData['concentrationN2O'][externalLabData['sampleID'] == outputDF['equilibratedAirSampleID'][x]] - # except NameError: - # pass #Populate the output file with water temperature data for streams - #for m in range(len(outputDF['waterSampleID'])): - # try: - # outputDF['waterTemp'][m] = fieldSuperParent['waterTemp'][fieldSuperParent['parentSampleID'] == outputDF['waterSampleID'][m]] - # except NameError: - # if outputDF['headspaceTemp'][m].isna() is True: - # try: - # outputDF['headspaceTemp'][m] = fieldSuperParent['waterTemp'][fieldSuperParent['parentSampleID'] == outputDF['waterSampleID'][m]] - # except NameError: - # pass + for m in range(len(outputDF['waterSampleID'])): + try: + outputDF.loc[outputDF.index[[m]], 'waterTemp'] = fieldSuperParent.loc[fieldSuperParent.loc[:, 'parentSampleID'] == outputDF.loc[outputDF.index[[m]], 'waterSampleID'].item(), 'waterTemp'].item() + except Exception: + pass + if pd.isna(outputDF['headspaceTemp'][m]) is True: + try: + outputDF.loc[outputDF.index[[m]], 'headspaceTemp'] = fieldSuperParent.loc[fieldSuperParent.loc[:, 'parentSampleID'] == outputDF.loc[outputDF.index[[m]], 'waterSampleID'].item(), 'waterTemp'].item() + except Exception: + pass #Flag values below detection (TBD) print("**********************************************************************")