Getting data for your models

PVRADAR allows users to automatically retrieve resources - usually time-series data - from a variety of different sources and in a single line of code.

resource = site.resource(R.resource_type)

Alternatively you can also add the required inputs to your model definition and have PVRADAR automatically handle the imports - we say “bind” - whenever this model is executed:

from typing import Annotated
from pvradar.sdk import R
import pandas as pd

def my_model(
	rain: Annotated[pd.Series, R.rainfall(to_unit='cm', to_freq='D')], # model expects total daily rainfall in cm from any datasource
	airtemp: Annotated[pd.Series, R.air_temperature(datasoure='era5')], # model expects average hourly (implicit) air temperature from ERA5
	):
	...
	
site.run(my_model) 

Learn more about use of resources in models here: Defining a Model (Chain)


In both examples R.resource_type() is the resource descriptor using PVRADAR’s R-Notation. This page explains the details.


About resources

Resources are data structures supported by PVRADAR for use in models. Most commonly, they are time-series data representing meteorological or environmental variables (e.g., temperature, rainfall, PM10), but they can also be any type of objects, such as dictionaries containing scalar parameters (e.g., design parameters or site configuration settings).


Resource types

Each resource is associated with a resource type, which defines the physical quantity it represents (e.g., global horizontal irradiance, air temperature, soiling loss factor, tracker rotation angle) and serves as its semantic identifier. For example, a model may request a resource of type air temperature, so the simulation context will attempt to bind it to any available resource (or model) of this type.


Get exactly what you need!

<aside> ✅

PVRADAR is all about accuracy and transparency!

</aside>

Users can get exactly what they need using resource attributes, such as:


To review what exact resource you are dealing with use describe function from pvradar to print short description of resource.

from pvradar.sdk import describe 
describe(rainfall)

rainfall: total hourly rainfall in mm from merra2 11664 data points (2013-02-01 00:00:00-08:00 to 2014-06-01 23:00:00-08:00)


Or you can inspect the attrs property.

rainfall.attrs

{'resource_type': 'rainfall', 'unit': 'mm', 'agg': 'sum', 'freq': 'h', 'datasource': 'merra2'}


Use the R-Notation to describe a resource

Describing a resource is very simple using our R-Notation: R.resource_type(attribute_1=value_1, …)

<aside> 💡

Note: all resource attributes are always optional. If not specified by the user, PVRADAR will assume default attributes. A list of all available resource types, their definitions and their default attributes can be found in .

</aside>

Here is an example: explicit user-defined parameters in bold, implicit default parameters in italic.

from pvradar.sdk import R
R.air_temperature # *mean hourly* air temperature *in degC from merra2*
R.rainfall(to_freq='D', to_unit='cm') # *total* **daily** rainfall **in cm** *from merra2*
R.snowfall_rate(to_freq='M', to_unit='m', datasource='era5') # *mean* **monthly** snowfall rate **in m from era5**

to_freq

Time-series data always comes with a frequency, for example hourly, daily or monthly, but also 1-min or 10-min, etc. Users can define the desired frequency of a resource using the attribute to_freq. When provided, pvradar will automatically resample the time-series data to match the expected frequency.

Useful values: D (daily), h (hourly), min (minute), Y (Yearly)

A full list can be found here in the pandas documentation.


to_unit

In PVRADAR, units are managed automatically using the pint library, ensuring consistency and easy conversion. For example, when you call the resource rainfall with to_unit=’cm’, its values are automatically multiplied with 0.1 to convert mm (default unit according to ) to cm.

Other examples for valid units are mm, degC, W/m^2, Kg/m^3, etc.fraction is a special unit meaning a number between 0 and 1 - related to % by a factor of 100 - used for loss factors.

If a unit conversion is not possible, an error message is shown.


Next to to_unit there is also the attribute set_unit which does not attempt a unit conversion, but simply sets the unit to the specified value (and potentially overwrites any existing unit)

When would you need this? This attribute is useful to automatically assign a unit to the output of models. For more information visit Defining a Model (Chain)


datasource

Some resources are the product of a model, others are taken from an online database, such as, for example ERA5 or MERRA2, or from a meteo station network like NOAA. Which datasources are available for each resource type can be reviewed in the .

When using data from meteo station networks like NOAA, users can also add an additional attribute station_id to define which station exactly the data should be taken from. If not passed, PVRADAR automatically selects the station with the highest score - a combination of short distance and gap-free, consistent data. More information here: Satellite Databases and Meteo Stations

Aggregation Type

Time-series data can be either cumulative or instantaneous.

Cumulative resources are always expressed as sums or totals over the measurement interval. Instantaneous resources, on the other hand, can represent averages (default), minimum or maximum values, or percentiles of measurements. The type of aggregation is defined by the resource attribute agg. This attribute becomes particularly important when resampling: Cumulative resources are summed during resampling, instantaneous resources are averaged.

Examples: