Saturday, 17 November 2012

Moving Physical Windows 7 to Virtual (VirtualBox) environment

Since I mostly operate in Ubuntu, recently I decided to give up my Windows 7 installation entirely by moving it from physical installation to the virtual one. This should work conviniently as I have a legacy Win 7 which came with the laptop I'm using. After all there are few moments when one needs Windows and I don't feel like rebooting too often.
The trick is that the laptop is a dual-boot machine, so things are not as simple as they could be.

So here are the steps I took:
1. install VirtualBox (in ubuntu simpy use Ubuntu Software Center to accomplish this step)
2. Boot into Windows
3. Make a virtual disk out of your installed Windows 7 partition. Use disk2vhd utility (available here). Select all drivers (don't deselect anything). Save the VHD file in some place that will be available from linux (ubuntu)
4. Make yourself a Windows Rescue Disck (will be needed at later stage); It's a standard Windows procedure, so I'll skip it here (--> google)
5. Reboot into linux and login
6. Start VirtualBox (I'm running version ...)
7. Create a new VM (press new, provide a name, select proper OS, i.e. Windows 7 64-bit)
8. Set VM parameters (RAM, CPU, ... to your preferences); in Storage section enable access to CD/DVD (will be needed to utilize Windows Recovery Disk). Make sure you can boot from a CD/DVD
9. Reboot the virtual machine
10. Select CD/DVD as boot option
11. Boot from Recovery Disk, log in when prompted
12. Select command line as utility
13. Execute the following commands:

Bootrec.exe /FixMbr
Bootrec.exe /FixBoot
Bootrec.exe /RebuildBcd

(the intention here is to get rid of grub in the VM, otherwise you'd be getting grub rescue at boot)

14. Reboot Virtual Machine
15. Log on; you can expect some updates and installations comming after loggin
16. Enjoy!

For now everything seems to work; or at least I'm able to start using my local installation of Win 7 in the virtual machine mode ;)
I intend to report issues if they appear.

P.S. So far no need to do anything with Win 7 registration ;)






Wednesday, 21 March 2012

Working on 2d interpolation in SciPy

For a project I'm working on (in SciPy), I need 2D interpolation routine.  I started playing around with interp2d, but soon found out that there is probably an issue with it. Below, the proof: interp2d output against griddata (yet another 2D interpolation method, which seems to be working correctly).

Both seem to be looking okey, but compare also the results at the edges. Furthermore, quite often the results are like these:

Please check and compare the colorbar alongside the imshow plots. These results are obtained without any warning from the interp2d, which happens too from time to time:

Warning: No more knots can be added because the number of B-spline coefficients
already exceeds the number of data points m. Probably causes: either
s or m too small. (fp>s)
kx,ky=3,3 nx,ny=22,19 m=256 fp=2019.239753 s=0.000000


I started googling the net, so here are some relevant links:
http://stackoverflow.com/questions/3526514/problem-with-2d-interpolation-in-scipy-non-rectangular-grid
http://www.scipy.org/Cookbook/Matplotlib/Gridding_irregularly_spaced_data

Friday, 17 February 2012

Preparing for syntax highlighting to include code snippets onto my blog

As I intend to use Python extensively, it's about the time to think how to enable code snippets to be included into a blog. I mean with syntax highlighting and all that.

After a bit of research, I think I may go for http://alexgorbatchev.com/syntaxhighlighter/

Here is the recipe to get things running
1. Go to your blogger.com, log on, go to you "Dashboard" -> "Design" -> "Edit HTML"
2. Within "Edit template" search for </head>
3. Copy-and-paste the following code, right before the </head> tag

<!-- Adding CSS styles -->
<link href='http://alexgorbatchev.com/pub/sh/current/styles/shCore.css' rel='stylesheet' type='text/css'/> 
<link href='http://alexgorbatchev.com/pub/sh/current/styles/shCoreDefault.css' rel='stylesheet' type='text/css'/> 
 
<!-- Adding JS scripts -->
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shCore.js' type='text/javascript'/> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shAutoloader.js' type='text/javascript'/> 
 
<!-- Adding Brushes -->
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJava.js' type='text/javascript'/> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushJScript.js' type='text/javascript'/> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCSharp.js' type='text/javascript'/> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushXml.js' type='text/javascript'/> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushSql.js' type='text/javascript'/> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCss.js' type='text/javascript'/> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushCpp.js' type='text/javascript'/> 
<script src='http://alexgorbatchev.com/pub/sh/current/scripts/shBrushPython.js' type='text/javascript'/> 
<!-- Of course, you can remove those unused -->

 
<!-- Calling SyntaxHighlighter -->
<script language='javascript' type='text/javascript'> 
    SyntaxHighlighter.config.bloggerMode = true;
    SyntaxHighlighter.all();
</script>


As stated, you can remove lines with unwanted brushes.

And here JS example
function foo()
{
}

and some python example
class MyClass():
   def __init__(self):
      print 'It works!'

Naturally, all the credits go to the author of this lovely tool, so check out http://alexgorbatchev.com/

To correctly post e.g. HTML code, use any of the encoders, like this one: http://www.helperblogger.com/p/html-code-encoder.html

Monday, 30 January 2012

Installing SciPy on Ubuntu 11.10

Preparing right working environment for my development project in Python, today I decided to setup SciPy. Here are the steps

import json
sudo pip install numpy
sudo apt-get install libatlas-base-dev gfortran 
sudo apt-get install swig 
sudo pip install scipy
sudo pip install matplotlib   # recommended


(inspiration from: here)

Wednesday, 25 January 2012

Working with octave

As I'm about to enter a development project (dealing with modeling of wireless communications networks), I'm looking for a suitable set of languages and tools.

For years I've been using Matlab. However, being on my own (I've quit and set up my own startup at wilabs.com), I look for reliable but inexpensive solutions. Unfortunately Matlab is not one of them.

Clearly, a straight forward alternative seems to be Octave (www.octave.org). Here are some discoveries I've made.

  1. Octave looks Matlab alike
  2. It is not 100% compatibilie, so don't be irritated if some of your old code does not work out of the box
  3. Octave lacs full featured IDE;
    There are supposed to be alternatives, but unfortunately they don't offer level of support one gets in Matlab IDE. Well, life is not perfect! Here are some I looked at:
    1. QtOctave
      Looked quite fine, but somehow debugging was not working correctly. At least for me. Although the product seemed to be quite advanced, the development has stopped :/ (well, there might be followers to pick it up)
    2. GUIOctave
      Looks fancy. I even switched to Win7 for a moment to check it out. Fresh installation (as of 26-01-2012) did not work with fresh Octave :( I did not feel like spending more time (my target OS environment is still GNU/Linux) and gave up.
    3. XOctave
      Have not tried it yet. Will do so. From the pictures it looks like debugging works (this would be surprise!)
    4. Emacs
      After a couple of hours looking for a solution I ended up with emacs (http://www.gnu.org/software/octave/doc/interpreter/Emacs-Octave-Support.html#Emacs-Octave-Support) - good stuff never dies! ;)
      Today I am setting up the stuff and getting to the old style development environment of emacs - I'm not (yet) complaining, although the learning curve seems quite steep already

My general experience: I very much admire all the efforts of all the people being involved in open source tools, including Octave and tools around. The achievement  is great, though, perhaps the weakest side of Octave is that it does not come with a reliable IDE which one can just launch and start Octave code development. Although I don't consider myself as computer illiterate, I had a hard time trying execute my old Matlab code, for which debugging with editing, etc. is obviously a must. My point is that probably many people (like me) would conisder Octave as very valuable alternative to matlab, but probably few have skills and persistence to try to live with one of the above.

But hey, I'm not giving up just yet :)
The idea is to try to tweak Emacs to do all good stuff it is able to, including debugging. Below I'm sharing my discoveries:

Useful emacs stuff, which I find convenient while working with Octave
  • line highlighting (to better see where you are): M-x hl-line
  • line numbering: M-x linum-mode 
  • as it turned out there are Octave/Matlab Emacs modes available
    • Octave-mod
      Comes with Emacs (included), but to my view lacks debugging capability (well there is some, I admit)
    • Matlab-mod
      Seems to have much more functionality. Though, it can suffer from Octave-Matlab incompatibility issues. The mode is meant to use GUD for debugging, which seems as very structured and elegant solution.


    Friday, 4 February 2011

    Self made wind turbine (ongoing)

    Motivation & background
    For some time now, I've been thinking about adding a wind turbine to my household. I'm effectively living outside a city for few years now and have noticed that there is much more wind here than in the city (what a discovery!). So, why not to use it...?

    I am generally in favor of "green" solutions. Hence, when designing the house I incorporated a heat pump as primary heating system for both heat and warm water.

    It is now the time to turn the wind to work for me too! This blog is setup to serve as a construction diary this idea (although the idea is about 2 years, I am just starting as a blogger).

    First things first - measurements
    Before going any further with the project I decided to take a bit of scientific approach and first check if the whole idea of placing a wind turbine make any sense.

    The basic question any wind power enthusiast should answer is: is there enough wind around to actually continue with the idea?

    The simple fact of matter is that  wind is not constant, so the energy generated by wind is not constant. The effort (and funds) put into designing a wind turbine should at least have some sense, I believe ;)
    Hence, as a first step of the project I decided to set up a wind (weather) monitoring station to continuously measure the strength and the direction of wind in my area.

    I purchased a weather station, WS2300 (like the one here). Having a WRT54GL linux-capable WiFi router I decided to use the router as a PC capable of reading and storing the measurements done by WS2300. Such a weather monitoring system has a great advantage of low power consumption since the router is up all the time anyway but it consumes just few Watts (clearly, this would not have been the case with full blown PC).
    As this action involves major modification to the router (enabling RS232 serial interface for communication with the weather station, and adding an SD card for data storage), it is a separate project by itself, and will be described on a separate blog (will appear soon).

    After all work was done and the weather monitoring system was in place, it was running (more or less) continuously for several months, where measurements were taken at 5 min intervals. All in all, lots of data was gathered, which is a good basis for the wind analysis.

    After more than a year of measurements, here are the results of analysis. I present
    - wind strength histogram
    - wind direction histogram

    While the former gives me some hints regarding if a wind turbine makes at all sense, the latter can provide some hints where is the best place to place the turbine.


    Assuming that an average wind turbine starts operation at 2,x m/s speed, from the first figure it seems that there is enough wind for 35-40% of a time. 

    [more to follow soon (I mean some day :) ]

    More measurements

    Maybe not yet ready with the turbine itself (delays, delays...), while playing around with Python, I decided to look up to the most recent measurement data (yes, my measurement system is still up and running!).
    So here is some more insight. First, let's check if there is some day-to-day pattern in the wind speed data. In other words I want to see/check if there is some pattern in the data; is it the case that there are some parts of the day, when the wind is stronger? (--> when will the most electric power be mostly generated?)

    To answer that, I decided to look at data in daily intervals, calculating the average for each hour (day time) and then for each measurement day (history). Here is the output (man, I love Python!) ;)

    And now the yearly averaged wind speed per daytime: