Skip to content

Surfrad data reader #595

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 12 commits into from
Oct 9, 2018
Merged

Surfrad data reader #595

merged 12 commits into from
Oct 9, 2018

Conversation

lboeman
Copy link
Contributor

@lboeman lboeman commented Oct 2, 2018

pvlib python pull request guidelines

Thank you for your contribution to pvlib python! You may delete all of these instructions except for the list below.

You may submit a pull request with your code at any stage of completion.

The following items must be addressed before the code can be merged. Please don't hesitate to ask for help if you're unsure of how to accomplish any of the items below:

  • Closes add SURFRAD data reader #590
  • I am familiar with the contributing guidelines.
  • Fully tested. Added and/or modified tests to ensure correct behavior for all reasonable inputs. Tests (usually) must pass on the TravisCI and Appveyor testing services.
  • Updates entries to docs/sphinx/source/api.rst for API changes.
  • Adds description and name entries in the appropriate docs/sphinx/source/whatsnew file for all changes.
  • Code quality and style is sufficient. Passes LGTM and SticklerCI checks.
  • New code is fully documented. Includes sphinx/numpydoc compliant docstrings and comments in the code where necessary.
  • Pull request is nearly complete and ready for detailed review.

Brief description of the problem and proposed solution (if not already fully described in the issue linked to above):

Dataframe with the fields found in SURFRAD_COLUMNS.
metadata: dict
Site metadata included in the file.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

W293 blank line contains whitespace

import inspect
import os

from numpy import isnan
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

F401 'numpy.isnan' imported but unused

test_dir = os.path.dirname(
os.path.abspath(inspect.getfile(inspect.currentframe())))
testfile = os.path.join(test_dir, '../data/surfrad-slv16001.dat')
network_testfile ='ftp://aftp.cmdl.noaa.gov/data/radiation/surfrad/Alamosa_CO/2016/slv16001.dat'
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E225 missing whitespace around operator
E501 line too long (96 > 79 characters)


@pytest.mark.parametrize('filename', [
testfile,
network_testfile ])
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E202 whitespace before ']'


def test_format_index():
start = pd.Timestamp('20160101 00:00')
expected_index = pd.DatetimeIndex(start = start,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E251 unexpected spaces around keyword / parameter equals

def test_format_index():
start = pd.Timestamp('20160101 00:00')
expected_index = pd.DatetimeIndex(start = start,
periods = 1440,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E251 unexpected spaces around keyword / parameter equals

'latitude': '37.70',
'longitude': '105.92',
'elevation': '2317',
'surfrad_version': '1' }
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

E202 whitespace before '}'

@wholmgren wholmgren added enhancement solarfx2 DOE SETO Solar Forecasting 2 / Solar Forecast Arbiter io labels Oct 2, 2018
@wholmgren wholmgren added this to the 0.6.1 milestone Oct 2, 2018
@pvlib pvlib deleted a comment from stickler-ci bot Oct 3, 2018
@pvlib pvlib deleted a comment from stickler-ci bot Oct 3, 2018
@pvlib pvlib deleted a comment from stickler-ci bot Oct 3, 2018
Copy link
Member

@wholmgren wholmgren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work.

zen float solar zenith angle (deg)
**Fields below have associated qc flags labeled <field>_flag.**
-----------------------------------------------------------------------
dw_solar float downwelling global solar(W/m^2)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this could be dw_solar, ghi and you could add another ** line with a note like **raw, mapped fields are controlled by the map_variables argument**. There's probably a better way to say that.

'Alamosa_CO/2016/slv16001.dat')


def test_read_surfrad():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this test is doing anything for us so we can delete it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry for setting a bad example in test_tmy.py


def test_format_index():
start = Timestamp('20160101 00:00')
expected_index = DatetimeIndex(start=start, periods=1440, freq='1min')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can supply tz='UTC' here and skip the localize call below. Seems a little more straightforward to me. I had to look up if localize modifies in place or not.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, thanks. This was a naive "fix" when I was reading the test failure incorrectly, I wasn't setting the timezone correctly in read_surfrad.
It looks like pandas 0.14.0 has some issues with setting the timezone the way you proposed though, so i'll have to figure that out.


def test_read_surfrad_metadata():
expected = {'name': 'Alamosa',
'latitude': '37.70',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the values here and below should be numeric. probably all floats.

@wholmgren
Copy link
Member

wholmgren commented Oct 4, 2018 via email

@wholmgren
Copy link
Member

wholmgren commented Oct 4, 2018 via email

@lboeman
Copy link
Contributor Author

lboeman commented Oct 4, 2018

@wholmgren Looks like the tz parameter is added to pandas.DatetimeIndex in 0.15.0

@wholmgren
Copy link
Member

Let's bump the minimum requirements to 0.15.0.

@mikofski will also appreciate the tz_localize(None) feature.

http://pandas.pydata.org/pandas-docs/stable/whatsnew.html#timezone-handling-improvements

@lboeman
Copy link
Contributor Author

lboeman commented Oct 4, 2018

The bump to pandas 0.15.0 is causing other tests to fail and after testing it looks like all versions from 15-18.1 all produce errors in the tests. So it's probably best to roll this back to 0.14.0?

Copy link
Member

@wholmgren wholmgren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a few minor comments below. I'll check out the tests.

@@ -9,6 +9,8 @@ release.
**Python 2.7 support will end on June 1, 2019**. Releases made after this
date will require Python 3. (:issue:`501`)

**Minimum pandas requirment bumped 0.14.0=>0.15.0**
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

requirement

Filepath or url.
map_variables: bool
When true, renames columns of the Dataframe to pvlib variable names
where applicable.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add: "See variable SURFRAD_COLUMNS"

@wholmgren
Copy link
Member

The min failures are due to a couple of issues.

test_clearsky and test_solarposition failures are solved with code suggested in #598. That should be addressed in a different PR, possibly #583.

test_pvsystem failures are due to pandas-dev/pandas#13006 and can be avoided by changing pvsystem.py lines 2651-2652 to:

    v_lim_upper = float(np.nanmax([v_max, vdc_max, mppt_hi]) * (1 + vtol))
    v_lim_lower = float(np.nanmax([v_min, mppt_low]) * (1 - vtol))

@wholmgren wholmgren mentioned this pull request Oct 5, 2018
8 tasks
@wholmgren
Copy link
Member

@lboeman can you merge the latest pvlib-python/master into your branch and make the changes to pvsystem.py proposed above? I think that should make the tests pass.

@lboeman
Copy link
Contributor Author

lboeman commented Oct 5, 2018

@wholmgren Updated those lines and all tests are passing now.

@cwhanse
Copy link
Member

cwhanse commented Oct 9, 2018

Just a thought, not requesting any change: the format_index function seems likely to be useful in other contexts. If I had an idea how to name it so that someone else would recognize its purpose from the name, I would suggest moving it to it.tools or something similar.

@wholmgren
Copy link
Member

@cwhanse do you know of other data sources that use the SURFRAD time format? If not, I suggest we leave it as for now.

@cwhanse
Copy link
Member

cwhanse commented Oct 9, 2018

@wholmgren not off the top of my head. I agree, leave where it is for now, but let's move it if we find another iotools member function that parses this date format.

* Created :py:func:`pvlib.iotools.read_srml` and :py:func:`pvlib.iotools.read_srml_month_from_solardat`
to read University of Oregon Solar Radiation Monitoring Laboratory data. (:issue:`589`)

* Created :py:func:`pvlib.iotools.read_surfrad` to read NOAA SURFRAD data. (:issue:`590`)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lboeman your rebase introduced duplicate entries here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Fixed.

@wholmgren wholmgren merged commit 8058272 into pvlib:master Oct 9, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement io solarfx2 DOE SETO Solar Forecasting 2 / Solar Forecast Arbiter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants