From 8fc48dfaff263bac0b96053ce91e426521b70de2 Mon Sep 17 00:00:00 2001 From: AdamRJensen Date: Sun, 15 Aug 2021 21:13:03 +0200 Subject: [PATCH 1/7] Change local_path to save_path --- pvlib/iotools/bsrn.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pvlib/iotools/bsrn.py b/pvlib/iotools/bsrn.py index 4c02c10f90..8dcb07bd82 100644 --- a/pvlib/iotools/bsrn.py +++ b/pvlib/iotools/bsrn.py @@ -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. @@ -87,7 +87,7 @@ 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 + save_path: str or path-like, optional If specified, path (abs. or relative) of where to save files Returns @@ -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 From dc768e104d97540ea0ece55fa82842f7afdcd817 Mon Sep 17 00:00:00 2001 From: AdamRJensen Date: Sun, 15 Aug 2021 21:23:18 +0200 Subject: [PATCH 2/7] Update test_bsrn.py --- pvlib/tests/iotools/test_bsrn.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pvlib/tests/iotools/test_bsrn.py b/pvlib/tests/iotools/test_bsrn.py index 412cbd5e8f..212cba4e55 100644 --- a/pvlib/tests/iotools/test_bsrn.py +++ b/pvlib/tests/iotools/test_bsrn.py @@ -85,7 +85,7 @@ def test_get_bsrn(expected_index, bsrn_credentials): station='tam', username=username, password=password, - local_path='') + save_path='') assert_index_equal(expected_index, data.index) assert 'ghi' in data.columns assert 'dni_std' in data.columns From 3cddc1017a3e12273499b0f7d2157853be9abf99 Mon Sep 17 00:00:00 2001 From: AdamRJensen Date: Sun, 15 Aug 2021 22:08:25 +0200 Subject: [PATCH 3/7] Update save_path description --- pvlib/iotools/bsrn.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pvlib/iotools/bsrn.py b/pvlib/iotools/bsrn.py index 8dcb07bd82..98ecfdcf6e 100644 --- a/pvlib/iotools/bsrn.py +++ b/pvlib/iotools/bsrn.py @@ -88,7 +88,7 @@ def get_bsrn(station, start, end, username, password, List of the logical records (LR) to parse. Options include: '0100', '0300', and '0500'. save_path: str or path-like, optional - If specified, path (abs. or relative) of where to save files + If specified, a direcotry path of where to save files Returns ------- From 58b272c3c1d29c16359ff14cd9d64d68a2b571c6 Mon Sep 17 00:00:00 2001 From: AdamRJensen Date: Sun, 15 Aug 2021 22:09:44 +0200 Subject: [PATCH 4/7] Fix spelling mistake --- pvlib/iotools/bsrn.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pvlib/iotools/bsrn.py b/pvlib/iotools/bsrn.py index 98ecfdcf6e..c7f4e1aa10 100644 --- a/pvlib/iotools/bsrn.py +++ b/pvlib/iotools/bsrn.py @@ -88,7 +88,7 @@ def get_bsrn(station, start, end, username, password, List of the logical records (LR) to parse. Options include: '0100', '0300', and '0500'. save_path: str or path-like, optional - If specified, a direcotry path of where to save files + If specified, a directory path of where to save files. Returns ------- From b661dcfcfb22d886ff04f19bf42a772ba843e3b7 Mon Sep 17 00:00:00 2001 From: AdamRJensen Date: Wed, 25 Aug 2021 23:04:05 +0200 Subject: [PATCH 5/7] Test that file downloaded with save_path is read correctly --- pvlib/tests/iotools/test_bsrn.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pvlib/tests/iotools/test_bsrn.py b/pvlib/tests/iotools/test_bsrn.py index 212cba4e55..fde33dc745 100644 --- a/pvlib/tests/iotools/test_bsrn.py +++ b/pvlib/tests/iotools/test_bsrn.py @@ -92,6 +92,10 @@ def test_get_bsrn(expected_index, bsrn_credentials): 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('tam0616.dat.gz') + assert_index_equal(expected_index, data2.index) + assert 'ghi' in data2.columns @requires_bsrn_credentials From cebfaf9479f3b4d51f770b43d6a0e6779f377d79 Mon Sep 17 00:00:00 2001 From: AdamRJensen Date: Wed, 25 Aug 2021 23:38:23 +0200 Subject: [PATCH 6/7] Update save_path description --- pvlib/iotools/bsrn.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pvlib/iotools/bsrn.py b/pvlib/iotools/bsrn.py index c7f4e1aa10..b9292b41ae 100644 --- a/pvlib/iotools/bsrn.py +++ b/pvlib/iotools/bsrn.py @@ -88,7 +88,7 @@ def get_bsrn(station, start, end, username, password, List of the logical records (LR) to parse. Options include: '0100', '0300', and '0500'. save_path: str or path-like, optional - If specified, a directory path of where to save files. + If specified, a directory path of where to save each monthly file. Returns ------- From b083acd17447cdf854e30fc22be508761213c5e3 Mon Sep 17 00:00:00 2001 From: AdamRJensen Date: Wed, 1 Sep 2021 16:33:41 +0200 Subject: [PATCH 7/7] Save testfile in temporary directory --- pvlib/tests/iotools/test_bsrn.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/pvlib/tests/iotools/test_bsrn.py b/pvlib/tests/iotools/test_bsrn.py index fde33dc745..815b5d84c9 100644 --- a/pvlib/tests/iotools/test_bsrn.py +++ b/pvlib/tests/iotools/test_bsrn.py @@ -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) @@ -78,6 +79,7 @@ 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), @@ -85,7 +87,7 @@ def test_get_bsrn(expected_index, bsrn_credentials): station='tam', username=username, password=password, - save_path='') + save_path=temp_dir.name) assert_index_equal(expected_index, data.index) assert 'ghi' in data.columns assert 'dni_std' in data.columns @@ -93,9 +95,10 @@ def test_get_bsrn(expected_index, bsrn_credentials): 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('tam0616.dat.gz') + 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