Rev Contribution

custom reV errors/exceptions

<2026-04-10 Fri>

story

implement custom rev exceptions to replace base exceptions

unused exceptions

  • SlurmWarning
  • SAMExecutionWarning
  • ExtrapolationWarning
  • NearestNeighborError
  • JSONError

SAM

SAM.py

  • SAMExecutionError
    • _getbasehandler - get base SAM resource handler
      • raises error if module not found
    • execute - call PySAM execute method
      • raises error if execution fails for some reason
    • collectoutputs - collect SAM outputrequest -> convert time-series outputs to UTC -> save outputs to self.outputs
      • raises error if bad request from PySAM object
  • SAMInputWarning
    • _makereskwargs - make Resource.preloadSam args and kwargs
      • raise warning if downscaling is request for any resource handler that is not NSRDB
    • assigninputs - assign a flat dict of inputs to the PySAM object
      • raise warning for inputs that are not set because they are not found in PySAM object
  • SAMInputError
    • setitem - set a PySAM input data attribute
      • raises error if attribute not found
      • catches error from `setattr(getattr(self.pysam, group), key, value)`
  • ResourceError
    • ensurereslen - ensure timeindex has a constant time-step and only covers 365 days (no leap days)
      • raises error if timeindex does not have a consistent time-step

econ.py

  • SAMExecutionError
    • parsesyscap - find the system capacity variable in either inputs or dataframe
      • raises error uf system capacity or turbine capacity is not included in the site-specific inputs in order to calculate annual energy yield for LCOE
  • KeyError
    • _getcfprofiles - get the multi-site capacity factor time series profiles
      • raises error if cfprofile values are not found
    • _parselcoeinputs - parse for non-site-specific LCOE inputs
      • raises error if cfmean values are not found for LCOE calculation

windbos.py

  • SAMInputError

defaults.py

  • NotImplementedError

generation.py

  • InputError
    • multiple vals for `temperature` for site
    • "" `potentialMW` ""
    • found nan vals for site {} in vars {}
  • SAMExecutionError
  • NotImplementedError
  • ValueError
    • lat/lon exception

versionchecker.py

  • PySAMVersionError
  • PySAMVersionWarning

bespoke

bespoke.py

  • ValueError
    • Unknown dataset name
  • TypeError
    • minspacing must be numeric
  • KeyError
    • user requested "lcoefcr" but did not input "fixedchargerate" in SAM system config
    • could not find LCOE kwargs in outputs; plantoptimizer, originalsamsysinputs, or meta
  • ModuleNotFoundError
  • RuntimeError
    • failed while running SAM windpower timeseries analysis
    • failed while running turbine placement optimizer
    • SC gid xxx failed
  • FileNotFoundError
    • exclusions file not found
  • FileInputError
    • techmap dataset not found in exclusions file
  • OSError

packturbs.py

  • WhileLoopPackingError

placeturbines.py

  • ValueError
    • will not eval string which contains xxx
  • WhileLoopPackingError

config

baseconfig.py

  • ConfigError
    • initconfig - initialize and load config from file
      • raises error if config file does not exist or cannot be parsed
  • IOError
    • initconfig - initialize and load config from file
      • raises error when config file path cannot be read

projectpoints.py

  • ConfigError
    • parse - parse project points from file or object
      • raises error when project points file type is not recognized
    • fromrange - create project points from a range of gids
      • raises error if sites argument has invalid form
  • ValueError
    • parsetech - parse the technology from the project points config
      • raises error if more than one unique technology is found in project points
  • TypeError
    • parse - parse project points from file or object
      • raises error when project points input type is not recognized
  • KeyError
    • samconfigobj - get the SAM config object for a given gid
      • raises error if gid not found in SAM config mapping
  • RuntimeError
    • split - split project points into sub-chunks
      • raises error when project points cannot be split into the requested number of chunks

execution.py

  • ConfigError
    • parseexecutioncontrol - parse execution control from config
      • raises error if required execution control parameters are missing or invalid

econ

econ.py

  • Exception
    • runsingleworker - run a single econ worker for a set of sites
      • raises base exception if `econfun` fails during SAM econ execution
  • ExecutionError
    • parseoutputrequest - parse and validate user output requests
      • raises error if none of the user output requests are recognized
    • getdatashape - get the output data shape from SAM config
      • raises error if non-scalar sitedata input key is passed as an outputrequest
  • ValueError
    • parseoutputrequest - parse and validate user output requests
      • raises error if econ outputs requested span incompatible SAM modules
  • Exception
    • run - run econ analysis for all sites
      • raises base exception if analysis sites from project points are not found in cf file
      • raises base exception if SmartParallelJob execution fails

cliecon.py

  • IOError
    • parsecffiles - parse capacity factor files for econ
      • raises error if a cf file does not exist on disk
  • ConfigError
    • parsecffiles - parse capacity factor files for econ
      • raises error if the number of cf files does not match the number of analysis years
      • raises error if a requested analysis year cannot be found in the cf files

economiesofscale.py

  • TypeError
    • preflight - run preflight checks on input data
      • raises error if data input is not a dict or DataFrame
  • KeyError
    • preflight - run preflight checks on input data
      • raises error if variables required for an equation are missing from input data
    • getprioritizedkeys - get keys from input dict by priority order
      • raises error if none of the requested keys are found in the input dict
  • ValueError
    • preflight - run preflight checks on input data
      • raises error if equation string evaluates to an invalid value

generation

base.py

  • Exception
    • out.setter - set site output results
      • raises base exception if site results are non-sequential
  • TypeError
    • out.setter - set site output results
      • raises error if output type is unrecognized
    • outputrequesttypecheck - validate the outputrequest argument type
      • raises error if outputrequest is not str, list, or tuple
  • ValueError
    • handleleapti - handle leap year time index by dropping Feb 29
      • raises error if time index length is not a multiple of 365
    • siteindex - get or set the current site index
      • raises error if outputindex is negative (site index already set)
    • patchwavegenpysam5 - patch wave generation output for PySAM 5
      • raises error if non-zero values are found at the end of the generation array
  • Exception
    • parsesitedata - parse site-specific SAM input data from csv or DataFrame
      • raises base exception if site data input is not a .csv or DataFrame
  • KeyError
    • parsesitedata - parse site-specific SAM input data from csv or DataFrame
      • raises error if gid column is missing from site data
    • getpc - get the points control object for a given technology
      • raises error if the technology string is not recognized
  • ExecutionError
    • getdatashapefromsamconfig - get output data shape from SAM config
      • raises error if a non-scalar SAM input key is passed as an outputrequest
    • getdatashapefrompysam - get output data shape from PySAM object
      • raises error if the requested dataset is not found in the PySAM object

cligen.py

  • ConfigError
    • parseresfiles - parse resource files from generation config
      • raises error if resourcefile is not a recognized type
      • raises error if resource file count does not match the number of analysis years

generation.py

  • KeyError
    • init - initialize the generation object
      • raises error if the technology string is not in OPTIONS dict
  • ProjectPointsValueError
    • meta - get the resource meta data for analysis sites
      • raises error if the max site gid exceeds the resource meta data length
  • ConfigError
    • handlelifetimeindex - handle lifetime index for multi-year modeling
      • raises error if multiple analysisperiods are found in the config
      • raises error if invalid output arrays are requested alongside lifetime modeling
  • Exception
    • runsingleworker - run a single generation worker for a set of sites
      • raises base exception if `cls.OPTIONS[tech].reVrun` fails
    • run - run generation for all sites with parallel execution
      • raises base exception if generation execution fails
  • InputError
    • parsegidmap - parse optional gid map to remap resource gids to supply curve gids
      • raises error if the gidmap file cannot be parsed

handlers

exclusions.py

  • TypeError
    • init - initialize exclusions handler
      • raises error if h5file is not str, list, or tuple
  • MultiFileExclusionError
    • preflightmultifile - run preflight checks for multi-file exclusions
      • raises error if a layer shape does not match lat/lon shapes
      • raises error if multi-file exclusions do not have matching coordinate profiles
  • HandlerKeyError
    • getlatitude - get latitude array from h5 file
      • raises error if latitude dataset is missing from h5 file
    • getlongitude - get longitude array from h5 file
      • raises error if longitude dataset is missing from h5 file
    • getlayer - get a single exclusion layer from h5 file
      • raises error if requested layer is not in available layers

multiyear.py

  • ConfigError
    • sourcefiles (MultiYearGroup) - get list of source files for multi-year aggregation
      • raises error if sourcefiles is not a list, tuple, or "PIPELINE"
      • raises error if neither sourcefiles nor sourcedir+sourceprefix are provided
  • CollectionRuntimeError
    • sourcefiles (MultiYearGroup) - get list of source files for multi-year aggregation
      • raises error if sourcepattern glob results in non-h5 files
    • parsesourcefilespattern - parse source files from a glob pattern
      • raises error if non-h5 files are found in the pattern results
  • FileNotFoundError
    • sourcefiles (MultiYearGroup) - get list of source files for multi-year aggregation
      • raises error if no source files are found matching the pattern
  • TypeError
    • parsesourcefilespattern - parse source files from a glob pattern
      • raises error if sourcefiles type is not recognized
  • HandlerRuntimeError
    • copydset - copy a dataset across source files into multi-year output
      • raises error if meta data lengths differ across source files
    • computemeans - compute multi-year means for a dataset
      • raises error if dataset shapes do not match across source files
    • computestdev - compute multi-year standard deviation for a dataset
      • raises error if dataset shapes do not match across source files
  • CollectionValueError
    • isprofile - check if dataset is a time-series profile
      • raises error if requested dataset is not found in the source file
  • CollectionWarning
    • copydset - copy a dataset across source files into multi-year output
      • warns if coordinates do not match between collection files
    • mycollectgroups - collect all groups into a single multi-year HDF5 file
      • warns when an existing multi-year output file is found and removed (clobber)

transmission.py

  • HandlerKeyError
    • getitem - get feature data by gid
      • raises error if the feature gid is invalid
    • featuresfromtable - build features dict from a transmission table
      • raises error if feature type is not recognized
    • substationcapacity - get capacity available at a substation
      • raises error if capacities are not found for the substation
  • ValueError
    • featuresfromtable - build features dict from a transmission table
      • raises error if features dict input is not valid
  • RuntimeError
    • checkfeaturedependencies - check that parent features exist for substations
      • raises error if parent features depend on missing transmission lines
    • connect - connect a supply curve point to a transmission feature
      • raises error if needed capacity exceeds available capacity
  • HandlerRuntimeError
    • availablecapacity - get available capacity at a transmission feature
      • raises error if available capacity cannot be parsed from the feature data
  • NotImplementedError
    • POIFeatures.cost - compute connection cost for POI features
      • raises error because cost computation is not supported for POI features
    • POIFeatures.calccost - internal cost calculation for POI features
      • raises error because POI cost calculation is not implemented

losses

powercurve.py

  • reVLossesValueError
    • PowerCurve.validatewindspeed - validate wind speed input array
      • raises error if wind speed contains negative values
    • PowerCurve.validategeneration - validate generation output array
      • raises error if there are no positive generation values in the power curve
      • raises error if non-zero generation values exist above the cutoff wind speed
    • PowerCurveLosses.validatewindresource - validate wind resource input
      • raises error if wind resource contains negative values
    • PowerCurveLosses.validateweights - validate bin weights for wind resource
      • raises error if weights size does not match wind resource size
    • PowerCurveLossesInput.validaterequiredkeysexist - validate required keys in loss spec
      • raises error if required keys are missing from the loss specification
    • PowerCurveLossesInput.validatetransformation - validate transformation name
      • raises error if transformation name is not in TRANSFORMATIONS dict
    • PowerCurveLossesInput.validatepercentage - validate loss percentage value
      • raises error if percentage is not in the range [0, 100]
    • PowerCurveWindResource.windresourceforsite - get wind resource for a single site
      • raises error if pressure units cannot be determined from dataset
    • AbstractPowerCurveTransformation.validatenonzerogeneration - validate transformed power curve
      • raises error if the calculated power curve is invalid (all zeros or negative)
    • AbstractPowerCurveTransformation.validatesamecutoff - validate cutoff wind speeds match
      • raises error if cutoff wind speeds of original and transformed curves don't match
    • PowerCurveLossesMixin.windresourcefrominput - get wind resource from user input
      • raises error if windresourcemodelchoice is incompatible with input type
  • NotImplementedError
    • AbstractPowerCurveTransformation.apply - apply the power curve transformation
      • raises error when subclass has not set transformedgeneration

utils.py

  • reVLossesValueError
    • validatearraysnotempty - validate that input data arrays are not empty
      • raises error if an input data array is empty

scheduled.py

  • reVLossesValueError
    • Outage.validaterequiredkeysexist - validate required keys in outage spec
      • raises error if required keys are missing from the outage specification
    • Outage.validatecount - validate outage count value
      • raises error if count is not an integer or is less than 1
    • Outage.validateandconverttofullnamemonths - validate and normalize month names
      • raises error if no recognized month names are provided
    • Outage.validateduration - validate outage duration value
      • raises error if duration is not an integer or is outside the valid range
    • Outage.validatepercentage - validate outage loss percentage
      • raises error if percentage is not in the range (0, 100]

nrwal

nrwal.py

  • KeyError
    • parsesitedata - parse and validate site data input
      • raises error if required columns (gid, config) are missing from sitedata
  • OffshoreWindInputError
    • preflightchecks - run preflight validation checks
      • raises error if config ids in sitedata are missing from the NRWAL config input
      • raises error if sitemetacols are not found in sitedata
    • getinputdata - get input data arrays for NRWAL analysis
      • raises error if required NRWAL input variables are not found in gen outputs or meta
  • DataShapeError
    • getinputdata - get input data arrays for NRWAL analysis
      • raises error if data shape is not 1D or 2D
    • savenrwalout - save NRWAL output arrays to the output file
      • raises error if a 1D output is found to be 2D but not all-NaN
      • raises error if NRWAL output shape cannot be understood
  • TypeError
    • valuetoarray - convert a NRWAL output value to a numpy array
      • raises error if a NRWAL key returns a value of an unrecognized type

qaqc

qaqc.py

  • TypeError
    • QaQcModule._init___ - initialize the QA/QC module handler
      • raises error if config input is not a dict
  • PipelineError
    • QaQcModule.fpath - get the file path for the module output
      • raises error if fpath cannot be parsed from previous pipeline jobs

repprofiles

repprofiles.py

  • FileInputError
    • RepProfilesBase.parserevsummary - parse the reV summary CSV file
      • raises error if the reV summary file cannot be parsed
  • TypeError
    • RepProfilesBase.parserevsummary - parse the reV summary CSV file
      • raises error if revsummary input is not a valid dtype (str path or DataFrame)
  • KeyError
    • RepProfilesBase.checkreqcols - check that required columns exist in the summary table
      • raises error if required column labels are not found in the revsummary table
    • RepProfilesBase.checkrevgen - check that the gen file has required datasets
      • raises error if cfdset is not in the gen file datasets
      • raises error if timeindex is not in the gen file datasets
  • DataShapeError
    • RegionRepProfile.runrepmethods - run representative profile methods for a region
      • raises error if the weights column length doesn't match the profiles shape
  • ValueError
    • RepProfiles._init___ - initialize representative profiles
      • raises error if regcols is None

supplycurves

aggregation.py

  • RuntimeError
    • runserial / runparallel - run supply curve aggregation
      • raises error if aggregation fails for a supply curve point
  • SupplyCurveInputError
    • checkfiles - check that required input files exist
      • raises error if required exclusions or resource files are not found
  • FileInputError
    • checkfiles - check that required input files exist
      • raises error if techmap dataset is not found in the exclusions file
  • FileNotFoundError
    • checkfiles - check that required input files exist
      • raises error if the exclusions h5 file does not exist
  • EmptySupplyCurvePointError
    • runsingle - run aggregation for a single supply curve point
      • raises error if no valid resource pixels are found within the supply curve cell

scaggregation.py

  • FileInputError
    • checkexclfiles - check exclusion file inputs
      • raises error if the techmap dataset is not found in the exclusions file
  • TypeError
    • parsescpoints - parse supply curve points
      • raises error if scpoints input type is not recognized
  • KeyError
    • parsecfdset - parse capacity factor dataset name
      • raises error if cfdset is not found in the resource file
  • ValueError
    • checkresfile - check resource file is valid
      • raises error if resource file does not contain required datasets
  • EmptySupplyCurvePointError
    • runsingle - run aggregation for a single supply curve point
      • raises error if supply curve point has no valid resource data

supplycurve.py

  • KeyError
    • parsescpoints - parse supply curve points from input
      • raises error if required columns are missing from the supply curve table
  • RuntimeError
    • run - run supply curve transmission mapping
      • raises error if supply curve execution fails
  • SupplyCurveInputError
    • checksctable - validate the supply curve table
      • raises error if required columns are missing or invalid in the supply curve table
  • SupplyCurveError
    • fullsort - sort supply curve by LCOE with transmission costs
      • raises error if supply curve sorting fails unexpectedly

competitivewindfarms.py

  • RuntimeError
    • removenoncompetitivewindfarms - remove wind farms that are not cost-competitive
      • raises error if the competitive wind farm removal process fails
  • ValueError
    • parsewinddirs - parse wind direction data for competitive analysis
      • raises error if wind direction input is invalid

points.py

  • IndexError
    • SupplyCurvePoint._init__ - initialize a supply curve point
      • raises error if the supply curve gid is out of range
  • SupplyCurveInputError
    • SupplyCurvePoint.parseresources - parse resource data for the point
      • raises error if required resource inputs are missing or invalid
  • EmptySupplyCurvePointError
    • SupplyCurvePoint.checkexcl - check exclusion data for the point
      • raises error if no valid (non-excluded) pixels remain in the supply curve cell
  • ValueError
    • SupplyCurvePoint.parselatlon - parse lat/lon for the supply curve point
      • raises error if latitude or longitude cannot be determined
  • DataShapeError
    • SupplyCurvePoint.parsedatashape - parse expected output data shape
      • raises error if resource and exclusion data shapes do not match
  • FileInputError
    • SupplyCurvePoint.parsetechmap - parse technology mapping from exclusions file
      • raises error if techmap dataset is not found in the exclusions file
  • TypeError
    • SupplyCurvePoint.parseinput - parse a generic input for the supply curve point
      • raises error if input type is not recognized

exclusions.py

  • ValueError
    • LayerMask.parseinclusionweights - parse inclusion weights for a layer
      • raises error if inclusion weight values are invalid
  • ExclusionLayerError
    • LayerMask._init__ - initialize a layer mask
      • raises error if the layer configuration is invalid
  • KeyError
    • ExclusionMask.getlayer - get a layer from the exclusions file
      • raises error if a requested layer is not found in the exclusions h5 file
  • SupplyCurveInputError
    • ExclusionMaskFromDict.parselayer - parse a single exclusion layer from dict
      • raises error if layer specification dict is invalid

techmapping.py

  • FileInputError
    • maptosupplycurve - map resource pixels to supply curve points
      • raises error if techmap dataset is not found in the exclusions file

utilities

curtailment.py

  • KeyError
    • Curtailment.parse - parse curtailment parameters from config
      • raises error if required curtailment parameter keys are missing from the config

implementation

  • Browse the different modules and note base exceptions and/or scenarios where an exception may be acceptable and valuable to users downstream
    • identify existing uses of custom exceptions and base exceptions
  • Replace/Modify exceptions one module at a time.

testing

foresight

certificate of origin

When AI tools contribute to development, proper attribution helps track the evolving role of AI in the development process. Contributions should include an Assisted-by tag in the following format:

Assisted-by: AGENTNAME:MODELVERSION [TOOL1] [TOOL2]

Where:

  • AGENTNAME is the name of the AI tool or framework
  • MODELVERSION is the specific model version used
  • [TOOL1] [TOOL2] are optional specialized analysis tools used (e.g., coccinelle, sparse, smatch, clang-tidy)
  • Basic development tools (git, editors) should not be listed

This contribution:

Assisted-by: Claude:claude-sonnet-4-6 [grep] [glob]

comments

  • “User code can raise built-in exceptions. This can be used to test an exception handler or to report an error condition “just like” the situation in which the interpreter raises the same exception; but beware that there is nothing to prevent user code from raising an inappropriate error.”

  • “ It’s recommended to only subclass one exception type at a time to avoid any possible conflicts between how the bases handle the args attribute, as well as due to possible memory layout incompatibilities.”

  • Allows downstream users of reV to catch reV exceptions explicitly