Skip to content

Commit 9929ad8

Browse files
committed
pandas parser refactor
1 parent 69d6f16 commit 9929ad8

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

pyspecchio/parser_pandas.py

+17-16
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,6 @@
1212
import pandas as pd
1313

1414

15-
DATADIR = "/home/dav/SPECCHIO-QGIS-python/DATA/"
16-
#DATADIR = "/home/dvalters/Projects/SPECCHIO/DATA/"
17-
18-
TEST_PRN_DIR = ("/home/dav/SPECCHIO-QGIS-python/DATA/ES/field_scale/"
19-
"ES_F1_2017/plot_scale_data/LAI/")
20-
#TEST_PRN_DIR = ("/home/dvalters/Projects/SPECCHIO/DATA/ES/field_scale/"
21-
# "ES_F1_2017/plot_scale_data/LAI/")
22-
23-
24-
2515
dataframes = {}
2616

2717
# Names of soil sheets in the Soils directory
@@ -38,8 +28,8 @@ def file_and_dict_name(dirname, fname):
3828
return (filefullname, dictname)
3929

4030

41-
def extract_dataframes():
42-
for (dirname, subdirs, files) in os.walk(DATADIR):
31+
def extract_dataframes(directory):
32+
for (dirname, subdirs, files) in os.walk(directory):
4333
# print('[' + dirname + ']')
4434
for fname in files:
4535
# Only match "xlsx" files, exclude recovery/backup files
@@ -116,6 +106,17 @@ class PRNdata(object):
116106

117107

118108
class TestParser(unittest.TestCase):
109+
110+
#DATADIR = "/home/dav/SPECCHIO-QGIS-python/DATA/"
111+
#DATADIR = "/home/dvalters/Projects/SPECCHIO/DATA/"
112+
DATADIR = "/home/centos/Python/test/DATA/"
113+
114+
#TEST_PRN_DIR = ("/home/dav/SPECCHIO-QGIS-python/DATA/ES/field_scale/"
115+
# "ES_F1_2017/plot_scale_data/LAI/")
116+
#TEST_PRN_DIR = ("/home/dvalters/Projects/SPECCHIO/DATA/ES/field_scale/"
117+
# "ES_F1_2017/plot_scale_data/LAI/")
118+
TEST_PRN_DIR = ("/home/centos/Python/test/DATA/ES/field_scale/"
119+
"ES_F1_2017/plot_scale_data/LAI/")
119120

120121
def test_correct_files_parsed(self):
121122

@@ -128,27 +129,27 @@ def test_correct_files_parsed(self):
128129

129130
def test_PRN_parsing_columns(self):
130131
"""PRN data should have nine columns if correctly ingested"""
131-
filefullname = TEST_PRN_DIR + "20170714_LAI.PRN"
132+
filefullname = self.TEST_PRN_DIR + "20170714_LAI.PRN"
132133
extract_PRN_format(filefullname, "TEST_PRN_dict")
133134
self.assertEqual(len(dataframes['TEST_PRN_dict'].columns), 9)
134135

135136
def test_PRN_parsing_rows(self):
136137
"""PRN data should have 261 rows if correctly ingested"""
137-
filefullname = TEST_PRN_DIR + "20170714_LAI.PRN"
138+
filefullname = self.TEST_PRN_DIR + "20170714_LAI.PRN"
138139
extract_PRN_format(filefullname, "TEST_PRN_dict")
139140
self.assertEqual(len(dataframes['TEST_PRN_dict']), 261)
140141

141142
def test_PRN_line(self):
142143
"""Test a line has been correctly parsed"""
143-
filefullname = TEST_PRN_DIR + "20170714_LAI.PRN"
144+
filefullname = self.TEST_PRN_DIR + "20170714_LAI.PRN"
144145
extract_PRN_format(filefullname, "TEST_PRN_dict")
145146

146147
df_line = dataframes['TEST_PRN_dict'].loc[0]
147148

148149
def test_generate_PRN_lines(self):
149150
"""Test that we can strip and print the PRN text file lines.
150151
Print statement around next() is removed now."""
151-
reader = generate_goodPRNline(TEST_PRN_DIR + "20170714_LAI.PRN")
152+
reader = generate_goodPRNline(self.TEST_PRN_DIR + "20170714_LAI.PRN")
152153
while True:
153154
try:
154155
next(reader)

0 commit comments

Comments
 (0)