Skip to content

Commit

Permalink
Delete suncalc dependency #47
Browse files Browse the repository at this point in the history
  • Loading branch information
FlorianK13 committed Oct 25, 2024
1 parent 965ce9d commit 9d6b581
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 71 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
},
"dependencies": {
"geotiff": "^2.1.3",
"suncalc": "^1.9.0",
"three": "^0.161.0"
},
"lint-staged": {
Expand Down
48 changes: 0 additions & 48 deletions src/sun.ts
Original file line number Diff line number Diff line change
@@ -1,54 +1,6 @@
import { GeoTIFFImage, fromUrl } from 'geotiff';
import SunCalc from 'suncalc';
import { SolarIrradianceData, SphericalPoint, SunVector } from './utils';

/**
* Creates arrays of sun vectors. "cartesian" is a vector of length 3*Ndates where every three entries make up one vector.
* "spherical" is a vector of length 2*Ndates, where pairs of entries are altitude, azimuth.
* @param Ndates
* @param lat
* @param lon
* @returns
*/
export function getRandomSunVectors(Ndates: number, lat: number, lon: number): SunVector[] {
let sunVectors: SunVector[] = [];

let i: number = 0;
while (i < Ndates) {
let date = getRandomDate(new Date(2023, 1, 1), new Date(2023, 12, 31));

const posSpherical = SunCalc.getPosition(date, lat, lon);
// pos.altitude: sun altitude above the horizon in radians,
// e.g. 0 at the horizon and PI/2 at the zenith (straight over your head)
// pos. azimuth: sun azimuth in radians (direction along the horizon, measured
// from south to west), e.g. 0 is south and Math.PI * 3/4 is northwest
if (posSpherical.altitude < 0.1 || isNaN(posSpherical.altitude)) {
continue;
}
sunVectors.push({
vector: {
cartesian: {
x: -Math.cos(posSpherical.altitude) * Math.sin(posSpherical.azimuth),
y: -Math.cos(posSpherical.altitude) * Math.cos(posSpherical.azimuth),
z: Math.sin(posSpherical.altitude),
},
spherical: {
radius: 1,
altitude: posSpherical.altitude,
azimuth: posSpherical.azimuth,
},
},
isShadedByElevation: false,
});
i++;
}
return sunVectors;
}

function getRandomDate(start: Date, end: Date): Date {
return new Date(start.getTime() + Math.random() * (end.getTime() - start.getTime()));
}

/**
* Converts an 2d vector of irradiance values in sperical coordinates to a 1d vector in euclidian coordinates
* @param irradiance Vector of shape N_altitude x N_azimuth
Expand Down
22 changes: 0 additions & 22 deletions tests/sun.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,28 +92,6 @@ const irradianceEuclidian: CartesianPoint[] = [
];

describe('Test functionalities from sun.ts: ', () => {
const N = 50;
let vectors = sun.getRandomSunVectors(N, 0, 0);
test('Get Correct number of positions for cartesian coordiantes.', () => {
expect(vectors.length).toStrictEqual(N);
});
test('Get Correct number of positions for spherical coordiantes.', () => {
expect(vectors.length).toStrictEqual(N);
});
test('Get normalized sun vectors.', () => {
for (let obj of vectors) {
let length = obj.vector.cartesian.x ** 2 + obj.vector.cartesian.y ** 2 + obj.vector.cartesian.z ** 2;
expect(length).to.closeTo(1, 0.001);
}
});
test('Sun is always above the horizon.', () => {
for (let i = 0; i < N / 3; i++) {
let z = vectors[i].vector.cartesian.z;
let altitude = vectors[i].vector.spherical.altitude;
expect(z).toBeGreaterThan(0);
expect(altitude).toBeGreaterThan(0);
}
});
test('ConvertSpericalToEuclidian works right.', () => {
const tolerance = 0.00001;
const calculatedIrradianceEuclidian = sun.convertSpericalToEuclidian(irradianceSpherical);
Expand Down

0 comments on commit 9d6b581

Please sign in to comment.