Skip to content
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

Add NSRDB GOES v4 to iotools #2378

Open
wants to merge 39 commits into
base: main
Choose a base branch
from

Conversation

williamhobbs
Copy link
Contributor

@williamhobbs williamhobbs commented Feb 6, 2025

  • Closes Add NSRDB GOES V4 #2326
  • I am familiar with the contributing guidelines
  • Tests added
  • Updates entries in docs/sphinx/source/reference for API changes.
  • Adds description and name entries in the appropriate "what's new" file in docs/sphinx/source/whatsnew for all changes. Includes link to the GitHub Issue with :issue:`num` or this Pull Request with :pull:`num`. Includes contributor name and/or GitHub username (link with :ghuser:`user`).
  • New code is fully documented. Includes numpydoc compliant docstrings, examples, and comments where necessary.
  • Pull request is nearly complete and ready for detailed review.
  • Maintainer: Appropriate GitHub Labels (including remote-data) and Milestone are assigned to the Pull Request and linked Issue.

@williamhobbs
Copy link
Contributor Author

What's the best practice for lines like this one that end up too long? Do I simply add # noqa or # noqa: F401? (I don't know what F401 is for, but I've seen it used here...)

GOES_URL = NSRDB_API_BASE + "/api/nsrdb/v2/solar/nsrdb-GOES-aggregated-v4-0-0-download.csv"

https://github.com/williamhobbs/pvlib-python/blob/4af81a76b4d8bb86b992b5a87ca81dbec6ecb8d5/pvlib/iotools/goes4.py#L15

@mikofski
Copy link
Member

mikofski commented Feb 6, 2025

You could use parentheses

GOES_URL = NSRDB_API_BASE + ("/api/nsrdb/v2/solar/"
"nsrdb-GOES-aggregated-v4-0-0-download.csv")

or just break the string smaller and add them

API_STUB = "/api/nsrdb/v2/solar/"
ENDPOINT = "nsrdb-GOES-aggregated-v4-0-0-download.csv"
GOES_URL = (NSRDB_API_BASE
    + API_STUB + ENDPOINT)

imo avoid ignoring pep8 warnings or else they become pointless.

@williamhobbs
Copy link
Contributor Author

Thanks, @mikofski!

@williamhobbs
Copy link
Contributor Author

I'm not 100% sure that I set up the tests in test_goes4.py correctly. I copied what was done in test_psm3.py and manually downloaded and reformatted as needed the test data csv files.

See test_read_goes4_map_variables() in particular. columns_mapped includes variables like 'Ozone' that are part of a manual download but are not addressed in pvlib.

I think it's correct, but I could be misunderstanding the goals of some of the tests.

@williamhobbs
Copy link
Contributor Author

Ok, made the switch from "goes4" to "psm4".

I haven't done anything with @kandersolar's suggestion for different get_ functions for different endpoints (e.g., get_nsrdb_goes4_aggregated, get_nsrdb_goes4_conus, and get_nsrdb_goes4_tmy). I'll wait for some consensus on that one.

@williamhobbs
Copy link
Contributor Author

Ok, I made an effort to create separate get_ functions in a new branch: https://github.com/williamhobbs/pvlib-python/tree/nsrdb_psm4_dedicated_get_functions.

I'll hold off on merging that with the branch in this PR (https://github.com/williamhobbs/pvlib-python/tree/nsrdb_goes_v4) until someone suggests that I do it - I don't want to make a mess of things too quickly.

@kandersolar kandersolar added this to the v0.11.3 milestone Feb 20, 2025
@kandersolar kandersolar modified the milestones: v0.11.3, v0.11.4 Mar 14, 2025
Copy link
Member

@AdamRJensen AdamRJensen 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 initial comments

return parse_psm4(fbuf, map_variables)


def parse_psm4(fbuf, map_variables=True):
Copy link
Member

Choose a reason for hiding this comment

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

I personally think we should get rid of the parse functions as it creates a LOT of duplicate documentation and significantly more functions than needed. It's unnecessary clutter and it takes very little to modify read functions to also take filebuffers.

Alternatively, we could consider making the parse functions private.

Copy link
Member

Choose a reason for hiding this comment

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

I am generally +1 to ditching parse_ and having read_ work with buffers as well as filenames. But let's do it as a follow-up PR.

Comment on lines 29 to 46
@pytest.fixture(scope="module")
def nrel_api_key():
"""Supplies pvlib-python's NREL Developer Network API key.
Azure Pipelines CI utilizes a secret variable set to NREL_API_KEY
to mitigate failures associated with using the default key of
"DEMO_KEY". A user is capable of using their own key this way if
desired however the default key should suffice for testing purposes.
"""
try:
demo_key = os.environ["NREL_API_KEY"]
except KeyError:
warnings.warn(
"WARNING: NREL API KEY environment variable not set! "
"Using DEMO_KEY instead. Unexpected failures may occur."
)
demo_key = 'DEMO_KEY'
return demo_key
Copy link
Member

Choose a reason for hiding this comment

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

If it's the same key as for the PSM3, then I suggest importing it from that test module (should be possible?) to avoid duplicating code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

holding off on this, per a conversation with @kandersolar

Copy link
Member

Choose a reason for hiding this comment

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

I moved the fixture to conftest and imported it in both psmN test modules

@AdamRJensen
Copy link
Member

Given the unanimous vote and the three weeks passed (see #2326 (comment)), you can go ahead with splitting the functions into individual ones.

Please still consider the comments above 😄

@williamhobbs
Copy link
Contributor Author

williamhobbs commented Apr 2, 2025

Ok @AdamRJensen, I implemented many of your comments into https://github.com/williamhobbs/pvlib-python/tree/nsrdb_psm4_dedicated_get_functions. I may be at the limit of my git/GitHub knowledge, though. What do I do next to get those changes (along with the dedicated functions) from that branch into this PR? I can follow up offline if that's best...

Edit: I sorted this out, thanks to help from @kandersolar.

@williamhobbs
Copy link
Contributor Author

@AdamRJensen - I think I addressed all of your comments in one way or another. Thanks for the review - I think I forgot to say that earlier.

iotools.get_nsrdb_psm4_conus
iotools.get_nsrdb_psm4_full_disc
iotools.read_nsrdb_psm4
iotools.parse_nsrdb_psm4
Copy link
Member

Choose a reason for hiding this comment

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

Why don't we make this a private function for now so we don't have to deprecate it later?

Copy link
Member

@wholmgren wholmgren Apr 10, 2025

Choose a reason for hiding this comment

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

Are we also going to add support for buffers to read_nsrdb_psm4? I recommend moving forward with this PR API as is and if you want to take that on before the next release then go for it.

Also need to edit the docstring returns sections if this function becomes private.

Comment on lines +100 to +103
names : str, default '2023'
PSM4 API parameter specifing year (e.g. ``2023``) to download. The
allowed values update periodically, so consult the NSRDB reference
below for the current set of options.
Copy link
Member

@AdamRJensen AdamRJensen Apr 10, 2025

Choose a reason for hiding this comment

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

No need to follow the strange naming convention of PSM. I suggest renaming this to year.

Comment on lines +122 to +129
url : str, optional
Full API endpoint URL. If not specified, the PSM4 GOES Aggregated v4
URL is used.
timeout : int, default 30
time in seconds to wait for server response before timeout
utc: bool, default : False
retrieve data with timestamps converted to UTC. False returns
timestamps in local standard time of the selected location
Copy link
Member

Choose a reason for hiding this comment

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

I suggest changing the order such that the api specific parameters comes first, i.e., have utc come before map_variables, url, and timeout - this is a somewhat unwritten convention for the iotools functions.

PSM4 API parameter specifing TMY variant to download (e.g. ``'tmy'``
or ``'tgy-2022'``). The allowed values update periodically, so
consult the NSRDB references below for the current set of options.
time_period : int, {60}
Copy link
Member

Choose a reason for hiding this comment

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

Time period could be thought of as what time period is covered, i.e., start to end. I think time_step is a better name for this parameter (this is also what is used by the pvlib.iotools.get_cams function).

return data, metadata


def read_nsrdb_psm4(filename, map_variables=True):
Copy link
Member

Choose a reason for hiding this comment

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

Could this function be called read_sam instead?

Copy link
Member

@cwhanse cwhanse Apr 10, 2025

Choose a reason for hiding this comment

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

I think read_sam could be misinterpreted. SAM isn't the NSRDB, it is a user of that data; read_sam could be confused with retrieve_sam; and SAM is moving towards exporting a JSON file for a simulation, which could be of future interest to pvlib users.

Co-authored-by: Adam R. Jensen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add NSRDB GOES V4
7 participants