示例#1
0
def _UpdateDataIndex(idx, fname):
    '''
	Updates the data index file.
	
	Input:
		idx: numpy.recarray containing the file names.
	'''

    pf.WriteASCIIData(fname, idx)
示例#2
0
def _UpdateDataIndex(idx, L):
    '''
	Updates the data index file.
	
	Input:
		idx: numpy.recarray containing the file names.
	'''

    fname = Globals.DataPath + 'Pos/PosIndex-L{:01d}.dat'.format(L)
    pf.WriteASCIIData(fname, idx)
示例#3
0
def _UpdateDataIndex(idx,sc='a',Inst='hope',L='l3.moments'):
	'''
	Updates the data index file.
	
	Input:
		idx: numpy.recarray containing the file names.
	'''
	
	fname = Globals.DataPath+'ECT/{:s}.{:s}.{:s}.dat'.format(Inst,L,sc)
	pf.WriteASCIIData(fname,idx)
示例#4
0
def _UpdateDataIndex(idx,sc='a'):
	'''
	Updates the data index file.
	
	Input:
		idx: numpy.recarray containing the file names.
	'''
	
	fname = Globals.DataPath+'MagEph/{:s}.dat'.format(sc)
	pf.WriteASCIIData(fname,idx)
示例#5
0
def _UpdateDataIndex(idx):
    '''
	Updates the data index file.
	
	Input:
		idx: numpy.recarray containing the file names, time resolution 
			and dates for all data files
	'''

    fname = Globals.DataPath + 'DataIndex.dat'
    pf.WriteASCIIData(fname, idx)
示例#6
0
def SaveSpeed(Date0=19500101, Date1=20500101):

    Dates = ListDates(Date0, Date1)
    ut = np.zeros(Dates.size, dtype='float32')
    s = Speed(Dates)

    sdtype = [('Date', 'int32'), ('utc', 'float64'), ('v', 'float32')]
    data = np.recarray(Dates.size, dtype=sdtype)
    data.Date = Dates
    data.utc = ContUT(data.Date, np.zeros(data.size))
    data.v = s

    fname = Globals.OutputPath + 'Mercury/MercurySpeed.dat'
    pf.WriteASCIIData(fname, data)
示例#7
0
def SaveSolarRotations(Date0=19500101, Date1=20500101):
    '''
	List all of the times when the Sun has completed a full rotation
	
	'''
    #list the dates
    Dates = ListDates(Date0, Date1)
    nd = Dates.size

    #some temporary arrays
    ut = np.zeros(nd, dtype='float32')
    x = np.zeros(nd, dtype='float32') + 1.496e8
    y = np.zeros(nd, dtype='float32')
    z = np.zeros(nd, dtype='float32')

    #convert coordinates
    nx, ny, nz = HCItoIAU_SUN(Dates, ut, x, y, z)

    #calculate longitude
    lon = np.arctan2(ny, nx) * 180.0 / np.pi

    #find the crossings and interpolate
    use0 = np.where((lon[:-1] >= 0.0) & (lon[1:] < 0.0))[0]
    use1 = use0 + 1
    n = np.size(use0)
    out = np.recarray(n, dtype=dtype)
    out.Date = Dates[use0]
    m = (lon[use1] - lon[use0]) / 24.0
    c = lon[use0]
    out.ut = -c / m
    out.utc = ContUT(out.Date, out, ut)

    #save
    outpath = Globals.OutputPath + 'Sun/'
    if not os.path.isdir(outpath):
        os.system('mkdir -pv ' + outpath)
    fname = outpath + '/SunRotations.dat'

    pf.WriteASCIIData(fname, data)
示例#8
0
def SaveMSTimes():
    '''
	Save a list of the times when MESSENGER is within the magnetopause.
	
	'''

    #the file name
    fname = Globals.ModuleData + 'MSTimes.dat'

    #the output dtype
    dtype = [('Date0', 'int32'), ('ut0', 'float32'), ('Date1', 'int32'),
             ('ut1', 'float32')]

    #get the crossings list
    mp = GetMPCrossings()

    #we want crossings where:
    # ctype[i] == 'i' and ctype[i+1] == 'o'
    # and the time difference is less than an orbit
    use = np.where((mp.ctype[:-1] == 'i') & (mp.ctype[1:] == 'o'))[0]
    out = np.recarray(use.size, dtype=dtype)

    out.Date0 = mp.Date1[use]
    out.ut0 = mp.ut1[use]

    out.Date1 = mp.Date0[use + 1]
    out.ut1 = mp.ut0[use + 1]

    dt = np.zeros(use.size, dtype='float32')
    for i in range(use.size):
        dt[i] = TT.TimeDifference(mp.Date1[use[i]], mp.ut1[use[i]],
                                  mp.Date0[use[i] + 1], mp.ut0[use[i] + 1])

    use = np.where(dt < 12.0)[0]
    out = out[use]

    #save the file
    pf.WriteASCIIData(fname, out)
示例#9
0
def UpdateDataIndex(Station=None, UpdateResolution=True, Verbose=True):

    #get current index
    idx = ReadDataIndex()
    ikeys = list(idx.keys())

    #list the files in the data directory
    nidx = _GetMagFiles()

    #loop through each staton
    if Station is None:
        ustns = list(nidx.keys())
    else:
        if isinstance(Station, list):
            ustns = Station
        else:
            ustns = [Station]
    ns = len(ustns)
    for i in range(0, ns):
        save = False
        s = ustns[i]
        print('Saving station {:d} of {:d}: {:s}'.format(i + 1, ns, s))

        #reduce to new files
        if s in ikeys:
            idxs = idx[s]
        else:
            idxs = None

        sidx = _CheckForNewFiles(idxs, nidx[s], Verbose=Verbose)

        if sidx is None:
            sidx = idxs
        elif not idxs is None:
            sidx = RT.JoinRecarray(sidx, idxs)
            save = True
        else:
            save = True

        if UpdateResolution and not sidx is None:
            bad = np.where(sidx.Res <= 0)[0]
            if bad.size > 0:
                save = True
                for i in range(0, bad.size):
                    if Verbose or (i == (bad.size - 1)) or (i % 100 == 0):
                        print('\rObtaining time resolution ({:8.4f}%)'.format(
                            100.0 * (i + 1) / bad.size),
                              end='')
                    try:
                        S = _ReadBinaryFile(Globals.DataPath +
                                            sidx.SubDir[bad[i]] +
                                            sidx.File[bad[i]],
                                            ReturnSize=True)
                        r = 86400 / S
                        if r > 1:
                            r = np.round(r)
                        sidx.Res[bad[i]] = r
                    except:
                        print('Bad file: {:s}'.format(Globals.DataPath +
                                                      sidx.SubDir[bad[i]] +
                                                      sidx.File[bad[i]]))
                        sidx.Res[bad[i]] = 0
                if Verbose:
                    print()

        if save:
            fname = Globals.DataPath + 'Index/{:s}.dat'.format(s.upper())
            pf.WriteASCIIData(fname, sidx)
    print('done')
    Globals.DataIndex = ReadDataIndex()