Menu

To generate monthly wet days from daily precipitation data

Help
Ricky Chu
2015-12-04
2015-12-09
  • Ricky Chu

    Ricky Chu - 2015-12-04

    Dear all,

    I have a daily precipitation data from 1950 to 2012, and I want to generate a monthly wet days file. The monthly wet days file contain the wet days (when precipitation > 0) of each month from 1950 to 2012.

    Is there a short way to do this using NCO?

    Thank you very much in advance.

    Sinerely,
    Ricky

     
  • Charlie Zender

    Charlie Zender - 2015-12-04

    Not sure I understand the question. This gives daily wet days only
    in out.nc, and sets the rest to missing values. You can subset to obtain monthly wet days:

    ncecat -u dummy in*.nc out.nc
    ncwa -a dummy -B 'precip > 0' out.nc out.nc
    
     
    • Ricky Chu

      Ricky Chu - 2015-12-05

      Thank you, Charlie.

      Seems can't be done using ncwa? Not sure I operated correctly.

      TO make it clear:

      I have a daily precipitation NC file: Precipitation1950-2012.nc, from 1950 to 2012, the time dimension is 23010 (days);

      Now, I want to make a monthly wet days data. Wetdays1950-2012.nc, from 1950 to 2012, the time dimension is 63years * 12= 756 (months). For each month, the value is the raining days (defined as precip > 0) of that month and should be an integer ( ranging from 0 to 31)

      Thanks again,

      Ricky

       
  • John

    John - 2015-12-05

    Ricky,

    The irregular lengths of months make this difficult, especially if you have leap days, like your dataset. If it were me, I'd just use brute force using a shell script. Not elegant, but probably faster than writing an ncap2 script if you're not familiar with ncap2 scripts.

    First, convert the data to 1's & 0's (rain & no rain) per Charlie's example. Then create a column of numbers representing numbers of days in a month, starting from Jan 1950, going to Dec 2012:

    31 # days in Jan 1950
    28
    ....
    31 # days in Dec 2012

    Then convert that column into a shell script that calculates the sum of 1's in each month:

    ncra -y ttl -d time,0,30 in.nc 1950_01.nc
    ncra -y ttl -d time,31,57 in.nc 1950_02.nc
    ...
    ncra -y ttl -d time,22979,23009 in.nc 2012_12.nc

    Run the shell script, and you'll have 756 files. Just concat those into a single file:

    ncrcat ????_??.nc wetdays.nc

     

    Last edit: John 2015-12-05
    • Ricky Chu

      Ricky Chu - 2015-12-05

      Thank you, John.

      I used

      ncwa -a time -B 'Precip > 0' Precipitation1950-2012.nc Precipitation1950-2012_BOOL.nc

      to convert the data to 1's & 0's (rain & no rain).

      But it seems not working. I use NCO under Cygwin.

      I notice that there is a note "Unfortunately the ‘-B’ and ‘--mask_condition’ options are unsupported on Windows" on NCO4.4.6 usr guide. I'm not sure if this is the reason why I can't get the right results. Or I used ncwa incorrectly?

      Thanks,

      Ricky

       
  • Charlie Zender

    Charlie Zender - 2015-12-05

    Try '-m Precip -T gt -M 0' instead of "-B 'Precip > 0'".
    The parser for the latter does not work under Windows.
    cz

     
  • John

    John - 2015-12-05

    I would do the conversion to 1's this way:

    ncap2 -s 'where(precip > 0) precip = 1' in.nc out.nc

     
  • Charlie Zender

    Charlie Zender - 2015-12-05

    Yes, that's simpler.
    c

     
  • Ricky Chu

    Ricky Chu - 2015-12-07

    Thanks very much, Charlie and John.

    I used
    ncap2 -s 'where(precip > 0) precip = 1' in.nc out.nc
    and then ran the shell scripts suggested by John and got the right results.

    By the way, I have another question.

    At the beginning, I used nco-4.4.4.win32.cygwin.tar.gz under cygwin, but I can't find ncap2. So, I try to build nco from source 4.5.2. All the pre-requisites suggested have been installed (curl,expat,gsl,hdf5,netcdf,udunits2) as well as Antlr. I tried many times, but the error below always there:
    ++++++++++++++++++++
    nco_ppc.c: In function 'nco_ppc_around':
    nco_ppc.c:387:36: error: 'M_LN10' undeclared (first use in this function)
    const double bit_per_dcm_dgt_prc=M_LN10/M_LN2; / 3.32 [frc] Bits per decimal digit of precision /
    ^
    nco_ppc.c:387:36: note: each undeclared identifier is reported only once for each function it appears in
    nco_ppc.c:387:43: error: 'M_LN2' undeclared (first use in this function)
    const double bit_per_dcm_dgt_prc=M_LN10/M_LN2; / 3.32 [frc] Bits per decimal digit of precision /
    ^
    nco_ppc.c: In function 'nco_ppc_bitmask':
    nco_ppc.c:596:36: error: 'M_LN10' undeclared (first use in this function)
    const double bit_per_dcm_dgt_prc=M_LN10/M_LN2; / 3.32 [frc] Bits per decimal digit of precision /
    ^
    nco_ppc.c:596:43: error: 'M_LN2' undeclared (first use in this function)
    const double bit_per_dcm_dgt_prc=M_LN10/M_LN2; / 3.32 [frc] Bits per decimal digit of precision /
    ^
    Makefile:1085: recipe for target 'nco_ppc.lo' failed
    make[3]: [nco_ppc.lo] Error 1
    make[3]: Leaving directory '/usr/zqa/nco-4.5.2/src/nco'
    Makefile:382: recipe for target 'all-recursive' failed
    make[2]:
    [all-recursive] Error 1
    make[2]: Leaving directory '/usr/zqa/nco-4.5.2/src'
    Makefile:444: recipe for target 'all-recursive' failed
    make[1]: [all-recursive] Error 1
    make[1]: Leaving directory '/usr/zqa/nco-4.5.2'
    Makefile:376: recipe for target 'all' failed
    make:
    [all] Error 2
    +++++++++++++++++++++++++++++++++++++++++++++++

    Finally, I found ncap2 in nco-4.0.6.win32.cygwin.tar.gz. I gave up build NCO myself and removed nco-4.4.4.win32.cygwin.tar.gz and now using nco-4.0.6.win32.

    I'm wondering why ncap2 was removed in the updated version. What's the probable reason for my failure building of NCO?

    Thanks both of you again,

    Ricky

     
  • Charlie Zender

    Charlie Zender - 2015-12-07

    Hi Ricky,
    Thanks for your feedback. You may have found a bug on Cygwin builds (we do not build Cygwin regularly) which I have just patched. If you have a chance, please pull the latest snapshot and try building that on Cygwin.
    cz

     
    • Ricky Chu

      Ricky Chu - 2015-12-08

      OK, Charlie. I'll try to build the new version as soon as it is released.

      BTW, is it possible to keep ncap2 in the Executables Cygwin-compatible new version? It would be much much easier to use NCO under cygwin.

      Ricky

       
  • Charlie Zender

    Charlie Zender - 2015-12-08

    creation of up-to-date cygwin executables relies on volunteers, i cannot do it, i have no cygwin machines. i am happy to upload binaries provided by others, but i'm afraid the answer to your question is no.
    cz

     
    • Ricky Chu

      Ricky Chu - 2015-12-09

      Thanks and understand...

       

Log in to post a comment.