[ncl-talk] calculating annual max values with varying amount of yearly values

Alan Brammer abrammer at albany.edu
Fri Sep 12 13:24:01 MDT 2014


Does this do what you originally questioned?
I may have interpreted the year file incorrectly.

Good luck,


years = asciiread("cittagong_years.txt",-1, "float")
wind = asciiread("cittagong_wind_all.txt",-1, "float")


year_min = min(years)
year_max = max(years)
year_span = fspan( year_min, year_max, toint((year_max-year_min)+1) )

output = new( dimsizes(year_span), typeof(wind) )
output!0 = "year"
output&year = year_span

do y=year_min, year_max
  year_ind = ind(years .eq. y)
  if(all(ismissing(year_ind)))
    delete(year_ind)
    continue            ;;;  if there are no matching years then move onto
the next year
  end if
  output({y}) = max( wind(year_ind) )  ; will return FillValue if all
values == FillValue.
  delete(year_ind)
end do



On Fri, Sep 12, 2014 at 2:56 PM, Marcella, Marc <MMarcella at air-worldwide.com
> wrote:

>  Hi Alan,
>
>
>
> Thanks, Ive attached the file for the wind values and the corresponding
> file for the years corresponding to each event.
>
>
>
> Thanks!
> Marc
>
>
>
> *From:* Alan Brammer [mailto:abrammer at albany.edu]
> *Sent:* Friday, September 12, 2014 2:40 PM
>
> *To:* Marcella, Marc
> *Cc:* ncl-talk at ucar.edu
> *Subject:* Re: [ncl-talk] calculating annual max values with varying
> amount of yearly values
>
>
>
> It might be worth attaching an example of both input files (year and
> value).  I'm struggling to work out your file structure.  It seems like it
> would be possible to create a single array of all your values and then use
> ind() to select the relevant values for each year.
>
>
>
> Good luck,
>
> Alan.
>
>
>
> On Fri, Sep 12, 2014 at 1:39 PM, Marcella, Marc <
> MMarcella at air-worldwide.com> wrote:
>
> Yeah, im really trying to streamline this and do it all in one
> language/program. I have to do it multiple times so it would be much better
> just to it all in NCL.  But thank you for your help/suggestions. Hopefully
> someone out there will have a solution!!
>
>
>
> *From:* jbuzan [mailto:jbuzan at purdue.edu]
> *Sent:* Friday, September 12, 2014 1:17 PM
>
>
> *To:* Marcella, Marc
> *Cc:* ncl-talk at ucar.edu
> *Subject:* Re: [ncl-talk] calculating annual max values with varying
> amount of yearly values
>
>
>
> hmmmm…
>
> You could use a csh script (or whatever shell you are comfortable with) to
> delimitate the text file year, start, and end values.  You feed this into
> environment variables and import into ncl.  ncl would then use ascii read,
> and the getenv to set the ranges.  After that, run stat_dispersion, and
> export to netcdf.
>
>
>
> http://www.ncl.ucar.edu/Document/Functions/Built-in/asciiread.shtml
>
> https://www.ncl.ucar.edu/Document/Functions/Built-in/fspan.shtml
>
> http://www.ncl.ucar.edu/Document/Functions/Built-in/getenv.shtml
>
>
>
> -Jonathan
>
>
>
>
>
> On Sep 12, 2014, at 1:05 PM, Marcella, Marc <MMarcella at AIR-WORLDWIDE.COM>
> wrote:
>
>
>
> Hmm thanks, but therein lies the problem, the start and end or increment
> is variable from year to year (and the year values are in a separate text
> file than the wind values which are in a text file) So start end for year
> one may be 1 4 but for year 2 it may be 5 5 and year 3 6-12, etc.
>
>
>
>
>
>
>
> *From:* jbuzan [mailto:jbuzan at purdue.edu <jbuzan at purdue.edu>]
> *Sent:* Friday, September 12, 2014 1:04 PM
> *To:* Marcella, Marc
> *Cc:* ncl-talk at ucar.edu
> *Subject:* Re: [ncl-talk] calculating annual max values with varying
> amount of yearly values
>
>
>
> ah.
>
> Well, a quick way to deal with this is to parse the data into years using
> nco commands.  (ncks -d time start,end,increment data_in.nc data_out.nc).
>  Then run stat_dispersion.
>
>
>
> -Jonathan
>
>
>
>
>
>
>
> On Sep 12, 2014, at 1:01 PM, Marcella, Marc <MMarcella at AIR-WORLDWIDE.COM>
> wrote:
>
>
>
>    This is 1D data. It’s an array for the wind value for each event for a
> given year at a specific lat/lon location
>
>
>
> *From:* jbuzan [mailto:jbuzan at purdue.edu <jbuzan at purdue.edu>]
> *Sent:* Friday, September 12, 2014 1:01 PM
> *To:* Marcella, Marc
> *Cc:* ncl-talk at ucar.edu
> *Subject:* Re: [ncl-talk] calculating annual max values with varying
> amount of yearly values
>
>
>
> stat_dispersion only works on 1D data.  So you have to loop through each
> grid cell.  However, it will provide you with the local statistics of each
> grid cell.
>
>
>
> -Jonathan
>
>
>
>
>
>
>
>
>
> On Sep 12, 2014, at 12:55 PM, Marcella, Marc <MMarcella at AIR-WORLDWIDE.COM>
> wrote:
>
>
>
>
>    Yes, I know of stat dispersion, but wont this look at the
> statistics/distribution of the entire dataset? I was looking to figure out
> only for each year. I believe I could use the max command provided I can
> get the beginning and final index value for each year easily enough.
>
>
>
> *From:* jbuzan [mailto:jbuzan at purdue.edu <jbuzan at purdue.edu>]
> *Sent:* Friday, September 12, 2014 12:54 PM
> *To:* Marcella, Marc
> *Cc:* ncl-talk at ucar.edu
> *Subject:* Re: [ncl-talk] calculating annual max values with varying
> amount of yearly values
>
>
>
> I recommend using stat_dispersion:
>
>
> http://www.ncl.ucar.edu/Document/Functions/Contributed/stat_dispersion.shtml
>
>
>
> -Jonathan
>
>
>
>
>
>
>
> On Sep 12, 2014, at 12:49 PM, Marcella, Marc <MMarcella at AIR-WORLDWIDE.COM>
> wrote:
>
>
>
>
>
>    Hi all,
>
>
> Im having a bit of a problem trying to elegantly script calculating annual
> max values when I have varying amount of values for each year. For example,
> I have one text file with the year stamp for each event, and in another I
> have the corresponding wind value for that event.  Some years there are
> four measurements, some years one, other years ten. Im trying to use a do
> loop that goes through each year in the text file to find the beginning and
> end index (i.e. what index refers to the beginning of that year’s values in
> the wind file and the index that refers to the last value of that year).  I
> was then going to use that specific year’s indices with the max command on
> the wind value file.  But I’m having not having too much luck and it’s
> getting messy with all the do and if statements.  Any ideas?  Are there
> simpler functions that Im not aware of built into NCL that can help with
> this?  Any help would be greatly appreciated.
>
>
>
> Thanks,
> Marc
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
>
>
> _______________________________________________
> ncl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20140912/9bb61f06/attachment.html 


More information about the ncl-talk mailing list