Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

ncap2 sort and median

Help
S. Morin
2013-02-25
2013-10-17
  • S. Morin
    S. Morin
    2013-02-25

    Dear all,

    From a series of model output and using ncecat I've generated a file containing some output data with dimensions time and record (record has been generated through ncecat). Now I'd like to compute the median of my output data for each time and across all records. I'm struggling with gsl_stats_median_from_sorted_data , probably because I'm struggling with the sort() function, which seems to operate over the entire file and not on a time-by-time basis (it works fine when I first use ncks to extract each time, but this is not satisfactory of course). Any hint on what the correct syntax should be ? Thanks ahead for the reply.

    Samuel

     
  • henry Butowsky
    henry Butowsky
    2013-02-26

    HI Sam,
    from what your saying sounds like you need to loop the time variable -
         then apply the sort & median function to each individual slab and then store the results in a predefined array of the correct size. Below is an example:

    /********************************* sam.nco **************************/
    *sz=time.size();
    var_in[$time,$lon]=1.0;
    var_in=10*gsl_rng_uniform(var_in);
    median[$time]=0.0;
    for(idx=0 ; idx<sz;idx++){
      median(idx)=var_in(idx,:).sort().gsl_stats_median_from_sorted_data();
    }
    print(median);
    /************************************************************************************/
    

    Then to run the above use the command

    ncap2 -v -O -S sam.nco in.nc foo.nc
    

    … hmb

     
  • S. Morin
    S. Morin
    2013-03-05

    I was kind of doing this by extracting single time slabs using ncks, the loop within ncap2 is clearly a better option and you example shows nicely how to proceed.

    Many thanks hmb for this nice solution.