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
5 changes: 4 additions & 1 deletion .github/workflows/test.yml → .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Run Tests
name: Run Checks and Tests

on:
push:
Expand All @@ -24,5 +24,8 @@ jobs:
- name: Install dependencies
run: npm ci

- name: Run checks
run: npm run lint

- name: Run tests
run: npm test
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ node_modules
.env
.env.*
!.env.example
CHANGELOG.md

# Package Managers
package-lock.json
2 changes: 1 addition & 1 deletion eslint.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export default ts.config(
globals: { ...globals.browser, ...globals.node },
parserOptions: {
projectService: {
allowDefaultProject: ['*.js', '*.ts']
allowDefaultProject: ['*.js', '*.ts', 'scripts/*.ts']
},
ecmaVersion: 'latest',
sourceType: 'module'
Expand Down
21 changes: 21 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
"eslint": "^9.38.0",
"eslint-config-prettier": "^10.1.8",
"globals": "^16.4.0",
"jiti": "^2.6.1",
"prettier": "^3.6.2",
"tsx": "^4.20.6",
"typescript": "5.9.3",
Expand Down
3 changes: 2 additions & 1 deletion src/grids/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ export class GridFactory {
return new ProjectionGrid(data, ranges);
case 'regular':
return new RegularGrid(data, ranges);
default:
default: {
// This ensures exhaustiveness checking
const _exhaustive: never = data;
throw new Error(`Unknown grid type: ${_exhaustive}`);
}
}
}
}
16 changes: 10 additions & 6 deletions src/grids/projected.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,30 +46,34 @@ export class ProjectionGrid implements GridInterface {
this.ny = ranges[0].end - ranges[0].start;

switch (data.type) {
case 'projectedFromBounds':
case 'projectedFromBounds': {
this.projection = createProjection(data.projection);
let sw = this.projection.forward(data.latitudeBounds[0], data.longitudeBounds[0]);
let ne = this.projection.forward(data.latitudeBounds[1], data.longitudeBounds[1]);
const sw = this.projection.forward(data.latitudeBounds[0], data.longitudeBounds[0]);
const ne = this.projection.forward(data.latitudeBounds[1], data.longitudeBounds[1]);
this.origin = sw;
this.dx = (ne[0] - sw[0]) / (data.nx - 1);
this.dy = (ne[1] - sw[1]) / (data.ny - 1);
break;
case 'projectedFromGeographicOrigin':
}
case 'projectedFromGeographicOrigin': {
this.projection = createProjection(data.projection);
this.origin = this.projection.forward(data.latitude, data.longitude);
this.dx = data.dx;
this.dy = data.dy;
break;
case 'projectedFromProjectedOrigin':
}
case 'projectedFromProjectedOrigin': {
this.projection = createProjection(data.projection);
this.origin = [data.projectedLongitudeOrigin, data.projectedLatitudeOrigin];
this.dx = data.dx;
this.dy = data.dy;
break;
default:
}
default: {
// This ensures exhaustiveness checking
const _exhaustive: never = data;
throw new Error(`Unknown projection: ${_exhaustive}`);
}
}

this.minX = this.origin[0] + this.dx * ranges[1].start;
Expand Down
3 changes: 2 additions & 1 deletion src/grids/projections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ export function createProjection(opts: ProjectionData): Projection {
return new LambertConformalConicProjection(opts);
case 'LambertAzimuthalEqualAreaProjection':
return new LambertAzimuthalEqualAreaProjection(opts);
default:
default: {
// This ensures exhaustiveness checking
const _exhaustive: never = opts;
throw new Error(`Unknown projection: ${_exhaustive}`);
}
}
}

Expand Down
15 changes: 0 additions & 15 deletions src/grids/regular.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,21 +72,6 @@ export class RegularGrid implements GridInterface {
return interpolateLinear(values, index, xFraction, yFraction, this.nx);
}

getIndex(lat:number, lon:number) {
if (
lat < this.bounds[1] ||
lat >= this.bounds[3] ||
lon < this.bounds[0] ||
lon >= this.bounds[2]
) {
return NaN;
}
const x = Math.floor((lon - this.bounds[0]) / this.dx);
const y = Math.floor((lat - this.bounds[1]) / this.dy);

return y * this.nx + x;
}

getBounds(): Bounds {
return this.bounds;
}
Expand Down
25 changes: 9 additions & 16 deletions src/utils/arrows.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,31 +33,24 @@ export const generateArrows = (
const grid = GridFactory.create(domain.grid);

for (let tileY = 0; tileY < extent + 1; tileY += size) {
let lat = tile2lat(y + tileY / extent, z);
const lat = tile2lat(y + tileY / extent, z);
for (let tileX = 0; tileX < extent + 1; tileX += size) {
let lon = tile2lon(x + tileX / extent, z);
const lon = tile2lon(x + tileX / extent, z);

let center = [tileX - size / 2, tileY - size / 2];
const center = [tileX - size / 2, tileY - size / 2];
const geom = [];

// make scale to zoomlevel
let index = grid.getIndex(lat, lon)
if (index % domain.grid.nx < 20) {
continue
}
if (index / domain.grid.ny > (domain.grid.nx -20)) {
continue
}

let speed = grid.getLinearInterpolatedValue(values, lat, lon);
let direction = degreesToRadians(grid.getLinearInterpolatedValue(directions, lat, lon) + 180);
const speed = grid.getLinearInterpolatedValue(values, lat, lon);
const direction = degreesToRadians(
grid.getLinearInterpolatedValue(directions, lat, lon) + 180
);

const properties: { value?: number; direction?: number } = {
value: speed,
direction: direction
};

let rotation = direction;
const rotation = direction;
let length = 0.95;
if (speed < 30) {
length = 0.9;
Expand Down Expand Up @@ -85,7 +78,7 @@ export const generateArrows = (
}

// left arrow head
let [xt0, yt0] = rotatePoint(
const [xt0, yt0] = rotatePoint(
center[0],
center[1],
rotation,
Expand Down
3 changes: 1 addition & 2 deletions src/utils/contours.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ export const generateContours = (
y: number,
z: number,
interval: number = 2,
extent: number = 4096,
threshold = undefined
extent: number = 4096
) => {
const features = [];
let cursor: [number, number] = [0, 0];
Expand Down
5 changes: 3 additions & 2 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as maplibregl from 'maplibre-gl';

import type { Domain, DomainMetaData, Variable } from '../types';
import type { Domain, Variable } from '../types';

const now = new Date();
now.setHours(now.getHours() + 1, 0, 0, 0);
Expand All @@ -24,7 +24,8 @@ export const closestDomainInterval = (time: Date, domain: Domain) => {
return newTime;
};

export const closestModelRun = (domain: Domain, selectedTime: Date, latest?: DomainMetaData) => {
// TODO: Is this used/needed?
export const closestModelRun = (domain: Domain, selectedTime: Date) => {
const year = selectedTime.getUTCFullYear();
const month = selectedTime.getUTCMonth();
const date = selectedTime.getUTCDate();
Expand Down
Loading