代做PSYCH 727 LAB 1

- 首页 >> Algorithm 算法

LAB 1 (S1, 2023)
OUTLINE FOR THIS LAB
The purpose of this laboratory session is to familiarise you with the Linux
environment and the shell, MATLAB, and the data we are working with (fMRI
images).
Today we will cover:
1. Setting Up Remote Access to the Lab VM
2. Linux file structure
3. Introduction to Linux and the Shell
4. Introduction to MATLAB
5. Introduction to MRI data
1. SETTING UP REMOTE ACCESS TO THE LAB VM
To begin, we have to access the Virtual Machine (VM) we have set up for storing and analysing
data in this course. To do so, follow these steps:
Open x2go
Enter the following settings for your session
o Host = fospsychprd01.its.auckland.ac.nz
o Session type = XFCE
Log into your session with your UoA password
2
Open a Terminal Window (look for the computer screen icon at the top of your VM
session)
2. LINUX FILE STRUCTURE
/ (root)
bin course home
rrob042 jblo001
At the top of the file structure in Linux is the root directory that holds everything else. We refer
to it using a slash character / on its own; this is the leading slash in for instance the following
path: /home/rrob042.
The home directory path looks different on different operating systems. On Linux it looks like
e.g. /home/rrob042, whereas on Windows it would be C:\Users\rrob042. When you start
the shell, you are in your home directory by default, but for this course we will actually not
work in our home directories (we will work in /course, see below).
Inside the root directory are several other directories, such as bin, which is where some built-
in programs are stored. We have created another directory called course to store all course
materials.
/
(root)
bin course home
Data Software UserFolders
3
$
$ whoami
rrob042
dadd001 rrob042
In course there are several folders: Data, install, Software, and UserFolders. Inside
UserFolders you will find a directory that is named after your UPI; this is the directory in which
you will be working during this course. So instead of e.g. /home/rrob042 we will be working
in /course/UserFolders/rrob042.
3. INTRODUCTION TO THE LINUX SHELL
Linux is an open source operating system that was developed in the mid-1990s. It is a
powerful tool as you can do complex things with a few keystrokes. It is very useful for
neuroimaging where we have thousands of files per participant (e.g., you can rename all files
with one command).
The “shell” (also known as “bash”) is the way in which the user communicates with the
computer. We type commands into the shell, the shell “translates” these commands and orders
the computer to execute the command (usually to run a programme or “script”). It is called a
“shell” because it encases the complexities of the operating system so it is easier to interact
with.
Basic Shell Commands: Navigation
The part of the operating system responsible for managing files and directories is called the
file system. It organizes our data into files, which hold information, and directories (also
called “folders”), which hold files or other directories.
Several commands are used to create, inspect, rename, and delete files and directories.
To start exploring them, we will use a shell window:
The dollar sign (or another character) is a prompt, which shows us that the shell is waiting
for input; your shell may also add information (e.g., your user name) before the prompt. When
typing in commands listed here, do not type the prompt, only the commands that follow it.
Type the command whoami, then press the Enter key to send the command to the shell. The
command’s output is the ID of the current user, i.e., it shows us who the shell thinks we are:
When we type whoami, the shell:
finds a program called whoami,
runs that program,
displays that program’s output, then
displays a new prompt to tell us that it’s ready for more commands.
4
$ pwd
/Users/rrob042
$ ls
Desktop media
$ cd Desktop
$ cd rrob042
-bash: cd: rrob042: No such file or directory
$ cd ..
$ pwd
/Users/rrob042
Next, let’s find out where we are by running a command called pwd (which stands for “print
working directory”). At the moment, our current working directory is our default directory, i.e.,
the home directory. Here, the computer’s response is /Users/rrob042, which is my home
directory:
Now let’s learn the command that will let us see the contents of our own filesystem. We can
see what’s in our home directory by running ls, which stands for “listing”:
Now we can change our location to a different directory, so we are no longer located in our
home directory. The command to change locations is cd followed by a directory name to
change our working directory. cd stands for “change directory”, which is a bit misleading:
the command doesn’t change the directory, it changes the shell’s idea of what directory we
are in.
Let’s say we want to move to the Desktop. We can use the following command to get there:
We now know how to go down the directory tree: how do we go up? We might try:
Why do we get this error? With our methods so far, cd can only see sub-directories inside your
current directory. There are different ways to see directories above your current location; we’ll
start with the simplest.
There is a shortcut in the shell to move up one directory level that looks like this:
As mentioned above, .. is a special directory name meaning “the directory containing this one”,
or more succinctly, the parent of the current directory. If we run run cd .. and then type pwd,
we’re back in /Users/rrob042:
So far, when specifying directory names we have been using relative paths. When you use a
relative path with a command like ls or cd, it tries to find that location from where we are,
rather than from the root (beginning) of the file system. However, it is possible to specify
the absolute path to a directory by including its entire path from the root directory, which is
indicated by a leading slash (see section 2). The leading / tells the computer to follow the path
5
$ cp -r /course/labs/Lab1 /course/UserFolders/UPI
from the root of the file system, so it always refers to exactly one directory, no matter where
we are when we run the command.
Now we will copy a directory for this lab into our won personal directories in
/course/UserFolders. This directory contains a single anatomical MRI image that we will be
using in this lab.
6
$ matlab
Current working directory
Workspace
(variable list)
Contents of
current directory
History of
commands
Command window
cd /course/UserFolders/UPI
spm fmri
INTRODUCTION TO MATLAB
To start MATLAB just type matlab into the shell:
In the Command Window or shell we can run and debug our code. You can use all the basic
shell commands from section 1 (cd, ls, etc.) in the MATLAB shell.
INTRODUCTION TO MRI DATA
Let’s explore some real brain data.
Running SPM
Make sure you are in the right directory (in this case, the directory containing anat.nii is
probably a good place, but it might the directory for the subject or the study):
Open SPM:
7
A note about image file types.
DICOM (Digital Imaging and Communications in Medicine) format. Raw data from the scanner;
must be converted to Analyze or nifti format for analysis.
Analyze format. Each image has two files: .hdr (header file containing metadata) and .img (the
actual image).
Nifti (Neuroimaging Informatics Technology Initiative) format. In this format, images can be
stored in the two file presentation (.hdr/.img) or a one file presentation (.nii). A critical advance over
Analyze format is that nifti files store the orientation of the image in an unambiguous manner.
Moreover, time can be included as a fourth dimension.
For more information, see https://brainder.org/2012/09/23/the-nifti-file-format/
8
A note about xyz coordinate systems.
xyz coordinates refer to the location of any given voxel (3D pixel) or element in the 3D image/matrix.
However, there are two types of “spaces” or coordinate systems when dealing with MRI images:
voxel space and world space (or mm space). Below is a 2D example of each coordinate system.
You will notice that all the values in voxel space are positive, while world space includes positive and
negative values (relative to the “origin” or the coordinate, 0 0 0).
Display
In the GUI (Graphics User Interface) for SPM, click
on ‘Display’, and select the ‘anat.nii’ file to view the
structural image. You should see the following
image:
Exercise:
Images are actually just 3D matrices of numbers: each value in the matrix corresponds to an
intensity value of a voxel in the brain.
If you click anywhere on the image, you will see that below the coordinates will update as well
as the intensity value. Using this knowledge, complete the following table:
Coordinates (world space) Intensity Value Observations
31 -19 -17
-32 -59 14
31 41 -46
-60 41 66
5 11 7
9
Linux Commands
Command Operation Performed Example
. Current location
.. Up 1 directory from current location
--help provides info about a certain command cd--help
cd Change directory cd spm/subject1
cd ../ Change directory one up cd ../subject2
pwd Present working directory
ls List contents of current directory
ls -l List contents with details of all files
ls | more List contents at a user specified rate
cp Copy file to another directory cp input_file new location
cp 001.img ../subject2
Copy but give another name cp input_file output_file
cp 001.img func.img
Copy file to another directory AND give it
another name
cp input_file new
location/output_file
cp 001.img ../subject2/func.img
cp -r Copy whole directory cp -r input_dir output_dir
cp -r subject2 subject2_backup
mv Move a file (can be used to rename file) mv input_file output_file
mv 001.img func.img
Move file to another directory (i.e. "Cut and
paste" file)
mv input_file new location
mv 001.img ../subject2
more View the contents of a file more timings.txt
rm Remove file (delete) rm 001.img
rm -r (or rmdir) Remove directory rm -r subject1
cat Create a file (e.g. a text file) cat file_name.txt
cat timings.txt
* Wildcard *.* = all files e.g. cp *.*
*.img = all files with img as
extension
subj* = all files starting with
string "subj"
top Lists current users and activity on server
df -k
Gives memory capacity remaining on your
dir
emacs Opens a text editing program
emacs *.txt
Opens a text editing program with a file
name
emacs file_name.txt
emacs Timing_Files.txt
^c Cancel
exit Exit
mkdir mkdir (in current location) mkdir new_dir_name
rename Renaming rename test subj1_test
Renaming multiple files if needed rename test subj1_test test*
More linux commands are available here: http://linuxcommand.org/

站长地图