Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions docs/snippets/js/weather/reading/absent_values.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Preamble, not shown on the page: a weather file the page's earlier step read.
import { monthlyMeans, type WeatherFile } from '@idfkit/weather';
declare const epw: WeatherFile;

// --8<-- [start:example]
// A measurement the file says was not taken is absent, not the number the format
// reserves for it. Absence is NaN: no weather file can express one, so it is not
// a value the column could otherwise have held.
const albedo = epw.hours.albedo;
Number.isNaN(albedo[0]); // true where the file wrote its missing value

// How many hours of a column are present is carried rather than recomputed.
epw.hours.presentCount.albedo;

// A monthly mean excludes the absent hours from the sum AND from the divisor, so
// it is the mean of the values that exist. The count says how many that was.
const january = monthlyMeans(epw, 'dryBulbTemperature')[0]!;
january.mean; // NaN when the month held no measurement at all
january.count; // and 0 beside it, which says why
// --8<-- [end:example]

export { albedo, january };
23 changes: 23 additions & 0 deletions docs/snippets/js/weather/reading/read_an_epw.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Preamble, not shown on the page: the EPW text the page's earlier step retrieved.
import { parseEpw } from '@idfkit/weather';
declare const epwText: string;

// --8<-- [start:example]
// Reading takes the text you already hold. No network, no filesystem, nothing
// asynchronous, so this runs in a browser tab as readily as in Node.
const epw = parseEpw(epwText);

epw.location.city; // 'Chicago Ohare Intl Ap'
epw.hours.rowCount; // 8760, taken from the file's declared data period

// Every numeric field is a named column, packed and the same length.
const temperature = epw.hours.dryBulbTemperature; // Float64Array, degrees C
temperature[0]; // the first hour of 1 January

// The hour column runs 1 to 24, and hour 24 is the last hour of its OWN day
// rather than hour 0 of the next.
epw.hours.hour[23]; // 24
epw.hours.day[23]; // still 1
// --8<-- [end:example]

export { epw, temperature };
22 changes: 22 additions & 0 deletions docs/snippets/js/weather/station-search/filter_by_climate_zone.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Preamble, not shown on the page: the index the page's earlier steps produced.
import type { StationIndex } from '@idfkit/weather';
declare const index: StationIndex;

// --8<-- [start:example]
// Ask for a zone by its code. The code is parsed out of the label rather than
// read off the front of it, which matters: 2,162 of the 69,638 bundled records
// are labelled '7A - ASHRAE Climate Zone could not be determined' or '8A - ...',
// and neither 7A nor 8A is an ASHRAE zone, since zones 7 and 8 carry no suffix.
const zone4a = index.filter({ climateZone: '4A' });

// Combine with the other keys, which all narrow together.
const seattleArea = index.filter({ climateZone: '4C', country: 'USA', state: 'WA' });

// The stations whose zone upstream could not determine are reachable, and only
// this way: no climateZone value returns them. Asking for them is a separate
// question because the zone key's domain is already every real code, so a
// reserved string could not be told apart from one.
const undetermined = index.filter({ climateZoneDetermined: false });
// --8<-- [end:example]

export { zone4a, seattleArea, undetermined };
Loading
Loading