Friday, 27 March 2015

Mac: How to ignore files with errors when copying

When copying files on a Mac using Finder, the copy operation will be interrupted if a file with errors is detected, which makes sense in many cases. However, in some cases you just want to copy "what you can get", and ignore invalid files. This can be done using the "cp" command in terminal, as described here.

Use the following syntax in terminal:

cp -Rp SourceFolder DestinationFolder

The -R flag will ensure that the copy operation is continued even if there are errors. The destination folder does not have to exist, you can specify a new folder name and it will be created.

Wednesday, 2 July 2014

Exporting report number and institution from Mendeley to Word

I currently work for a research institution which produces a lot of reports, and I have struggled to get proper citations for these reports when using the Mendeley Word plugin. If you use the "report" type in Mendeley, you're able to enter institution and issue, but these are not exported to Word. This is my workaround: Use the "journal article" type when entering the report metadata, fill in the report number in the "issue" field, and set the journal as "XXX report" (where XXX is the name of the institution).

This may not be strictly correct, but it works for me. Check out the Mendeley citation style editor if you want to do something similar (and do it properly).

Monday, 14 October 2013

Making an animation from a set of images in Powerpoint

If you have a set of images which shows how something changes with time, it is often useful to display them in rapid succesion in a presentation. If you're using LaTeX, I recommend looking into the Beamer class (search for "overlay" in the Beamer manual). However, this post is about PowerPoint.

Let's assume that you have three images, named im1.png, im2.png and im3.png, which are the same size. You want to start the slide by displaying im1, and then "overlay" im2 and im3 as you click the mouse or the right arrow button. One way to do this is to create a slide for im1, copy this twice, and inserting im2 and im3 in the two copies. However, this creates several nearly-identical slides, and you would probably also have to manually resize and position each image in the exact same location. If you have several images, this approach will be very time-consuming.

A better way is to add all the images to the same slide, and to display each one in turn using animations. You then want to add an animation for each image after the first one. For example, you import im1 to your slide, then import im2 and add "appear" as an animation, and repeat the same for im3. Pretty simple! The main annoyance here is that the images should be exactly the same size and in exactly the same position, to get the proper "animation" effect.

Rather than adjusting size and position for each image as you add it, you can first add all the images with animations, and then change size and position for all images simultaneously:

  • Add the images in the order in which they should be displayed. For every image after the first, add an "appear" animation
  • Select all the images by drawing a selection rectangle, right-click and choose "size and position" (or something like that, I currently have a Norwegian version of Powerpoint :)
  • Adjust the position. Since all the images are selected, they are now shifted to the same position (for example zero offset from upper left corner) and are perfectly overlapping. You can reposition the images later by selecting all and dragging them to a new position.
  • Adjust the size so that the images fit nicely on the page
With this approach you can make a 10-image animation in less than a minute. 

Wednesday, 27 February 2013

Merging two videos into a single video with side-by-side view using FFMPEG

I am currently evaluating lots of test videos, recorded at different conditions, and found myself wanting to display them both in a side-by-side view, in a single video. As always when it comes to video, I searched for a solution employing ffmpeg, and found a post on Stack Overflow describing almost exactly what I wanted to do. The post gives a demonstration example with scaling and fading of videos, so I had to simplify it to just

  • Pad the left video with extra space on the right, making space for the right video
  • Overlay the left and right videos, and output them to a single video file

This is the syntax I arrived at after some tweaking (all on a single line in the terminal):

ffmpeg.exe -i LeftInput.VOB -vf "[in] pad=2*iw:ih [left]; movie=RightInput.VOB [right]; 
[left][right] overlay=main_w/2:0 [out]" -b:v 3000k Output.mp4

Since I'm not a ffmpeg wizard, I won't claim to understand all the details of the line above. Hopefully, the syntax is (kind of) self-explanatory. However, note the "-b:v 3000k" parameter, which sets the bitrate of the output video to 3000kbits/second. This has to be adjusted in each individual case. 

Thursday, 24 January 2013

Upgrading to Subversion 1.7 in Ubuntu

Just a quick post this time. I recently had to upgrade the Subversion (SVN) software on my Ubuntu system to version 1.7. This version is (currently) not included in the regular Ubuntu distribution, but I found the solution in an Ubuntu forum thread - simply run this in a terminal:

echo "deb lucid svn17" | sudo tee /etc/apt/sources.list.d/svn.list
sudo wget -q -O- | sudo apt-key add -
sudo apt-get update
sudo apt-get dist-upgrade

Monday, 12 November 2012

Batch cropping white space borders in Matlab figures

Matlab figures have, by default, a white space border around them. This is fine if you want to view them by themselves, but wastes space if you want to add them to a text document, where the white borders are "added" to the document margins. It is possible to adjust the border width in Matlab, but if you already have exported the figures to an image file, it's too late. (Note: When exporting to EPS the border is not included by default).

If you want to remove this white space for a large number of image files in one go, ImageMagick is your friend. For example,

mogrify -trim +repage *.png

will remove the white border of all PNG files in the current directory, using the "smart crop" trim option. Consult the ImageMagick documentation on cropping for further options.

Tuesday, 16 October 2012

Editing Grub boot menu order and changing default OS

I recently decided to try running a dual-boot system with Windows 7 and Ubuntu. I first installed Windows 7, and then installed Ubuntu. And with Ubuntu comes the GRUB boot loader, which pops up when I start the machine, and lets me choose which OS to use. If I don't choose anything, the item at the top of the list is selevted automatically after about 10 seconds.

I want to use Windows 7 by default, but unfortunatly Windows is at number 6 or 7 on the list. If I'm not paying attention when I start the machine, it boots into Ubuntu, and I have to restart it. How can I make Windows 7 the default OS?

The answer lies in reconfiguring the GRUB menu. There are several ways to do this, but I used the grub-customizer GUI app, which seems both very simple and flexible. Install it using the terminal:

sudo add-apt-repository ppa:danielrichter2007/grub-customizer
sudo apt-get update
sudo apt-get install grub-customizer

In the grub-customizer, you can reorder the GRUB menu items, and for example check the option "Default OS: Last used OS". You can read more about the grub-customizer on the How-To Geek Blog.