Re: Loop through grid cells

From: jbuzan <jbuzan_at_nyahnyahspammersnyahnyah>
Date: Wed Jul 09 2014 - 06:03:57 MDT

M. Wiston;

I would use the 'where' function to first create an array where the =
values you are looking for are 'true', and everything else is =
@_FillValue
https://www.ncl.ucar.edu/Document/Functions/Built-in/where.shtml

Then applying your calculations to the entire array.
That'll probably speed things up.

-Jonathan R. Buzan



On Jul 9, 2014, at 7:59 AM, Modise Wiston =
<modise.wiston@postgrad.manchester.ac.uk> wrote:

> Hi 'NCl-talkers'
>
> I want to determine the maximum (&/or min'm) cloud droplet (Qndrop) =
number from the cloud layers. How can I write (use a code) to loop =
through all the x- and y-directions and get/calculate the maximum =
droplet number along the z-plane. The idea is to find the maximum Qndrop =
so as to determine the corresponding CCN number (supersaturation level). =
i.e. going through cloud layers/height levels from the cloud base.
>
> Below is [part of] my script code I have. Currently this plots droplet =
number in horizontal cross section (map overlaid) for the first 5 levels =
(from the ground surface), but I want to get Qndrop at specific points =
(x,y,z coordinates); only at points where I have clouds. While I want to =
loop through cloud height/layers -say height z0 [cloud base] to zn =
[cloud top]. I only need to go up to point where I 'hit' the first cloud =
base and its top (not necessarily going through all clouds above). Is =
there a way that I can write this to get Qndrop at a given height and =
location?
>
> =
--------------------------------------------------------------------------=
-----------------------------------------
> do ispec = 0, nspecies-1 ; =
spec
> species = speclist(ispec)
>
> dt = 6
>
> do ifil = 0, numFILES-1, dt =
; file loop
>
> print("Opening file "+FILES(ifil))
> a = addfile(FILES(ifil)+".nc","r")
>
> ;Define the time step to output data
> times = wrf_user_list_times(a)
> ntimes = dimsizes(times)
>
> do it = 0,ntimes-1,2 ; =
time loop
> map = wrf_map(wks,a,mpres)
>
> ;Obtain the variables from the file
> if(isfilevar(a,"QNDROP"))
> Nd = wrf_user_getvar(a,"QNDROP",it)
> conv = Nd*1.2923/1e6 ; convert =
from /kg to /sm^3 then to /scm^3
> Nd@units = "/cm^3" ; =
converted units
> end if
>
> do level = 0,5,1 =
;model level loop
> Lvl = level + 1
> opts@cnFillOn = True
> opts@gsnSpreadColors = False
> opts@PlotLevelID = "Level " + Lvl
>
> ;define an array to hold data
> ; Nd = (/i,j,k/)
>
> min_Nd = new(2,float)
> max_Nd = new(2,float)
>
> ; do k = 0, k-1
> do j = 0, j-1
> do i = 0, i-1
>
> ; min_Nd(i) = min(Nd(:,i)) ;goes through x-direction and =
finds min along y-direction
> ; max_Nd(i) = max(Nd(:,i)) ;finds max along y-direction
> ; min_Nd(j) = min(Nd(:,j)) ;goes through y-direction and =
finds min along x-direction
> ; max_Nd(j) = max(Nd(:,j)) ;finds max along x-direction
>
> min_Nd(k) = min(Nd(:,j,i)) ;goes through x-y direction =
and finds min along k-direction
> max_Nd(k) = max(Nd(:,j,i)) ;finds max along k-direction
>
> end do
> end do
> ; end do
>
> if (isvar("Nd"))
> print(min(Nd))
> print(max(Nd))
> opts@FieldTitle = Nd@description +" at: " +times(it) +" =
Nmbr /cm^3"
> contour = wrf_contour(a,wks,conv(level,:,:),opts)
> plot = wrf_map_overlays(a,wks,(/contour/),pltres,mpres)
> delete(contour)
> end if
>
> end do ; spec
> end do ;file
> end do ; time
>
> end do ;level
> =
--------------------------------------------------------------------------=
----------------------------------
>
> Any help would be appreciated please
>
> Thank you in advance
> M. Wiston
> (The University of Manchester)
> _______________________________________________
> 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


Received on Wed Jul 09 12:04:10 2014

This archive was generated by hypermail 2.1.8 : Wed Jul 23 2014 - 15:33:46 MDT