Stand With Ukraine
Showing posts with label Météo. Show all posts
Showing posts with label Météo. Show all posts

Friday, February 6, 2015

A python script: example for downloading GlobSnow data (snow extent in this case)

Recently a friend asked me if it is possible to selectively download folders from http servers in linux.. Probably it is possible by using wget or rsync, but I have never succeeded to make them work exactly the way I needed. So I wrote a small script for the task and passed it to him hoping that this might be his first step to learning Python. And below are 2 versions of the same script:
  1. The version I have actually given to my friend,
  2. The improved a bit more scary-looking version, which is a bit closer to the way I think it should be written.

First, below I show a quick and simple way of downloading files, with a minimal account for possible errors. The next step is to check if the sizes of existing files are the same as the sizes of the remote files and to replace the bad files, if required. Of course, it takes some time to download the data, especially if you need several years. If you work remotely I would suggest using tmux or screen, so your program would continue running even if the ssh session is closed for some reason. But if those are not installed, you still can get away by using nohup as follows:
nohup pyhton download.py >& log.txt &

Cheers and any comments are welcome

Sunday, July 15, 2012

Gradient of scalar product or divergence of a tensor.

When you read a scientific work with equations there could be surprises and confusion even in the notation. Here I want to speak about the one I encountered recently, when looking at the Navier-Stokes equation.
First I thought, the result of the operation should be a vector since it appears as a term in a vectorial equation so it was natural for me to consider it as a gradient of a scalar product of two vectors. Then I started remembering the formula for the gradient of a scalar product.
Here the star represents the vector on which the nabla operator acts. Those could be expressed as follows( (*,*) - scalar product, [*,*] - vector product ):
and swapping a and b we also get
Then combining the last 3 equations we get:
Which differs from the first equation. Then It came to me that the term
is a flux of a momentum, that is a flux of a vector quantity. This means that each coordinate of the quantity should be multiplied by each coordinate of the velocity, which gives us the following tensor:
Then each component of the divergence D of the flux will have the following form
which is equivalent to
Which, I suppose, is exactly what the author had in mind.

Friday, January 6, 2012

Summation along a dimension

Suppose you have a netcdf file with temporal data of say evaporation (in meters). And you want to know how much water evaporates during a year. And also you do not want to loose time writing a program for this. Fortunately we have NCO. I did the procedure for the ERA-Interim reanalysis file downloaded from the ECMWF site. I picked the year 1985. The header of the file looks like this:


Here is the description of the procedure that I used:
  1. Calculate the mean of the variable along the specified dimension (time in my case).
    ~# ncra -d time,0,729 -v e evap-1985.nc mean_evap_1985.nc
    
    Here I was not sure whether I should take care of the scale_factor and add_offset. The answer is no, because nco takes care of it for you.
  2. Then, since sum = mean * ntimes, I use the mean to get the sum. Minus is because of the model convention, they consider the flux negative if it is upwards.
    ~# ncap -O -s "e=-730*e" mean_evap_1985.nc sum_evap_1985.nc
    
  3. So we have our resulting field in the file sum_evap_1985.nc, which can be viewed using ncview. The field looks as shown below. I do not know how to save the legend in ncview, so the figure is not very informative. The result corresponds to the means given by ECMWF: E-P and P.

Data source: "ECMWF ERA-Interim data used here have been obtained from the ECMWF data server."

Thursday, December 24, 2009

Gravity waves

Gravity waves.

Gravity waves in a system with rotation.

Gravity waves in a system with rotation. (So called geostrophic adjustment). Here is an analytic solution expressed in terms of the Bessel functions (see Gill, "Atmosphere and ocean dynamics" 1982).


All the pictures were created using python library matplotlib and converted to gif using the command convert from imagemagick.

Wind velocity vector, at a given point (sea breeze modelling)

Rotation of wind vector at a given point given by a solution of 2 dimensional linearized system of Euleur's equations. Taking into account only the pressure and Coriolis forces.

Friday, September 11, 2009

Le premier devoir à l'UQAM


C'est le champ de la pression.
Si vous verrez les fautes, n'hesitez pas à m'écrire, merci beaucoup.