Automatised Night-time Scan Failure Alarm for Your Guest House Room
What is this document about?
This documents explains how to load spec data files into your laptop in your guest house room and analyze the data automatically so that if unexpected beam losses etc. occur, you will be notified.
Why to do this? Well, did you ever had any failures in the experiment because something happened just when you left your beamline to scan overnight and went to sleep?
- Lost the beam?
- Monochromator not tweaking up properly?
- Sample mount or environment failing?
- Beam moving too much?
- Control computer failure?
You will only need a computer with a network capability and a network cable. If you don't have a cable, ask if your can borrow one from the beamline.
You also need software to download the data from NICE (e.g. an FTP client) and another software to analyze the data automatically (e.g. Matlab). We will see how to download and setup the FTP client program. We are not going to learn here how to use Matlab or how to process data files. We are merely going to present the general philosophy of the analysis and provide a couple of Matlab M-files as an example.
This document is intended mainly for spec users, but also users of other software may apply the idea with small modificiations.
How does it work?
- Download the data file(s) to our local computer automatically every minute or so
- Run a script that does basic data analysis automatically when new data arrives
- Play a sound to alert in cases of
- signal and/or monitor count rates are not acceptable
- scans have stopped
How to setup your computer?
The guest house has a DHCP server that gives your computer a network address automatically. Just plug your network cable to the appropriate plug near your desk and start your computer. If your computer does not automatically configure itself for the internet, you might need go to your network settings and select "Obtain IP address automatically".
This is done in Windows by navigating from Start -> Settings -> Control Panel -> Network -> select TCP/IP -> click Properties -> Choose "Obtain IP address automatically"
For XP users, Start -> Settings -> Network settings -> Right-click on "LAN settings" -> select "Properties" -> select TCP/IP -> click Properties -> Choose "Obtain IP address automatically"
File transfer
Your experiment has an account on NICE. The username is your experiment code, and the password is a word consisting of the two first characters in the main proposer's last name and the experiment number. For example, if the main proposer of experimetn HA-4599 is Mr. Smith, the username and passwords are
username: ha4599
password: smha4599
We are assuming that your data directory is visible on your NICE account. Usually your data directory is on NICE in the directory /data/, where = id16 etc. The beamline directory contains subdirectories so that you may need to navigate yourself through the directory tree to find the data directory. For example it could be
/data/id00/external/Data2004/ha4599
This directory on NICE is write protected, so there is no risk of writing over your data when you are handling this directory. If your data directory is not accessible from NICE, it may also be possible to download the data from your beamline computer directly. Ask your local contact for more information on that issue.
If you are running Windows:
Your FTP client needs to have a possibility for scheduling, e.g. to download the data file automatically from time to time. There are dozens of FTP clients available for download in the web. One example of a suitable client is WS_FTP PRO (http://www.ipswitch.com/_download/wsftppro.asp). When you have installed it, select Tools -> Scheduler, and you are able to set automatic download with the interval of your choice, e.g. every five minutes.
If you are running Linux:
Linux comes with an efficient ftp program that supports scripting.
If you set up a .netrc file to your home directory with the lines
machine nice login password
macdef init
get /data/id00/external/Data2004/ha4599
bye
the command "ftp nice" will automatically retrieve the file and quit. Now
create a shell script, i.e. a file that has the following lines: #!/bin/tcsh
while (1)
ftp nice
sleep 60
end
Call this file for example "download". To be able to run it, we need to
type the unix command chmod o+x downloadNow, when you run the shell script
downloadit will continue downloading the file every 60 seconds until we press Ctrl-C.
Data analysis
To analyze the data automatically, we need a data analysis software that can run scripts. One of the most often used software packages is Matlab, and we provide a couple of Matlab scripts to show how the analysis can be done.
The flow of the Matlab (or another data analysis software) script should be of the following type:
while 1
analyze_data
plot_data
if data_is_not_consistent, alert; end
pause(60)
end
Whatever we wish to put instead of the commands "analyze_data",
"plot_data" and "data_is_not_consistent", depends on your experimental setup.
You can take a look at some working
examples.
The script "alert" could for example play a sound, like in Matlab:
> [y,fs]=wavread('alert.wav');
> wavplay(y,fs);
If you are not able to play WAV files with these commands, you can for
example use the Matlab command BEEP, or you can use your favourite external
music player program. Many people use mpg123
in Linux or Winamp in Windows.
For example in Matlab for Linux: > !mpg123 my_favourite_music.mp3or, if you don't have mpg123 (or xmms), you can use the sound player program "play" that usually comes with your Linux distribution but can only play WAV audio, not MP3:
> !play my_favourite_music.wavIn Matlab for Windows (assuming your player is Winamp... check your system):
> !"C:\Program Files\Winamp\winamp.exe" C:\Media\My_favourite_music.mp3
Thank you!
Using these guidelines, it should be possible to make your beamtime more effective and make you sleep better during nights when your control computer is collecting data.