Trixology

WeatherCat => WeatherCat Web Templates => Topic started by: mcrossley on August 20, 2016, 04:12:43 PM

Title: SunPlot
Post by: mcrossley on August 20, 2016, 04:12:43 PM
I thought I'd start a new thread for the Sun Plot script as it was clogging up the Gauges thread....

You chaps may be interested in another little PHP script for your web pages I knocked up last week - Sun Plot.
You can see it in use on my home page (not much sun today  :( ), and the download is here

(http://weather.wilmslowastro.com/downloads/sunplot.png)

It doesn't matter if you don't have a database that stores the sunshine data, you can use the plot just to show the Suns position as the day progresses and the relative day/night length and changes in Suns elevation. It's self contained, no other libraries etc. required.

You should be able to embed it in a HTML page just like a PHP page (so long as the server is running PHP obviously). Just using a standard <img> tag, like...
Code: [Select]
<img src="sunplot.php" alt="Sun Plot" width="X" height="Y">
Where X and Y are the width height you also specify in the php.
Title: Re: SunPlot
Post by: mcrossley on August 20, 2016, 04:15:50 PM
I almost did not dare to ask, but:

What about adding a time-line from 0 to 24 to the png?

 :-X

A bit like this?

Title: Re: SunPlot
Post by: wurzelmac on August 20, 2016, 04:27:33 PM
Ohh Yesss, Sir!

 [tup]
Title: Re: SunPlot
Post by: Blicj11 on August 20, 2016, 04:33:54 PM
Me too. I just downloaded version 1.1 but the timeline is not included.  :-\
Title: Re: SunPlot
Post by: wurzelmac on August 20, 2016, 04:43:33 PM
Just for reference to others:
Script is located at Marks Homepage:
http://weather.wilmslowastro.com/scripts.php

Examples:
http://weather.wilmslowastro.com/index.php
http://timberlakesutah.com/weather/
http://wetter.unterwurzacher.at/wetterwerte.html#sonne
Update on 24th of August:
http://www.eastdallasweather.com/wxastronomy.php
Title: Re: SunPlot
Post by: mcrossley on August 20, 2016, 04:52:22 PM
Me too. I just downloaded version 1.1 but the timeline is not included.  :-\
It will be in version 1.2 I want to do some more testing before releasing it.
Title: Re: SunPlot
Post by: wurzelmac on August 20, 2016, 04:58:16 PM
 ::)

Time Line color and font customizable.

 :-*

 :) :) :)
Title: Re: SunPlot
Post by: mcrossley on August 20, 2016, 05:52:20 PM
::)

Time Line color and font customizable.

 :-*

 :) :) :)
Well, they are if you edit the script ;)

It is black in the supplied script for both the ticks and numbers - but just change the RGB values of "$colHours". It doesn't draw a axis line, just tick marks down from the horizon.

It also uses a True Type font (arial.ttf by default), so you will need that font file on your web server somewhere - and don't forget to set the path/filename in the script. If it can't find the font you will get the tick marks but no numbers.

Version 1.2 now uploaded - go get it!
Title: Re: SunPlot
Post by: xairbusdriver on August 20, 2016, 05:59:27 PM
Quote
Time Line color and font customizable.
I think he just did that with an image editor. ;) But he can probably add it easily in the script. After all, coding is really just typing! [computer] [lol] Right now I don't see any 'echoing' in the script, but I'm sure he could 'write' the numbers in most any font, color, and size you'd like. I'd suggest that colors might need to be different depending on the background color. Colors don't show well on like-colored backgrounds. DOH!

I think "$colHours" must be in a later version? Don't see it in 1.0. Well, of course, flyboy! You need to type faster! Maybe using more than two fingers? [banghead]
But you proved my point about "coding"! [lol]
Title: Re: SunPlot
Post by: wurzelmac on August 20, 2016, 06:05:53 PM
Version 1.2 now uploaded - go get it!

You are ... great.

 ;D
Title: Re: SunPlot
Post by: wurzelmac on August 20, 2016, 06:24:28 PM
Done the trick with the font (using DINAlternateBold.otf as that is the font I use mainly in my website).

I really would like to donate some bucks to you - anywhere possible?
Title: Re: SunPlot
Post by: mcrossley on August 20, 2016, 07:30:29 PM
I saw you had used a custom font, it looks good.

I have a link for SteelSeries dontations (https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=R3Y5CFQPA9J5W), you could use that if you like. Don't feel obliged, I do this stuff for my own entertainment as much as anything...
Title: Re: SunPlot
Post by: wurzelmac on August 20, 2016, 07:55:16 PM
Thanks a lot for all your work! Stay tuned and share your scripts!
Title: Re: SunPlot
Post by: xairbusdriver on August 20, 2016, 07:55:27 PM
Reinhard's site is too beautiful not to visit at least once a week! Here's his <page (http://wetter.unterwurzacher.at/wetterwerte.html)> with the Sunplot (just below half way down the page depending on how big a window you may have). He has cleverly labeled the spot "Sonne"! ;)
Title: Re: SunPlot
Post by: wurzelmac on August 20, 2016, 07:58:00 PM
 :-[

 :)
Title: Re: SunPlot
Post by: wurzelmac on August 21, 2016, 02:40:07 PM
xair:

I forgot to say: Thank you for the flowers.
(http://images.clipartpanda.com/flowers-clipart-animated-happy-flower-clipart-1.jpg)
Title: Re: SunPlot
Post by: Blicj11 on August 22, 2016, 05:51:49 AM
How do I point the script to where the fonts are installed on my Mac?

This is what I thought should work because the font is located in library/fonts (not my user library, and not the system library but the "local" library where Apple recommends any use can add or modify fonts.

Code: [Select]
$fontFile = $_SERVER['DOCUMENT_ROOT'] . '/Library/Fonts/arial.ttf';
Title: Re: SunPlot
Post by: wurzelmac on August 22, 2016, 08:13:10 AM
Here is how I did it:

Uploaded the desired font file into my webspace in exact the same directory where the sunplot.php is doing its job. Then pointed to this file.
Code: [Select]
$fontFile = $_SERVER['DOCUMENT_ROOT'] . 'DINAlternateBold.otf';Be sure to type the font file name exactly into the script and avoid spaces in this name.

Hope this helps,
Title: Re: SunPlot
Post by: mcrossley on August 22, 2016, 10:18:04 AM
How do I point the script to where the fonts are installed on my Mac?

This is what I thought should work because the font is located in library/fonts (not my user library, and not the system library but the "local" library where Apple recommends any use can add or modify fonts.

Code: [Select]
$fontFile = $_SERVER['DOCUMENT_ROOT'] . '/Library/Fonts/arial.ttf';

Blic, the "$_SERVER['DOCUMENT_ROOT']" bit starts the path in your web server root folder (typically). If you want to use a file elsewhere on the system then try...
Code: [Select]
$fontFile = '/Library/Fonts/arial.ttf';[/quote]

Title: Re: SunPlot
Post by: Blicj11 on August 22, 2016, 03:43:56 PM
Still no joy for me.

First, tried pointing at the font where it is on my Mac. That didn't work.

Next I uploaded the font to the same directory where sunplot.php resides on my site and used the following line in the script:

Code: [Select]
$fontFile = $_SERVER['DOCUMENT_ROOT'] . 'Arial.ttf';
I tried this as well:

Code: [Select]
$fontFile = $_SERVER['DOCUMENT_ROOT'] . 'arial.ttf';
Still not working.

I have verified the font is there and spelled correctly.

Any ideas about what I am missing?
Title: Re: SunPlot
Post by: wurzelmac on August 22, 2016, 03:57:17 PM
John,

use a .otf font - just for trying and just a shot in the blue. I first uploaded a .woff font and it didn't work, either. You may use this one as test:
Title: Re: SunPlot
Post by: Blicj11 on August 22, 2016, 04:05:20 PM
Thanks, but still nothing for me.

Code: [Select]
$fontFile = $_SERVER['DOCUMENT_ROOT'] . 'DINAlternateBold.otf';
The font and the script are in the same directory. This should work.
Title: Re: SunPlot
Post by: wurzelmac on August 22, 2016, 04:10:23 PM
Another idea: Maybe this dierctory is NOT your web server root folder? In my case it is. Try duplicating the font file and put it to your root folder as well.

Or alternatively point to this in your case:
Code: [Select]
$fontFile = $_SERVER['DOCUMENT_ROOT'] . '/wp-content/uploads/Weather/DINAlternateBold.otf';
Title: Re: SunPlot
Post by: Blicj11 on August 22, 2016, 04:45:49 PM
Reinhard, you are genius. [cheer]

I am one of the few WeatherCatters using a WordPress site. In WordPress, all uploads go into a folder called uploads. On my site, I created a folder in uploads called Weather. All of my FTP for WeatherCat goes into the Weather folder. This is where sunplot.php and the font reside. I just needed to specify the full path name (Duh!!):

Code: [Select]
$fontFile = $_SERVER['DOCUMENT_ROOT'] . '/wp-content/uploads/Weather/DINAlternateBold.otf';
Thank you for patiently prompting me along on this.

Danke!
Title: Re: SunPlot
Post by: wurzelmac on August 22, 2016, 04:49:19 PM
 [bounce]
Title: Re: SunPlot
Post by: mcrossley on August 22, 2016, 08:48:38 PM
Glad you got it sorted. The alternative is to drop the "$_SERVER['DOCUMENT_ROOT'] . " bit and just specify the full path to the file from the system drive root folder.

use a .otf font - just for trying and just a shot in the blue. I first uploaded a .woff font and it didn't work, either. You may use this one as test:
Yep, PHP GD will not work with .woff files, it requires a True Type format, either .ttf or .otf. Browsers understand .woff format bit not PHP.
Title: Re: SunPlot
Post by: awilltx on August 23, 2016, 03:11:52 PM
Thanks for this script. I've been playing around with it and added it to my site just for grins:


http://www.eastdallasweather.com/wxastronomy.php


Alan
Title: Re: SunPlot
Post by: mcrossley on August 23, 2016, 03:19:13 PM
Hi Alan, you may want to play around with the colours a bit to get a better match with the rest of the page. Turning off the 'ground' may look better as well?

Anywho, nice to see it working for other people.

Now, can WeatherCat supply the sunshine data....?
Title: Re: SunPlot
Post by: awilltx on August 23, 2016, 03:28:18 PM
Hi Alan, you may want to play around with the colours a bit to get a better match with the rest of the page. Turning off the 'ground' may look better as well?

Anywho, nice to see it working for other people.

Now, can WeatherCat supply the sunshine data....?


Thanks for the suggestion. Turning off ground looks better.


WC certainly has the data. I'd have to see what the Cumulus database looks like to do the insert, retrieval, etc.


Cheers,
Alan
Title: Re: SunPlot
Post by: mcrossley on August 23, 2016, 03:56:10 PM
Basically the plot just uses a 'realtime' table with a row inserted per minute (I keep a rolling 10 days of data in my realtime table), with a column 'IsSunny' which is set to 0 or 1 (no sun / sun). If you have something like that then the script should be easy to adapt to WC.

I also have as yet an unreleased version that reads a Blake-Larson sun detector log file. That has a line per sunshine 'event', with the start/end time of when the sun was shining.
Title: Re: SunPlot
Post by: Blicj11 on August 24, 2016, 02:08:39 AM
Alan: I like it on your site.

Mark: WeatherCat tracks total sunshine hours so I know it's in the database somewhere.
Title: Re: SunPlot
Post by: wurzelmac on August 24, 2016, 05:54:30 AM
Mark,

we are able to indicate sun shining now in SteelGauges, so the data for taht must be somewhere, or it is computed by the script somehow:

Code: [Select]
showSunshineLed    : true,                   //Show 'sun shining now' LED on solar gauge
Title: Re: SunPlot
Post by: Blicj11 on August 24, 2016, 02:09:43 PM
Reinhard, I believe the LED to display sun shining now on the SteelSereies Gauges is a calculation done by the Gauges software. There are two lines in the gauges.js where you can experiment with the parameters so you can tweak that LED to be more accurate depending on your specific location. But I assume that some kind of similar calculation exists in WeatherCat in order for the 'Cat to calculate total sunshine hours.
Title: Re: SunPlot
Post by: mcrossley on August 24, 2016, 02:31:47 PM
The script does do the calculation as not all the weather programs provide the "IsShining" data, so as the calculation is simple I do it on the fly.

Title: Re: SunPlot
Post by: Blicj11 on August 24, 2016, 02:35:29 PM
The WeatherCat data should be more accurate as it is based on readings from the Solar Radiation sensor.
Title: Re: SunPlot
Post by: mcrossley on August 24, 2016, 07:30:08 PM
Well, the script uses the data supplied by WC too ;) The key is the percentage threshold, and any absolute cutoff value (the WMO uses 120 W/m2 as the minimum threshold required for sunshine - I think to maintain consistency in readings with the Campbell-Stokes recorders which need a minimum level to burn the card)
Title: Re: SunPlot
Post by: wurzelmac on August 24, 2016, 07:42:47 PM
...so as the calculation is simple I do it on the fly...

 :)  [tup]
Title: Re: SunPlot
Post by: Blicj11 on August 25, 2016, 02:57:09 PM
I have my threshold set much lower because the light wasn't turning on when it should have been in the late afternoon, so I just stared playing around until I got it to where I felt it was reasonable accurate compared to what I saw looking out the window.
Title: Re: SunPlot
Post by: xairbusdriver on August 25, 2016, 03:38:23 PM
Quote
compared to what I saw looking out the window.
HERETIC! BLASPHEMER!! I hope the Admins here take note of your lower moral behavior! [rockon] [rolleyes2]
Title: Re: SunPlot
Post by: Blicj11 on January 30, 2021, 04:25:53 PM
Mark or Reinhard:

I noticed starting this morning, the sunplot.php display has gone missing from my website. I haven't changed anything in the file and have verified it is in the same directory where it has resided since 2016. The font is sitting in the same directory. It was all working fine yesterday. I'm out of ideas. Would you mind taking a look and see if you can see something?

Thanks.

Here is the code from the main section, and as I said, I have not touched this for years.

######################## User Editable Variable Section ############################

// Set your station time zone (valid PHP/MySQL TZ string)
$tz = 'America/Denver';

// We need the decimal latitude and longitude of the station to calc sun position
$LAT = 40.1;  // +ve North
$LON = -111.2;  // +ve East

// Realtime database table name
$realtimeTableName = 'realtime';

// Path to TTF font - only required for Hour markers
// $fontFile = $_SERVER['DOCUMENT_ROOT'] . '/wp-content/uploads/Weather/PTSans.ttc';
$fontFile = $_SERVER['DOCUMENT_ROOT'] . '/wp-content/uploads/Weather/Arial_Bold.ttf';
// plot options - note these can be overridden by posted parameters
$sizeH        = 425;        // Horizontal image size
$sizeV        = 150;        // Vertical image size
$showGround   = false;       // Show the ground as shaded
$showSunshine = false;      // Plot sunshine from your MySQL database
$transparent  = true;      // Make the image background transparent
$showTwilight = false;      // Plot civil/nautical/astro twilight
$showHours    = true;      // Plot the hours 0-24 along the horizon axis

###################### END: User Editable Variable Section #########################
Title: Re: SunPlot
Post by: xairbusdriver on January 30, 2021, 05:47:57 PM
I guess it's moot since the line is simply a comment... Is the suffix "ttc" correct for the "PTSans" font? Perhaps a typo in your post? [blush]

Other WAGS:
  I assume the PHP files are still in the correct directories at your web space and locally.
  Do you know what version of PHP the scripts used? Did your host recently change the default versions?
Title: Re: SunPlot
Post by: mcrossley on January 30, 2021, 05:59:37 PM
When I load your page, I'm getting an error 404 (file not found) for https://timberlakesutah.com/wp-content/uploads/Weather/sunplot.php
Title: Re: SunPlot
Post by: Blicj11 on January 30, 2021, 08:51:49 PM
Thanks for checking Mark. I can't figure it out. That file is definitely in that directory, with Permissions 644. I can see it in CPanel and in my FTP client. I deleted it, downloaded from your website again, edited the script, uploaded it to that directory, and I still get a 404 error. That is the only PHP file in that directory. All the other files are jpg, png, or html, and each of them will open up, but when I try to open the sunplot in a browser tab it can't find it. I even got desperate and tried clearing cache and rebooting. Hahaha. It's got something to do with looking for a PHP file that's somehow different that everything else it can find. I'll keep thinking, but I'm just about out of ideas.
Title: Re: SunPlot
Post by: wurzelmac on January 31, 2021, 04:06:28 PM
Hi Blick - very strange, indeed. I just compared your posted "User Editable Variable Section" and it looks exact as mine (except Time Zone and Lat Lon). My script is running on my main site (wetter.unterwurzacher.at) with this code:

Code: [Select]
<span style="text-align:center;">
<h2>Aktuelle Sonnenposition<br><?php echo date($dateFormat,time())?></h2>
<br>
</span>
<img src="https://wetter.unterwurzacher.at/meteo/scripts/sunplot.php" width="95%" alt="Sonnenplot" title="Aktuelle Sonnenposition">
<br>
<span style="text-align:center;">Script von <a href="http://weather.wilmslowastro.com/scripts.php">Mark Crossley</a></span>

The directory where I am hosting the script has permission 775, the script itself 640, maybe it is worth trying these permissions.  Sorry, but this is all I can say to this mystery. Hope you can solve the puzzle...
Title: Re: SunPlot
Post by: Blicj11 on February 01, 2021, 11:53:34 PM
Thanks Reinhard, still no joy. :(

Oh well, it was great whilst it lasted.
Title: Re: SunPlot
Post by: wurzelmac on February 02, 2021, 07:45:26 AM
To come back to xair's mention: Has anything changed with the ISP you are using? Maybe the host is not executing PHP's any more?  ???
Title: Re: SunPlot
Post by: Blicj11 on February 02, 2021, 11:24:01 PM
Reinhard:

You are a genius! Mystery solved. Your question triggered a moment of illumination in my mind.

I tried out some firewall software and I didn't like it because it was blocking legitimate users from my site. I deleted it. I did not know that before I deleted it, it added an .htaccess file to my uploads directory, blocking all php files from executing. Deleting that file restored the sunplot to it's original function.

Once again you have saved the day.

I love this little script Mark wrote and am glad I can still use it.

Thank you, mate!
Title: Re: SunPlot
Post by: wurzelmac on February 03, 2021, 07:24:21 AM
Blick: Glad the amazing script is back online on your site!  [tup]

Cheers,
Title: Re: SunPlot
Post by: Blicj11 on February 03, 2021, 08:01:09 AM
Thank you! I just sent an hour clicking on every link your site. You have great taste in color and graphic design. Have a great day.

Gruß, Blick
Title: Re: SunPlot
Post by: wurzelmac on February 03, 2021, 06:34:43 PM
Thanks alot visiting my site - and thanks for your honorable words, Sir.

 [cheers1]