Skip to content

Commit

Permalink
set floor of solar intensity to 0
Browse files Browse the repository at this point in the history
  • Loading branch information
bacalj committed Aug 14, 2024
1 parent 675c6ec commit 9666942
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const App: React.FC = () => {
const [dataContext, setDataContext] = useState<any>(null);

const handleDayUpdateInTheSimTab = (day: number) => {
console.log("The day of the year has been updated in the simulation tab to: ", day); // TODO: remove it later
// console.log("The day of the year has been updated in the simulation tab to: ", day); // TODO: implement this
// We might to debounce this call, as if the animation is on, or user is dragging the slider, there will be
// lot of events and API calls to CODAP.
updateRowSelectionInCodap(latitude, longitude, Math.floor(day));
Expand Down
14 changes: 9 additions & 5 deletions src/utils/daylight-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,14 @@ export function getSolarNoonIntensity(dayNum: number, latitude: number): number
Math.cos(latitudeRad) * Math.cos(declinationRad);

const solarNoonIntensity = solarConstant * eccentricityFactor * cosSolarZenithAngle;
return solarNoonIntensity;

// Note: This calculation returns theoretical intensity at the top of the atmosphere.
// Negative values are clamped to zero, which
// represents times when the sun is below the horizon
// In reality, some diffuse light might still be present due to atmospheric scattering.
// None of the calculations in this plugin use "civil twighlight" or associated definitions
// For day length either, so this is consistent with the rest of the calculations.
return Math.max(0, solarNoonIntensity);
}

export function getSunrayAngleInDegrees(dayNum: number, earthTilt: number, lat:number): number {
Expand All @@ -96,10 +103,7 @@ export function getSunrayAngleInDegrees(dayNum: number, earthTilt: number, lat:n
}

export function getMinutesSinceMidnight(time: Dayjs): number {
if (!time.isValid()) {
return 0;
}
return time.hour() * 60 + time.minute();
return !time.isValid() ? 0 : time.hour() * 60 + time.minute();
}

export function getDayLightInfo(options: DaylightCalcOptions): DaylightInfo[] {
Expand Down

0 comments on commit 9666942

Please sign in to comment.