@@ -59,7 +59,12 @@ def _open_compressed(fname):
5959
6060
6161def _read_file (fname ):
62- """Read file contents."""
62+ """Read file contents, or read from StringIO object."""
63+ if isinstance (fname , StringIO ):
64+ fname .seek (0 )
65+ text = fname .read ()
66+ return StringIO (text )
67+
6368 if not isinstance (fname , Path ):
6469 fname = Path (fname ).resolve ()
6570
@@ -102,6 +107,7 @@ def _parse_seabird(lines, ftype):
102107 """Parse searbird formats."""
103108 # Initialize variables.
104109 lon = lat = time = None , None , None
110+ fname = None
105111 skiprows = 0
106112
107113 metadata = {}
@@ -119,6 +125,9 @@ def _parse_seabird(lines, ftype):
119125 # Seabird headers starts with *.
120126 if line .startswith ("*" ):
121127 header .append (line )
128+ if "FileName" in line :
129+ file_path = line .split ("=" )[- 1 ].strip ()
130+ fname = Path (file_path ).stem
122131
123132 # Seabird configuration starts with #.
124133 if line .startswith ("#" ):
@@ -172,6 +181,7 @@ def _parse_seabird(lines, ftype):
172181 names .append ("Statistic" )
173182 metadata .update (
174183 {
184+ "name" : fname if fname else "unknown" ,
175185 "header" : "\n " .join (header ),
176186 "config" : "\n " .join (config ),
177187 "names" : _remane_duplicate_columns (names ),
@@ -261,7 +271,9 @@ def from_btl(fname):
261271
262272 df ["Statistic" ] = df ["Statistic" ].str .replace (r"\(|\)" , "" ) # (avg) to avg
263273
264- name = _basename (fname )[1 ]
274+ if "name" not in metadata :
275+ name = _basename (fname )[1 ]
276+ metadata ["name" ] = str (name )
265277
266278 dtypes = {
267279 "bpos" : int ,
@@ -282,7 +294,6 @@ def from_btl(fname):
282294 warnings .warn ("Could not convert %s to float." % column )
283295
284296 df ["Date" ] = pd .to_datetime (df ["Date" ])
285- metadata ["name" ] = str (name )
286297 setattr (df , "_metadata" , metadata )
287298 return df
288299
0 commit comments