Wednesday, July 25, 2012

Physics-Intro to Mechanics



Vector Rules
A . B = A + A + A z
A x B = (A B z - A - B ) î - (A B z - A - B ) ĵ
More information on vectors available in the Introduction to Vectors and Calculus page as well as the Introduction to Linear Algebra page.

Positional equations
if a x is a constant acceleration then the movement for some object is governed by:
= v x0 + a t
= x + v x0 t + 1/2 a x0 
= v x0 + 2 a t (x- x )
if a non-constant:
v (t) = v + ∫ a(t') dt'
x (t) = x + ∫ v(t') dt'
This is basically the same result as before, we are just integrating over a time dependent acceleration and velocity, so we take the areas under these curves to find the velocity.

Momentum and Energy
p = m v
Kinetic - m v / 2
Potential due to gravity on earth - m g h
The most important aspect of this is that the total momentum in a closed system or frame is conserved. This is the famous conservation of momentum law, or newton's second law in its more complete form.
Force
F = m a
F = dp/dt = m dv/dt + v dm/dt
Gravitation
g = 9.8 m/s^2
approximate acceleration due to gravity on earth
G = 6.7 x 10^-11 N m^2/kg^2
Gravitational constant
F = -(G M )/R 12
U = -(G M )/R 2 12
Frictional Force
fric = μ F Norm
Norm is the normal force, which is perpendicular to the direction of movement.
Parameter Relations
F = - dU/dx
W = ∫ F . ds
P = dE/dt = F . v
J = ∫ F dt = Δ p
Center of mass
cm = Σ m i R i / Σ m i
I = Σ m i
Rotational Motion
if α is constant
ω = ω + α t
θ = θ + ω t + 1/2 α t 
ω = ω + 2 α (θ - θ )
Combined Rotational and Non-Rotational kinetic energy
K = 1/2 I ω + 1/2 m v 2
τ = r x F
L = r x p
τ = dL/dt
τ = I α
L = I ω
W = ∫ τ d θ

Trinary Dwarfs-Data Reduction Summary

The goal of the data reduction was to take radial velocity measurements of certain observed low mass stars. In order to accomplish this we used the redspec data reduction package.

The first step in doing a reduction is combining the flat and dark files. In later steps this lets us remove influences from background sources and correct for the dark current in the telescope. This is followed by beginning the reduction by setting up how files will be used in parfile. In this step we define the file paths to the spec files to denote the target star, and the calibration star. The calibration star is used later on in the reduction to eliminate telluric absorption, and other features associated with the location of the target star. In this case, as we are working with high resolution spectra, we use an A type star as a source of calibration because they have few intrinsic lines in their spectra.

Spatial rectification with redspec is accomplished by summing an A+B pair of a calibration star to produce an image with two spectra. By finding polynomial fits to each spectral trace, and calculating guassian centroids to define the separation between the two, a curved or distorted spectra can be remapped to produce straight spectral traces with respect to the rows of the detector. Once this is done the spectral rectification step follows, where we use a polynomial fit of order 1-4 in order to fit the spectra to known arc lines or oh lines. This step matches the pixels of the picture to fitted wavelengths with regular intervals.

The last step is the main portion of the redspec. This is the step where the target and the calibrator get divided by the dark subtracted flat to remove the background sources for both the calibration star and the target star. The divided spectra gets multiplied against a normalized blackbody function corresponding to the spectral type of the calibration star to provide a relative flux calibration.

The observations for this project were made using filters N7 and N3. For the N7 observations the echelle was 63, with a cross dispersion of 35.52, and the N3 observations were made with an 62.95, and a cross dispersion of 34.08. The reductions for this project involved the use of both arc lines and oh lines for the spectral mapping portion of the reduction. The values for the oh lines came from a paper written by Emily Rice rather than the standard lines used in the echelle format simulator. The reason for this was simply greater accuracy. The N7 reduction used arc lines for the order we were interested, order 33 due to the strong methane absorption features. In the spectral mapping portion of the reduction, the fit to each individual arc line was of order 1 or 2, while the overall lambda fit used to map the arc lines to pixels was of order 1. This is because there were only 3 arc lines total on that particular echelle order when using xenon, krypton, argon, and neon line lists from keck, and due to the nature of polynomial fits, we can't use the higher order fits without introducing large errors as for example the 2nd order fit would match any 3 points with 0 error. The N3 reduction used OH lines, and we were primarily interested in order 59. For this fit, although there were a possible 10 lines to be fitted, the most accurate reduction was found using 6 out of those 10 lines, with an order 3 fit for the oh lines, and an order 2 fit for the overall lambda fit. The reason for this was that adding in additional lines caused significantly greater error even with a higher order lambda fit, and the lines themselves were not only very weak in terms of signal, but often shifted around greatly from observation to observation, relative to the 6 lines that were used in the fit.

Trinary Dwarfs-Nirspec Data Reduction Walkthrough


Nirspec Data Reduction Walkthrough
Directory structure:
Usually directories with raw data for spectra are categorized 
by date, create a reduction folder to store your reductions.
Then, within reduction, create a folder for source name, a 
folder within that for order number, and if more than one pair
of exposures was taken a folder within that for nod set e.g.
/data/nirspec/110715/reduction/2026-2943/order33/nod1/
/data/nirspec/110715/reduction/2026-2943/order33/nod2/
etc...

Create or copy in a spec1.in file which is a text file that
contains linelist information to use for the further steps
in reduction. This can be created using the efs simulator

cd into the reduction directory and start idl by entering
idl as a command into the terminal.


nirspecfd:
from the reduction directory, after starting idl type in 
nirspecfd. This is a shell script that creates flat and 
dark files. Other scripts can be used or created on your 
own, but the idea is to combine the images and average
them. If you want to use this on a file, for example
jul06s0019.fits you would do:
IDL> nirspecfd 
raw='../spec' 
out='./'
prefix='aug19s'
darks='20-34'
flats='5-19'

The prefix is the date signifier in the name of the data 
fits files, the darks variable is set to the range of file 
numbers for your darks, and the flats variable is set to the 
range of file numbers for your flat fields.  Run this for 
each set of flats and darks you've generated for each filter
/slit combination used during the night.


parfile:
from the source/order/nod directory, start idl and type:

IDL> parfile

on left side:
keep spatial map and spectral map as they are, they
are usually set to spat.map, spec.map in order to 
facilitate the later steps. set flat and dark to the 
files created in nirspecfd (in your reduction folder) 
set arc1 to the closest arc file taken to your source 
or if using oh lines set the arc to the A frame of the
target. Leave arc 2, reference arc and ref spec map 
blank set nod 1 and nod 2 to the AB frames of your 
source

on right side:
make the entries blank, spat.map.cal, spec.map.cal
are useful in a different context and not in the
first reduction for a given set of data.
set nod 1 and nod 2 to the AB frames of your A0 V star
set T_eff to 9480

spatmap:
First ascertain which orders you are looking at by using the
efs to simulate the same slit, filter and x-dispersion. Select
the echelle order by clicking above and below the tracing
standard, and keep the default options. It is less important in
this step to ensure accuracy in selection, and more important
to select all of the order's information.


Then the next step is to create a fit to the data, which
is done by just clicking on the traces, and adjusting
the sigma, fit height, fit width, and fit order.


specmap:
Options, these are less set in stone and more of guidelines. 
The line fit order can vary between 1-3. First off click on display
arc lamp fit. Then after clicking on an line to fit, judge from the
plot that shows up which line fit order is best to use. Usually,
there is some curvature so line fit order 2-3 is often used. 
Set fit height to 6 and fit width = 13. In general for this type
of reduction in N3/N7 the fit height is not often varied.
Fit width is often changed, based on two criteria, one is how well
the arc lamp fit graph aligns, and the other is just to select
the proper portion of the line. If a line is too thin and close to
a secondary line, it can be difficult to select the correct one. In
this case lower the fit width, and click on the line at different
heights. Lambda fit order is set to the lowest error that can be
achieved without going so low as to 0 out all the error by choosing
for example a 2nd order fit, when there are only 3 points as the low
error comes from needing 3 points just to define a 2nd order fit
rather than an accurate fit. The goal here is to get as many oh or
arc lamp lines matched as possible without compromising the error.
Usually including the maximum number of lines is optimal, but 
in some cases, it is better to have less lines for a better
increase in accuracy, however the more lines fit, means that you
are using more of the data available.

redspec:
standard extraction - increase the contrast with sliders usually
when the contrast is maximum allows you to select more accurately. 
center the lines on standard trace, then reduce clip height until dashed 
lines just cover trace. Its okay when on maximum contrast to make the
clip height slightly within colored areas. The centering and keeping
the clip height low are the two most important parts. source extraction 
- same, but you can make the clip height smaller (but no smaller than 
~5) the resulting data file is tar.dat




tricks:
- Take screenshots when using the efs. This lets you more accurately 
place the arc lines in specmap.
- when reducing a second nod pair, simply copy the files from one 
folder to the next and change just the relevant data files in parfile.  
and as long as you are using the same arc and standard, you can skip 
spatmap and specmap

Trinary Dwarfs-EFS Echelle Format Simulator


The Echelle Format Simulator is very useful for planning and operation, and
is also useful for data reduction. It can be downloaded at:
For data reduction, its useful to use the echelle format simulator to figure
out where in the echelle order the arc lines are. In order to open the
EFS, cd into the nirspec simulate folder after downloading the files,
then use the command idl simstartup to start the EFS. In the
simulator, set the filter, echelle, and cross dispersion.
Then to show the arc lines click on overlays and select OH Lines or
arc lines.
To prepare for the specmap portion of the data reduction it is a
good idea to take a screenshot using printscreen on a windows or
using command shift 4 to take a cropped screenshot of the EFS.
The following is a screenshot of the arc lines for neon, argon,
xenon, and krypton as viewed in the simulator for echele 63
and cross dispersion 35.53.

The following screenshot shows the oh lines as
as viewed in the simulator for echele 63
and cross dispersion 35.53.


Trinary Dwarfs-Nirspec Data Reduction



Nirspec Data Reduction
Directory structure:
Usually directories with raw data for spectra are categorized 
by date, create a reduction folder to store your reductions.
Then, within reduction, create a folder for source name, a 
folder within that for order number, and if more than one pair
of exposures was taken a folder within that for nod set e.g.
/data/nirspec/110715/reduction/2026-2943/order33/nod1/
/data/nirspec/110715/reduction/2026-2943/order33/nod2/
etc...

Create or copy in a spec1.in file which is a text file that
contains linelist information to use for the further steps
in reduction. This can be created using the efs simulator

cd into the reduction directory and start idl by entering
idl as a command into the terminal.

nirspecfd:
from the reduction directory, after starting idl type in 
nirspecfd. This is a shell script that creates flat and 
dark files. Other scripts can be used or created on your 
own, but the idea is to combine the images and average
them. If you want to use this on a file, for example
jul06s0019.fits you would do:

IDL> nirspecfd 
raw='../spec' 
out='./'
prefix='aug19s'
darks='20-34'
flats='5-19'

The prefix is the date signifier in the name of the data 
fits files, the darks variable is set to the range of file 
numbers for your darks, and the flats variable is set to the 
range of file numbers for your flat fields.  Run this for 
each set of flats and darks you've generated for each filter
/slit combination used during the night.

parfile:
from the source/order/nod directory, start idl and type:

IDL> parfile

on left side:
keep spatial map and spectral map as they are, they
are usually set to spat.map, spec.map in order to 
facilitate the later steps. set flat and dark to the 
files created in nirspecfd (in your reduction folder) 
set arc1 to the closest arc file taken to your source 
or if using oh lines set the arc to the A frame of the
target. Leave arc 2, reference arc and ref spec map 
blank set nod 1 and nod 2 to the AB frames of your 
source

on right side:
make the entries blank, spat.map.cal, spec.map.cal
are useful in a different context and not in the
first reduction for a given set of data.
set nod 1 and nod 2 to the AB frames of your A0 V star
set T_eff to 9480

spatmap:
First ascertain which orders you are looking at by using the
efs to simulate the same slit, filter and x-dispersion. Select 
the echelle order by clicking above and below the tracing 
standard, and keep the default options. It is less important in
this step to ensure accuracy in selection, and more important
to select all of the order's information.

specmap:
Options, these are less set in stone and more of guidelines. 
The line fit order can vary between 1-3. First off click on display
arc lamp fit. Then after clicking on an line to fit, judge from the
plot that shows up which line fit order is best to use. Usually,
there is some curvature so line fit order 2-3 is often used. 
Set fit height to 6 and fit width = 13. In general for this type
of reduction in N3/N7 the fit height is not chanced very often.
Fit width is often changed, based on two criteria, one is how well
the arc lamp fit graph aligns, and the other is just to select
the proper portion of the line. If a line is too thin and close to
a secondary line, it can be difficult to select the correct one. In
this case lower the fit width, and click on the line at different 
heights. Lambda fit order is set to the lowest error that can be
achieved without going so low as to 0 out all the error by choosing
for example a 2nd order fit, when there are only 3 points as the low
error comes from needing 3 points just to define a 2nd order fit
rather than an accurate fit. The goal here is to get as many oh or
arc lamp lines matched as possible without compromising the error.
Usually including the maximum number of lines is optimal, but 
in some cases, it is better to have less lines for a better
increase in accuracy, however the more lines fit, means that you
are using more of the data available. 

redspec:
standard extraction - increase the contrast with sliders usually
when the contrast is maximum allows you to select more accurately. 
center the lines on standard trace, then reduce clip height until dashed 
lines just cover trace. Its okay when on maximum contrast to make the
clip height slightly within colored areas. The centering and keeping
the clip height low are the two most important parts. source extraction 
- same, but you can make the clip height smaller (but no smaller than 
~5) the resulting data file is tar.dat

tricks:
- Take screenshots when using the efs. This lets you more accurately 
place the arc lines in specmap.
- when reducing a second nod pair, simply copy the files from one 
folder to the next and change just the relevant data files in parfile.  
and as long as you are using the same arc and standard, you can skip 
spatmap and specmap

Trinary Dwarfs-Using VI



The following are some useful commands to use in the text editor vi.
Note-Editor commands in vi are  case sensitive and the editor removes spaces in text filenames
vi - opens vi text editor
vi filename - opens a file or creates a new file
esc - is used to switch from text insertion mode to command mode
Command mode-:q - is the quit command
:w - is the write/save command, w filename writes to that filename
:wq - writes and quits from vi
:q! exclamation point forces the quit command
:w filename is used to write to another file, save as function
ctrl u/ctrl d is used page up page down, file may open at bottom of page
:11 goes to text line 11
/word seaches for the character string word, while in this mode N goes to the closest word up from current line n goes to the closest word below current line
Cursor controlarrow keys or h j k l can be used to move cursor
0     beginning of line (zero)
$     end of line
W    w     word right
B    b     word left
E    e     end of word right
a goes into insert mode one space right of cursor
A is end line insert
:r filename inserts a file directly below current line
dw deletes forward word
db deletes back word
dd deletes line
Replacement
:%s/\r//
:%s/oldText/newText/g this command will replace instances of one text string with another text string

Trinary Dwarfs-Setting up Directories



Introduction to Unix

Open up a terminal window, this will vary depending on what 
system you are in, X11 is common for modern macs. From here 
you are able to navigate about your own personal files and 
among the server your in. The following are some common 
commands that will make it easy to set up your files.
Of particular use is tabbing. Pressing tab can be used to 
autocomplete an entry. For example given a directory name, 
e.g. echelle_33 typing e tab if that is the only file in 
your directory that starts with an e, it will autocomplete 
the command to echelle_33, autocompletion makes going to
different directories easier.

ls --- lists files in directory
ls -l --- lists your files in with additional information, 
size of the file, who owns the file and who has the right to 
look at it and/or modify it, and when it was last modified. 
The categories in which rights are given are your terminal, 
those on the same server and the world.
ls -a --- lists all files, including the ones whose filenames 
begin in a dot, which you do not always want to see. In 
particular swap files designate files which are in use. This 
is a temporary storage for data. When files are closed incorrectly 
these files can sometimes be used to retrieve data, however they 
can also cause some issues when opening files
emacs filename this is a common text editor to let you create 
files, filename can includes suffixes such as .txt, .in, etc. 
Your system may or may not include this but most likely will.
mv filename_1 filename_2 this moves a file into a different 
directory or can be used to rename a file. This is especially 
useful for renaming the type of file.
rm filename this is used to remove a file, there are additions 
you can add to this in particular rm -f is a force remove
rmdir directoryname this can be used to remove a directory, 
a common addition is rmdir -rf which recursively force removes 
a directory.
diff filename_1 filename_2 this is used to find the 
differences in the text of the two files.
cd directoryname  this allows you to go to a directory 
within the one that you are in. If you do instead cd .. this 
allows you to go up one directory, you can also do cd /filepath 
in order to go to a completely new directory
mkdir directoryname this allows you to create a new 
directory/folder with the given name
vi this is another common text editor, in most systems. This 
can be used alternative to emacs. vim is a more powerful 
version of vi. vi filename creates a text file with name 
filename
tkdiff this is another common checker, it is a gui that
actively shows and highlights the differences between two
text files and shows them side by side matched by lines.
cat filename filename filename ... > newfile is a very
useful command that can be used to combine multiple
textfiles into one.
find -name \*.txt > list.txt
prints all txt files with filepath into list.txt file.
find . -name '*' -print|xargs grep 'text to search' finds filename that contains text you wanted to find