A typical run

This is a complete run with your own model: one tower and a thermal comfort (UTCI) analysis. Each comment is one step of the diagram. polygon is a GeoJSON polygon in longitude and latitude. coordinates and indices are your mesh, in metres, in the local frame of the polygon. See Your model and Coordinates.

TypeScript
import {
  InfraredClient, initializeCore, areaGridValuesF32, type AreaResult,
} from "@infrared-city/infrared-sdk";

// 1. Client. Start the core one time: in Node, runArea and runAreaAndWait
//    need it. The key comes from the option or from INFRARED_API_KEY.
await initializeCore();
const client = new InfraredClient({ apiKey: process.env.INFRARED_API_KEY });

// 2. Your model. One mesh for each building, in metres.
const buildings = { tower: { coordinates, indices } };

// 3. Weather. Find the nearest public station, then keep the hours you need.
const period = { start: { month: 7, day: 15, hour: 12 }, end: { month: 7, day: 15, hour: 16 } };
const stations = await client.weather.getWeatherFileFromLocation(48.2085, 16.3725);
const rows = await client.weather.filterWeatherData(stations[0].uuid, { period });

// 4. Request. A plain object. analysisType selects the analysis.
const input = {
  analysisType: "thermal-comfort-index",
  latitude: 48.2085, longitude: 16.3725,
  dateFilters: { period },
  weatherData: rows,
};

// 5. Preview. This sends no job. plannedJobCount is the number of billed jobs.
const preview = await client.previewAreaBatches(input, polygon, { buildings });
console.log(preview.plannedJobCount);

// 6. Run. One call plans, uploads, submits, waits and merges.
const result = await client.runAreaAndWait(input, polygon, { buildings });

// 7. Values. One 32-bit float for each cell, in degrees C. NaN means no value.
const values = areaGridValuesF32(result as AreaResult);

To use your own weather file, give weather: client.weather.parseEpw(text) in place of weatherData. An analysis that needs no weather takes only analysisType, for example { analysisType: "sky-view-factors" }. See Weather and time period, The ten analyses, Cost and retry and How a run works.

Variant: no data yet

Read public buildings, trees and ground materials for the polygon. Give the objects to the run as they are: then the run can check the frame and the read margin. Buildings and ground materials need npm install hyparquet hyparquet-compressors. See Public context.

TypeScript
const buildings = await client.buildings.getBuildingsInArea(polygon);
const vegetation = await client.vegetation.getArea(polygon);
const groundMaterials = await client.groundMaterials.getArea(polygon);
const result = await client.runAreaAndWait(input, polygon,
  { buildings, vegetation, groundMaterials });

Variant: facades instead of ground

Set analysisSurfaces to "facades", "roofs" or "all". The run gives SurfaceColumns: one value for each sensor cell on your buildings, not a ground grid. previewAreaBatches counts the facade jobs correctly. See Facade and roof runs.

TypeScript
import { surfaceValuesF32, surfaceRenderBuffers, type SurfaceColumns }
  from "@infrared-city/infrared-sdk";

const input = { analysisType: "sky-view-factors", analysisSurfaces: "facades", surfaceGridSize: 3 };
const preview = await client.previewAreaBatches(input, polygon, { buildings });
const columns = (await client.runAreaAndWait(input, polygon, { buildings })) as SurfaceColumns;
const values = surfaceValuesF32(columns);       // one value for each cell, NaN = no value
const buffers = surfaceRenderBuffers(columns);  // flat arrays to draw the cells

Variant: submit now, merge later

runArea submits the jobs and returns an AreaSchedule. Merge when the jobs are complete. checkAreaState (and client.jobs.getStatusBatch(ids)) asks for up to 50 jobs in one request. A status request that fails is asked again. Do not ask for each job in a loop. For a facade run, merge with mergeSurfaceAreaJobs.

TypeScript
const schedule = await client.runArea(input, polygon, { buildings });
while (!(await client.checkAreaState(schedule)).isComplete) {
  await new Promise((done) => setTimeout(done, 10_000));
}
const result = await client.mergeAreaJobs(schedule);

Save, reload and free

Save the layout of a facade run one time for each geometry, and the values of each run: layout.toBytes() and surfaceColumnsToBytes(columns, { layoutKey }). Reload with FacadeLayout.fromBytes and surfaceColumnsFromBytes, then attachValues. Call layout.free() for each layout, forgetSchedule on client.jobs.captures for a schedule that you will not merge, and client.jobs.captures.free() when you finish. See Save, reload and free.

Which module does what

The package has several entry points. See Import paths.

PageRoleMain calls
ClientThe entry point and the area runsinitializeCore, InfraredClient, runAreaAndWait, runArea, checkAreaState, mergeAreaJobs, previewArea
Run an analysisPlanning and previewspreviewAreaBatches, AreaSchedule
RequestsThe analysis request fieldsanalysisType, dateFilters, weather
Buildings, Vegetation, Ground materialsPublic context for an areagetBuildingsInArea, vegetation.getArea, groundMaterials.getArea
WeatherThe weather catalog and EPW textgetWeatherFileFromLocation, filterWeatherData, parseEpw
Results and legendRead and save resultsareaGridValuesF32, surfaceValuesF32, surfaceRenderBuffers, surfaceColumnsToBytes
Facade layoutThe outline of facade and roof resultsFacadeLayout, attachValues
WorkerThe client in a Web Workersee Serve many users
ErrorsError classessee below

Errors you meet

  • CoreNotReadyError: you called the SDK before await initializeCore().
  • AreaTimeoutError: the run passed its area timeout.
  • AreaRunError: runAreaAndWait or the stream ended without the full result: a tile failed, a result did not download, or a submit is uncertain.
  • JobPollError: a status request was refused for good (for example 403). It holds the status.
  • PricingUnavailableError: a preview cannot fetch the API price list and the client has none.
  • JobFailedError: one job failed on the server.
  • SubmissionUncertainError: a submit got no answer. Do not send it again by hand: the retry keys do it safely.
  • ReadMarginError: a public layer was read with a margin that is too narrow for the analysis.

An incomplete merge throws an Error whose message says which tiles did not contribute and how to recover. See Cost and retry.

Topics

Import paths

The package has these entry points. Each symbol's page names the ones it can be imported from.

  • @infrared-city/infrared-sdk
  • @infrared-city/infrared-sdk/tiling
  • @infrared-city/infrared-sdk/utilities
  • @infrared-city/infrared-sdk/geodata
  • @infrared-city/infrared-sdk/billing
  • @infrared-city/infrared-sdk/worker