@nexgen-os/pvgis 0.0.0-stage → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Nexgen OS contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,11 @@
1
- # Temporary Holding Version
1
+ # `@nexgen-os/pvgis` — PVGIS hourly energy and irradiance
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Hourly energy, in-plane irradiance and temperature of a PV system over whole years (seriescalc), and its multi-year yield (PVcalc), from [PVGIS](https://joint-research-centre.ec.europa.eu/pvgis-online-tool_en) of the European Commission. Source `pvgis`. MIT; free, no key, no restriction on use. The azimuth from true north is turned into PVGIS's aspect from south; hours are dated at their start in UTC.
4
+
5
+ ```ts
6
+ import { pvgis } from '@nexgen-os/pvgis';
7
+
8
+ const provider = pvgis();
9
+ ```
10
+
11
+ Decision [0011](../../../docs/decisions/0011-external-data.md).
@@ -0,0 +1,63 @@
1
+ import type { Fetch } from '@nexgen-os/core';
2
+ import { azimuthFromSouth, type CollectedSeries, type Point } from '@nexgen-os/core';
3
+ export declare const SOURCE_CODE = "pvgis";
4
+ export interface PvgisSystem {
5
+ /** Peak power, kWp. 1 gives yields per kWp. */
6
+ kwp: number;
7
+ /** Degrees clockwise from true north, as the core stores it. */
8
+ azimuth_deg: number;
9
+ /** Degrees from horizontal. */
10
+ tilt_deg: number;
11
+ /** `building` for roof-mounted, `free` for open rack. */
12
+ mounting: 'building' | 'free';
13
+ /** PVGIS's one aggregate loss, percent. */
14
+ system_loss_pct: number;
15
+ technology?: 'crystSi' | 'CIS' | 'CdTe' | 'Unknown';
16
+ /** Use the digital-elevation horizon. Default true. */
17
+ horizon?: boolean;
18
+ }
19
+ export interface PvgisHourly {
20
+ /** What PVGIS used: the radiation database (SARAH3, ERA5), the years. */
21
+ meta: {
22
+ radiation_db: string;
23
+ meteo_db: string;
24
+ year_min: number;
25
+ year_max: number;
26
+ horizon: string | null;
27
+ };
28
+ /** Energy per hour (kWh, interval), plane-of-array irradiance (W/m², interval mean), air temperature (°C, instant). */
29
+ series: CollectedSeries[];
30
+ }
31
+ export interface PvgisYearly {
32
+ meta: {
33
+ radiation_db: string;
34
+ meteo_db: string;
35
+ };
36
+ /** kWh per year for the system given (per kWp when kwp = 1). */
37
+ annual_kwh: number;
38
+ /** kWh per month, January first. */
39
+ monthly_kwh: number[];
40
+ /** Yearly in-plane irradiation, kWh/m². */
41
+ annual_poa_kwh_m2: number;
42
+ }
43
+ export declare function pvgis(options?: {
44
+ baseUrl?: string;
45
+ fetch?: Fetch;
46
+ }): {
47
+ source_code: string;
48
+ /** Hourly series of a system over whole years: what a yield estimate of the `pvgis_like` profile stores. */
49
+ hourly(where: Point, system: PvgisSystem, years: {
50
+ from: number;
51
+ to: number;
52
+ }, extra?: {
53
+ raddatabase?: string;
54
+ }): Promise<PvgisHourly>;
55
+ /** The multi-year average yield of a system: the quick figure of PVGIS's PV calculator. */
56
+ yearly(where: Point, system: PvgisSystem, extra?: {
57
+ raddatabase?: string;
58
+ }): Promise<PvgisYearly>;
59
+ };
60
+ /** The core's azimuth (from true north, clockwise) as PVGIS's aspect (from south, west positive), in (-180, 180]. */
61
+ export declare const aspectOf: typeof azimuthFromSouth;
62
+ /** `20230101:1210` → the start of that hour in UTC, ISO 8601. */
63
+ export declare function hourStart(stamp: string): string;
package/dist/index.js ADDED
@@ -0,0 +1,81 @@
1
+ // PVGIS — https://re.jrc.ec.europa.eu/pvg_tools/, the European Commission's
2
+ // photovoltaic geographical information system: satellite irradiance (SARAH3)
3
+ // where it covers, ERA5 elsewhere, a digital-elevation horizon, and a PV
4
+ // calculation. Free, no key, no restriction on use (API 5.3, read 13/10/2026).
5
+ //
6
+ // Three conventions are kept straight here so that nobody downstream has to
7
+ // know them: PVGIS counts the azimuth from south (west positive) while the
8
+ // core counts from true north clockwise; PVGIS stamps each hourly value
9
+ // `YYYYMMDD:HHMM` in UTC at the minute of the satellite image, and the core
10
+ // dates an hour at its start; PVGIS gives power in watts, the core keeps
11
+ // kilowatts and kilowatt-hours.
12
+ import { azimuthFromSouth } from '@nexgen-os/core';
13
+ export const SOURCE_CODE = 'pvgis';
14
+ export function pvgis(options = {}) {
15
+ const base = (options.baseUrl ?? 'https://re.jrc.ec.europa.eu/api/v5_3').replace(/\/+$/, '');
16
+ const doFetch = options.fetch ?? globalThis.fetch;
17
+ const systemParams = (system) => ({
18
+ peakpower: String(system.kwp),
19
+ loss: String(system.system_loss_pct),
20
+ angle: String(system.tilt_deg),
21
+ aspect: String(aspectOf(system.azimuth_deg)),
22
+ mountingplace: system.mounting,
23
+ pvtechchoice: system.technology ?? 'crystSi',
24
+ usehorizon: system.horizon === false ? '0' : '1',
25
+ });
26
+ return {
27
+ source_code: SOURCE_CODE,
28
+ /** Hourly series of a system over whole years: what a yield estimate of the `pvgis_like` profile stores. */
29
+ async hourly(where, system, years, extra = {}) {
30
+ const params = new URLSearchParams({
31
+ lat: String(where.lat), lon: String(where.lon),
32
+ startyear: String(years.from), endyear: String(years.to),
33
+ pvcalculation: '1', ...systemParams(system), outputformat: 'json',
34
+ });
35
+ if (extra.raddatabase)
36
+ params.set('raddatabase', extra.raddatabase);
37
+ const body = (await getJson(doFetch, `${base}/seriescalc?${params}`));
38
+ const m = body.inputs.meteo_data;
39
+ const rows = body.outputs.hourly;
40
+ return {
41
+ meta: { radiation_db: m.radiation_db, meteo_db: m.meteo_db, year_min: m.year_min, year_max: m.year_max, horizon: m.horizon_data ?? null },
42
+ series: [
43
+ { quantity_code: 'production_energy', value_kind: 'interval', step: '1 hour', values: rows.map((r) => ({ at: hourStart(r.time), value: round((r.P ?? 0) / 1000) })) },
44
+ { quantity_code: 'poa_irradiance', value_kind: 'interval', step: '1 hour', values: rows.map((r) => ({ at: hourStart(r.time), value: r['G(i)'] })) },
45
+ { quantity_code: 'temperature', value_kind: 'instant', step: '1 hour', values: rows.map((r) => ({ at: hourStart(r.time), value: r.T2m })) },
46
+ ],
47
+ };
48
+ },
49
+ /** The multi-year average yield of a system: the quick figure of PVGIS's PV calculator. */
50
+ async yearly(where, system, extra = {}) {
51
+ const params = new URLSearchParams({ lat: String(where.lat), lon: String(where.lon), ...systemParams(system), outputformat: 'json' });
52
+ if (extra.raddatabase)
53
+ params.set('raddatabase', extra.raddatabase);
54
+ const body = (await getJson(doFetch, `${base}/PVcalc?${params}`));
55
+ return {
56
+ meta: { radiation_db: body.inputs.meteo_data.radiation_db, meteo_db: body.inputs.meteo_data.meteo_db },
57
+ annual_kwh: body.outputs.totals.fixed.E_y,
58
+ monthly_kwh: [...body.outputs.monthly.fixed].sort((a, b) => a.month - b.month).map((x) => x.E_m),
59
+ annual_poa_kwh_m2: body.outputs.totals.fixed['H(i)_y'],
60
+ };
61
+ },
62
+ };
63
+ }
64
+ /** The core's azimuth (from true north, clockwise) as PVGIS's aspect (from south, west positive), in (-180, 180]. */
65
+ export const aspectOf = azimuthFromSouth;
66
+ /** `20230101:1210` → the start of that hour in UTC, ISO 8601. */
67
+ export function hourStart(stamp) {
68
+ const m = /^(\d{4})(\d{2})(\d{2}):(\d{2})(\d{2})$/.exec(stamp);
69
+ if (!m)
70
+ throw new Error(`pvgis_time_unreadable: ${stamp}`);
71
+ return new Date(Date.UTC(Number(m[1]), Number(m[2]) - 1, Number(m[3]), Number(m[4]), 0)).toISOString();
72
+ }
73
+ async function getJson(doFetch, url) {
74
+ const response = await doFetch(url, { headers: { Accept: 'application/json' } });
75
+ if (!response.ok)
76
+ throw new Error(`source_unavailable: ${response.status} from PVGIS`);
77
+ return response.json();
78
+ }
79
+ function round(n) {
80
+ return Math.round(n * 1e6) / 1e6;
81
+ }
package/package.json CHANGED
@@ -1,6 +1,37 @@
1
1
  {
2
2
  "name": "@nexgen-os/pvgis",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.4.0",
4
+ "description": "PVGIS hourly PV energy and irradiance as a Nexgen OS connector.",
5
+ "license": "MIT",
6
+ "repository": {
7
+ "type": "git",
8
+ "url": "git+https://github.com/nexgen-os/nexgen-os.git",
9
+ "directory": "packages/connectors/pvgis"
10
+ },
11
+ "publishConfig": {
12
+ "access": "public"
13
+ },
14
+ "type": "module",
15
+ "engines": {
16
+ "node": ">=20"
17
+ },
18
+ "files": [
19
+ "dist",
20
+ "README.md",
21
+ "LICENSE"
22
+ ],
23
+ "main": "./dist/index.js",
24
+ "types": "./dist/index.d.ts",
25
+ "exports": {
26
+ ".": {
27
+ "types": "./dist/index.d.ts",
28
+ "import": "./dist/index.js"
29
+ }
30
+ },
31
+ "scripts": {
32
+ "build": "tsc -p tsconfig.build.json"
33
+ },
34
+ "dependencies": {
35
+ "@nexgen-os/core": "^0.4.0"
36
+ }
37
+ }