[ncl-talk] wind_speed: dimension size mismatch

Dennis Shea shea at ucar.edu
Thu Jan 16 12:28:40 MST 2020


WRF variables are on a staggered grid: Arakawa-C grid

*https://en.wikipedia.org/wiki/Arakawa_grids*
<https://en.wikipedia.org/wiki/Arakawa_grids>

*https://www.openwfm.org/wiki/How_to_interpret_WRF_variables*
<https://www.openwfm.org/wiki/How_to_interpret_WRF_variables>

====
Use : *wrf_user_getvar*
<http://www.ncl.ucar.edu/Document/Functions/WRF_arw/wrf_user_getvar.shtml>
using '*ua'* and '*va'* as variable names.
These returned wind components will be on the 'mass grid'

; Velocidad del viento a los niveles establecidos

u := wrf_user_getvar(a[nf],"ua",-1)

v := wrf_user_getvar(a[nf],"va",-1)

wspd := wind_speed(u,v)

if (nf.eq.0) then   ; 1st time thru
    If (.not.all(dimsizes(u).eq.dimsizes(v))) then
        print("FATAL: unexpected dimension sizes")
        printVarSummary(u)
        printVarSummary(v)
        exit
    end if
end if

Good luck

On Thu, Jan 16, 2020 at 11:34 AM Rashed Mahmood via ncl-talk <
ncl-talk at ucar.edu> wrote:

> Hi Borja,
> Could you please send a couple of wrf files and a clean script as
> attachment? Without more information it would just be a "guessing" by the
> community which is hard to do.
> What does printVarSummary(u) and printVarSummary(v) suggest? At which line
> number error occurred? I "guess" that at some point inside the loop, either
> u or v may be missing, but then again I cannot be sure without running your
> script!
> Cheers,
> Rashed
>
> On Thu, Jan 16, 2020 at 8:34 AM Borja Sas González via ncl-talk <
> ncl-talk at ucar.edu> wrote:
>
>> I have another wrfout file, which is called wrfzl, the difference is that
>> heights are what I enter. Instead of the variable U is U_ZL and instead of
>> V is V_ZL, but basically they are the same. In that case the script works
>> correctly, that's why I can't find the error as much as I'm looking for.
>>
>> What is indicated in the CSV is that in wspd it is written for all hours,
>> at the height that I want (0-27), for the indicated latitude and longitude.
>>
>> El jue., 16 ene. 2020 a las 15:01, Barry Lynn (<barry.h.lynn at gmail.com>)
>> escribió:
>>
>>> Hi:
>>>
>>> You should compare what you see in the printVarSummary with how you are
>>> indexing your csv table write.  For instanc,e there are three dimensions in
>>> wspd.  Do they match what you are writing?
>>>
>>> On Thu, Jan 16, 2020 at 3:01 PM Borja Sas González <saszalez at gmail.com>
>>> wrote:
>>>
>>>> printVarSummary prints:
>>>>
>>>> Variable: wspd
>>>> Type: float
>>>> Total Size: 20601540 bytes
>>>>             5150385 values
>>>> Number of Dimensions: 3
>>>> Dimensions and sizes: [Time | 785] x [south_north | 81] x [west_east |
>>>> 81]
>>>> Coordinates:
>>>> Number Of Attributes: 2
>>>>   units : m s-1
>>>>   long_name : wind speed
>>>>
>>>> El jue., 16 ene. 2020 a las 12:41, Barry Lynn (<barry.h.lynn at gmail.com>)
>>>> escribió:
>>>>
>>>>> Hello:
>>>>>
>>>>> A most important step is to do a printVarSummary of the variables you
>>>>> with to write to the table and to see (compare) if you are referencing them
>>>>> correctly (which it appears you are not).
>>>>>
>>>>> Barry
>>>>>
>>>>> On Thu, Jan 16, 2020 at 2:27 PM Borja Sas González via ncl-talk <
>>>>> ncl-talk at ucar.edu> wrote:
>>>>>
>>>>>> Hi everyone. I am trying to put in a CSV file the wind speed and
>>>>>> direction for level 1 of the out file of the WRF output. I have reviewed
>>>>>> the script a thousand times, but I can't find where the error is. The
>>>>>> answer that prints me is:
>>>>>>
>>>>>> (0) wind_speed: dimension size mismatch
>>>>>>
>>>>>> (0)         u: 1000
>>>>>>
>>>>>> (1)         u: 27
>>>>>>
>>>>>> (2)         u: 81
>>>>>>
>>>>>> (3)         u: 82
>>>>>>
>>>>>> (0)         v: 1000
>>>>>>
>>>>>> (1)         v: 27
>>>>>>
>>>>>> (2)         v: 82
>>>>>>
>>>>>> (3)         v: 81
>>>>>>
>>>>>> The script is:
>>>>>>
>>>>>> begin
>>>>>>
>>>>>>
>>>>>> ; Abrir archivos
>>>>>>
>>>>>> files = systemfunc("ls
>>>>>> /home/ssd/begur/WRF/test/em_real/wrfout_d03_*") + ".nc"
>>>>>>
>>>>>> a = addfiles(files,"r")
>>>>>>
>>>>>>
>>>>>> ; Definir latitud y longitud
>>>>>>
>>>>>> lat = 41.935165
>>>>>>
>>>>>> lon = 3.158911
>>>>>>
>>>>>>
>>>>>> ; Opciones del encabezado
>>>>>>
>>>>>> csv_filename = "wind_levels.csv"
>>>>>>
>>>>>> system("rm -f " + csv_filename)
>>>>>>
>>>>>> fields = (/"TIME","WIND SPEED (m/s)","WIND DIRECTION (º)"/)
>>>>>>
>>>>>>
>>>>>> ; Crear encabezado
>>>>>>
>>>>>> dq = str_get_dq()
>>>>>>
>>>>>> fields = dq + fields + dq
>>>>>>
>>>>>> header = [/str_join(fields,",")/]
>>>>>>
>>>>>>
>>>>>> ; Formato de escritura de las variables
>>>>>>
>>>>>> format = "%s,%g,%g,%g,%g" ; Para escribir sin espacios
>>>>>>
>>>>>>
>>>>>> ; Crea el archivo con el encabezado
>>>>>>
>>>>>> write_table(csv_filename,"w",header,"%s")
>>>>>>
>>>>>>
>>>>>> ; Para leer archivo por archivo
>>>>>>
>>>>>> nfiles = dimsizes(files)
>>>>>>
>>>>>>
>>>>>> ; Bucle archivo por archivo
>>>>>>
>>>>>> do nf = 0,nfiles-1
>>>>>>
>>>>>>
>>>>>> ; Localización del punto más próximo
>>>>>>
>>>>>> opt = True ; Devuelve la coordenada entera
>>>>>>
>>>>>> loc := wrf_user_ll_to_xy(a[nf],lon,lat,opt) ; Pasa lon/lat a xy más
>>>>>> próximo
>>>>>>
>>>>>>
>>>>>> ; Coordenadas para las variables
>>>>>>
>>>>>> lat2 = loc(1) ; Latitud para las variables
>>>>>>
>>>>>> lon2 = loc(0) ; Longitud para las variables
>>>>>>
>>>>>>
>>>>>> ; Velocidad del viento a los niveles establecidos
>>>>>>
>>>>>> u := wrf_user_getvar(a[nf],"U",-1)
>>>>>>
>>>>>> v := wrf_user_getvar(a[nf],"V",-1)
>>>>>>
>>>>>> wspd := wind_speed(u,v)
>>>>>>
>>>>>> wspd = decimalPlaces(wspd,2,True)
>>>>>>
>>>>>>
>>>>>> ; Dirección del viento a los niveles establecidos
>>>>>>
>>>>>> wdir := wind_direction(u,v,0)
>>>>>>
>>>>>>
>>>>>> ; Loop temporal
>>>>>>
>>>>>> times := wrf_user_getvar(a[nf],"times",-1)
>>>>>>
>>>>>> ntimes = dimsizes(times)
>>>>>>
>>>>>>
>>>>>> ; Bucle temporal
>>>>>>
>>>>>> do it = 0,ntimes-1
>>>>>>
>>>>>>
>>>>>> ; Crea el archivo CSV con las variables
>>>>>>
>>>>>> alist = [/times(it),wspd(it,0,lat2,lon2),wdir(it,0,lat2,lon2)/]
>>>>>>
>>>>>> write_table(csv_filename,"a",alist,format)
>>>>>>
>>>>>>
>>>>>> end do
>>>>>>
>>>>>>
>>>>>> end do
>>>>>>
>>>>>>
>>>>>> end
>>>>>>
>>>>>> If anyone can help me I appreciate it.
>>>>>>
>>>>>> --
>>>>>> Borja Sas González
>>>>>> _______________________________________________
>>>>>> ncl-talk mailing list
>>>>>> ncl-talk at ucar.edu
>>>>>> List instructions, subscriber options, unsubscribe:
>>>>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> Barry H. Lynn, Ph.D
>>>>> Senior Associate Scientist, Lecturer,
>>>>> The Institute of the Earth Science,
>>>>> The Hebrew University of Jerusalem,
>>>>> Givat Ram, Jerusalem 91904, Israel
>>>>> Tel: 972 547 231 170
>>>>> Fax: (972)-25662581
>>>>>
>>>>> C.E.O, Weather It Is, LTD
>>>>> Weather and Climate Focus
>>>>> http://weather-it-is.com
>>>>> Jerusalem, Israel
>>>>> Local: 02 930 9525
>>>>> Cell: 054 7 231 170
>>>>> Int-IS: x972 2 930 9525
>>>>>
>>>>>
>>>>
>>>> --
>>>> Borja Sas González
>>>>
>>>
>>>
>>> --
>>> Barry H. Lynn, Ph.D
>>> Senior Associate Scientist, Lecturer,
>>> The Institute of the Earth Science,
>>> The Hebrew University of Jerusalem,
>>> Givat Ram, Jerusalem 91904, Israel
>>> Tel: 972 547 231 170
>>> Fax: (972)-25662581
>>>
>>> C.E.O, Weather It Is, LTD
>>> Weather and Climate Focus
>>> http://weather-it-is.com
>>> Jerusalem, Israel
>>> Local: 02 930 9525
>>> Cell: 054 7 231 170
>>> Int-IS: x972 2 930 9525
>>>
>>>
>>
>> --
>> Borja Sas González
>> _______________________________________________
>> ncl-talk mailing list
>> ncl-talk at ucar.edu
>> List instructions, subscriber options, unsubscribe:
>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> 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/20200116/f38fa0fc/attachment.html>


More information about the ncl-talk mailing list