9
9
import io
10
10
import os
11
11
12
+ from pvlib .tools import _file_context_manager
13
+ from pvlib ._deprecation import deprecated
14
+
12
15
BSRN_FTP_URL = "ftp.bsrn.awi.de"
13
16
14
17
BSRN_LR0100_COL_SPECS = [(0 , 3 ), (4 , 9 ), (10 , 16 ), (16 , 22 ), (22 , 27 ),
@@ -136,7 +139,7 @@ def get_bsrn(station, start, end, username, password,
136
139
137
140
See Also
138
141
--------
139
- pvlib.iotools.read_bsrn, pvlib.iotools.parse_bsrn
142
+ pvlib.iotools.read_bsrn
140
143
141
144
References
142
145
----------
@@ -191,7 +194,7 @@ def get_bsrn(station, start, end, username, password,
191
194
bio .seek (0 ) # reset buffer to start of file
192
195
gzip_file = io .TextIOWrapper (gzip .GzipFile (fileobj = bio ),
193
196
encoding = 'latin1' )
194
- dfi , metadata = parse_bsrn (gzip_file , logical_records )
197
+ dfi , metadata = _parse_bsrn (gzip_file , logical_records )
195
198
dfs .append (dfi )
196
199
# FTP client raises an error if the file does not exist on server
197
200
except ftplib .error_perm as e :
@@ -217,7 +220,7 @@ def get_bsrn(station, start, end, username, password,
217
220
return data , metadata
218
221
219
222
220
- def parse_bsrn (fbuf , logical_records = ('0100' ,)):
223
+ def _parse_bsrn (fbuf , logical_records = ('0100' ,)):
221
224
"""
222
225
Parse a file-like buffer of a BSRN station-to-archive file.
223
226
@@ -382,7 +385,7 @@ def read_bsrn(filename, logical_records=('0100',)):
382
385
Parameters
383
386
----------
384
387
filename: str or path-like
385
- Name or path of a BSRN station-to-archive data file
388
+ Name, path, or in-memory buffer of a BSRN station-to-archive data file
386
389
logical_records: list or tuple, default: ('0100',)
387
390
List of the logical records (LR) to parse. Options include: '0100',
388
391
'0300', and '0500'.
@@ -439,7 +442,7 @@ def read_bsrn(filename, logical_records=('0100',)):
439
442
440
443
See Also
441
444
--------
442
- pvlib.iotools.parse_bsrn, pvlib.iotools. get_bsrn
445
+ pvlib.iotools.get_bsrn
443
446
444
447
References
445
448
----------
@@ -457,7 +460,11 @@ def read_bsrn(filename, logical_records=('0100',)):
457
460
if str (filename ).endswith ('.gz' ): # check if file is a gzipped (.gz) file
458
461
open_func , mode = gzip .open , 'rt'
459
462
else :
460
- open_func , mode = open , 'r'
463
+ open_func , mode = _file_context_manager , 'r'
461
464
with open_func (filename , mode ) as f :
462
- content = parse_bsrn (f , logical_records )
465
+ content = _parse_bsrn (f , logical_records )
463
466
return content
467
+
468
+
469
+ parse_bsrn = deprecated (since = "0.13.0" , name = "parse_bsrn" ,
470
+ alternative = "read_bsrn" )(read_bsrn )
0 commit comments