[ncl-talk] Monthly average from csv file

Dennis Shea shea at ucar.edu
Fri Mar 3 19:04:07 MST 2023


***Untested***

[1] Read the csv file and extract the year, month,day,hour,value into
one-dimensional arrays: year(*),...val_units(*),val(*)
     Since each line in the csv file has integer, text and float values, it
is best to read the values as strings and convert.


   ncol = 6
   data = *readAsciiTable*
<https://www.ncl.ucar.edu/Document/Functions/Contributed/readAsciiTable.shtml>("....",
ncol, "string", 1)

   yyyy = *toint*
<https://www.ncl.ucar.edu/Document/Functions/Built-in/toint.shtml>(data(:,0))
   mm   = toint(data(:,1))
        :
   val_unit = data(:,4)       ; string values
   val  = *tofloat*
<https://www.ncl.ucar.edu/Document/Functions/Built-in/tofloat.shtml>(data(:,5))

; create required minute and second arrays

   nval = dimsizes(val)
   mn   = *new*
<https://www.ncl.ucar.edu/Document/Functions/Built-in/new.shtml>
(nval,integer)
   sc   = new (nval,integer)

   mn   = 0
   sc   = 0

[2] Use *cd_inv_calendar*
<https://www.ncl.ucar.edu/Document/Functions/Built-in/cd_inv_calendar.shtml>


; time units are arbitrary
    tunits = "hours since 2000-01-01 00:00:00" ; "seconds/hours/days since ...."
    time   = *cd_inv_calendar*(yyyy,mm,dd,hh,mn,sc,tunits, 0)
    time!0 = "time"
    *printVarSummary*
<https://www.ncl.ucar.edu/Document/Functions/Built-in/printVarSummary.shtml>(time)
   ;  print(time)

    val!0= "time"
    val at units = val_unit(0)  ; assign scalar descriptor
    val&time  =  time
    *printVarSummary*
<https://www.ncl.ucar.edu/Document/Functions/Built-in/printVarSummary.shtml>(val)

; calculate monthly mean values

    val_month  = *calculate_monthly_values*
<https://www.ncl.ucar.edu/Document/Functions/Contributed/calculate_monthly_values.shtml>(val,
"avg", 0, False)

    printVarSummary(val_month)

    *printMinMax*
<https://www.ncl.ucar.edu/Document/Functions/Contributed/printMinMax.shtml>(val_month,
1)




On Fri, Mar 3, 2023 at 11:03 AM MORICHETTI MAURO via ncl-talk <
ncl-talk at mailman.ucar.edu> wrote:

> Hi all,
>
>
>
> are there any chances to do a monthly average from hourly values csv file?
>
>
>
>
> I have different files with the hourly values of temperature, wind-speed
> and relative humidity. I would like to calculate the monthly values, so I
> was thinking if there is a function in order to use the date reported in
> the file as coordinate for the meteorological values.
>
>
>
> Attached part of the script and one some files as example.
>
>
>
> If you need more information, ask me thanks.
>
>
>
> Mauro
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at mailman.ucar.edu
> List instructions, subscriber options, unsubscribe:
> https://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20230303/1c91b8df/attachment.htm>


More information about the ncl-talk mailing list