Sunday, December 11, 2011

R -> output to CSV -> Latex -> pdf (CSV -> Latex -> pdf)

Update: My friend pointed out that there are in fact several ways of including the output of R into a tex file. However what I'm using now is the package csvtool.

I would like to carry out data analysis in R and generate pdf files using Latex which include the results of the analysis.  

The issue: For graphics, one option is to save the figures as eps files in R (for e.g. by using postscript() command) and to include them in the final pdf file through Latex. What about other numerical results ? One option is to calculate the output (for e.g. the values of some variables) then copy those values from R into the Latex file. How ever I do not want to copy-paste them. I would like to run some R script, generate some results, and then run Latex which will pick up those results and create the pdf file. 

A solution: In R export the results as a csv file (for e.g. using the write.csv() command). I find it best to first put the results in a tabular form and then write it to the csv file. Then using Latex include this csv file in the final pdf output as a table with the command  \DTLdisplaydb{file_name}, which is available in the datatool package(\usepackage{datatool}). If the table is large and runs out of the page (in the portrait page setting), you can consider rotating the table by 90 degrees with the \begin{sidewaystable} ... \end{sidewaystable} command available in the rotating package. 


So basically something of this sort in Latex:
.
\usepackage{datatool}
\usepackage{rotating}

.
\DTLloaddb[noheader,keys={},headers={}]{}{} % Look up the documentation for command options
.
\begin{sidewaystable}[] % Look up the documentation for command options
\centering \caption{}
\DTLdisplaydb{file_name}
% Look up the documentation for command options
\end{sidewaystable}
.

Note: There are macros available for MS-Excel using which you can select a table in Excel and generate the corresponding Latex commands. However for that you will have to open the csv file first in MS-Excel.

Saturday, October 15, 2011

Hiking: Cascades (VA)


Cascades is one place we have hiked in Summer, Winter and (now) Fall. The Fall colors seemed to be all around us and we decided to go to Cascades to make the most of the sunny (though not so warm) Saturday afternoon. The hike starts from a parking lot which is about 20 miles from Virginia Tech. The drive is nice and quick.




At the parking lot you have to pay $3.00. On a nice day the lot can be full, in which case you would park on the road side.


There is a board which will explain to you that there are two different routes you can take to the cascades. Though initially and finally they both merge. It is easier and more fun to cross the first bridge and go to the right and come the other way.
 

All along the trail is nice, though unlike the typical AT-trail there are no markings here.


For most part you will be walking next to the water (assuming that you crossed the first bridge).
 

Now with the Fall colors the trail looked even more beautiful.






I did take pictures along the way but I'm not in a mood to upload all of them to explain landmarks etc. Also, the cascades are shown in the picture at the beginning of this post. This time we also went over to a new trail which leads to the upper-falls. 

Sunday, October 9, 2011

Hiking - distances from Drillfield Dr to parking

Approximate driving distances from War Memorial Chapel (Drillfield) Virginia Tech. to the trail parking:

Sharp Top..........................69.4 miles (1 hr 18 min)
Rock Castle Gorge................38.4 miles (1 hour)
Tinkers Cliff.......................30.3 miles (51 mins)
McAfee's Knob.....................23.1 miles (41 mins)
Angels Rest........................25 miles   (35 mins)
Dragons Tooth.....................21.4 miles (39 mins)
Kelly's Knob........................16.1 miles (26 mins)

Hiking: Tinkers Cliff (VA)


 This weekend we went to Tinkers Cliff. The trail starts from a parking lot off Catawba Rd. (VA-799), close to the intersection of Little Catawba Creek Rd. and Catawba Rd.

Time stamps:
Photo which shows the yellow mark on the tree (almost at the start of the hike): 11:16am
Photo with the no trespassing sign: 12:10pm
Photo with wooden signs on the tree: 1:08pm
Photo showing the rocks at the top: 1:35pm

From the parking lot the trail is marked with the yellow signs on the trees.



At the beginning of the trail there are two wooden bridges and a small stretch next to a stream.

  

  


For most part the trail is shaded with lots of trees. 



 

You will arrive at a No Trespassing sign. Right next to the sign, on a tree, there is a posted sign which points in the direction of the trail. This basically tells you to ignore the sign and go ahead in the direction which otherwise you would think the sign is warning you not to go. Just remember, follow the yellow signs. 


 After some nice upward climbs you will see wooden signs on a tree pointing you in the direction of Tinkers cliff. After this point you have to follow the white marks on the tree (for the AT).

 

From this point the Tinkers Cliff overlook is 0.5 miles. At the overlook there are numerous rocks from which you can select the one most comfortable for yourself and, sit, relax and enjoy the view.   

 

Saturday, July 30, 2011

Exposure: Part 1, Shutter speed, aperture and ISO value ~ Brightness

Controlling Exposure

In case you just need the key points, they are:

  • You need a brighter image: use a bigger aperture i.e. smaller F-number, longer exposure time, and higher ISO.
  • Larger the aperture opening brighter the image.
  • Larger the exposure time brighter the image.
  • Higher the ISO value brighter the image and more the noise.
  • The aperture also determines the depth-of-field i.e. over what distance do the things appear to be in-focus. This can be used to blur-out the background for e.g. as in this picture. You can read more about this here.   
  • You need to keep your hand stable for the duration of the exposure time else the final picture will be blurry. This blur caused due to camera shake can be used creatively for e.g. as in this picture. Use a tripod. Longer exposure time can be used to create silky water effect, get lovely night pictures etc. 
  • At high ISO noise can be an issue. 
Now the illustrated story 

When you press the button to take a picture light falls on the sensors and it is recorded. The brightness (I will also call it the exposure) of the final image is therefore dependent on three things:
  1. How big is the opening through which light is coming in i.e. aperture value
  2. For how long does light fall on the sensors i.e. shutter speed or exposure time
  3. How sensitive are the sensors to light i.e. ISO value
The aperture size also determines the distance over which everything looks sharp and in-focus. This is typically called the depth-of-field. I won't address that part here. You can read about it in one of the previous posts

Below I will show you some pictures which will hopefully explain to you the use of the three values (aperture, shutter, ISO) in determining the final exposure or brightness of an image. Lets deal with them one at a time.

How big is the opening through which light is coming in: Aperture

The aperture is the opening through which light passes and then reaches the sensors. Obviously larger the aperture more light comes in, and smaller the aperture less light comes in. You can think of it like a window in your room. If the window is bigger more light can come in. The aperture value is typically mentioned as the F-number.  What you need to remember is this:
  • Smaller the F-number <==> Larger is the aperture opening <==> More light comes in
  • Larger the F-number <==> Smaller is the aperture opening <==> Less light comes in
Also as I mentioned above, aperture also determines the depth-of-field.

Consider the six pictures shown below in Figure 1. All the six pictures were taken with a Nikon D40 mounted on a tripod. For all the six, the shutter speed or exposure time was 1/10 sec. and the ISO value was 200. However a different aperture value was used for each of them. This makes it easier to see the effect of aperture on the final exposure. The aperture values that were used are mentioned in the bottom right corner of each individual picture.

Figure 1: The effect of aperture on brightness. The aperture values for individual pictures are mentioned in the bottom right corner. The same shutter speed (1/10 sec.) and ISO value (200) were used in all the six cases. 

What you will notice from the six pictures shown in Figure 1 is that as the F-number increases from 4 to 25 the pictures become darker. That is because as the F-number increases, the aperture opening becomes smaller and thus less light makes it to the sensors for the same exposure time.   

How long does light fall on the sensors: shutter speed or exposure time

The light will pass through the aperture and be collected by the sensors for the duration commonly called the shutter speed or the exposure time. This is mentioned in seconds. What you need to remember is:

  • Shutter speed or exposure time of for e.g. say 1/10 seconds means that light will be captured for 1/10 seconds.  
  • So with a shutter speed of 1/10 seconds you will capture more light than with 1/100 seconds. 
  • Also, say for e.g. you use a shutter speed of 1/10 second. Then light will be captured for 1/10 second and the camera needs to be stable for that 1/10 second else the final picture will be blurred. This blur caused due to camera shake during the exposure time is typically undesirable but can also be used creatively for e.g. in this picture
Anyway. Consider the six pictures shown below in Figure 2. All the six pictures were taken with a Nikon D40 mounted on a tripod. For all the six, the aperture value was F/5.6 and the ISO value was 200. However a different shutter speed was used for each of them. This makes it easier to see the effect of shutter speed on the final exposure. The shutter speeds that were used are mentioned in the bottom right corner of each individual picture.

Figure 2: The effect of shutter speed on brightness. The shutter speed for individual pictures are mentioned in the bottom right corner. The same aperture (F/5.6) and ISO value (200) were used in all the six cases.

What you will notice from the six pictures shown in Figure 2 is that as the shutter speed goes from 1/4 sec. to 1/250 sec. the pictures become darker. That is because as the exposure time, or the time for which light falls on the sensors, decreases the picture becomes less and less bright for the same sized aperture.

How sensitive are the sensors: ISO value

The light comes in through an opening, the size of which is the aperture value, and falls on the sensors, for duration equal to the shutter speed or exposure time value, and then falls on the sensors. So by altering the sensitivity of the sensors you can control the final brightness. The sensitivity of the sensors is mentioned in terms of the ISO value. What you need to remember is this:
  • Lower the ISO value <<==>> Lower is the sensitivity of the sensors <<==>> Less is the noise in the final image
  • Higher the ISO value <<==>> Higher is the sensitivity of the sensors <<==>> More is the noise in the final image
I will come to "noise" in a minute. First consider the four pictures shown in Figure 3. All the four pictures were taken with a Nikon D40 mounted on a tripod. For all the four, the aperture value was F/5.6 and the shutter speed was 1/8 sec. However a different ISO value was used for each of them. This makes it easier to see the effect of ISO value on the final exposure. The ISO values that were used are mentioned in the bottom right corner of each individual picture.


 Figure 3: The effect of ISO value on brightness. The ISO values for individual pictures are mentioned in the bottom right corner. The same aperture (F/5.6) and shutter speed  (1/8 sec) were used in all the six cases.

What you will notice by comparing the four pictures is that the one with ISO 200 is darker than the one with ISO 1600. This is because at 1600, the sensors are more sensitive and thus the picture is brighter even though the same shutter speed and aperture value were used. Actually, the sensors don't get magically more sensitive, but lets just leave that issue.   

Typically you would want to use the least ISO value possible but at that value the noise is least. However for e.g. if shooting in the low-light conditions you might want to increase the ISO. Now something about noise.

Consider the four pictures shown in Figure 4 below. Only the ISO values (as mentioned in the bottom right corners) were changed and the shutter speed (1/50 sec) and aperture (F/5.6) were the same for all the four pictures.

 Figure 4: The effect of ISO value on noise. Shutter speed: 1/50, F/5.6

Well, this is not a very good example but you should be able to see the "grainy" noise in the picture with ISO 1600. This picture is shown separately below in Figure 5.

  Figure 5. ISO: 1600, hope that you can see the noise

Happy shooting. 

In summary
  • You need a brighter image: use a bigger aperture i.e. smaller F-number, longer exposure time, and higher ISO.
  • Larger the aperture opening brighter the image.
  • Larger the exposure time brighter the image.
  • Higher the ISO value brighter the image and more the noise.
  • The aperture also determines the depth-of-field i.e. over what distance do the things appear to be in-focus. This can be used to blur-out the background for e.g. as in this picture. You can read more about this here.   
  • You need to keep your hand stable for the duration of the exposure time else the final picture will be blurry. This blur caused due to camera shake can be used creatively for e.g. as in this picture. Use a tripod. Longer exposure time can be used to create silky water effect, get lovely night pictures etc. 
  • At high ISO noise can be an issue.  

Tuesday, June 28, 2011

War Spur Overlook (VA)


If you have been to the Wind Rock overlook then most likely you would know about the War Spur (WS) overlook. The WS overlook is about 3 miles from the Mountain Lake resort. The road side parking  spot is off SR-613. I will not explain the exact location but in short its: US460 --> Mountain Lake Rd. --> SR 613. The last about 1.5 miles or maybe 2 miles of the driving stretch is gravel and with lots of pot holes. 

The WS overlook is a peaceful spot with lots of rocks to sit and look at the mountains. However, unlike the Wind Rock overlook I don't think you can see the lovely sunset colors from here. The mountains in front of you would block the view. 

 The hike for the WS overlook starts from the off-the road parking spot on SR-613. At this point you have the wooden sign indicating the loop. The hike is small, about 3 miles for the complete loop.


Its a loop so you can go either from the left side (clockwise)


or the right side (anti-clockwise). I started from the right.


The hike is through the forest area and is well shaded with lots of greenery.
 

There is a small stream which you will cross.


Soon you will arrive at a wooden post which will point you in the direction of the overlook.  


 After a small mainly down-slope stretch (so it will be up-slope while returning) you will come to the clearing of the overlook.


The overlook has lots of stones where you can sit and enjoy the scenery. 




Do remember that a portion of the drive is not so good. Also, in case you haven't been there, then also visit the Wind Rock overlook.

Monday, May 30, 2011

Wind Rock overlook (VA)


 

This is simple. You drive. You park. Walk for less than 10 minutes. You get the best view. Even great is the fact that you will be facing west (of-course you can decide to face the other way) so the view is simply great if you wait till after sunset. The pictures in the post are from two different trips to Wind Rock and thus the difference in greenery.

Where is it ?

Heard of Mountain Lake Resort in Virginia ? Heard of the movie "Dirty Dancing" ? One of the reasons why the Mountain Lake Resort is popular is that it was the location where the movie "Dirty Dancing" was shot. About 5 miles from the Mountain Lake Resort is the Appalachian Trail. That's where the Wind Rock overlook is.

Where exactly on the map ?

You can find information about it on the internet. In Google-maps search for "37.412001,-80.522675". This location is on State Route 613 or the Mountain Lake Road. Here is the link:
http://local.google.com/maps?q=37.412001,-80.522675&num=1&sll=37.0625,-95.677068&sspn=23.875,57.630033&ie=UTF8&ll=37.412105,-80.522691&spn=0.001672,0.001548&z=19

If you zoom-in and look in the "Satellite view", you will notice a clearing just off 613. That is the parking place. Depending on how you are looking at it, if the parking is on the left, then on the right is the trail where you need to go. There is a wooden board on the right and the trail is pretty obvious. Also, it has white marks on the trees. So park here and then walk.  


What is the best way to get there ?

From the Virginia Tech campus there are two ways you can reach the Wind Rock parking lot. Obviously I'm assuming that you will drive and that you need a straightforward route. 
  • One way is: US460 --> Mountain Lake Rd (613) --> Wind Rock
  • Another option is: US460 --> Big Stoney Creek Rd (635) (this is after you cross the road to Cascades) --> State Route 613 --> Wind Rock
On both these routes look out for deer's. (The picture below was taken by a friend. I tried taking pictures of deer's but they just did not like the idea)


How is the drive ?

The final stretch, my guess is the last 2 to 3 miles, on both these routes is "bad". I would say it is less bad when taking the first route. The drive is bad but not that bad really. But in case you or your car or others in the car really don't feel comfortable then there is an option of park-and-walk. When you are taking the first route, an option is to park about 2 miles from Wind Rock (about 3 miles after the Mountain Lake resort) in a parking area from where another loop trail starts. In this case you will have to walk about 2 miles (uphill) to reach the Wind Rock parking spot. I think this is the place where you can park (don't come after me if it is not) :



Anything else ?
If you make the effort to reach Wind Rock then stay there till after sunset to see some amazing views. Visit it in different weather conditions. Obviously take your safety into consideration. You can also camp there for the night.