def readoutput(maindirmeta): """ This function reads the saved output of the relative TEC measurement processing. If the processed data directory doesn't exist it returns None. Args: maindir (:obj:`str`): Path for RF data. Returns: outdict (dict[str, obj]): Output data dictionary. If the directory doesn't exists it returns None:: { "rTEC": Relative TEC in TECU, "rTEC_sig":Relative TEC STD in TECU, "S4": The S4 parameter, "snr0":snr0, "snr1":snr1, "time": Time for each measurement in posix format, } """ try: dmeta = drf.DigitalMetadataReader(maindirmeta) except IOError: return None metadict = dmeta.read_latest() outdict = list(metadict.values())[0] return outdict
def ephem_doponly(maindir, tleoff=10.): """ This function will output a dictionary that can be used to remove the frequency offset. Args: maindir (:obj:'str'): Directory that holds the digital rf and metadata. tleoff (:obj:'float'): Offset of the tle from the actual data. Returns: outdict (dict[str, obj]): Output data dictionary:: { 't': Time in posix, 'dop1': Doppler frequency of 150 MHz channel from TLE , 'dop2': Doppler frequency of 400 MHz channel from TLE , } """ #%% Get Ephem info # Assuming this will stay the same ut0 = 25567.5 e2p = 3600. * 24 #ephem day to utc seconds passpath = os.path.expanduser(os.path.join(maindir, 'metadata/pass/')) passmeta = drf.DigitalMetadataReader(passpath) pdict = passmeta.read_latest() pdict1 = pdict[pdict.keys()[0]] rtime = (pdict1['rise_time'] - ut0) * e2p Dop_bw = pdict1['doppler_bandwidth'] t = sp.arange(0, (Dop_bw.shape[0] + 1) * 10, 10.) + rtime t = t.astype(float) # XXX Extend t vector because for the most part the velocities at the edge # are not changing much so to avoid having the interpolation extrapolate. # If extrapolation used then error messages that the time was off t[-1] = t[-1] + 600 t[-2] = t[-2] + 500 t[0] = t[0] - 70 tdop = (t[0:(len(t) - 1)] + t[1:len(t)]) / 2.0 tdop[0] = tdop[0] - 35.0 # XXX Used this to line up inital TLE times tdop = tdop - tleoff return ({ "t": t, "dop1": sp.interpolate.interp1d(tdop, Dop_bw[:, 0], kind="cubic"), "dop2": sp.interpolate.interp1d(tdop, Dop_bw[:, 1], kind="cubic") })
Assumes the example Digital Metadata write script has already been run. """ from __future__ import absolute_import, division, print_function import os import tempfile import digital_rf import numpy as np metadata_dir = os.path.join(tempfile.gettempdir(), "example_metadata") stime = 1447082580 try: dmr = digital_rf.DigitalMetadataReader(metadata_dir) except IOError: print("Run example_write_digital_metadata.py before running this script.") raise print("init okay") start_idx = int(np.uint64(stime * dmr.get_samples_per_second())) first_sample, last_sample = dmr.get_bounds() print("bounds are %i to %i" % (first_sample, last_sample)) fields = dmr.get_fields() print("Available fields are <%s>" % (str(fields))) print("first read - just get one column simple_complex") data_dict = dmr.read(start_idx, start_idx + 2, "single_complex") for key in data_dict.keys():
def ephem_doponly(maindir, tleoff=10.): """ This function will output a dictionary that can be used to remove the frequency offset. Args: maindir (:obj:'str'): Directory that holds the digital rf and metadata. tleoff (:obj:'float'): Offset of the tle from the actual data. Returns: outdict (dict[str, obj]): Output data dictionary:: { 't': Time in posix, 'dop1': Doppler frequency of 150 MHz channel from TLE , 'dop2': Doppler frequency of 400 MHz channel from TLE , } """ #%% Get Ephem info # Assuming this will stay the same ut0 = 25567.5 e2p = 3600. * 24 #ephem day to utc seconds sitepath = os.path.expanduser(os.path.join(maindir, 'metadata/config/site')) sitemeta = drf.DigitalMetadataReader(sitepath) sdict = sitemeta.read_latest() sdict1 = list(sdict.values())[0] infopath = os.path.expanduser(os.path.join(maindir, 'metadata/info')) infometa = drf.DigitalMetadataReader(infopath) idict = infometa.read_latest() idict1 = list(idict.values())[0] passpath = os.path.expanduser(os.path.join(maindir, 'metadata/pass/')) passmeta = drf.DigitalMetadataReader(passpath) pdict = passmeta.read_latest() pdict1 = list(pdict.values())[0] rtime = (pdict1['rise_time'] - ut0) * e2p tsave = list(pdict.keys())[0] Dop_bw = pdict1['doppler_bandwidth'] t = sp.arange(0, (Dop_bw.shape[0] + 1) * 10, 10.) + rtime t = t.astype(float) obsLoc = ephem.Observer() obsLoc.lat = sdict1['latitude'] obsLoc.long = sdict1['longitude'] satObj = ephem.readtle(idict1['name'], idict1['tle1'][1:-1], idict1['tle2'][1:-1]) tephem = (t - rtime) * ephem.second + pdict1['rise_time'] sublat = sp.zeros_like(tephem) sublon = sp.zeros_like(tephem) for i, itime in enumerate(tephem): obsLoc.date = itime satObj.compute(obsLoc) sublat[i] = sp.rad2deg(satObj.sublat) sublon[i] = sp.rad2deg(satObj.sublong) # XXX Extend t vector because for the most part the velocities at the edge # are not changing much so to avoid having the interpolation extrapolate. # If extrapolation used then error messages that the time was off t[-1] = t[-1] + 600 t[-2] = t[-2] + 500 t[0] = t[0] - 240 tdop = (t[0:(len(t) - 1)] + t[1:len(t)]) / 2.0 tdop[0] = tdop[0] - 35.0 # XXX Used this to line up inital TLE times tdop = tdop - tleoff tephem = (tdop - rtime) * ephem.second + pdict1['rise_time'] sublat = sp.zeros_like(tephem) sublon = sp.zeros_like(tephem) for i, itime in enumerate(tephem): obsLoc.date = itime satObj.compute(obsLoc) sublat[i] = sp.rad2deg(satObj.sublat) sublon[i] = sp.rad2deg(satObj.sublong) return ({ "t": t, 'tsave': tsave, "dop1": sp.interpolate.interp1d(tdop, Dop_bw[:, 0], kind="cubic"), "dop2": sp.interpolate.interp1d(tdop, Dop_bw[:, 1], kind="cubic"), 'sublat': sp.interpolate.interp1d(tdop, sublat, kind="cubic"), 'sublon': sp.interpolate.interp1d(tdop, sublon, kind="cubic"), 'site_latitude': float(sdict1['latitude']), 'site_longitude': float(sdict1['longitude']) })
def __init__(self, control): """__init__: Initializes a data plotter for STI plotting. """ self.control = control self.dio = [] self.dmd = [] self.channel = [] self.sub_channel = [] self.bounds = [] for idx, p in enumerate(self.control.path): ch = string.split(self.control.channel[idx], ':') self.channel.append(ch[0]) self.sub_channel.append(int(ch[1])) # open digital RF path self.dio.append(drf.DigitalRFReader(p)) if self.control.verbose: print 'bounds:', self.dio[idx].get_bounds(self.channel[idx]) self.bounds.append(self.dio[idx].get_bounds(self.channel[idx])) # oepn digital metadata path self.dmd.append( drf.DigitalMetadataReader(p + '/' + self.channel[idx] + '/metadata')) # processing pair list pl = range(len(self.dio)) if self.control.xtype == 'self': self.xlist = list(it.product(pl, repeat=2)) elif self.control.xtype == 'pairs': args = [iter(pl)] * 2 self.xlist = list(it.izip_longest(*args)) elif self.control.xtype == 'combo': self.xlist = list(it.combinations(pl, 2)) elif self.control.xtype == 'permute': self.xlist = list(it.permutations(pl, 2)) else: print 'unknown processing pair type ', self.control.xtype sys.exit(1) print 'pair list ', pl print 'xlist ', self.xlist # Figure setup # two plots coherence and phase for each pair self.f = [] self.gridspec = [] self.subplots = [] for n in numpy.arange(len(self.xlist)): f = matplotlib.pyplot.figure( figsize=(7, numpy.min([numpy.max([4, self.control.frames]), 7])), dpi=128) self.f.append(f) gridspec = matplotlib.gridspec.GridSpec(self.control.frames * 2, 1) self.gridspec.append(gridspec) subplots = [] self.subplots.append(subplots) """ Setup the subplots for this display """ for n in numpy.arange(len(self.xlist)): for m in numpy.arange(self.control.frames * 2): ax = self.f[n].add_subplot(self.gridspec[n][m]) self.subplots[n].append(ax)
def __init__(self, startDT, endDT, source, dest, verbose=False): """ __init__ will create a Digital RF archive Inputs: startDT - start datetime for the data archive endDT end datetime for the data archive source - string defining data source. Either a path, or a url. dest - where archive is to be created. May be a path, or a scp type path (user@host:/path) If scp-type, keypair must allow scp without passwords verbose - if True, print one line for each subdirectory. If False (the default), no output except for errors. Attributes: self._source_type - local if local input data, remote if remote """ # verify arguments if endDT <= startDT: print('endDT <%s> must be after startDT <%s>' % (str(endDT), str(startDT))) sys.exit(-1) # save args self.startDT = startDT self.endDT = endDT if source[-1] == '/': source = source[:-1] self.source = source # name of digital metadata directory self.dm_basename = os.path.basename(source) self.dest = dest self.verbose = bool(verbose) self._source_type = 'local' if len(self.source) > 5: if self.source[0:5] == 'http:': self._source_type = 'remote' if self._source_type == 'local': # make sure source is full path if self.source[0] != '/': self.source = os.path.join(os.getcwd(), self.source) dmd = digital_rf.DigitalMetadataReader(self.source) self._samples_per_second = int(dmd.get_samples_per_second()) self._subdir_cadence_secs = int(dmd.get_subdir_cadence_secs()) self._file_cadence_secs = int(dmd.get_file_cadence_secs()) self._file_name = dmd.get_file_name_prefix() self.metadata_dir = os.path.basename(self.source) if len(self.metadata_dir) == 0: raise ValueError, 'No metadata dir found in %s' % (self.source) self._dest_type = 'local' hyphen = self.dest.find(':') slash = self.dest.find('/') if hyphen != -1: if slash == -1: self._dest_type = 'remote' elif hyphen < slash: self._dest_type = 'remote' if self.verbose: # set up a timer t = time.time() # get start and end sample sample0 = calendar.timegm( self.startDT.timetuple()) * self._samples_per_second sample1 = calendar.timegm( self.endDT.timetuple()) * self._samples_per_second file_list = self._get_file_list(sample0, sample1) if self._source_type == 'local' and self._dest_type == 'local': count = self._archive_local_local(file_list) elif self._source_type == 'local' and self._dest_type == 'remote': count = self._archive_local_remote(file_list) if self.verbose: print( 'digital_metadata_archive took %f seconds, and backed up %i files' % (time.time() - t, count)) if count == 0: print("WARNING - no digital metadata files backed up")