Skip to content

Change local_path to save_path in get_bsrn #1282

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Sep 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions pvlib/iotools/bsrn.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ def _empty_dataframe_from_logical_records(logical_records):


def get_bsrn(station, start, end, username, password,
logical_records=('0100',), local_path=None):
logical_records=('0100',), save_path=None):
"""
Retrieve ground measured irradiance data from the BSRN FTP server.

Expand All @@ -87,8 +87,8 @@ def get_bsrn(station, start, end, username, password,
logical_records: list or tuple, default: ('0100',)
List of the logical records (LR) to parse. Options include: '0100',
'0300', and '0500'.
local_path: str or path-like, optional
If specified, path (abs. or relative) of where to save files
save_path: str or path-like, optional
If specified, a directory path of where to save each monthly file.

Returns
-------
Expand Down Expand Up @@ -178,10 +178,10 @@ def get_bsrn(station, start, end, username, password,
# Check that transfer was successfull
if not response.startswith('226 Transfer complete'):
raise ftplib.Error(response)
# Save file locally if local_path is specified
if local_path is not None:
# Save file locally if save_path is specified
if save_path is not None:
# Create local file
with open(os.path.join(local_path, filename), 'wb') as f:
with open(os.path.join(save_path, filename), 'wb') as f:
f.write(bio.getbuffer()) # Write local file
# Open gzip file and convert to StringIO
bio.seek(0) # reset buffer to start of file
Expand Down
9 changes: 8 additions & 1 deletion pvlib/tests/iotools/test_bsrn.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pandas as pd
import pytest
import os
import tempfile
from pvlib.iotools import read_bsrn, get_bsrn
from ..conftest import (DATA_DIR, RERUNS, RERUNS_DELAY, assert_index_equal,
requires_bsrn_credentials)
Expand Down Expand Up @@ -78,20 +79,26 @@ def test_read_bsrn_logical_records_not_found():
def test_get_bsrn(expected_index, bsrn_credentials):
# Retrieve irradiance data from the BSRN FTP server
# the TAM station is chosen due to its small file sizes
temp_dir = tempfile.TemporaryDirectory() # create temporary directory
username, password = bsrn_credentials
data, metadata = get_bsrn(
start=pd.Timestamp(2016, 6, 1),
end=pd.Timestamp(2016, 6, 29),
station='tam',
username=username,
password=password,
local_path='')
save_path=temp_dir.name)
assert_index_equal(expected_index, data.index)
assert 'ghi' in data.columns
assert 'dni_std' in data.columns
assert 'dhi_min' in data.columns
assert 'lwd_max' in data.columns
assert 'relative_humidity' in data.columns
# test that a local file was saved and is read correctly
data2, metadata2 = read_bsrn(os.path.join(temp_dir.name, 'tam0616.dat.gz'))
assert_index_equal(expected_index, data2.index)
assert 'ghi' in data2.columns
temp_dir.cleanup() # explicitly remove temporary directory


@requires_bsrn_credentials
Expand Down