magao-x / MagAOX

The MagAO-X Software System
https://magao-x.org/
GNU General Public License v3.0
10 stars 10 forks source link

seeing corrections inconsistent #121

Closed jaredmales closed 5 months ago

jaredmales commented 1 year ago

tcsi mag1_fwhm_corr matches what is plotted. dimm_fwhm matches what is plotted, not _corr. similarly, the web ui presents the numbers that match the plot.

is the dimm corrected on the plot / in the data stream that get seeting is using?

joseph-long commented 1 year ago

Recording my investigation here:

Inspecting http://weather.lco.cl/clima/weather/Magellan/JS/seeingCalPlotFunc.js shows the fetching and pre-processing. The mapping of sources to numbers is here:

// initial data PHP script
seeingPlot.initialphp1 = "PHP/grabCalMag1.php";
seeingPlot.initialphp2 = "PHP/grabCalMag2.php";
seeingPlot.initialphp3 = "PHP/grabCalDimm.php";

After fetching from those endpoints, we have on line 143:

// main drawing function. Gets the data, parses and draws all
// plot elements.
seeingPlot.initialData = function () {
    d3.json(seeingPlot.initialphp1, function(error1, data1) {
        // after getting the data it's parsed into array
        data1.forEach(function(d){
            d.tm = seeingPlot.parseDate(d.tm);
            d.el = 1.0/Math.cos((90-d.el)*Math.PI/180.0);
            d.fw = d.fw / Math.pow(d.el, 0.6); // treating elevation as airmass!
            seeingPlot.jsondata1.push(d);
        })

    d3.json(seeingPlot.initialphp2, function(error2, data2) {
        // after getting the data it's parsed into array
        data2.forEach(function(d){
            d.tm = seeingPlot.parseDate(d.tm);
            d.el = 1.0/Math.cos((90-d.el)*Math.PI/180.0);
            d.fw = d.fw / Math.pow(d.el, 0.6);
            seeingPlot.jsondata2.push(d);
        })

    d3.json(seeingPlot.initialphp3, function(error3, data3) {
     // after getting the data it's parsed into array
     data3.forEach(function(d){
        d.tm = seeingPlot.parseDate(d.tm);
        d.el = 1.0/Math.cos((90-d.el)*Math.PI/180.0);
        //d.fw = d.fw / Math.pow(d.el, 0.6); //if its not unscaled
        d.fw = +d.fw;
        seeingPlot.jsondata3.push(d);
     })
// ... rest omitted ...

If Apache is to be believed, this file is unchanged since Dec 29 2015, so I don't think the formulae have changed in recent memory.

To summarize:

joseph-long commented 1 year ago

MagAO-X automates collection of seeing information by launching a short Python script at regular intervals.

This script hits the PHP script endpoints to retrieve recent/current seeing measurements and writes them to files in /tmp.

$ cat /tmp/*.tsv
datetime fwhm elevation
2023-05-25 00:25:21 0.68 52.84
datetime fwhm elevation
2023-05-25 00:25:05 0.9 52.48
datetime fwhm elevation
2023-05-25 00:25:05 0.81 35.02

$ ls /tmp/*.tsv
/tmp/dimm.tsv  /tmp/mag1.tsv  /tmp/mag2.tsv

This script gets called by tcsi (the TCS interface app/device):

https://github.com/magao-x/MagAOX/blob/ea799436921200e84ca1229ecd9f8e19c332e4e7/apps/tcsInterface/tcsInterface.hpp#L1495

not more often than

https://github.com/magao-x/MagAOX/blob/ea799436921200e84ca1229ecd9f8e19c332e4e7/apps/tcsInterface/tcsInterface.hpp#L59

The formulae are applied to mag1: https://github.com/magao-x/MagAOX/blob/ea799436921200e84ca1229ecd9f8e19c332e4e7/apps/tcsInterface/tcsInterface.hpp#L1579

mag2: https://github.com/magao-x/MagAOX/blob/ea799436921200e84ca1229ecd9f8e19c332e4e7/apps/tcsInterface/tcsInterface.hpp#L1615

and, it appears, erroneously, to dimm: https://github.com/magao-x/MagAOX/blob/ea799436921200e84ca1229ecd9f8e19c332e4e7/apps/tcsInterface/tcsInterface.hpp#L1543

joseph-long commented 1 year ago

The takeaway is that we should ignore the dimm_fwhm_corr element in historical data because it's been double-corrected

joseph-long commented 5 months ago

Going forwards the historical data will call the usable dimm data dimm_fwhm_corr and the unusable data dimm_fwhm_bad. See https://github.com/magao-x/MagAOX/commit/b2e7918ca9bdd4b79d0c3209f2e1a62bf1dd9faa