Modifying Metadata#

In this example we will show how to modify the metadata of a SDFITS file using dysh.

You can find a copy of this tutorial as a Jupyter notebook here or download it by right clicking here and selecting “Save Link As”.

Background#

We will use a practical example. For observations with the GBT it is recommended to observe a flux density calibrator (see e.g., Perley & Butler 2017 for a list of calibrator sources and their flux densities) with the same configuration as that used for the science observations. The reason being that the values of the temperature equivalent power of the noise diodes stored in the SDFITS files can be out of date.

In this example we won’t use observations of a flux density calibrator, but instead we will use the analysis of Goddy et al (2020). They find that the temperature stored in the SDFITS files is on average lower than the measured values, so that the temperature must be corrected by 20%

\[ T_{\rm{CAL,corr}}=1.2T_{\rm{CAL,file}}. \]
Here we use this to correct the temperature of the noise diode.

Loading Modules#

We start by loading the modules we will use for this example.

For display purposes, we use the static (non-interactive) matplotlib backend in this tutorial. However, you can tell matplotlib to use the ipympl backend to enable interactive plots. This is only needed if working on jupyter lab or notebook.

# Set interactive plots in jupyter.
#%matplotlib ipympl

# These modules are required for working with the data.
from dysh.fits.gbtfitsload import GBTFITSLoad

# These modules are only used to download the data.
from pathlib import Path
from dysh.util.download import from_url

Data retrieval#

We download the data we will use for this example, if necessary.

url = "https://www.gb.nrao.edu/dysh/example_data/positionswitch/data/AGBT05B_047_01/AGBT05B_047_01.raw.acs/AGBT05B_047_01.raw.acs.fits"
savepath = Path.cwd() / "data"
savepath.mkdir(exist_ok=True) # Create the data directory if it does not exist.
filename = from_url(url, savepath)

Data loading#

We load the data and inspect its contents.

sdfits = GBTFITSLoad(filename)
sdfits.summary()
SCAN OBJECT VELOCITY PROC PROCSEQN RESTFREQ DOPFREQ # IF # POL # INT # FEED AZIMUTH ELEVATION
51 NGC5291 4386.0 OnOff 1 1.420405 1.420405 1 2 11 1 198.3431 18.6427
52 NGC5291 4386.0 OnOff 2 1.420405 1.420405 1 2 11 1 198.9306 18.7872
53 NGC5291 4386.0 OnOff 1 1.420405 1.420405 1 2 11 1 199.3305 18.3561
54 NGC5291 4386.0 OnOff 2 1.420405 1.420405 1 2 11 1 199.9157 18.4927
55 NGC5291 4386.0 OnOff 1 1.420405 1.420405 1 2 11 1 200.3042 18.0575
56 NGC5291 4386.0 OnOff 2 1.420405 1.420405 1 2 11 1 200.8906 18.1860
57 NGC5291 4386.0 OnOff 1 1.420405 1.420405 1 2 11 1 202.3275 17.3853
58 NGC5291 4386.0 OnOff 2 1.420405 1.420405 1 2 11 1 202.9192 17.4949

Metadata inspection#

Now we inspect the current noise diode temperature stored in the SDFITS file.

sdfits["TCAL", "PLNUM"]
TCAL PLNUM
0 1.424292 1
1 1.424292 1
2 1.452650 0
3 1.452650 0
4 1.424292 1
... ... ...
347 1.452650 0
348 1.424292 1
349 1.424292 1
350 1.452650 0
351 1.452650 0

352 rows × 2 columns

For polarization 0 the noise diode temperature is 1.452650 K and for polarization 1 it is 1.424292 K.

We will calibrate the data using these values to compare after we update the noise diode temperature. We use position switching calibration, then we time average all the scans and remove an order 1 polynomial.

ps_original = sdfits.getps(plnum=0, ifnum=0, fdnum=0).timeaverage()
ps_original.baseline(degree=1, remove=True)

Metadata update#

Now we update the temperature of the noise diode by multiplying by 1.2.

sdfits["TCAL"] *= 1.2
/home/docs/checkouts/readthedocs.org/user_builds/dysh/checkouts/release-0.8.0b/src/dysh/fits/gbtfitsload.py:2811: UserWarning: Changing an existing SDFITS column TCAL
  warnings.warn(f"Changing an existing SDFITS column {items}")  # noqa: B028
/home/docs/checkouts/readthedocs.org/user_builds/dysh/checkouts/release-0.8.0b/src/dysh/fits/sdfitsload.py:1115: UserWarning: Changing an existing SDFITS column TCAL
  warnings.warn(f"Changing an existing SDFITS column {items}")  # noqa: B028

Now we check that the values were updated.

sdfits["TCAL", "PLNUM"]
TCAL PLNUM
0 1.70915 1
1 1.70915 1
2 1.74318 0
3 1.74318 0
4 1.70915 1
... ... ...
347 1.74318 0
348 1.70915 1
349 1.70915 1
350 1.74318 0
351 1.74318 0

352 rows × 2 columns

The values were updated. We proceed with the data reduction.

ps_updated = sdfits.getps(plnum=0, ifnum=0, fdnum=0).timeaverage()
ps_updated.baseline(degree=1, remove=True)

Now plot and compare the result. Since the antenna temperature is directly proportional to the temperature of the noise diode, now the line profile after the update should be 20% brighter than without the update.

ps_original.plot(ymin=-0.5, ymax=0.3)
ps_updated.plot(ymin=-0.5, ymax=0.3)
<dysh.plot.specplot.SpectrumPlot at 0x70dc91db4fd0>
../../_images/3404ffc761d365d0075f9cda928965eec0bd798ddb7f1ae9c319cb4546b5609d.png ../../_images/448e742cef1315376f1c5b6fc029042b5e88045a0dc790226eabdf4c8b25b1e8.png