[ncl-talk] Error when using center_finite_diff_n

Dennis Shea shea at ucar.edu
Wed Mar 3 19:46:10 MST 2021


Please mentions these issues  (eg: missing_values, _FillValue) in a post to
ncl-talk
=======================================
[1] Same input part as previous script
[2] Use *uv2vr_cfd*
<http://www.ncl.ucar.edu/Document/Functions/Built-in/uv2dv_cfd.shtml> and
*grad_latlon_cfd*
<http://www.ncl.ucar.edu/Document/Functions/Contributed/grad_latlon_cfd.shtml>
[3] CFD -> centered finite differences

;************************************************
; calculate vorticity on a rectilinear grid with missing values via CFD
;************************************************
  vr = *uv2vr_cfd*
<http://www.ncl.ucar.edu/Document/Functions/Built-in/uv2dv_cfd.shtml>(u,v,u&lat,u&lon,
2)
  copy_VarMeta(u,vr)
  vr at long_name = "vorticity"
  vr at units     = "per second"
  printVarSummary(vr)
  printMinMax(vr,0)
  print("-------------")

;************************************************
; calculate gradients on a rectilinear grid with missing values via CFD
;************************************************

  u_gradLatLon  = *grad_latlon_cfd *(u, u&lat, u&lon, True, False)
  dUdY  = u_gradLatLon[0]    ; for clarity; explicitly extract variables
from returned 'list'
  dUdX  = u_gradLatLon[1]
  delete(u_gradLatLon)

  dUdX at long_name = "longitudinal gradient of zonal wind U"
  dUdX at units     = "1/m"                                         ; ;
(m/s)*(1/m) = 1/m
  dUdY at long_name = "latitudinal gradient of zonal wind U"
  dUdY at units     = "1/m"
  printVarSummary(dUdX)
  printMinMax(dUdX,0)
  print("-------------")
  printVarSummary(dUdY)
  printMinMax(dUdY,0)
  print("-------------")

  v_gradLatLon  = *grad_latlon_cfd *(v, v&lat, v&lon, True, False)
  dVdY  = v_gradLatLon[0]    ; for clarity; explicitly extract variables
from returned 'list'
  dVdX  = v_gradLatLon[1]
  delete(v_gradLatLon)

  dVdX at long_name = "longitudinal gradient of meridional wind V"
  dVdX at units     = "1/m"                                           ;
(m/s)*(1/m) = 1/m
  dVdY at long_name = "latitudinal gradient of meridional wind V"
  dVdY at units     = "1/m"
  printVarSummary(dVdX)
  printMinMax(dVdX,0)
  print("-------------")
  printVarSummary(dVdY)
  printMinMax(dVdY,0)
  print("-------------")

On Wed, Mar 3, 2021 at 7:15 PM Lyndz <olagueralyndonmark429 at gmail.com>
wrote:

> Dear Sir Dennis,
>
> Thank you for this.
> My data has missing values, that's why  I used cfd.
>
> Sincerely,
>
> On Thu, Mar 4, 2021 at 7:28 AM Dennis Shea <shea at ucar.edu> wrote:
>
>>
>> Given the dimension sizes (73x144), I am sure the data are global.
>> In fact, a 2.5 degree grid. I speculate, it is ordered North-to-South.
>>
>> I am not sure why you used centered finite differences (cfd).
>> Of course, it can be done. However, it is recommended to use the "highly"
>> accurate spherical harmonic functions.
>> ===
>> Based on your script, try the following. **If ** your source grid is
>> ordered South-to-North, no reordering is needed. Skip that part.
>> ====
>>
>>   ufile  = addfile("uwnd_2008.nc","r")       ; open netcdf file
>>   u   = short2flt(ufile->uwnd(:,{925},:,:))                             ;
>> pull u off file
>>
>>   vfile  = addfile("vwnd_2008.nc","r")
>>   v   = short2flt(vfile->vwnd(:,{925},:,:))                             ;
>> pull v off file
>>
>> ;*******************************************************************
>> ; Spherical harmonics require the data to be South-to-North
>> ; Skip this step if source data are already South-to-North
>> ;******************************************************************
>>
>>   u = u(:,::-1,:)                  ; make grid South-to-North
>>   printVarSummary(u)
>>   printMinMax(u,0)
>>   print("-------------")
>>
>>   v = v(:,::-1,:)                  ; make grid South-to-North
>>   printVarSummary(v)
>>   printMinMax(v,0)
>>
>> ;*******************************************************************
>> ; calculate vorticity on a Global Fixed Grid via spherical harmonics
>> ;*******************************************************************
>>
>>   vr = uv2vrF_Wrap (u,v)
>>   printVarSummary(vr)
>>   printMinMax(vr,0)
>>   print("-------------")
>>
>>
>> ;**********************************************************************************
>> ; calculate wind component gradients on a Global Fixed Grid via spherical
>> harmonics
>>
>> ;**********************************************************************************
>>
>>   u_grad_lon = u                ; create arrays to hold output, same size
>> and type as input
>>   u_grad_lat = u
>>   gradsf (u, u_grad_lon, u_grad_lat)
>>   u_grad_lon at long_name = "U longitudinal gradient: dUdX"
>>   u_grad_lon at units     = "1/m"
>>   u_grad_lat at long_name = "U latitudinal gradient: dUdY"
>>   u_grad_lat at units     = "1/m"                        ; (m/s)*(1/m) = 1/m
>>   printVarSummary(u_grad_lon)
>>   printMinMax(u_grad_lon,0)
>>   print("-------------")
>>   printVarSummary(u_grad_lat)
>>   printMinMax(u_grad_lat,0)
>>   print("-------------")
>>
>>   v_grad_lon = v                ; create arrays to hold output, same size
>> and type as input
>>   v_grad_lat = v
>>   gradsf (v, v_grad_lon, v_grad_lat)
>>   v_grad_lon at long_name = "V longitudinal gradient: dVdX"
>>   v_grad_lon at units     = "1/m"
>>   v_grad_lat at long_name = "V latitudinal gradient: dVdY"
>>   v_grad_lat at units     = "1/m"
>>   printVarSummary(v_grad_lon)
>>   printMinMax(v_grad_lon,0)
>>   print("-------------")
>>   printVarSummary(v_grad_lat)
>>   printMinMax(v_grad_lat,0)
>>   print("-------------")
>>
>>
>> On Wed, Mar 3, 2021 at 10:35 AM Lyndz via ncl-talk <
>> ncl-talk at mailman.ucar.edu> wrote:
>>
>>> Dear. NCL-experts,
>>>
>>> I want to get the dV/dx and dU/dy when calculating the relative
>>> vorticity.
>>>
>>> I tried using the *center_finite_diff_n* but encountered this error:
>>>
>>> *fatal:center_finite_diff_n: r must either be a scalar, a 1D array the
>>> same length as the dim-th dimemsion of q, or the same size as q*
>>>
>>> *fatal:["Execute.c":8637]:Execute: Error occurred at or near line 39 in
>>> file orig_vort.ncl*
>>>
>>>
>>> Attached file is the script that I am using.
>>>
>>> The input file has the following dimension:
>>>
>>> *Dimensions and sizes: [time | 4] x [lat | 73] x [lon | 144]*
>>>
>>>
>>>
>>> I am using the lat and lon for dY and dX, respectively.
>>>
>>> I'll appreciate any help on this matter.
>>>
>>>
>>> Sincerely,
>>> Lyndz
>>> _______________________________________________
>>> 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/20210303/e9087f18/attachment.html>


More information about the ncl-talk mailing list