Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/imballinst/solar-beam
Solar position calculator powered by TypeScript
https://github.com/imballinst/solar-beam
Last synced: 26 days ago
JSON representation
Solar position calculator powered by TypeScript
- Host: GitHub
- URL: https://github.com/imballinst/solar-beam
- Owner: imballinst
- License: mit
- Created: 2020-04-29T14:59:04.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2023-01-06T05:28:02.000Z (almost 2 years ago)
- Last Synced: 2024-09-14T12:10:55.577Z (about 2 months ago)
- Language: TypeScript
- Homepage:
- Size: 1.03 MB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 13
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# solar-beam
![CI](https://github.com/Imballinst/solar-beam/workflows/CI/badge.svg?branch=master)
General solar position calculator powered with TypeScript. The calculation is based on the spreadsheet from [Earth System Research Laboratory](https://www.esrl.noaa.gov/gmd/grad/solcalc/calcdetails.html).
DISCLAIMER: Please be mindful when using this library, as there is no guarantee that the values are valid. As written on the section "Data for Litigation":
> The NOAA Solar Calculator is for research and recreational use only. NOAA cannot certify or authenticate sunrise, sunset or solar position data. The U.S. Government does not collect observations of astronomical data, and due to atmospheric conditions our calculated results may vary significantly from actual observed values.
## Installation
```bash
# npm
npm install --save solar-beam# yarn
yarn add solar-beam
```## Usage
```ts
import { getJulianDate } from 'solar-beam';// May 5th, 2020, 12am o'clock, GMT +7.
const date = new Date(2020, 4, 9);
getJulianDate(date, -420); // 2458978.2083333335.
```For more detailed information, please see the [test file](src/index.test.ts).
## Available functions
### Common utils
| Function name | Parameter | Description |
| --------------- | ------------------------ | -------------------------------------------------------------------------- |
| `getJulianDate` | `(date: Date) => number` | Returns the current [Julian day](https://en.wikipedia.org/wiki/Julian_day) |### Fractions
| Function name | Parameter | Description |
| ---------------------------- | ---------------------------------------- | --------------------------------------------------------------------- |
| `getSolarNoonLSTInFractions` | `(params: MainFunctionParams) => number` | Returns the solar noon time fraction from the given date and location |
| `getSunriseInFractions` | `(params: MainFunctionParams) => number` | Returns the sunrise time fraction from the given date and location |
| `getSunsetInFractions` | `(params: MainFunctionParams) => number` | Returns the sunset time fraction from the given date and location |### Seconds
| Function name | Parameter | Description |
| -------------------------- | ---------------------------------------- | -------------------------------------------------------------------------- |
| `getSolarNoonLSTInSeconds` | `(params: MainFunctionParams) => number` | Returns the solar noon seconds (of a day) from the given date and location |
| `getSunriseInSeconds` | `(params: MainFunctionParams) => number` | Returns the sunrise seconds (of a day) from the given date and location |
| `getSunsetInSeconds` | `(params: MainFunctionParams) => number` | Returns the sunset seconds (of a day) from the given date and location |### Date
| Function name | Parameter | Description |
| --------------------- | ---------------------------------------- | --------------------------------------------------------------------------------- |
| `getSolarNoonLSTDate` | `(params: MainFunctionParams) => string` | Returns the solar noon time in `HH:mm:ss` format from the given date and location |
| `getSunriseDate` | `(params: MainFunctionParams) => string` | Returns the sunrise time in `HH:mm:ss` format from the given date and location |
| `getSunsetDate` | `(params: MainFunctionParams) => string` | Returns the sunset time in `HH:mm:ss` format from the given date and location |### Angles
| Function name | Parameter | Description |
| ------------------------ | ---------------------------------------- | ----------------------------------------------------------------------------- |
| `getSolarElevationAngle` | `(params: MainFunctionParams) => number` | Returns the solar elevation angle in degrees from the given date and location |## Trying it locally
```bash
# Build first to generate the dist/ folder.
yarn build
# Run the example file.
node example/index.js
```## Testing
```bash
yarn test
```## Next updates
- [ ] Breakdown functions to separate folders. So, `dist/` will contain `index.js`, `index.min.js`, and all other functions from `src/`. Hence, when browsers include it from `` tag, they can access `index.min.js` directly, while users who want to use ESM can do, e.g. `import getJulianDate from 'solar-beam/getJulianDate';`.
## LICENSE
MIT