linefit

Fit a line to a set of X,Y data in a table-format file. By "table-format" I mean a file that has a "# data" header delimeter. I show an example below. The raw answers are sent to standard out, but a hard-copy explanation file is also produced. I use this files directly, for example, as input for things like my tools that overplot spectral features in ds9 images.

% 
% linefit.sh 

Usage: linefit.sh fin.dat  
arg1 - name of input file   

Below I show a practical example for linefit.sh:
% 
% ls
keep/  linefit.explain  RU_lrs2r.dat  S/

% cat RU_lrs2r.dat
Measured bandheads on a RU from 20160312  obs=306 exp=01
3
X_pix   
Y_angstroms 
Name 
# data 
 159.3     8349.0       sky8349
 534.3     8830.0       sky8830
 965.0     9320.0       sky9320
1018.0     9380.0       sky9380 
1388.0     9800.0       sky9800 
1827.0    10291.0       sky10291

% linefit.sh RU_lrs2r.dat
   1.1581805  8191.0771484    17.8655643       6   RU_lrs2r.dat                 

% ls
keep/  linefit.explain  RU_lrs2r.dat  S/

% cat linefit.explain
Results from linefit:
     1.1581805       0.0150665    (slope, m.e.) 
  8191.0771484      14.7942867    (Y-intercept, m.e.) 
    17.8655643                    (Y-sigma)
     6                            (number of fitted points)

The rationale for the two output methods is this: I want a simple output to standard out that I can easily ingest with other scripts. At the same time, I want a file (linefit.explain) that gives a little more information. I can also use this file for input to other otw codes pretty easily. These files could go directly into python and bash scripts, but my I/O skills there are still rudimentary.




Back to SCO CODES page