Installing PyEphem in Ubuntu–computing sunrise/sunset in Python

PyEphem has some of the functionality for Python that the NAIF SPICE package has for C, FORTRAN, IDL, and MATLAB–specifically, the ability to perform high-precision astronomical calculations.

PyEphem may be obtained from:

http://pypi.python.org/pypi/pyephem

To install the PyEphem or Ephem packages for Python 2.7 or 3.x respectively, you must first have the python-dev or python3-dev respectively installed, or you will get an error something like:
extensions/_libastro.c:3:20: fatal error: Python.h: No such file or directory

This Python example computes Boston sunrise/sunset times at Fenway Park.

Step-by-step in Terminal
1) for Python 2:
sudo apt-get install python-dev
for Python 3:
sudo apt-get install python3-dev
2) download the PyEphem package,
Python2: http://pypi.python.org/pypi/pyephem/#downloads
Python3: http://pypi.python.org/pypi/ephem/#downloads
unzip to your /tmp directory, then cd to that directory and
for Python 2.7 type:
sudo python setup.py install
for Python 3.x type:
sudo python3 setup.py install

Now you’re ready to use the PyEphem.

Example of PyEphem usage for local sunrise/sunset–note, this example uses Python 3.x syntax for “print” and WILL NOT work for Python 2.7 unless you modify the print statement.


import ephem
import datetime

now = datetime.datetime.now() #get current time

Boston=ephem.Observer()
Boston.pressure = 1010 # millibar
Boston.temp = 25 # deg. Celcius
Boston.horizon = 0
Boston.lat='42.3462'
Boston.lon='-71.0978'
Boston.elevation = 3 # meters
Boston.date = now

sun = ephem.Sun()

print("Next sunrise in Boston will be: ",ephem.localtime(Boston.next_rising(sun)))
print("Next sunset in Boston will be: ",ephem.localtime(Boston.next_setting(sun)))

One-double-click SSH Tunnel with RDP (from Linux to a remote Windows PC)

Assuming you have a remotely located Windows PC, and you’re using a Linux PC, and there is a port-forwarding router on the remote end, say:
remote router WAN (internet-facing) address: 1.2.3.4
remote router forwarded port: 4321

remote PC RDP port: 3389
remote PC LAN address: 192.168.1.10

remote PC SSH login: MyPC
remote PC name: MyPCname
I have made the numbers above up–you must set them to be for your PC situation!

Type in Terminal:
ssh -f -p 4321 -L 3390:192.168.1.10:3389 MyPC@1.2.3.4 sleep 1;
xfreerdp -t 3390 -u MyPC -d MyPCname -x m --sec nla 192.168.1.10

You should then be asked for your SSH password (you must have an SSH server such as CopSSH running on the remote Windows PC).

You can create a simple double-click to connect BASH script file by creating a plain text file named something like “ConnectMyPC” and put into this file:

#!/bin/bash
ssh -f -p 4321 -L 3390:192.168.1.10:3389 MyPC@1.2.3.4 sleep 1;
xfreerdp -t 3390 -u MyPC -d MyPCname -x m --sec nla 192.168.1.10

Then save and type chmod 755 ConnectMyPC to make your BASH script executable, and double-click to connect in one easy step.

Ubuntu: setting Nautilus default view to detailed list-view

I always want to see the “Date Modified” etc. detailed list-view in Nautilus. You can make the list-view be default in Ubuntu 12.04 by typing in Terminal:

gsettings set org.gnome.nautilus.preferences default-folder-viewer 'list-view'

If you wanted to check what your setting was first, you can read the current value by typing:
gsettings get org.gnome.nautilus.preferences default-folder-viewer

Implementing Barron “Performance of Optical Flow Techniques” 1994 C code

W.r.t. the C code horn.c, lucas.c from the J.L. Barron 1994 article “Performance of Optical Flow Techniques”

http://dx.doi.org/10.1007/BF01420984

http://www.cs.toronto.edu/~fleet/research/Papers/ijcv-94.pdf

final psflow output
final psflow output

the original FTP site ftp://ftp.csd.uwo.ca/pub/vision is no longer available.
There may be a partial mirror at University of Oviedo: ftp://ftp.uniovi.es/pub/vision/
Prof. Barron has reposted the data to his website:
http://www.csd.uwo.ca/faculty/barron/FTP/

———————————————————————-
To compile the C code, we have to use appropriate compiler options. Try this in the HORN direcotry:
gcc -std=c89 -O3 -march=native horn.c -o horn -lm

You might need to add these includes:
#include <string.h>
#include <stdlib.h>

also change this line:

#define PI 3.14159265358979323846

You can find the necessary “rasterfile.h” under pub/vision/SOFTWARE to read the RAS files typically used. You can use Imagemagick or Irfanview to view the RAS files. You need to uncompress these .Z files first by typing:

gunzip -r TESTDATA/

Example run (first make output directory):
./horn newbinarytreet. 0.5 1.5 20 100 ../TESTDATA/TREE_DATA/TRANS ../output -B 150 150 -MH -T 5.0

To read this data you will need SOFTWARE/psflow which is compiled by:
edit psflow.c, adding the line:
#define M_PI 3.14159265358979323846
and compile with:

gcc -std=c89 -O3 -march=native psflow.c -o psflow -lm

then type:

./psflow ../output/horn.modified.newbinarytreet.F-5.00 ../output/hornOF.ps

to get the image on this page.

Making a 2D pyramid in MATLAB

To make a square-base 2D data pyramid in Matlab, where:
N is the number of pixels per side (e.g. 512)
MinVal is the minimum data value (e.g. 0)
MaxVal is the maximum data value (e.g. 65535)

do:
N = 256;
MinVal = 0;
MaxVal = 2^16 -1;

data = nan(N);
temp = uint16(MinVal:round((MaxVal-MinVal)/(N/2)):MaxVal);
for i = 1:N/2
data(i,i:end-i+1) = temp(i);
data(i:end-i+1,i) = temp(i);
data(end-i+1,i:end-i+1) = temp(i);
data(i:end-i+1,end-i+1) = temp(i);
end

figure, mesh(data)

This will produce a figure:
Pyramid created in MATLAB

Here, the values at the “base” of the pyramid are zero, and increase linearly on each side to 65,535. This sort of figure might be useful when testing an optical flow algorithm.

Installing FFMPEG and FFPLAY on Windows

To install FFMPEG and FFPLAY on Windows (XP through 7) follow these steps:

1) download FFMPEG, get the 64-bit “shared” version.
2) unzip the folders inside to c:\ffmpeg
3) set your PATH to include c:\ffmpeg\bin

You can now use the powerful FFMPEG from the Windows Command Prompt.

Note: if you don’t already have 7zip installed on Windows, download 7zip

Playing Motion JPEG 2000 (.mj2) videos from Matlab

MATLAB can create and read lossy and lossless Motion JPEG 2000 videos on Windows and Linux. You can play back Motion JPEG 2000 files on Linux with “ffplay” as follows:

Linux
In Terminal, type
ffplay movie.mj2
where of course “movie.mj2″ is the .mj2 Motion JPEG 2000 video to be played.

Windows
from the Command Prompt, type c:\ffmpeg\bin\ffplay movie.mj2
(assuming you downloaded ffmpeg to c:\ffmpeg)

Rotate180CCW-checkerboard.mj2 (51kB)
is a sample Motion JPEG 2000 .mj2 video of a rotating greyscale checkerboard you can use to test your Motion JPEG 2000 player.

———
Note, if you get an errow about missing CODECs, you will need to update your ffmpeg to a version that included libopenjpeg. Thankfully for Ubuntu users, there is a PPA with the most recenter FFMPEG with MJ2 support:
sudo apt-add-repository ppa:jon-severinsson/ffmpeg
sudo apt-get update
sudo apt-get install ffmpeg

Then it should play for you. I have tested with FFMPEG version 0.10.7

Animated movies with image or imagesc in GNU Octave

As of GNU Octave 3.6.1, there does NOT seem to be a way to quickly update image (2D) data plots in a movie-like fashion. Here’s a code snippet for how to display movies of 2D timeseries data in MATLAB:

% create data, 25 frames of 512x512 pixels
data = rand(512,512,25);
% create blank image
img = imagesc(rand(512));
ht = title(''); % to show frame number
% for loop to play "movie"
for i = 1:25
set(img,'cdata',data(:,:,i)) % update latest frame
set(ht,'string',['Frame (',num2str(i),'/25)'])
pause(0.2)
end

In MATLAB, you can display 15+ frames per second that way. In Octave, it’s more like 5 seconds per frame, and the window keeps open and closing–not usable.

Karol Krizka has proposed a way to write the images to disk, then make a movie out of them. This could be scripted in Windows or Linux.

http://www.krizka.net/2009/11/06/creating-animations-with-octave/

Finding the biggest directories on Linux

Note, a very nice and small interactive program is ncdu.
sudo apt-get install ncdu

It will “graphically” show you the biggest directories and let you navigate your directories and delete large files.

If you can’t install ncdu, try the process below using built-in functions.
———————————————————–
To find the biggest directories on your Linux system, in the example below, your home directory as indicated by the tilde, in Terminal type:

du -a ~ | sort -n -r | head -n 25

This will list the 25 biggest directories in home.

———
Here is a Bash script to do the same:

#!/bin/bash
# finds the biggest files in a directory you specify
#
# example #1:
# findbig ~ 15
# would tell you the biggest 15 files under your HOME directory (including all subfolders)
#
# example #2:
# findbig
# just finds the 10 biggest files in your current directory
#
# tested on bash 4.2.25 (ubuntu 12.04)
# Michael Hirsch BSD License July 2013

if [ $# -gt 0 ]; then fDir=$1; else fDir=".";fi
if [ $# -gt 1 ]; then nFile=$2; else nFile=10; fi

# NOT -execdir, or else you can't see the directory the big files are in!
find $fDir -type f -exec ls --size {} \; | sort --numeric-sort --reverse | head --lines=$nFile

Reference: http://www.unixmen.com/how-to-find-large-files-and-directories-in-linux/