Packages

Python XY with all packages installed

PyEphem

  • Ephemeris program for calculating planet and satellite positions
  • Written in C
  • “import ephem

Pydap

  • Tools for using OPeNDAP
  • “import pydap
  • Installed from the internet using the command prompt:
  1. “easy_install Paste”  (not sure if this is needed, but doesn’t take long)
  2. “easy_install Pydap”

Sync into the clouds

During the time I left my flashdrive in the computer lab and was not able to pick it up for a week, I decided to look for a good way to backup my files. Long story short: Skydrive – doesn’t sync >> Live Mesh –  syncs but hidden sync status >> Dropbox – much better! I’ve been using it for several days now. It is great. I really like having the little status icon on each file showing its sync status. It also saves old versions of all files which Live Mesh does not do. And if files were changed on different computers before syncing then it appears to create a separate file with an extended name showing the computer of origin.

The only advantage for Live Mesh that I can see so far (apart from having extra cloud space if you run out of Dropbox space) is that you can sync any folder. Dropbox creates a single folder where you throw everything you want synced into.

Right now, I’m using Live Mesh to sync the .spyder2 configuration folder with no problem so far. This might possibly be problematic if the configuration file is made for the particular computer it is on. I wanted to keep my template and workspace configurations the same on all three computers that I use for programming.  I use Dropbox for all my programs and everything else.

Live Mesh – sync any folder you can’t conveniently move to the Dropbox.

  • Program folders with configuration files (possibly may cause problems)
  • Sync any folder you want

Dropbox – sync all files you frequently work with on multiple computers.

  • Sync programming code and frequently used data
  • Quickly confirm sync status with file icon (or badge)
  • Stores old versions of all files for recovery

Skewness and Kurtosis

http://www.dreamincode.net/code/snippet3048.htm

 

Found a code for skewness and kurtosis. Just putting it here for reference.

from math import *
from Numeric import *
n=input("Enter the number of class:")
h=input("Enter class interval:")
sum_f=0
sum_fm=0
total1=0
total2=0
total3=0
a=zeros(n,Int)
b=zeros(n,Int)
for i in range(n):
    print "For class-%s"%(i+1)
    f=input("Frequency:")
    l=input("Lower limit:")
    u=l+h    #upper limit
    ul=(l+u)/2.0	#mean of upper and lower limit
    ful=f*ul	#multiplication of frequency and mean
    a[i]=ul
    b[i]=f
    sum_f=f+sum_f
    sum_fm=ful+sum_fm
x=sum_fm/sum_f		#arithmetic mean
for i in range(n):
    d=a[i]-x
    v1=pow(d,2)*b[i]
    v2=pow(d,3)*b[i]
    v3=pow(d,4)*b[i]
    total1=v1+total1
    total2=v1+total2
    total3=v1+total3    m2=total1/sum_f    #2nd moment
m3=total2/sum_f    #3rd moment
m4=total3/sum_f    #4th moment
s=pow(m3,2)/pow(m2,3)    #skewness
k=m4/pow(m2,2)    #kurtosis
print "The skewness is %s & kurtosis is %s"%(s,k)

Interpreting FFT results and plotting

I don’t frequently use FFT, so it still confounds every time I try to interpret the results from FFT, I’ll try to organize my understanding here…

INFORMATION ABOUT THE DATA FILE TO PROCESS

data = array of samples
data_pts = total samples in data file (number of samples/lines in data file)
data_srate = sampling rate (points per second)
data_stime = total time covered in seconds (data_pts / data_srate)

THE numpy.fft() FUNCTION AND THE RESULTS

fft_result = fft(data)
fft_freqs = fftfreq( len(fft_result) )

(fft_result has a real and imag part, but I’m focusing on the real part here)

len(fft_result) == len(data)

but this is mostly meaningless

fft_result[n] corresponds to fft_freqs[n]

PRECISION
The interval difference if fft_freqs equals the inverse of data_stime.
This interval has nothing to do with the number of samples which is what confused me most. I had expected that having 1024 samples per second would return a more precise frequency plotting versus 2 samples per second.
In other words, if the sampled time period is 10 seconds long. No matter if you have 2 or 100 samples per second, the intervals of the frequency ‘bins’ will be 0.1. The number of 0.1-bins depends on the number of samples. In this case, 2 samples per second will produce 20 bins ranging from -1.0 to 0.9; 100 samples will give 1000 bins, from -50.0 to 49.9.

dfreq = 1/data_stime
range = (-dfreq*data_stime*data_srate/2 , dfreq*data_stime*data_srate/2 - dfreq)
      = (-data_srate/2                  , data_srate/2 - dfreq                 )

IN SHORT
That seems more complicated than it needs to be, but it was the thought process that helped me arrive at a better solution. After doing the math and comparisons I find that there is no need to do all these calculations. The sampling rate only needs to be applied to the freq bins, similar to dividing the x-axis array by the rate when plotting the data. Squaring the FFT values helps accentuate the peaks.

    data = []       #array to hold data read from file
    srate=2.        #sample rate
    samples = 0     #counter for the number of lines in file (# of data samples)
    with open(filename, 'r') as rawfile:
        for i, line in enumerate(rawfile):
            data.append(float(line))
        samples = i + 1

    x = arange(samples)/srate

    # PLOT THE ORIGINAL DATA READ FROM FILE
    plt.plot(x, data)
    plt.show()

    # APPLY FFT
    FFT = fft(data)
    freqs = fftfreq(samples) * srate
    print 'bin range=', [freqs.min(), freqs.max()]
    print 'bin interval=', srate/samples

    # PLOT THE POSITIVE HALF OF FREQ VALUES
    plt.plot(freqs[:samples/2], (abs(FFT.real)**2)[:samples/2], 'g*')
    plt.show()