Skip to content

Commit 45aeb46

Browse files
committed
allow point csv files to be compressed
1 parent 07ce135 commit 45aeb46

2 files changed

Lines changed: 35 additions & 2 deletions

File tree

oceanval/matchall.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,23 @@
2929
from oceanval.gridded import gridded_matchup
3030

3131

32+
def read_point(ff):
33+
try:
34+
df = pd.read_csv(ff)
35+
return df
36+
except:
37+
pass
38+
compressions = ['infer', 'gzip', 'bz2', 'zip', 'xz']
39+
for compression in compressions:
40+
try:
41+
df = pd.read_csv(ff, compression = compression)
42+
return df
43+
except:
44+
pass
45+
raise ValueError(f"Could not read file {ff} with any of the following compression types: {compressions}. Error: {e}")
46+
47+
48+
3249
def is_z_up(ff, variable=None):
3350
import netCDF4 as nc4
3451

@@ -1260,7 +1277,7 @@ def point_match(
12601277
]
12611278

12621279
def read_csv_simyears(ff, layer = None):
1263-
df = pd.read_csv(ff)
1280+
df = read_point(ff)
12641281
min_year = session_info["min_year"]
12651282
max_year = session_info["max_year"]
12661283
if "year" in df.columns:

oceanval/parsers.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,22 @@
66
import warnings
77
from oceanval.session import session_info
88

9+
def read_point(ff):
10+
try:
11+
df = pd.read_csv(ff)
12+
return df
13+
except:
14+
pass
15+
compressions = ['infer', 'gzip', 'bz2', 'zip', 'xz']
16+
for compression in compressions:
17+
try:
18+
df = pd.read_csv(ff, compression = compression)
19+
return df
20+
except:
21+
pass
22+
raise ValueError(f"Could not read file {ff} with any of the following compression types: {compressions}. Error: {e}")
23+
24+
925
#session_info["keys"] = []
1026

1127
recipe_list = [
@@ -757,7 +773,7 @@ def add_point_comparison(self,
757773
vertical_option = False
758774
for vv in point_files:
759775
# read in the first row
760-
df = pd.read_csv(vv, nrows=1)
776+
df = read_point(vv, nrows=1)
761777
# throw error something else is in there
762778
bad_cols = [col for col in df.columns if col not in valid_vars]
763779
if len(bad_cols) > 0:

0 commit comments

Comments
 (0)