Project

General

Profile

CAlculating the Mode

Added by Yousef Albuhaisi about 4 years ago

Hi,

is there anyway to calculate the mode for nc file? I have tried cdo mod in.nc out.nc and it ask for divisor? is that the solution?

Regards.

Yousef


Replies (11)

RE: CAlculating the Mode - Added by Ralf Mueller about 4 years ago

hi!

what do you mean with 'mode'?

cheers
ralf

RE: CAlculating the Mode - Added by joao ferreira about 3 years ago

Yes

That could be great to find the dominant wind direction in a day, for example, since the mean and median of a direction doesn't make sense...

I've tried with histcount but I'm stucked getting the greatest value of the bins and assign that bin to the day.

See my last post in the forum...

RE: CAlculating the Mode - Added by Brendan DeTracey about 3 years ago

Um, you need to read up on Circular/Directional Statistics. It is a thing. It is important. And there are already toolboxes in the wild. It is well covered ground.

Try these as a start:
https://en.wikipedia.org/wiki/Directional_statistics
https://www.frontiersin.org/articles/10.3389/fpsyg.2018.02040/full
https://www.jstatsoft.org/article/view/v031i10

Nmu'ltis!

RE: CAlculating the Mode - Added by joao ferreira about 3 years ago

Thanks for the links.

I'm sure I will appreciate them later...

For now I just needed a cdo tool that was able to calculate the mode...

Of course I could just calculate the daily mean_U and mean_V and assume

mean_DD =atan2(mean_U,mean_V) + 180

but I would like to know what is the measured/modeled wind direction that occured more often during the day (ignoring wind speed...) for 10 000 days and 86 000 grid points

And I'm sure the mode could be a good implementation in cdo not only for circular variables...

Just a thought however...

Regards

RE: CAlculating the Mode - Added by Brendan DeTracey about 3 years ago

Let me stew on this. It can be done but with more "code" than usual for cdo. You have to wrap your data around 0/360, so that will involve some data padding, if you know what I mean. Some day, directional stats will be added to cdo, somewhere over the rainbow.

I'll brew on this and get back to you but I make no promises about when I can do this. Life, ya know? The great big juggling act of life.

Later.....
b.

Edit: the first step will be normalizing each single vector in the time series to unit length. This "un-weights" the wind speed with respect to direction.

RE: CAlculating the Mode - Added by joao ferreira about 3 years ago

Hi

Yep... Life is cruel... :-)

Did you see mu post before this one? I will put it here again...

(In fact, using histcount like I did, the problem is not circular anymore, because with the direction classes I used I don't have the 0/360 degrees descontinuity...)

I'm trying to use histcount to know what is the dominant wind direction (8 directions...) for each grid point on each 24 hours day (i have 24 hourly directions each day...)

I'm doing:

cdo -histcount,0,45,90,135,180,225,270,315,+inf -selday,1 -selmonth,1 -selyear,2010 hourly_DIR_mercator.nc count.nc

This gives me the number of ocurrences on each direction bin, but now I want to choose the highest one to be the unique direction for the day...

For example, if I have 13 ocurrences for the bin between 0 and 45, I want to assign 0 to this day, because no other bin can have more than 13, since the total is 24...

Also, I have a unique file with all timesteps and I wanted to avoid the -selday,$day -selmonth,$month -selyear,$year stuff... Can it be done?

(1-3/3)

RE: CAlculating the Mode - Added by Brendan DeTracey about 3 years ago

Nope. I did not see your other post. Your post to this stale thread triggered an email notification to me.
I'll digest that extra info, but truthfully, there often comes time when a scripting tool is required. In the future something might be changed in cdo that solves your problem, but that is the unknown future.

RE: CAlculating the Mode - Added by Brendan DeTracey about 3 years ago

joao ferreira wrote in RE: CAlculating the Mode:

For example, if I have 13 ocurrences for the bin between 0 and 45, I want to assign 0 to this day, because no other bin can have more than 13, since the total is 24...

Hi Joao,
So 0 is your index for your first bin?

Did you upload sample files in the other post or this one? Having a sample file is essential to let me try and help you. If you can either select a single grid index, or reduce the number of timesteps to 12 or so, that would be perfect.

RE: CAlculating the Mode - Added by joao ferreira about 3 years ago

Hi,

I'm sending the file in attachment.

So, I'm doing:

cdo -histcount,0,45,90,135,180,225,270,315,+inf dir.nc count.nc

Now I would like to choose 0,45,90,135,180,225,270 or 315 as the unique value, being this unique value the most populated bin in count.nc

Regards

Joao

RE: CAlculating the Mode - Added by joao ferreira about 3 years ago

I'm sending again now with direction only...

dir.nc (10.9 MB) dir.nc
    (1-11/11)