{ "metadata": { "name": "" }, "nbformat": 2, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "All MCS0030 (SDF-based) observations will have associated metadata in the form of a metadata tarball. The LWA1 Data Archive stores all of the metadata files that have been aquired so that observers can access the metadata. This tutorial demonstrates the LSL interfaces to the metadata and how to extract various information.", "", "First, lets get a metadata tarball:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "# This may take a bit...", "import os", "import urllib2", "", "if not os.path.exists('LK003_0113.tgz'):", " fh1 = urllib2.urlopen('http://lda10g.alliance.unm.edu/metadata/observation/130921_done/LK003_0113.tgz')", " fh2 = open('LK003_0113.tgz', 'wb')", " fh2.write(fh1.read())", " fh1.close()", " fh2.close()", " ", "print \"Metadata Size: %.1f kB\" % (os.path.getsize('LK003_0113.tgz')/1024.)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "Metadata Size: 470.6 kB" ] } ], "prompt_number": 3 }, { "cell_type": "markdown", "metadata": {}, "source": [ "The lsl.common.metabundle module provides access to the contents of the tarball. To get the SDF included in the tarball run:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "from lsl.common import metabundle ", "", "project = metabundle.getSessionDefinition('LK003_0113.tgz')", "print \"Project ID: %s\" % project.id", "print \"Session ID: %i\" % project.sessions[0].id" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "Project ID: LK003", "Session ID: 113" ] } ], "prompt_number": 4 }, { "cell_type": "markdown", "metadata": {}, "source": [ "The \"project\" variable contains all of the observations in the SDF as well:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "from datetime import datetime, timedelta", "", "nObs = len(project.sessions[0].observations)", "for i in xrange(nObs):", " currDur = project.sessions[0].observations[i].dur", " currDur = timedelta(seconds=int(currDur/1000), microseconds=(currDur*1000) % 1000000)", " ", " print \" Observation #%i\" % (i+1,)", " print \" Target: %s\" % project.sessions[0].observations[i].target", " print \" Mode: %s\" % project.sessions[0].observations[i].mode", " print \" Start:\"", " print \" MJD: %i\" % project.sessions[0].observations[i].mjd", " print \" MPM: %i\" % project.sessions[0].observations[i].mpm", " print \" Duration: %s\" % currDur" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ " Observation #1", " Target: M31", " Mode: TRK_RADEC", " Start:", " MJD: 56556", " MPM: 13692273", " Duration: 4:00:00" ] } ], "prompt_number": 5 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Working with MJD and MPM values isn't particularlly transparent but a MJD/MPM pair can be easily converted to a Python datetime object storing UTC time:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "from lsl.astro import utcjd_to_unix, MJD_OFFSET", "", "mjd = project.sessions[0].observations[0].mjd", "mpm = project.sessions[0].observations[0].mpm", "tStart = utcjd_to_unix(mjd + MJD_OFFSET)", "tStart += mpm / 1000.0", "", "print \"MJD: %i\" % mjd", "print \"MPM: %i\" % mpm", "print \"-> %s\" % datetime.utcfromtimestamp(tStart)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "MJD: 56556", "MPM: 13692273", "-> 2013-09-21 03:48:12.273000" ] } ], "prompt_number": 6 }, { "cell_type": "markdown", "metadata": {}, "source": [ "The metadata tarball also stores information about the filename and DRSU barcode that the data were recorded on though the getSessionMetadata function:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "fileInfo = metabundle.getSessionMetaData('LK003_0113.tgz')", "for obsID in fileInfo.keys():", " print \" Obs. #%i: %s on %s\" % (obsID, fileInfo[obsID]['tag'], fileInfo[obsID]['barcode'])" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ " Obs. #1: 056556_000068631 on S15TCV13S0001" ] } ], "prompt_number": 11 }, { "cell_type": "markdown", "metadata": {}, "source": [ "Finally, the metadata also contains the ASP settings before and after the observation so that observers can find out what ASP was set to during their observations. This is accomplised through the getASPConfigurationSummary function:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "for which in ('Beginning', 'End'):", " aspConfig = metabundle.getASPConfigurationSummary('LK003_0113.tgz', which=which)", " print ' %s' % which", " for k in aspConfig.keys():", " print ' %s: %i' % (k, aspConfig[k])" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ " Beginning", " filter: 0", " at2: 6", " atsplit: 15", " at1: 8", " End" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "", " filter: 0", " at2: 6", " atsplit: 15", " at1: 8" ] } ], "prompt_number": 13 } ], "metadata": {} } ] }