@johnmorrisdotca/chikyu-earth 0.54.0 → 0.56.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/CHANGELOG.md CHANGED
@@ -1,6 +1,21 @@
1
1
  # Changelog
2
2
 
3
- ## Unreleased
3
+ ## 0.56.0 - 2026-11-17
4
+
5
+
6
+ - **Real time is smooth: a frame each time the quickest thing has moved half a pixel** (MODULES-1448). At real time the globe and the satellites were drawn once a second, and zoomed in or riding along that stepped visibly. Now, at real time and up to 60 times it, `<chikyu-space>` and `<chikyu-earth-realistic>` draw each time the quickest thing in the picture has moved half a CSS pixel on the screen.
7
+ - **What is measured.** The Earth's turn at the current zoom; a satellite dot, from the group's own quickest speed (the new `Satellites.fastest`, Earth radii a second, worked out from the two SGP4 places the group already holds, once for each pair, so about once a second and never at a frame) times the Earth's radius on the screen; and, in `<chikyu-space>`, the ridden craft and the camera in a ride. SGP4 still runs about once a second, with the places between interpolated.
8
+ - **Limits.** At least once a second while satellites are on show or a ride along (as before), so a whole Earth at real time stays at one or two a second; at most `smooth-fps` a second, 15 by default (the new attribute and property `smoothFps`, from 1 to 30); half of that on a small device (2 GB of memory or less, or 2 cores or fewer) or a battery at 20% or lower that is not charging; one a second for a reader who prefers reduced motion; nothing at rest, held, out of sight or in a hidden tab, as before. Above real time up to 60 times it the picture is drawn at least as often as before (a frame for each pixel, up to 30 a second), and above 60 times as before. With only the Earth turning, real time still waits up to a minute (`live-seconds` on `<chikyu-earth-realistic>`) but comes sooner when the turn has moved half a pixel, which happens zoomed in.
9
+ - **Seen.** `stats.pace` on both elements: `pixelsPerSecond`, `perSecond`, `cap` and `waitMs` as last worked out. New pure functions in `@johnmorrisdotca/chikyu-earth/realistic`: `framesPerSecond`, `waitFor`, `readSmoothFps`, `smoothCap` and `watchLowBattery`.
10
+ - **Measured** (software drawing, headless Chromium): whole Earth with 2,252 satellites at real time 1.00 frames a second; zoomed in 2.0; riding the ISS 8 to 10 (the software GPU draws a ride slowly; the page asked for 14); reduced motion 1.00 in both; `smooth-fps="4"` while riding 4.00. On a phone's screen with the CPU slowed to a quarter and 18,252 satellites: whole Earth 1.00 frames a second, zoomed in 1.4, riding the ISS 11.2, at 4.2 ms of JavaScript a frame on average while riding (28 ms for the one frame a second that also runs the SGP4 batch, 25 to 29 ms). Tests: `e2e/freeze.demo.ts` (the three cases and reduced motion), `e2e/satellites.gl.ts` (the phone), `test/pace.test.ts`.
11
+ - **Finer tiles: a daily layer's end is respected, and another layer stands in** (MODULES-1446). Suomi NPP VIIRS stops at 2026-11-02 in NASA's capabilities, but any later day was still asked of it, so its finer tiles for those days did not come. A layer that has ended is now asked for no day after its last. When the layer asked for has no picture for a day, the first of NOAA-20 VIIRS, NOAA-21 VIIRS, Suomi NPP VIIRS, MODIS Terra and MODIS Aqua that has it is read instead, and a day still to come shows the newest day there is. The credit line says when the picture is not the one asked for ("Shown: NOAA-20 VIIRS, 2026-11-10 (Suomi NPP VIIRS has no picture for that day)."). The days of every daily layer are one table, read on 2026-11-17 (`GIBS_DAYS_READ`), which `/photos` uses too; how to refresh it is beside it in `src/door/gibs.ts`. `gibsTiles` takes `now` (the present moment, `Date.now` when left out). Unit tests of each case from the table (no request to NASA), and a browser test that a past-end day of Suomi NPP draws NOAA-20's ground, not black.
12
+
13
+ ## 0.55.0 - 2026-11-17
14
+
15
+ - **Real satellite pictures of the ground under a point: `@johnmorrisdotca/chikyu-earth/photos`** (MODULES-1368). Pure functions that make the address of a NASA GIBS (Worldview) true-colour snapshot of a box around a point, so a page can show the ground under a satellite or a ride. The reader's browser fetches the picture from NASA (no key, no account, no server cache); about 250 m a pixel, clouds left in.
16
+ - **Functions.** `photoUrl({ lat, lon, sizeKm, date, widthPx })` (a WMS GetMap request, EPSG:4326, JPEG; a box over the date line or a pole is moved inside the world), `photoPieces` (the exact box as one request, or two across the date line), `photoBox`, `photoLayer`, `photoFallbacks` (the days to try, newest first, when a day's picture is black) and `photoCredit(lang, full?)` (the short credit line, English and Japanese, or NASA's own acknowledgement sentence). The layer is NOAA-20 VIIRS from 2018-01-05, then Suomi NPP VIIRS (2015-11-24 to 2026-11-02, when it ends) and MODIS Terra (from 2000-02-24); before that there is no picture.
17
+ - **Demo.** The flat map page has "The ground under it": choose a satellite, pick 100, 300 or 1,000 km, press the button, and the picture of the place under it appears with the credit line. English and Japanese.
18
+ - **Docs and tests.** English and Japanese guides, a tested example `examples/node/photos.mjs`, and unit tests of every function (the address strings only: no test asks NASA), each shown to fail when its code is broken. `NOTICE.md` has the terms.
4
19
 
5
20
  ## 0.54.0 - 2026-11-17
6
21
 
package/NOTICE.md CHANGED
@@ -76,10 +76,14 @@ The service's page "Data Use Guidance and Acknowledgements" (https://www.earthda
76
76
 
77
77
  The tile matrix was read the same day from `https://gibs.earthdata.nasa.gov/wmts/epsg4326/best/1.0.0/WMTSCapabilities.xml`. Geographic tiles are 512 pixels, the corner of the matrix is longitude -180 and latitude 90, and a pixel is 0.5625/2^level degrees. Levels 0, 1 and 2 run past the Earth (2×1, 3×2 and 5×3 tiles); from level 3 the matrix covers the Earth in 10×5 tiles and doubles from there. A successful tile for the static shaded-relief layer answered `access-control-allow-origin: *` and `cache-control: public, max-age=259200`. A successful tile for a daily true-colour layer on the same day answered `access-control-allow-origin: *` and `cache-control: max-age=0, no-store`. No key is sent.
78
78
 
79
- The default layer is `Landsat_WELD_CorrectedReflectance_TrueColor_Global_Annual` (NASA GWELDYR, "NASA Global Web-Enabled Landsat Data Annual Global 30 m V031", LP DAAC, concept id C2763268459-LPCLOUD; 31.25m matrix, JPEG, levels 0 to 11, a picture a year: 1984 to 1985, 1988 to 1990 and 1998 to 2000, the page uses 2000-12-01). Checked against the live service on 2026-11-13, with a few requests each: tiles answer 200 with `content-type: image/jpeg`, `cache-control: public, max-age=2592000`, `access-control-allow-origin: *`, `layer-time-actual: 2000-12-01T00:00:00Z`; the tile addresses are the ones this package's grid names (Vancouver level 9 row 72 column 101, level 10 row 144 column 202, level 11 row 289 column 404; Tokyo 9/96/568; Paris 10/146/648; the Sahara 9/115/337). Coverage as seen: land at 49 N, 35 N, 25 N and in the Amazon; no data (a 200 with an all-black, 4,723-byte picture, the same as a daily layer's) over the Pacific, Antarctica, Greenland at 72 N, Svalbard at 78 N and at the pole. The picture is cloud-free and sharp (streets and fields at level 9) but of the year 2000, and straight scene edges show in places (for example west of Tokyo). The page treats a wholly black tile as no picture, clears black and nearly black pixels (luminance up to 20 clear, from 32 opaque: the sea in the mosaic is about (7, 25, 12) and a dark wooded slope (8, 39, 6) to (22, 54, 7)), and multiplies the colours by 0.76, 0.66 and 0.55: the median, over six land places (Paris, the Sahara, the Amazon, Kansas, Siberia, Australia), of the package's own level 5 over this layer's mean colour in the same 2.25 degree square (0.75 0.77 0.77 0.70 0.81 0.68 red, 0.65 0.71 0.70 0.61 0.61 0.56 green, 0.53 0.64 0.59 0.51 0.54 0.53 blue). Layer-specific credit: NASA's acknowledgement is the one the data-use page asks for; the layer's metadata names the product and its data centre only, so the credit line names the Global Web-Enabled Landsat Data and LP DAAC as well. Other layers checked and not used as the default: `ASTER_GDEM_Color_Shaded_Relief` (31.25m, colour-coded height, not true colour); `MODIS_Terra_L3_SurfaceReflectance_Bands143_8Day` (500 m, an 8-day true-colour composite, speckled with cloud); `HLS_S30_Nadir_BRDF_Adjusted_Reflectance` and the L30 twin (31.25m daily scenes, 600 KB PNG tiles, solid cloud over Paris on 2026-11-05); `BlueMarble_NextGeneration` (500 m, the package's own source); no Blue Marble at 250 m exists on the service. `MODIS_Terra_CorrectedReflectance_TrueColor` (250 m, JPEG, days 2000-02-24 to 2026-11-13 with gaps; the name `today`): the page looks for the most recent day that answers with a picture, from the day before the moment on show back at most 10 days, one tile a day (2026-11-13 answered 200 with an all-black picture, 2026-11-12 and 2026-11-11 with pictures; the daily tiles answer `cache-control: max-age=0, no-store, no-cache, must-revalidate` and `access-control-allow-origin: *`, and carry `layer-time-actual`). `VIIRS_SNPP_CorrectedReflectance_TrueColor` has days from 2015-11-24 to 2026-11-02 with gaps. `BlueMarble_ShadedRelief_Bathymetry` (500 m) has no day. A daily layer's day before its first day, or in a gap of the list that was read, is not requested; a day after the last listed day is, because a daily layer goes on growing. The daily layers are true colour with the clouds left in, and a day's picture has black gaps between passes, which the page clears.
79
+ The default layer is `Landsat_WELD_CorrectedReflectance_TrueColor_Global_Annual` (NASA GWELDYR, "NASA Global Web-Enabled Landsat Data Annual Global 30 m V031", LP DAAC, concept id C2763268459-LPCLOUD; 31.25m matrix, JPEG, levels 0 to 11, a picture a year: 1984 to 1985, 1988 to 1990 and 1998 to 2000, the page uses 2000-12-01). Checked against the live service on 2026-11-13, with a few requests each: tiles answer 200 with `content-type: image/jpeg`, `cache-control: public, max-age=2592000`, `access-control-allow-origin: *`, `layer-time-actual: 2000-12-01T00:00:00Z`; the tile addresses are the ones this package's grid names (Vancouver level 9 row 72 column 101, level 10 row 144 column 202, level 11 row 289 column 404; Tokyo 9/96/568; Paris 10/146/648; the Sahara 9/115/337). Coverage as seen: land at 49 N, 35 N, 25 N and in the Amazon; no data (a 200 with an all-black, 4,723-byte picture, the same as a daily layer's) over the Pacific, Antarctica, Greenland at 72 N, Svalbard at 78 N and at the pole. The picture is cloud-free and sharp (streets and fields at level 9) but of the year 2000, and straight scene edges show in places (for example west of Tokyo). The page treats a wholly black tile as no picture, clears black and nearly black pixels (luminance up to 20 clear, from 32 opaque: the sea in the mosaic is about (7, 25, 12) and a dark wooded slope (8, 39, 6) to (22, 54, 7)), and multiplies the colours by 0.76, 0.66 and 0.55: the median, over six land places (Paris, the Sahara, the Amazon, Kansas, Siberia, Australia), of the package's own level 5 over this layer's mean colour in the same 2.25 degree square (0.75 0.77 0.77 0.70 0.81 0.68 red, 0.65 0.71 0.70 0.61 0.61 0.56 green, 0.53 0.64 0.59 0.51 0.54 0.53 blue). Layer-specific credit: NASA's acknowledgement is the one the data-use page asks for; the layer's metadata names the product and its data centre only, so the credit line names the Global Web-Enabled Landsat Data and LP DAAC as well. Other layers checked and not used as the default: `ASTER_GDEM_Color_Shaded_Relief` (31.25m, colour-coded height, not true colour); `MODIS_Terra_L3_SurfaceReflectance_Bands143_8Day` (500 m, an 8-day true-colour composite, speckled with cloud); `HLS_S30_Nadir_BRDF_Adjusted_Reflectance` and the L30 twin (31.25m daily scenes, 600 KB PNG tiles, solid cloud over Paris on 2026-11-05); `BlueMarble_NextGeneration` (500 m, the package's own source); no Blue Marble at 250 m exists on the service. `MODIS_Terra_CorrectedReflectance_TrueColor` (250 m, JPEG, days 2000-02-24 to 2026-11-13 with gaps; the name `today`): the page looks for the most recent day that answers with a picture, from the day before the moment on show back at most 10 days, one tile a day (2026-11-13 answered 200 with an all-black picture, 2026-11-12 and 2026-11-11 with pictures; the daily tiles answer `cache-control: max-age=0, no-store, no-cache, must-revalidate` and `access-control-allow-origin: *`, and carry `layer-time-actual`). `BlueMarble_ShadedRelief_Bathymetry` (500 m) has no day. The days of the daily true-colour layers were read again on 2026-11-17 from the same WMTS capabilities file (the WMS capabilities list the same days), and are one table in `src/door/gibs.ts` (`GIBS_LAYERS`, `GIBS_DAYS_READ`; how to refresh it is beside it): `VIIRS_NOAA20_CorrectedReflectance_TrueColor` 2018-01-05 to 2026-11-16, `VIIRS_NOAA21_CorrectedReflectance_TrueColor` 2023-02-10 to 2026-11-16, `VIIRS_SNPP_CorrectedReflectance_TrueColor` 2015-11-24 to 2026-11-02 (its last day, two weeks behind the others: taken as ended), `MODIS_Terra_CorrectedReflectance_TrueColor` 2000-02-24 to 2026-11-17 and `MODIS_Aqua_CorrectedReflectance_TrueColor` 2002-07-03 to 2026-11-16, each with gaps. A tile of Suomi NPP for 2026-11-10 answered 404 that day, and the same tile of NOAA-20 a 77 KB picture. A layer's day before its first day, in a gap of its list, or after the last day of a layer that has ended, is not requested from it: the first of NOAA-20, NOAA-21, Suomi NPP, MODIS Terra and MODIS Aqua that has the day is read instead, and the credit line says so. A day after the last listed day of a layer still running is requested, up to today, because such a layer goes on growing. The daily layers are true colour with the clouds left in, and a day's picture has black gaps between passes, which the page clears.
80
80
 
81
81
  The 500 m maps could fill one more level (65536 across for the day map); the pyramid stops at level 5 (day) and level 4 (night) for now. Where the pyramid is hosted: GitHub Pages of this public repository, which costs nothing (docs/guides/earth-tiles.md). It adds 3,412 files and 35.4 MB to the site (852 files and 10.3 MB before the 500 m levels; the levels above day 4 and night 3 go out only when the repository variable EARTH_TILES_ALL is yes, see docs/guides/earth-tiles.md). The source files are downloaded by the build (688 MB, once, kept by CI's cache) and are not part of the site.
82
82
 
83
+ ## Pictures of the ground under a point
84
+
85
+ `@johnmorrisdotca/chikyu-earth/photos` makes the address of a snapshot (a WMS GetMap request, `https://gibs.earthdata.nasa.gov/wms/epsg4326/best/wms.cgi`) of NASA's Global Imagery Browse Services for a box on a day, and the demo's flat map page asks for it from the reader's browser when a button is pressed. Nothing is fetched by the package and nothing is stored or sent through this site. The terms are those of the section above (the same page, the same acknowledgement, which `photoCredit(lang, true)` returns) and of NASA's media guidelines (https://www.nasa.gov/nasa-brand-center/images-and-media/: NASA content "generally are not subject to copyright in the United States", "NASA should be acknowledged as the source of the material"); not endorsed by NASA. The layers are `VIIRS_NOAA20_CorrectedReflectance_TrueColor`, `VIIRS_SNPP_CorrectedReflectance_TrueColor` and `MODIS_Terra_CorrectedReflectance_TrueColor`, with the days NASA's WMS capabilities document (`https://gibs.earthdata.nasa.gov/wms/epsg4326/best/wms.cgi?SERVICE=WMS&REQUEST=GetCapabilities&VERSION=1.3.0`) listed on 2026-11-17. On that day a GetMap for Suomi NPP after 2026-11-02 returned a black picture (the satellite's last day in the list), and one for NOAA-20 and MODIS Terra returned a picture; the answers carry `access-control-allow-origin: *`. NASA publishes no rate limit that this repository has read.
86
+
83
87
  ## The Moon's picture
84
88
 
85
89
  `moon-*.webp` is made by `scripts/make-textures.py` from NASA's Scientific Visualization Studio item 4720, "Moon: LROC colour mosaic" (https://svs.gsfc.nasa.gov/4720/,
package/README.md CHANGED
@@ -614,7 +614,7 @@ console.log(countryList().filter((country) => country.alpha2 === null).map((coun
614
614
 
615
615
  ## How to cite
616
616
 
617
- > Morris, J. (2026). *Chikyu Earth* (version 0.54.0) [Computer software]. https://github.com/johnmorrisdotca/chikyu-earth
617
+ > Morris, J. (2026). *Chikyu Earth* (version 0.56.0) [Computer software]. https://github.com/johnmorrisdotca/chikyu-earth
618
618
 
619
619
  GitHub's "Cite this repository" button reads [CITATION.cff](CITATION.cff) and gives BibTeX and APA. Cite the version you used (`npm ls @johnmorrisdotca/chikyu-earth`), and credit the sources behind the numbers and pictures: [NOTICE.md](NOTICE.md) says who made each one and under what terms.
620
620
 
@@ -37,16 +37,31 @@ export declare const GIBS_CREDIT: {
37
37
  readonly en: "We acknowledge the use of imagery provided by services from NASA's Global Imagery Browse Services (GIBS), part of NASA's Earth Science Data and Information System (ESDIS).";
38
38
  readonly ja: "NASAの地球科学データ情報システム(ESDIS)の一部である Global Imagery Browse Services(GIBS)が提供する画像を使用していることを記します。";
39
39
  };
40
- /** A day the layer has imagery, inclusive, as the capabilities document listed it on 2026-11-13. Dates sort as text. */
40
+ /**
41
+ * The day the daily layers' days in `GIBS_LAYERS` were read, from the capabilities documents (the tiles' WMTS and the snapshots' WMS list the same days).
42
+ *
43
+ * To refresh the table: fetch `https://gibs.earthdata.nasa.gov/wmts/epsg4326/best/1.0.0/WMTSCapabilities.xml`, and for each daily layer copy the `<Value>` ranges of its `Time` dimension
44
+ * (`start/end/P1D`) into `ranges`, oldest first. Mark a layer `ended` when its last day stays behind the others' (the satellite has stopped, or its processing has), and take the mark off if it starts again. Then change this date.
45
+ */
46
+ export declare const GIBS_DAYS_READ = "2026-11-17";
47
+ /** A day the layer has imagery, inclusive, as the capabilities document listed it on `GIBS_DAYS_READ`. Dates sort as text. */
41
48
  interface DayRange {
42
49
  start: string;
43
50
  end: string;
44
51
  }
52
+ /** One layer of NASA's service, as the package uses it. */
45
53
  interface GibsLayer {
46
54
  id: string;
47
55
  matrix: "31.25m" | "250m" | "500m";
48
- /** Empty for a picture that has no day (the shaded relief, and the annual Landsat mosaics, which have `years`). */
56
+ /** The days it has, oldest first. Empty for a picture that has no day (the shaded relief, and the annual Landsat mosaics, which have `years`). */
49
57
  ranges: readonly DayRange[];
58
+ /**
59
+ * True when the layer has stopped: no day after its last listed one is asked for. A layer still running is taken to go on to the present day after its last listed one, because the list is of the day it was read and
60
+ * the satellite goes on sending.
61
+ */
62
+ ended?: boolean;
63
+ /** The satellite and instrument, for the credit line when this layer stands in for another (see `gibsPick`). */
64
+ name?: string;
50
65
  /** True when the picture is one day of the satellite and clouds are left in. */
51
66
  clouds: boolean;
52
67
  /** For a layer with one picture a year: the years' times, as the service names them (`yyyy-mm-dd`), oldest first. The newest is the one used unless a page names another of them. */
@@ -64,10 +79,15 @@ interface GibsLayer {
64
79
  };
65
80
  }
66
81
  /**
67
- * The layers a page may ask for. The ranges are the days the capabilities document listed on 2026-11-13; a day outside them is not requested.
68
- * The two daily layers are true colour with the clouds left in. The shaded relief is the same kind of picture as the package's own level 5, and is only a stand-in.
82
+ * The layers a page may ask for, and the one table of the days each daily layer has (read on `GIBS_DAYS_READ`; how to refresh it is there). A day outside a layer's days is not requested from it.
83
+ * The daily layers are true colour with the clouds left in. Suomi NPP VIIRS has ended: its last day is 2026-11-02, and a later day is a black picture. The shaded relief is the same kind of picture as the package's own level 5, and is only a stand-in.
69
84
  */
70
85
  export declare const GIBS_LAYERS: Readonly<Record<string, GibsLayer>>;
86
+ /**
87
+ * The daily true-colour layers in the order one stands in for another: when the layer a page asked for has no picture for a day (it has ended, it had not started, or the day is in a gap of its list), the first of these that has the day is used.
88
+ * NOAA-20 VIIRS, NOAA-21 VIIRS, Suomi NPP VIIRS (VIIRS is finer and newer than MODIS), then MODIS Terra and MODIS Aqua.
89
+ */
90
+ export declare const GIBS_DAILY_ORDER: readonly string[];
71
91
  /**
72
92
  * The layer a page gets without naming one: the Landsat annual true-colour mosaic (30 m, no cloud, land only; the year 2000, the newest it has). The daily layers are a named choice: `today` for MODIS Terra.
73
93
  * A layer id is taken as it is, and these short names stand for two of them.
@@ -120,9 +140,36 @@ export declare function utcDay(ms: number): string;
120
140
  */
121
141
  export declare function previousUtcDay(ms: number): string;
122
142
  /**
123
- * Whether the layer may have imagery for a day: inside one of the ranges listed on 2026-11-13, or after the last of them (a daily layer goes on growing, and the list does not). A day before the layer's first day, or in a gap the list shows, has none, and is not asked for.
143
+ * Whether the layer may have imagery for a day: inside one of its listed ranges, or, for a layer still running (not `ended`), after the last of them and no later than `today` (the list is of the day it was read, and the layer goes on growing).
144
+ * A day before the layer's first day, in a gap the list shows, after the last day of a layer that has ended, or after `today`, has none, and is not asked for.
145
+ *
146
+ * @param today - The present UTC day, `yyyy-mm-dd`. Left out, a running layer has every day after its last listed one.
147
+ */
148
+ export declare function gibsHasDay(layer: GibsLayer, day: string, today?: string): boolean;
149
+ /** Why `gibsPick` chose what it did: the layer asked for has the day, another layer stands in for it, or no layer has the day and the newest day there is is shown instead. */
150
+ type GibsPickWhy = "asked" | "layer" | "newest";
151
+ /** The layer and the day the tiles are read from, for a layer asked for and a day wanted. */
152
+ interface GibsPick {
153
+ layer: GibsLayer;
154
+ day: string;
155
+ /** The day that was wanted. */
156
+ wanted: string;
157
+ why: GibsPickWhy;
158
+ }
159
+ /** The newest day each daily layer surely has by `today`: the day before it for a layer still running (that day's passes are in), the last listed one for a layer that has ended. The newest of them, from the first layer in `GIBS_DAILY_ORDER` that has it. */
160
+ export declare function gibsNewest(today: string): {
161
+ layer: GibsLayer;
162
+ day: string;
163
+ } | undefined;
164
+ /**
165
+ * The layer and day to read for a day wanted. The layer asked for when it has the day. Else, for a daily true-colour layer, the first of `GIBS_DAILY_ORDER` that has it (Suomi NPP has ended on 2026-11-02, so a later day is NOAA-20's).
166
+ * Else, when the day is after the newest day any of them has (a day still to come), that newest day, from the layer asked for if it has it. A day no layer has that is not after all of them (before 2000-02-24, when MODIS Terra began) gives `undefined`: nothing is requested.
167
+ *
168
+ * @param today - The present UTC day, `yyyy-mm-dd`: no layer has a day after it.
124
169
  */
125
- export declare function gibsHasDay(layer: GibsLayer, day: string): boolean;
170
+ export declare function gibsPick(asked: GibsLayer, day: string, today: string): GibsPick | undefined;
171
+ /** The days the default rule tries, newest first, each with the layer it is read from: from `start` (or, when `start` is after every layer, from the newest day there is), back, `GIBS_LOOKBACK_DAYS` days, skipping a day no layer has. */
172
+ export declare function gibsPickCandidates(asked: GibsLayer, start: string, today: string): GibsPick[];
126
173
  /** A day the layer can serve for a fixed rule (`latest`, the default, starts at the day before `ms`), or `undefined` when it lands where the layer has no imagery (nothing is requested). */
127
174
  export declare function gibsDay(layer: GibsLayer, rule: string, ms: number): string | undefined;
128
175
  /** The days the default rule looks at, newest first: from `start`, back, skipping days the layer is known to lack, until the layer's first day or `GIBS_LOOKBACK_DAYS` days have been counted. */
@@ -153,6 +200,8 @@ export interface GibsTilesOptions extends EarthTilesOptions {
153
200
  changed?: () => void;
154
201
  /** How many milliseconds a tile is given to arrive (`GIBS_SLOW_MS`, 2000, when left out). A page on a slow link can give it longer. */
155
202
  slowMs?: number;
203
+ /** The present moment, which no layer has a picture after (`Date.now` when left out; not the moment on show, which may be one still to come). */
204
+ now?: () => number;
156
205
  }
157
206
  /**
158
207
  * Where a tile's luminance (0 to 255) is at or below this, the picture has no data there (the service paints it black) and the loader draws it clear; from `NODATA_FULL` it is opaque, and between the two a share, so the edge of a gap is not a hard
package/dist/door/gibs.js CHANGED
@@ -49,8 +49,24 @@ const INFO = {
49
49
  retrieved: GIBS_READ,
50
50
  };
51
51
  /**
52
- * The layers a page may ask for. The ranges are the days the capabilities document listed on 2026-11-13; a day outside them is not requested.
53
- * The two daily layers are true colour with the clouds left in. The shaded relief is the same kind of picture as the package's own level 5, and is only a stand-in.
52
+ * The day the daily layers' days in `GIBS_LAYERS` were read, from the capabilities documents (the tiles' WMTS and the snapshots' WMS list the same days).
53
+ *
54
+ * To refresh the table: fetch `https://gibs.earthdata.nasa.gov/wmts/epsg4326/best/1.0.0/WMTSCapabilities.xml`, and for each daily layer copy the `<Value>` ranges of its `Time` dimension
55
+ * (`start/end/P1D`) into `ranges`, oldest first. Mark a layer `ended` when its last day stays behind the others' (the satellite has stopped, or its processing has), and take the mark off if it starts again. Then change this date.
56
+ */
57
+ export const GIBS_DAYS_READ = "2026-11-17";
58
+ /** A daily true-colour layer on the 250 m matrix, with the clouds left in. */
59
+ const daily = (id, name, ranges, ended = false) => ({
60
+ id,
61
+ name,
62
+ matrix: "250m",
63
+ clouds: true,
64
+ ranges: ranges.map(([start, end]) => ({ start, end })),
65
+ ...(ended ? { ended: true } : {}),
66
+ });
67
+ /**
68
+ * The layers a page may ask for, and the one table of the days each daily layer has (read on `GIBS_DAYS_READ`; how to refresh it is there). A day outside a layer's days is not requested from it.
69
+ * The daily layers are true colour with the clouds left in. Suomi NPP VIIRS has ended: its last day is 2026-11-02, and a later day is a black picture. The shaded relief is the same kind of picture as the package's own level 5, and is only a stand-in.
54
70
  */
55
71
  export const GIBS_LAYERS = {
56
72
  Landsat_WELD_CorrectedReflectance_TrueColor_Global_Annual: {
@@ -69,39 +85,59 @@ export const GIBS_LAYERS = {
69
85
  ja: "Landsat画像:NASAのGlobal Web-Enabled Landsat Data(GWELD)の年間30 mモザイク。NASAのLP DAACが配布しています。",
70
86
  },
71
87
  },
72
- VIIRS_SNPP_CorrectedReflectance_TrueColor: {
73
- id: "VIIRS_SNPP_CorrectedReflectance_TrueColor",
74
- matrix: "250m",
75
- clouds: true,
76
- ranges: [
77
- { start: "2015-11-24", end: "2022-07-27" },
78
- { start: "2022-08-10", end: "2024-05-31" },
79
- { start: "2024-06-04", end: "2024-07-11" },
80
- { start: "2024-07-16", end: "2024-07-24" },
81
- { start: "2024-07-29", end: "2024-11-03" },
82
- { start: "2024-11-06", end: "2026-04-28" },
83
- { start: "2026-04-30", end: "2026-07-10" },
84
- { start: "2026-07-16", end: "2026-11-02" },
85
- ],
86
- },
87
- MODIS_Terra_CorrectedReflectance_TrueColor: {
88
- id: "MODIS_Terra_CorrectedReflectance_TrueColor",
89
- matrix: "250m",
90
- clouds: true,
91
- ranges: [
92
- { start: "2000-02-24", end: "2000-04-25" },
93
- { start: "2000-04-28", end: "2000-08-06" },
94
- { start: "2000-08-18", end: "2001-06-15" },
95
- { start: "2001-07-03", end: "2002-03-19" },
96
- { start: "2002-03-28", end: "2003-12-16" },
97
- { start: "2003-12-24", end: "2008-12-20" },
98
- { start: "2008-12-23", end: "2016-02-18" },
99
- { start: "2016-02-27", end: "2022-10-10" },
100
- { start: "2022-10-23", end: "2026-11-13" },
101
- ],
102
- },
88
+ VIIRS_NOAA20_CorrectedReflectance_TrueColor: daily("VIIRS_NOAA20_CorrectedReflectance_TrueColor", "NOAA-20 VIIRS", [
89
+ ["2018-01-05", "2018-02-21"],
90
+ ["2018-02-24", "2018-03-12"],
91
+ ["2018-03-14", "2019-12-31"],
92
+ ["2020-01-02", "2022-01-12"],
93
+ ["2022-01-14", "2026-11-16"],
94
+ ]),
95
+ VIIRS_NOAA21_CorrectedReflectance_TrueColor: daily("VIIRS_NOAA21_CorrectedReflectance_TrueColor", "NOAA-21 VIIRS", [
96
+ ["2023-02-10", "2023-02-23"],
97
+ ["2023-02-25", "2023-03-09"],
98
+ ["2023-03-11", "2024-02-26"],
99
+ ["2024-02-29", "2026-11-16"],
100
+ ]),
101
+ VIIRS_SNPP_CorrectedReflectance_TrueColor: daily("VIIRS_SNPP_CorrectedReflectance_TrueColor", "Suomi NPP VIIRS", [
102
+ ["2015-11-24", "2022-07-27"],
103
+ ["2022-08-10", "2024-05-31"],
104
+ ["2024-06-04", "2024-07-11"],
105
+ ["2024-07-16", "2024-07-24"],
106
+ ["2024-07-29", "2024-11-03"],
107
+ ["2024-11-06", "2026-04-28"],
108
+ ["2026-04-30", "2026-07-10"],
109
+ ["2026-07-16", "2026-11-02"],
110
+ ], true),
111
+ MODIS_Terra_CorrectedReflectance_TrueColor: daily("MODIS_Terra_CorrectedReflectance_TrueColor", "MODIS Terra", [
112
+ ["2000-02-24", "2000-04-25"],
113
+ ["2000-04-28", "2000-08-06"],
114
+ ["2000-08-18", "2001-06-15"],
115
+ ["2001-07-03", "2002-03-19"],
116
+ ["2002-03-28", "2003-12-16"],
117
+ ["2003-12-24", "2008-12-20"],
118
+ ["2008-12-23", "2016-02-18"],
119
+ ["2016-02-27", "2022-10-10"],
120
+ ["2022-10-23", "2026-11-17"],
121
+ ]),
122
+ MODIS_Aqua_CorrectedReflectance_TrueColor: daily("MODIS_Aqua_CorrectedReflectance_TrueColor", "MODIS Aqua", [
123
+ ["2002-07-03", "2002-07-30"],
124
+ ["2002-08-07", "2002-09-12"],
125
+ ["2002-09-14", "2022-03-31"],
126
+ ["2022-04-17", "2026-11-16"],
127
+ ]),
103
128
  BlueMarble_ShadedRelief_Bathymetry: { id: "BlueMarble_ShadedRelief_Bathymetry", matrix: "500m", clouds: false, ranges: [] },
104
129
  };
130
+ /**
131
+ * The daily true-colour layers in the order one stands in for another: when the layer a page asked for has no picture for a day (it has ended, it had not started, or the day is in a gap of its list), the first of these that has the day is used.
132
+ * NOAA-20 VIIRS, NOAA-21 VIIRS, Suomi NPP VIIRS (VIIRS is finer and newer than MODIS), then MODIS Terra and MODIS Aqua.
133
+ */
134
+ export const GIBS_DAILY_ORDER = [
135
+ "VIIRS_NOAA20_CorrectedReflectance_TrueColor",
136
+ "VIIRS_NOAA21_CorrectedReflectance_TrueColor",
137
+ "VIIRS_SNPP_CorrectedReflectance_TrueColor",
138
+ "MODIS_Terra_CorrectedReflectance_TrueColor",
139
+ "MODIS_Aqua_CorrectedReflectance_TrueColor",
140
+ ];
105
141
  /**
106
142
  * The layer a page gets without naming one: the Landsat annual true-colour mosaic (30 m, no cloud, land only; the year 2000, the newest it has). The daily layers are a named choice: `today` for MODIS Terra.
107
143
  * A layer id is taken as it is, and these short names stand for two of them.
@@ -171,9 +207,12 @@ export function previousUtcDay(ms) {
171
207
  return day.toISOString().slice(0, 10);
172
208
  }
173
209
  /**
174
- * Whether the layer may have imagery for a day: inside one of the ranges listed on 2026-11-13, or after the last of them (a daily layer goes on growing, and the list does not). A day before the layer's first day, or in a gap the list shows, has none, and is not asked for.
210
+ * Whether the layer may have imagery for a day: inside one of its listed ranges, or, for a layer still running (not `ended`), after the last of them and no later than `today` (the list is of the day it was read, and the layer goes on growing).
211
+ * A day before the layer's first day, in a gap the list shows, after the last day of a layer that has ended, or after `today`, has none, and is not asked for.
212
+ *
213
+ * @param today - The present UTC day, `yyyy-mm-dd`. Left out, a running layer has every day after its last listed one.
175
214
  */
176
- export function gibsHasDay(layer, day) {
215
+ export function gibsHasDay(layer, day, today) {
177
216
  if (layer.ranges.length === 0)
178
217
  return true;
179
218
  const first = layer.ranges[0];
@@ -181,9 +220,62 @@ export function gibsHasDay(layer, day) {
181
220
  if (day < first.start)
182
221
  return false;
183
222
  if (day > last.end)
184
- return true;
223
+ return !layer.ended && (today === undefined || day <= today);
185
224
  return layer.ranges.some((range) => day >= range.start && day <= range.end);
186
225
  }
226
+ /** The day before `day`. */
227
+ const dayBefore = (day) => previousUtcDay(Date.parse(`${day}T12:00:00Z`));
228
+ const isDaily = (layer) => GIBS_DAILY_ORDER.includes(layer.id);
229
+ /** The newest day each daily layer surely has by `today`: the day before it for a layer still running (that day's passes are in), the last listed one for a layer that has ended. The newest of them, from the first layer in `GIBS_DAILY_ORDER` that has it. */
230
+ export function gibsNewest(today) {
231
+ let best;
232
+ const yesterday = dayBefore(today);
233
+ for (const id of GIBS_DAILY_ORDER) {
234
+ const layer = GIBS_LAYERS[id];
235
+ const day = layer.ended ? layer.ranges[layer.ranges.length - 1].end : yesterday;
236
+ if (!gibsHasDay(layer, day, today))
237
+ continue;
238
+ if (best === undefined || day > best.day)
239
+ best = { layer, day };
240
+ }
241
+ return best;
242
+ }
243
+ /**
244
+ * The layer and day to read for a day wanted. The layer asked for when it has the day. Else, for a daily true-colour layer, the first of `GIBS_DAILY_ORDER` that has it (Suomi NPP has ended on 2026-11-02, so a later day is NOAA-20's).
245
+ * Else, when the day is after the newest day any of them has (a day still to come), that newest day, from the layer asked for if it has it. A day no layer has that is not after all of them (before 2000-02-24, when MODIS Terra began) gives `undefined`: nothing is requested.
246
+ *
247
+ * @param today - The present UTC day, `yyyy-mm-dd`: no layer has a day after it.
248
+ */
249
+ export function gibsPick(asked, day, today) {
250
+ if (gibsHasDay(asked, day, today))
251
+ return { layer: asked, day, wanted: day, why: "asked" };
252
+ if (!isDaily(asked))
253
+ return undefined;
254
+ for (const id of GIBS_DAILY_ORDER) {
255
+ const other = GIBS_LAYERS[id];
256
+ if (other !== asked && gibsHasDay(other, day, today))
257
+ return { layer: other, day, wanted: day, why: "layer" };
258
+ }
259
+ const newest = gibsNewest(today);
260
+ if (!newest || day <= newest.day)
261
+ return undefined;
262
+ // the layer asked for, when it has that newest day too
263
+ return { layer: gibsHasDay(asked, newest.day, today) ? asked : newest.layer, day: newest.day, wanted: day, why: "newest" };
264
+ }
265
+ /** The days the default rule tries, newest first, each with the layer it is read from: from `start` (or, when `start` is after every layer, from the newest day there is), back, `GIBS_LOOKBACK_DAYS` days, skipping a day no layer has. */
266
+ export function gibsPickCandidates(asked, start, today) {
267
+ const first = gibsPick(asked, start, today);
268
+ const from = first?.why === "newest" ? first.day : start;
269
+ const found = [];
270
+ let day = from;
271
+ for (let count = 0; count < GIBS_LOOKBACK_DAYS; count += 1) {
272
+ const pick = gibsPick(asked, day, today);
273
+ if (pick && pick.why !== "newest")
274
+ found.push(first?.why === "newest" ? { ...pick, wanted: start, why: "newest" } : pick);
275
+ day = dayBefore(day);
276
+ }
277
+ return found;
278
+ }
187
279
  /** The day a fixed rule names (`previous-day`, `shown`, or one `yyyy-mm-dd`), or `undefined` for `latest`, which has to be looked for. */
188
280
  function fixedDay(rule, ms) {
189
281
  if (/^\d{4}-\d{2}-\d{2}$/.test(rule))
@@ -206,8 +298,6 @@ export function gibsDay(layer, rule, ms) {
206
298
  const named = fixedDay(rule, ms) ?? previousUtcDay(ms);
207
299
  return gibsHasDay(layer, named) ? named : undefined;
208
300
  }
209
- /** The day before `day`. */
210
- const dayBefore = (day) => previousUtcDay(Date.parse(`${day}T12:00:00Z`));
211
301
  /** The days the default rule looks at, newest first: from `start`, back, skipping days the layer is known to lack, until the layer's first day or `GIBS_LOOKBACK_DAYS` days have been counted. */
212
302
  export function gibsCandidates(layer, start) {
213
303
  const found = [];
@@ -221,7 +311,7 @@ export function gibsCandidates(layer, start) {
221
311
  }
222
312
  return found;
223
313
  }
224
- /** The days the default rule has settled, by layer and starting day: a day with imagery, or `null` for none. Kept for the session, so a view that moves asks nothing again. */
314
+ /** The days the default rule has settled, by layer and starting day: the day with imagery and the layer it is read from, or `null` for none. Kept for the session, so a view that moves asks nothing again. */
225
315
  const settled = new Map();
226
316
  const probing = new Set();
227
317
  /** Forget what the default rule has settled (for a page that wants to look again, and for the tests). */
@@ -253,6 +343,17 @@ async function pictureIsBlank(image) {
253
343
  return false;
254
344
  }
255
345
  }
346
+ /** The sentence the credit line adds when the picture is not the one asked for: another layer stands in for a day, or the newest day there is stands in for one still to come. */
347
+ function pickNote(asked, pick) {
348
+ const name = pick.layer.name ?? pick.layer.id;
349
+ if (pick.why === "layer") {
350
+ const was = asked.name ?? asked.id;
351
+ return { en: `Shown: ${name}, ${pick.day} (${was} has no picture for that day).`, ja: `表示中:${name}、${pick.day}(${was}にはこの日の画像がありません)。` };
352
+ }
353
+ if (pick.why === "newest")
354
+ return { en: `Shown: ${name}, ${pick.day}, the newest day with a picture (there is none yet for ${pick.wanted}).`, ja: `表示中:${name}、${pick.day}。画像のある最新の日です(${pick.wanted}の画像はまだありません)。` };
355
+ return undefined;
356
+ }
256
357
  /**
257
358
  * A map source that reads NASA's imagery service directly. It declares its own grid (512 pixel tiles, the Geographic matrix, which is not the package's pyramid). `need` names no tile for a day outside the layer's range.
258
359
  * `load` gives a tile two seconds, and treats a 404 or an all-black tile as no imagery. The clouds are not taken out of the daily layers.
@@ -276,6 +377,11 @@ export function gibsTiles(options) {
276
377
  const rule = options.date ?? "latest";
277
378
  const get = options.fetch ?? ((url, init) => globalThis.fetch(url, init));
278
379
  const decode = options.decode ?? ((blob) => createImageBitmap(blob, { premultiplyAlpha: "none", colorSpaceConversion: "none" }));
380
+ const today = () => utcDay(options.now ? options.now() : Date.now());
381
+ /** The layer a key's day is read from: the one asked for, or the daily layer that stands in for it on that day (`gibsPick`). */
382
+ const layerOf = (day) => (known && isDaily(layer) ? (gibsPick(layer, day, today())?.layer ?? layer) : layer);
383
+ /** The pick the tiles in view were last named from, for the credit line. */
384
+ let shown;
279
385
  /** One tile of one day, as `load` reads it: nothing for a 404, a blank picture, a slow answer or a failure. */
280
386
  const fetchTile = async (key, signal) => {
281
387
  const parts = tileKeyParts(key);
@@ -285,7 +391,8 @@ export function gibsTiles(options) {
285
391
  throw new RangeError(`"${key}" is not the key of a tile`);
286
392
  if (!gridOnEarth(level, parts.col, parts.row, grid.extent))
287
393
  throw new RangeError(`"${key}" is off the Earth`);
288
- const url = `${TILE_URL}/${layer.id}/default/${day}/${layer.matrix}/${parts.level}/${parts.row}/${parts.col}.jpg`;
394
+ const from = layerOf(day);
395
+ const url = `${TILE_URL}/${from.id}/default/${day}/${from.matrix}/${parts.level}/${parts.row}/${parts.col}.jpg`;
289
396
  const timer = AbortSignal.timeout(options.slowMs && options.slowMs > 0 ? options.slowMs : GIBS_SLOW_MS);
290
397
  let response;
291
398
  try {
@@ -308,14 +415,14 @@ export function gibsTiles(options) {
308
415
  probing.add(settledKey);
309
416
  void (async () => {
310
417
  let found = null;
311
- for (const day of gibsCandidates(layer, start)) {
312
- const keys = gridKeys(grid, place, detail, `${day}/`);
418
+ for (const pick of gibsPickCandidates(layer, start, today())) {
419
+ const keys = gridKeys(grid, place, detail, `${pick.day}/`);
313
420
  if (keys.length === 0)
314
421
  break;
315
422
  try {
316
423
  const tile = await fetchTile(keys[0], new AbortController().signal);
317
424
  tile.image.close?.();
318
- found = day;
425
+ found = pick;
319
426
  break;
320
427
  }
321
428
  catch {
@@ -329,24 +436,42 @@ export function gibsTiles(options) {
329
436
  })();
330
437
  };
331
438
  // an unknown layer has no published range, so no day is inside it and nothing is requested
332
- const dayOf = (place, detail) => {
439
+ const pickOf = (place, detail) => {
333
440
  if (!known)
334
441
  return undefined;
335
442
  const ms = options.time().getTime();
336
- if (layer.years || fixedDay(rule, ms) !== undefined || layer.ranges.length === 0)
337
- return gibsDay(layer, rule, ms);
443
+ if (layer.years || layer.ranges.length === 0) {
444
+ const day = gibsDay(layer, rule, ms);
445
+ return day === undefined ? undefined : { layer, day, wanted: day, why: "asked" };
446
+ }
447
+ const fixed = fixedDay(rule, ms);
448
+ const now = today();
449
+ if (fixed !== undefined)
450
+ return gibsPick(layer, fixed, now);
338
451
  const start = previousUtcDay(ms);
339
- const settledKey = `${layer.id}|${start}`;
452
+ const settledKey = `${layer.id}|${start}|${now}`;
340
453
  if (settled.has(settledKey))
341
454
  return settled.get(settledKey) ?? undefined;
342
455
  if (!probing.has(settledKey))
343
456
  lookFor(settledKey, start, place, detail);
344
457
  return undefined;
345
458
  };
459
+ const baseInfo = layer.credit ? { ...INFO, credit: { en: `${GIBS_CREDIT.en} ${layer.credit.en}`, ja: `${GIBS_CREDIT.ja}${layer.credit.ja}` } } : INFO;
460
+ let noted = { key: "", info: baseInfo };
461
+ /** The credit, with a sentence when another layer or the newest day stands in for the one asked for; the same object while that does not change. */
462
+ const infoNow = () => {
463
+ const note = shown ? pickNote(layer, shown) : undefined;
464
+ const key = note ? note.en : "";
465
+ if (key !== noted.key)
466
+ noted = { key, info: note ? { ...baseInfo, credit: { en: `${baseInfo.credit.en} ${note.en}`, ja: `${baseInfo.credit.ja}${note.ja}` } } : baseInfo };
467
+ return noted.info;
468
+ };
346
469
  const source = {
347
470
  kind: "tiles",
348
471
  layer: "day",
349
- info: layer.credit ? { ...INFO, credit: { en: `${GIBS_CREDIT.en} ${layer.credit.en}`, ja: `${GIBS_CREDIT.ja}${layer.credit.ja}` } } : INFO,
472
+ get info() {
473
+ return infoNow();
474
+ },
350
475
  holes: true,
351
476
  // the loader draws the tile with these on the graphics card: clear where it is dark, and each colour multiplied (nothing is done to the pixels on the processor)
352
477
  look: { clear: layer.clear ?? [NODATA_BELOW, NODATA_FULL], ...(layer.gain ? { gain: layer.gain } : {}) },
@@ -354,10 +479,11 @@ export function gibsTiles(options) {
354
479
  need(place, detail) {
355
480
  if (gridLevelFor(grid, detail, 0) === undefined)
356
481
  return [];
357
- const day = dayOf(place, detail);
358
- if (day === undefined)
482
+ const pick = pickOf(place, detail);
483
+ shown = pick;
484
+ if (pick === undefined)
359
485
  return [];
360
- return gridKeys(grid, place, detail, `${day}/`);
486
+ return gridKeys(grid, place, detail, `${pick.day}/`);
361
487
  },
362
488
  levels() {
363
489
  return { tileSize: grid.tileSize, levels: grid.levels.map((level) => ({ level: level.level, width: level.width })) };