Skip to content

Commit

Permalink
Merge pull request #133 from mcrossley/master
Browse files Browse the repository at this point in the history
v3.14.1
  • Loading branch information
mcrossley committed Dec 21, 2021
2 parents 73db04e + e5bb4ba commit ee52360
Show file tree
Hide file tree
Showing 15 changed files with 377 additions and 238 deletions.
30 changes: 27 additions & 3 deletions CumulusMX/AstroLib.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,23 @@ private static double RadToDeg(double angle)
}

public static double SolarMax(DateTime timestamp, double longitude, double latitude, double altitude,
out double solarelevation, double transfactor, double turbidity, int method)
out double solarelevation, SolarOptions options)
{
double factor = 0;
if (options.SolarCalc == 0)
{
factor = GetFactor(timestamp, options.RStransfactorJul, options.RStransfactorDec);
}
if (options.SolarCalc == 1)
{
factor = GetFactor(timestamp, options.BrasTurbidityJul, options.BrasTurbidityDec);
}
return SolarMax(timestamp, longitude, latitude, altitude, out solarelevation, factor, options.SolarCalc);
}


public static double SolarMax(DateTime timestamp, double longitude, double latitude, double altitude,
out double solarelevation, double factor, int method)
{
DateTime utctime = timestamp.ToUniversalTime();

Expand All @@ -72,16 +88,24 @@ public static double SolarMax(DateTime timestamp, double longitude, double latit
//cumulus.LogMessage(utctime+" lat="+latitude+" lon="+longitude+" sun elev="+solarelevation);
if (method == 0)
{
return RyanStolzSolar(solarelevation, erv, transfactor, altitude);
return RyanStolzSolar(solarelevation, erv, factor, altitude);
}
if (method == 1)
{
return BrasSolar(solarelevation, erv, turbidity);
return BrasSolar(solarelevation, erv, factor);
}

return 0;
}

// Calculate the interpolated factor using a cosine function
private static double GetFactor(DateTime timestamp, double jul, double dec)
{
var range = jul - dec;
var doy = timestamp.DayOfYear;
return dec + Math.Cos((doy - 172) / 183.0 * Math.PI / 2) * range;
}

// http://guideving.blogspot.co.uk/2010/08/sun-position-in-c.html

public static void CalculateSunPosition(
Expand Down
91 changes: 56 additions & 35 deletions CumulusMX/Cumulus.cs
Original file line number Diff line number Diff line change
Expand Up @@ -456,8 +456,6 @@ public struct TExtraFiles
public double Longitude;
public double Altitude;

public double RStransfactor = 0.8;

internal int wsPort;
private readonly bool DebuggingEnabled;

Expand Down Expand Up @@ -540,6 +538,8 @@ public struct TExtraFiles
public EmailSender emailer;
public EmailSender.SmtpOptions SmtpOptions = new EmailSender.SmtpOptions();

public SolarOptions SolarOptions = new SolarOptions();

public string AlarmEmailPreamble;
public string AlarmEmailSubject;
public string AlarmFromEmail;
Expand Down Expand Up @@ -4272,7 +4272,7 @@ private void ReadIniFile()
FtpOptions.FtpMode = (FtpProtocols)ini.GetValue("FTP site", "Sslftp", 0);
// BUILD 3092 - added alternate SFTP authentication options
FtpOptions.SshAuthen = ini.GetValue("FTP site", "SshFtpAuthentication", "password");
if (!sshAuthenticationVals.Any(FtpOptions.SshAuthen.Contains))
if (!sshAuthenticationVals.Contains(FtpOptions.SshAuthen))
{
FtpOptions.SshAuthen = "password";
LogMessage($"Error, invalid SshFtpAuthentication value in Cumulus.ini [{FtpOptions.SshAuthen}], defaulting to Password.");
Expand All @@ -4282,7 +4282,7 @@ private void ReadIniFile()
if (FtpOptions.SshPskFile.Length > 0 && (FtpOptions.SshAuthen == "psk" || FtpOptions.SshAuthen == "password_psk") && !File.Exists(FtpOptions.SshPskFile))
{
FtpOptions.SshPskFile = "";
LogMessage($"Error, file name specified by SshFtpPskFile value in Cumulus.ini does not exist [{FtpOptions.SshPskFile}], defaulting to None.");
LogMessage($"Error, file name specified by SshFtpPskFile value in Cumulus.ini does not exist [{FtpOptions.SshPskFile}].");
rewriteRequired = true;
}
FtpOptions.DisableEPSV = ini.GetValue("FTP site", "DisableEPSV", false);
Expand Down Expand Up @@ -4853,15 +4853,35 @@ private void ReadIniFile()
xapUID = ini.GetValue("xAP", "UID", "4375");
xapPort = ini.GetValue("xAP", "Port", 3639);

SunThreshold = ini.GetValue("Solar", "SunThreshold", 75);
RStransfactor = ini.GetValue("Solar", "RStransfactor", 0.8);
SolarMinimum = ini.GetValue("Solar", "SolarMinimum", 30);
LuxToWM2 = ini.GetValue("Solar", "LuxToWM2", 0.0079);
UseBlakeLarsen = ini.GetValue("Solar", "UseBlakeLarsen", false);
SolarCalc = ini.GetValue("Solar", "SolarCalc", 0);
BrasTurbidity = ini.GetValue("Solar", "BrasTurbidity", 2.0);
//SolarFactorSummer = ini.GetValue("Solar", "SolarFactorSummer", -1);
//SolarFactorWinter = ini.GetValue("Solar", "SolarFactorWinter", -1);
SolarOptions.SunThreshold = ini.GetValue("Solar", "SunThreshold", 75);
SolarOptions.SolarMinimum = ini.GetValue("Solar", "SolarMinimum", 30);
SolarOptions.LuxToWM2 = ini.GetValue("Solar", "LuxToWM2", 0.0079);
SolarOptions.UseBlakeLarsen = ini.GetValue("Solar", "UseBlakeLarsen", false);
SolarOptions.SolarCalc = ini.GetValue("Solar", "SolarCalc", 0);

// Migrate old single solar factors to the new dual scheme
if (ini.ValueExists("Solar", "RStransfactor"))
{
SolarOptions.RStransfactorJul = ini.GetValue("Solar", "RStransfactor", 0.8);
SolarOptions.RStransfactorDec = SolarOptions.RStransfactorJul;
rewriteRequired = true;
}
else
{
SolarOptions.RStransfactorJul = ini.GetValue("Solar", "RStransfactorJul", 0.8);
SolarOptions.RStransfactorDec = ini.GetValue("Solar", "RStransfactorDec", 0.8);
}
if (ini.ValueExists("Solar", "BrasTurbidity"))
{
SolarOptions.BrasTurbidityJul = ini.GetValue("Solar", "BrasTurbidity", 2.0);
SolarOptions.BrasTurbidityDec = SolarOptions.BrasTurbidityJul;
rewriteRequired = true;
}
else
{
SolarOptions.BrasTurbidityJul = ini.GetValue("Solar", "BrasTurbidityJul", 2.0);
SolarOptions.BrasTurbidityDec = ini.GetValue("Solar", "BrasTurbidityDec", 2.0);
}

NOAAconf.Name = ini.GetValue("NOAA", "Name", " ");
NOAAconf.City = ini.GetValue("NOAA", "City", " ");
Expand Down Expand Up @@ -5731,12 +5751,15 @@ internal void WriteIniFile()
ini.SetValue("xAP", "UID", xapUID);
ini.SetValue("xAP", "Port", xapPort);

ini.SetValue("Solar", "SunThreshold", SunThreshold);
ini.SetValue("Solar", "RStransfactor", RStransfactor);
ini.SetValue("Solar", "SolarMinimum", SolarMinimum);
ini.SetValue("Solar", "UseBlakeLarsen", UseBlakeLarsen);
ini.SetValue("Solar", "SolarCalc", SolarCalc);
ini.SetValue("Solar", "BrasTurbidity", BrasTurbidity);
ini.SetValue("Solar", "SunThreshold", SolarOptions.SunThreshold);
ini.SetValue("Solar", "SolarMinimum", SolarOptions.SolarMinimum);
ini.SetValue("Solar", "UseBlakeLarsen", SolarOptions.UseBlakeLarsen);
ini.SetValue("Solar", "SolarCalc", SolarOptions.SolarCalc);
ini.SetValue("Solar", "LuxToWM2", SolarOptions.LuxToWM2);
ini.SetValue("Solar", "RStransfactorJul", SolarOptions.RStransfactorJul);
ini.SetValue("Solar", "RStransfactorDec", SolarOptions.RStransfactorDec);
ini.SetValue("Solar", "BrasTurbidityJul", SolarOptions.BrasTurbidityJul);
ini.SetValue("Solar", "BrasTurbidityDec", SolarOptions.BrasTurbidityDec);

ini.SetValue("NOAA", "Name", NOAAconf.Name);
ini.SetValue("NOAA", "City", NOAAconf.City);
Expand Down Expand Up @@ -6184,21 +6207,6 @@ private void ReadStringsFile()
}


public bool UseBlakeLarsen { get; set; }

public double LuxToWM2 { get; set; }

public int SolarMinimum { get; set; }

public int SunThreshold { get; set; }

public int SolarCalc { get; set; }

public double BrasTurbidity { get; set; }

//public double SolarFactorSummer { get; set; }
//public double SolarFactorWinter { get; set; }

public int xapPort { get; set; }

public string xapUID { get; set; }
Expand Down Expand Up @@ -6743,7 +6751,7 @@ public async void DoLogFile(DateTime timestamp, bool live)
// make sure solar max is calculated for those stations without a solar sensor
LogMessage("DoLogFile: Writing log entry for " + timestamp);
LogDebugMessage("DoLogFile: max gust: " + station.RecentMaxGust.ToString(WindFormat));
station.CurrentSolarMax = AstroLib.SolarMax(timestamp, Longitude, Latitude, station.AltitudeM(Altitude), out station.SolarElevation, RStransfactor, BrasTurbidity, SolarCalc);
station.CurrentSolarMax = AstroLib.SolarMax(timestamp, Longitude, Latitude, station.AltitudeM(Altitude), out station.SolarElevation, SolarOptions);
var filename = GetLogFileName(timestamp);

var sb = new StringBuilder(256);
Expand Down Expand Up @@ -10674,6 +10682,19 @@ public class EasyWeatherOptions
public double PressOffset { get; set; }
}

public class SolarOptions
{
public int SunThreshold { get; set; }
public int SolarMinimum { get; set; }
public double LuxToWM2 { get; set; }
public bool UseBlakeLarsen { get; set; }
public int SolarCalc { get; set; }
public double RStransfactorJul { get; set; }
public double RStransfactorDec { get; set; }
public double BrasTurbidityJul { get; set; }
public double BrasTurbidityDec { get; set; }
}

public class GraphOptions
{
public bool TempVisible { get; set; }
Expand Down
2 changes: 1 addition & 1 deletion CumulusMX/DavisStation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2539,7 +2539,7 @@ private void GetArchiveData()
DoSolarRad(archiveData.SolarRad, timestamp);

// add in archive period worth of sunshine, if sunny
if ((SolarRad > CurrentSolarMax * cumulus.SunThreshold / 100.00) && (SolarRad >= cumulus.SolarMinimum))
if ((SolarRad > CurrentSolarMax * cumulus.SolarOptions.SunThreshold / 100.00) && (SolarRad >= cumulus.SolarOptions.SolarMinimum))
SunshineHours += (interval / 60.0);
}

Expand Down
Loading

0 comments on commit ee52360

Please sign in to comment.