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

Improved error codes for irradproc, solar_resource_data #1219

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

mjprilliman
Copy link
Collaborator

-Fixes #973
-Add output errorcodes from irrad::check(), not just codes
-Add checks for solar_resource_data, including header information such as elev, lat, lon, tz
-Tested on pvwattsv8, feedback needed before propagating across irrad and solar_resource_data instances
@cpaulgilman review needed on language of error messages
@brtietz review needed on functionality

@mjprilliman mjprilliman added enhancement pv photovoltaic, pvsam, pvwatts labels Oct 8, 2024
@mjprilliman mjprilliman added this to the SAM Fall 2024 Release milestone Oct 8, 2024
@mjprilliman mjprilliman self-assigned this Oct 8, 2024
@mjprilliman
Copy link
Collaborator Author

Copy link
Collaborator

@cpaulgilman cpaulgilman left a comment

Choose a reason for hiding this comment

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

@mjprilliman Thanks for tackling this. I'll look over and revise the text of the messages. I think the variable name "errorCode" is misleading. Not sure if it's worth the effort to change, but something like "error_message" would make it clearer that it's a text message and not a numeric code.

@cpaulgilman
Copy link
Collaborator

@mjprilliman I'm using PVWatts to test this in the SAM UI because it is the only model that calls irradproc's getErrorCode(). When I use this weather file with invalid time zone data, SAM crashes:

image

@mjprilliman
Copy link
Collaborator Author

@mjprilliman I'm using PVWatts to test this in the SAM UI because it is the only model that calls irradproc's getErrorCode(). When I use this weather file with invalid time zone data, SAM crashes:

image

Sorry Paul, there was an extra callout to code that was in the util::format call in pvwattsv8 that I had been using for troubleshooting. That meant it was trying to format a error code as a string, a string as a integer, and so on. The most recent push should fix that, and rename the errorCode references to errorMessage.

@cpaulgilman
Copy link
Collaborator

@mjprilliman This is working now in PVWatts, thanks for the fix.

I would like to be able to use formatted strings like this to include useful data in the error messages:

    if (latitudeDegrees < -90 || latitudeDegrees > 90 || longitudeDegrees < -180 || longitudeDegrees > 180 ||
        timezone < -15 || timezone > 15) {
        std::sprintf(errorMessage, "Invalid latitude (%f), longitude (%f), or time zone (%f)", latitudeDegrees, longitudeDegrees, timezone);
        return -2;
    }

But this doesn't work because errorMessage is a string, not the required char. I tried a few things but couldn't figure out how to do this. Is there an easy way to make this work? If not I'll work with the message text as it is.

@mjprilliman
Copy link
Collaborator Author

@mjprilliman This is working now in PVWatts, thanks for the fix.

I would like to be able to use formatted strings like this to include useful data in the error messages:

    if (latitudeDegrees < -90 || latitudeDegrees > 90 || longitudeDegrees < -180 || longitudeDegrees > 180 ||
        timezone < -15 || timezone > 15) {
        std::sprintf(errorMessage, "Invalid latitude (%f), longitude (%f), or time zone (%f)", latitudeDegrees, longitudeDegrees, timezone);
        return -2;
    }

But this doesn't work because errorMessage is a string, not the required char. I tried a few things but couldn't figure out how to do this. Is there an easy way to make this work? If not I'll work with the message text as it is.

Paul, I tested it out and something like this should work:

errorMessage = util::format("Invalid latitude (%lg), longitude (%lg), or time zone (%lg)", latitudeDegrees, longitudeDegrees, timezone);

Not a very elegant example but it reports out this:

image

@cpaulgilman
Copy link
Collaborator

@mjprilliman util::format is what I need -- thanks for the reminder~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement pv photovoltaic, pvsam, pvwatts
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Solar Resource Data does not throw errors for bad fields
2 participants