From 58842db248dc6e27450ab8d3c6fbf4c4316d8334 Mon Sep 17 00:00:00 2001 From: Roland Date: Sun, 4 Oct 2026 18:13:07 -0600 Subject: [PATCH] Credit NASA POWER as it asks, and say how the data was changed - The calculator gains a "Data attribution" link under the location with NASA POWER's requested acknowledgment, the data reference (Climatology API v2.10.0, downloaded 2026/10/04), the CC BY 4.0 license, and how WROLPi modified the data (rounded to one byte per value, temperature averaged into 1 degree cells, interpolated between cells), which CC BY 4.0 requires. - The build script writes the same text to solar-climatology.LICENSE.txt beside the data, with the API version taken from NASA's responses and the date the tiles were downloaded. A test keeps the page and file in step. - Bumps wrolpi-help for the updated attribution in the help page. Co-Authored-By: Claude Opus 5.5 --- app/public/data/solar-climatology.LICENSE.txt | 11 ++++ .../components/calculators/SolarCalculator.js | 24 ++++++++- .../calculators/SolarCalculator.test.js | 10 ++++ app/src/components/calculators/solarData.js | 14 ++++++ .../components/calculators/solarData.test.js | 28 ++++++++++- docker/help/wrolpi-help | 2 +- scripts/build_solar_climatology.py | 50 ++++++++++++++++++- 7 files changed, 133 insertions(+), 6 deletions(-) create mode 100644 app/public/data/solar-climatology.LICENSE.txt diff --git a/app/public/data/solar-climatology.LICENSE.txt b/app/public/data/solar-climatology.LICENSE.txt new file mode 100644 index 00000000..4290e795 --- /dev/null +++ b/app/public/data/solar-climatology.LICENSE.txt @@ -0,0 +1,11 @@ +Solar climatology for the WROLPi Solar calculator + +Source: NASA POWER, https://power.larc.nasa.gov/ +Data: 2001-2020 monthly climatology of ALLSKY_SFC_SW_DWN, ALLSKY_SFC_SW_DIFF, ALLSKY_SRF_ALB, T2M, on a 1° grid. +The data was obtained from the POWER Project's POWER Climatology API v2.10.0 version on 2026/10/04. + +The data was obtained from National Aeronautics and Space Administration (NASA) Langley Research Center's Prediction Of Worldwide Energy Resources (POWER) project funded through the NASA Earth Science Division. + +License: Creative Commons Attribution 4.0 International (CC BY 4.0), https://creativecommons.org/licenses/by/4.0/ + +Changes: WROLPi modified the data: values are rounded to fit one byte each (0.04 kWh/m²/day for irradiance, 0.004 for albedo, 0.5 °C for temperature), temperatures are averaged from NASA's 0.5° x 0.625° grid into 1° cells, and the calculator interpolates between cells. diff --git a/app/src/components/calculators/SolarCalculator.js b/app/src/components/calculators/SolarCalculator.js index 2e078f10..e8734eba 100644 --- a/app/src/components/calculators/SolarCalculator.js +++ b/app/src/components/calculators/SolarCalculator.js @@ -2,6 +2,7 @@ import React from "react"; import {useSearchParams} from "react-router"; import { Accordion, + Anchor, Button, Grid, Group, @@ -36,7 +37,15 @@ import { totalLoss, TRACKING, } from "./solar"; -import {CLIMATOLOGY_SOURCE, lookupClimatology, useClimatology} from "./solarData"; +import { + CLIMATOLOGY_ACKNOWLEDGMENT, + CLIMATOLOGY_CHANGES, + CLIMATOLOGY_DATA_REFERENCE, + CLIMATOLOGY_LICENSE, + CLIMATOLOGY_SOURCE, + lookupClimatology, + useClimatology, +} from "./solarData"; import {SolarOffGrid} from "./SolarOffGrid"; // Every input lives in the URL query so the Share button (which shares window.location.href) shares @@ -207,6 +216,7 @@ const GEOLOCATION_ERRORS = { function LocationSection({get, set, s, climatology}) { const [locating, setLocating] = React.useState(false); + const [showAttribution, setShowAttribution] = React.useState(false); const [geoError, setGeoError] = React.useState(null); const latError = get('lat') && s.latitude === null ? 'Latitude must be between -90 and 90' : null; const lonError = get('lon') && s.longitude === null ? 'Longitude must be between -180 and 180' : null; @@ -238,7 +248,17 @@ function LocationSection({get, set, s, climatology}) { Enter your own monthly sunlight under "Use my own sunlight data" below. ; } else { - source = `Sunlight and temperature: ${CLIMATOLOGY_SOURCE}.`; + source = <> + Sunlight and temperature: {CLIMATOLOGY_SOURCE}.{' '} + setShowAttribution(!showAttribution)}> + Data attribution + + {showAttribution &&
+

{CLIMATOLOGY_ACKNOWLEDGMENT} {CLIMATOLOGY_DATA_REFERENCE}

+

License: {CLIMATOLOGY_LICENSE}

+

{CLIMATOLOGY_CHANGES}

+
} + ; } return <> diff --git a/app/src/components/calculators/SolarCalculator.test.js b/app/src/components/calculators/SolarCalculator.test.js index f06083e6..4ee7020b 100644 --- a/app/src/components/calculators/SolarCalculator.test.js +++ b/app/src/components/calculators/SolarCalculator.test.js @@ -122,6 +122,16 @@ describe('SolarCalculator', () => { expect(global.fetch).toHaveBeenCalledWith(expect.stringMatching(/\/data\/solar-climatology\.bin$/)); }); + test('the data attribution expands', async () => { + renderWithProviders(, {route: DENVER}); + await findEstimate(); + expect(screen.queryByText(/Prediction Of Worldwide Energy Resources/)).not.toBeInTheDocument(); + fireEvent.click(screen.getByRole('button', {name: 'Data attribution'})); + expect(screen.getByText(/Prediction Of Worldwide Energy Resources/)).toBeInTheDocument(); + expect(screen.getByText(/WROLPi modified the data/)).toBeInTheDocument(); + expect(screen.getByText(/CC BY 4\.0/, {selector: 'p'})).toBeInTheDocument(); + }); + test('typing writes the URL and leaves defaults out', async () => { renderWithProviders(, {route: BASE}); fireEvent.change(screen.getByLabelText('Latitude'), {target: {value: '40°0\'54"N'}}); diff --git a/app/src/components/calculators/solarData.js b/app/src/components/calculators/solarData.js index 2c8fda84..3ccad825 100644 --- a/app/src/components/calculators/solarData.js +++ b/app/src/components/calculators/solarData.js @@ -7,6 +7,20 @@ import React from "react"; export const CLIMATOLOGY_URL = `${process.env.PUBLIC_URL || ''}/data/solar-climatology.bin`; export const CLIMATOLOGY_SOURCE = 'NASA POWER 2001–2020 monthly averages (CC BY 4.0)'; +// Attribution, as NASA asks (https://power.larc.nasa.gov/docs/referencing/) and CC BY 4.0 requires. The +// build script writes the same text, with the API version and download date, to +// public/data/solar-climatology.LICENSE.txt; a test keeps the two in step. +export const CLIMATOLOGY_ACKNOWLEDGMENT = 'The data was obtained from National Aeronautics and Space ' + + 'Administration (NASA) Langley Research Center\'s Prediction Of Worldwide Energy Resources (POWER) project ' + + 'funded through the NASA Earth Science Division.'; +export const CLIMATOLOGY_DATA_REFERENCE = 'The data was obtained from the POWER Project\'s POWER Climatology API ' + + 'v2.10.0 version on 2026/10/04.'; +export const CLIMATOLOGY_LICENSE = 'Creative Commons Attribution 4.0 International (CC BY 4.0), ' + + 'https://creativecommons.org/licenses/by/4.0/'; +export const CLIMATOLOGY_CHANGES = 'WROLPi modified the data: values are rounded to fit one byte each ' + + '(0.04 kWh/m²/day for irradiance, 0.004 for albedo, 0.5 °C for temperature), temperatures are averaged from ' + + 'NASA\'s 0.5° x 0.625° grid into 1° cells, and the calculator interpolates between cells.'; + const MAGIC = 'WSOL'; const VERSION = 1; const HEADER_BYTES = 8; diff --git a/app/src/components/calculators/solarData.test.js b/app/src/components/calculators/solarData.test.js index c3ee7e26..16a15177 100644 --- a/app/src/components/calculators/solarData.test.js +++ b/app/src/components/calculators/solarData.test.js @@ -1,6 +1,13 @@ import fs from "fs"; import path from "path"; -import {decodeClimatology, lookupClimatology} from "./solarData"; +import { + CLIMATOLOGY_ACKNOWLEDGMENT, + CLIMATOLOGY_CHANGES, + CLIMATOLOGY_DATA_REFERENCE, + CLIMATOLOGY_LICENSE, + decodeClimatology, + lookupClimatology, +} from "./solarData"; import {estimateProduction} from "./solar"; import {encodeClimatology, uniformClimatology} from "./solarData.fixtures"; @@ -139,3 +146,22 @@ describeReal('the built climatology file', () => { expect(lookupClimatology(grid, 80, 15).ghi[11]).toBeLessThan(0.05); }); }); + +describe('attribution', () => { + // The build script writes this notice beside the data; the page shows the same text. + const notice = fs.readFileSync(path.join(__dirname, '../../../public/data/solar-climatology.LICENSE.txt'), 'utf8'); + + test('the notice and the page credit NASA identically', () => { + expect(notice).toContain(CLIMATOLOGY_ACKNOWLEDGMENT); + expect(notice).toContain(CLIMATOLOGY_DATA_REFERENCE); + expect(notice).toContain(CLIMATOLOGY_LICENSE); + expect(notice).toContain(CLIMATOLOGY_CHANGES); + }); + + test('the acknowledgment is NASA POWER\'s requested wording', () => { + // https://power.larc.nasa.gov/docs/referencing/ + expect(CLIMATOLOGY_ACKNOWLEDGMENT).toBe('The data was obtained from National Aeronautics and Space ' + + 'Administration (NASA) Langley Research Center\'s Prediction Of Worldwide Energy Resources (POWER) ' + + 'project funded through the NASA Earth Science Division.'); + }); +}); diff --git a/docker/help/wrolpi-help b/docker/help/wrolpi-help index 46f78431..241ba003 160000 --- a/docker/help/wrolpi-help +++ b/docker/help/wrolpi-help @@ -1 +1 @@ -Subproject commit 46f7843174b8e12cea5c5843437fd81d3289e148 +Subproject commit 241ba0032e3b571f1919b2b4f1905449fbd567ed diff --git a/scripts/build_solar_climatology.py b/scripts/build_solar_climatology.py index f4673c56..2fd4654e 100644 --- a/scripts/build_solar_climatology.py +++ b/scripts/build_solar_climatology.py @@ -11,7 +11,9 @@ when NASA publishes a new climatology period, so regenerating it should be rare. Downloaded tiles are cached (see --cache), so an interrupted run resumes where it stopped. -NASA POWER data is licensed CC BY 4.0; the calculator credits it. https://power.larc.nasa.gov/ +NASA POWER data is licensed CC BY 4.0. The build also writes solar-climatology.LICENSE.txt beside the +data, crediting NASA as it asks (https://power.larc.nasa.gov/docs/referencing/), with the API version, +the date the data was downloaded, and how WROLPi changed it. File format (all integers little-endian), decoded by app/src/components/calculators/solarData.js: @@ -26,6 +28,7 @@ bands centered on -179.5 ... 179.5 (west to east). 255 means no data. Each par round((value + offset) / step); see PARAMETERS. """ import argparse +import datetime import json import math import pathlib @@ -49,6 +52,16 @@ ROWS, COLUMNS = 180, 360 MISSING = 255 VERSION = 1 +# NASA's requested acknowledgment. Must match CLIMATOLOGY_ACKNOWLEDGMENT in solarData.js. +ACKNOWLEDGMENT = ('The data was obtained from National Aeronautics and Space Administration (NASA) Langley ' + 'Research Center\'s Prediction Of Worldwide Energy Resources (POWER) project funded through the ' + 'NASA Earth Science Division.') +LICENSE = 'Creative Commons Attribution 4.0 International (CC BY 4.0), https://creativecommons.org/licenses/by/4.0/' +# CC BY 4.0 requires saying what was changed. Must match CLIMATOLOGY_CHANGES in solarData.js. +CHANGES = ('WROLPi modified the data: values are rounded to fit one byte each (0.04 kWh/m²/day for irradiance, ' + '0.004 for albedo, 0.5 °C for temperature), temperatures are averaged from NASA\'s 0.5° x 0.625° grid ' + 'into 1° cells, and the calculator interpolates between cells.') + # (NASA parameter, offset, step). Must match PARAMETERS in solarData.js, in the same order. PARAMETERS = [ ('ALLSKY_SFC_SW_DWN', 0, 0.04), # global horizontal, kWh/m²/day, 0-10.16 @@ -71,13 +84,17 @@ def tile_url(parameter, lat_min, lon_min): return f'{API}?{query}' +def tile_path(cache, parameter, lat_min, lon_min): + return cache / f'{parameter}_{lat_min}_{lon_min}.json' + + def fetch_tile(parameter, lat_min, lon_min, cache, pause, retries=8): """Return the tile's GeoJSON, from the cache when possible. NASA rate limits the API (HTTP 429); back off for up to 10 minutes rather than give up, since a full build is about 2,600 requests. """ - path = cache / f'{parameter}_{lat_min}_{lon_min}.json' + path = tile_path(cache, parameter, lat_min, lon_min) if path.is_file(): return json.loads(path.read_text()) @@ -117,6 +134,24 @@ def bin_points(points): return {cell: [s / n if n else None for s, n in months] for cell, months in sums.items()} +def notice(api, accessed): + """The attribution written beside the data. `api` is like "POWER Climatology API v2.10.0".""" + parameters = ', '.join(p for p, _, _ in PARAMETERS) + return ( + 'Solar climatology for the WROLPi Solar calculator\n' + '\n' + 'Source: NASA POWER, https://power.larc.nasa.gov/\n' + f'Data: 2001-2020 monthly climatology of {parameters}, on a 1° grid.\n' + f'The data was obtained from the POWER Project\'s {api} version on {accessed:%Y/%m/%d}.\n' + '\n' + f'{ACKNOWLEDGMENT}\n' + '\n' + f'License: {LICENSE}\n' + '\n' + f'Changes: {CHANGES}\n' + ) + + def quantize(value, offset, step): if value is None: return MISSING @@ -134,6 +169,7 @@ def main(): tiles = [(lat, lon) for lat in range(-90, 90, TILE) for lon in range(-180, 180, TILE)] out = bytearray(b'WSOL' + struct.pack('