Plotting the contents of the constants directory¶
The constFile
class has a method for easily plotting the contents of a constants file.
Reading in data¶
When you initialise an instance of constFile
it reads in a text file.
For example:
import cbasspy.constantsPlotting.fromFileNames as ffn
inFileName = 'noise_diode_values_ptcross.txt'
columns = ['MJD','srcNo','el','parAng','Tnd1','Tnd2','err1','err2','flag1','flag2','method']
labels = ['MJD','Source','Elevation [rad]','Paralactic Angel [rad]',
'$T_{ND1}$','$T_{ND2}$','$\\Delta T_{ND1}$','$\\Delta T_{ND2}$','Flag 1', 'Flag 2', 'Method']
inDir = '/stegodon/Reductions/Calibrations/cals20Feb18/calibration_constants'
ndv_ptcross = ffn.constFile(inFileName,columns,labels,inDir=inDir)
- inFileName is the name of the text file to load in.
- columns are identifiers for each column in the text file. They are the keys to dictionaries containing the data.
- labels are pretty names for the columns, these will automatically be used to label axes.
- inDir is the directory that contains the input file.
The built in method formatMjdTimes()
converts MJDs
to matplotlib date numbers.
This is useful when plotting.
It is called as follows:
ndv_ptcross.formatMjdTimes('MJD')
You have to pass the method the name of the column that contains MJDs that you want to convert.
Noise diode files¶
The noise diode files have a slightly strange structure. The first five columns are fixed and contain the MJD, mean I1 signal, error on I1 signal, mean I2 signal and its error. Each line then contains a variable number of columns, and the meaning of the columns changes. The remaining columns list the calibrators that were used and can be split into two halves, the first half lists the calibrators used for I1 and the second half lists the calibrators used for I2 - these should be the same. Each of these halves can have up to three columns, the columns contain integers that identify the sources used.
For example the columns could read:
1 2 8 1 2 8
which would mean that both I1 and I2 were calibrated off of sources 1, 2 and 8.
The columns could read:
2 8 2 8
which would mean that both I1 and I2 were calibrated off of sources 2 and 8.
In principle the columns could read:
1 8 2
The meaning of which would be completely ambiguous!! We assume that both I1 and I2 were calibrated off of the same number of sources.
Files like this can be read in by setting the optional argument isNoisediodeFile to True. For example:
inFileName = 'pipeline_noisediodes_cals20Feb18.txt'
columns = ['MJD', 'mean_I1', 'err_I1', 'mean_I2', 'err_I2']
labels = ['MJD', 'I1', 'err_I1', 'I2', 'err_I2']
inDir = '/stegodon/Reductions/Calibrations/cals20Feb18/calibration_cals20Feb18'
pipeline_noisediodes = ffn.constFile(inFileName,columns,labels,inDir=inDir,isNoisediodeFile=True)
The MJD column can then be converted to matplotlib date numbers in the same way as above:
pipeline_noisediodes.formatMjdTimes('MJD')
Plotting¶
The constFile
class has a built in method that can do most
of the plotting you might be interested in.
Let’s consider the noise_diode_values_ptcross.txt file that we read in earlier to make the ndv_ptcross instance of constFile
.
We can easily plot the temperature of noise diode 1 against that of noise diode 2:
fig,ax = plt.subplots()
ndv_ptcross.plotSimpleScatter(ax,'Tnd1','Tnd2',fmt='.k')
ffn.overplotStraightLine(ax,1.0,0.0,'g')
plt.title('Noise diode from ptcross, 2vs1')
(Remember to import numpy and matplotlib.pyplot).
First we created the figure and axis, then we called plotSimpleScatter()
.
We then used the convenience function cbasspy.constantsPlotting.fromFileNames.overplotStraightLine()
to overplot the line y=x in green.
Masking¶
The constFile
class has an attribute extraFlags,
which is an array of ones and zeros.
Ones inidcate the point should be included, zero indicates that it should be excluded.
By default an instance of the class is initialized with this set to all ones.
It can be reset to all ones by calling the built in method resetFlags()
.
You can manually change it to anything that you like, there is a built in method that checks what you are setting it to is the
correct length (overwriteFlags()
).
Here is an example of it being used:
fig,axes = plt.subplots(nrows=2,ncols=1,sharex='all')
ndv_ptcross.overwriteFlags((ndv_ptcross.data['srcNo']==11).astype(int))
ndv_ptcross.plotSimpleScatter(axes[0],'MJD','Tnd1',fmt='.m',label='M42')
ndv_ptcross.overwriteFlags((ndv_ptcross.data['srcNo']!=11).astype(int))
ndv_ptcross.plotSimpleScatter(axes[0],'MJD','Tnd1',fmt='.c',label='All others')
ndv_ptcross.overwriteFlags((ndv_ptcross.data['srcNo']==11).astype(int))
ndv_ptcross.plotSimpleScatter(axes[1],'MJD','Tnd2',fmt='.m',label='M42')
ndv_ptcross.overwriteFlags((ndv_ptcross.data['srcNo']!=11).astype(int))
ndv_ptcross.plotSimpleScatter(axes[1],'MJD','Tnd2',fmt='.c',label='All others')
ffn.xaxisFormatDates(axes[1])
plt.legend()
plt.suptitle('Noide diode values from ptcross, source M42')
This is highlighting the points corresponding to source number 11 (M42). The flux value of M42 in this reduction was set to an approximate place holder, in the plot the values are clearly offset from the others.
More examples¶
For more examples of plotting see the example script in cbasspy/constantsPlotting/fromFileNames/example_run.py