Numerical Precision#

The data served by the PSM3 API has limited numerical precision, and that precision varies by variable. Many variables, including the various irradiance quantities, are limited to integer precision. Some variables have one, two, or four digits after the decimal point. Additionally, for variables served by multiple endpoints (e.g. GHI is available at both hourly and 5-minute endpoints), the precision does not change between endpoints.

Note that some ostensibly numerical variables are actually categorical (e.g. fill_flag and cloud_type); this notebook excludes those and considers only “true” numerical variables.

[1]:
import pvlib
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
[2]:
# PSM3 API request parameter cases

base_attributes = [  # attributes available at all endpoints
    'ghi', 'dni', 'dhi', 'air_temperature', 'wind_speed',
    'wind_direction', 'surface_albedo', 'surface_pressure', 'dew_point',
]
extra_attributes = [  # attributes only for at 5-min and hourly endpoints
    'relative_humidity', 'total_precipitable_water',
    'clearsky_ghi', 'clearsky_dni', 'clearsky_dhi',
    'solar_zenith_angle',
]
cases = {
    'TMY': {
        'attributes': base_attributes,
        'names': 'tmy',
        'interval': 60,
    },
    'Hourly': {
        'attributes': base_attributes + extra_attributes + ['ghuv-280-400', 'ghuv-295-385'],
        'names': 2020,
        'interval': 60,
    },
    '5-min': {
        'attributes': base_attributes + extra_attributes,
        'names': 2020,
        'interval': 5,
    }
}
[3]:
precisions = pd.DataFrame()

for label, kwargs in cases.items():
    df, meta = pvlib.iotools.get_psm3(40, -80, 'DEMO_KEY', 'assessingsolar@gmail.com',
                                      map_variables=False, leap_day=True, **kwargs)
    df = df.drop(columns=['Year', 'Month', 'Day', 'Hour', 'Minute'])

    for column in df:
        step = min(np.diff(sorted(np.unique(df[column]))))
        precisions.loc[column, label] = step

[4]:
precisions.sort_values('Hourly').plot.bar(logy=True, figsize=(8, 3), width=0.7)
plt.ylabel('Precision (in returned units)');
../_images/pages_numerical-precision_4_0.png
[5]:
%load_ext watermark
%watermark --iversions -u -d -t
Last updated: 2023-02-01 09:23:40

numpy     : 1.23.4
matplotlib: 3.6.2
pvlib     : 0.9.3
pandas    : 1.5.2