- Accurate VPD calculation using Magnus formula
- Growth stage specific classifications (propagation/veg/flower)
- Chart-ready data matrix generation for visualization
- CLI tool for quick VPD lookup from your terminal
- Interactive Web Chart to dynamically adjust parameters and visualize VPD
- Type-safe API with strict input validation
- Zero dependencies for core calculations - uses
chart.jsandcanvasfor chart rendering,honofor web server.
bash npm install @adametherzlab/vpd-calculator
bun add @adametherzlab/vpd-calculator
After installing globally (or via npx):
bash
vpd-calc --temp 25 --rh 60
vpd-calc -t 28 -r 55 -s flower
vpd-calc -t 22 -r 70 --all
vpd-calc -t 25 -r 60 -u psi
vpd-calc --chart
vpd-calc --chart --port 8080
vpd-calc --help
To start the interactive web chart, run:
bash vpd-calc --chart
Then, open your browser to http://localhost:3000 (or the custom port you specified). You can adjust temperature and humidity ranges using sliders and immediately see the updated VPD chart.
import { calculateVpd, VpdStage, generateChartData, renderVpdChart, setVpdThresholds } from 'vpd-calculator';
// 1. Calculate VPD for specific conditions
const result = calculateVpd(25, 60, VpdStage.Veg);
console.log(VPD: ${result.vpd} kPa, Range: ${result.range});
// Output: VPD: 1.268 kPa, Range: optimal
// 2. Generate data for a chart
const chartOptions = {
stage: VpdStage.Flower,
tempMinC: 20,
tempMaxC: 30,
tempStepC: 1,
humidityMin: 40,
humidityMax: 70,
humidityStep: 5,
};
const chartData = generateChartData(chartOptions);
console.log(Generated ${chartData.points.length} data points for the chart.);
// 3. Render a chart to a PNG buffer (Node.js/Bun environment) async function createChartImage() { const imageBuffer = await renderVpdChart(chartData, { stage: VpdStage.Flower, width: 800, height: 600 }); // imageBuffer is a Node.js Buffer containing PNG data // You can save it to a file, send it as an HTTP response, etc. // require('fs').writeFileSync('vpd_chart.png', imageBuffer); console.log('Chart image generated.'); } createChartImage();
// 4. Customize VPD thresholds
setVpdThresholds(VpdStage.Propagation, { low: 0.7, high: 0.9 });
const customResult = calculateVpd(22, 75, VpdStage.Propagation);
console.log(Custom VPD for Propagation: ${customResult.vpd} kPa, Range: ${customResult.range});
// Reset to default thresholds // resetVpdThresholds(VpdStage.Propagation);
Calculates the Vapor Pressure Deficit (VPD) in kilopascals (kPa) for given temperature and humidity, and classifies it based on the specified growth stage's thresholds.
Classifies a given VPD value ('low', 'optimal', 'high') based on the thresholds for the specified growth stage.
Retrieves the active VPD thresholds (low and high kPa values) for a given growth stage. Returns custom thresholds if set, otherwise defaults.
Sets custom VPD thresholds for a specific growth stage, overriding the defaults. These will be used in subsequent calculations and classifications.
Resets custom VPD thresholds for a specific stage to its default values. If no stage is provided, all custom thresholds are reset.
Generates a matrix of VPD data points across specified temperature and humidity ranges, suitable for charting.
(Node.js/Bun only) Renders the generated ChartData into a PNG image buffer using chart.js and canvas.
VpdStage: Enum for plant growth stages (Propagation,Veg,Flower).VpdRange: Type for VPD classification ('low','optimal','high').VpdResult: Interface{ vpd: number; range: VpdRange; }.VpdThresholds: Interface{ low: number; high: number; }.ChartDataPoint: Interface{ temperatureC: number; humidityPercent: number; vpd: number; range: VpdRange; }.ChartDataOptions: Interface forgenerateChartDataoptions.ChartData: Interface{ points: readonly ChartDataPoint[]; }.ChartRenderOptions: Interface forrenderVpdChartoptions.
To run tests:
bash bun test
To build:
bash npm run build