Re: Error: scalar_field: If the input data is 1-dimensional, you must ...

From: Mary Haley <haley_at_nyahnyahspammersnyahnyah>
Date: Wed Jun 30 2010 - 10:20:14 MDT

On Jun 30, 2010, at 9:28 AM, Yi Wang wrote:

> Hi Mary,
>
> I tried
>
> data@lat=nlat
> data@lon=mlon
>
> or
>
> data@lat1d=nlat
> data@lon1d=mlon
>
> or
>
> res@sfXArray = lon
> res@sfYArray =colat,

None of the above will work.

The only "@" attribute recognized by the gsn_csm_xxx scripts
is lon2d and lat2d, and really, you can just use sfXArray
and sfYArray instead. I probably should have never implemented
the "@lat2d" and "@lon2d" method because it confuses people.

>
> but alway got error or warning messages, finally I tried
>
> data!0="lat"
> data!1="lon"
>
> data&lat=lat
> data&lon=lon
>

This will only work if your 1D arrays are actually coordinate arrays,
and you have a 2D array that you are plotting. In this case, the
length of lat will need to be the same length as the leftmost
dimension of your data, and lon will need to be the same length
as the rightmost dimension.

The original array you were trying to plot was 1D, but I see you are
plotting a different variable now.

--Mary

> Then it works.
>
> In addition, you are absolutely correct about using
>
> lat = 90. -lat
> lon = where(lon.gt.180,lon-360,lon)
>
> to replace the do loops.
>
> Thanks a lot for your help. :)
>
>
> Best,
> Yi
>
>
> On Wed, Jun 30, 2010 at 10:02 AM, Mary Haley <haley@ucar.edu> wrote:
> Good work Yi! Did Dennis help you with this? Did you just decide to
> try a different variable?
>
> --Mary
>
> On Jun 30, 2010, at 8:49 AM, Yi Wang wrote:
>
>> Hi Mary,
>>
>> Thank you very much for your help. Now it works. The codes are as
>> below.
>>
>> load "$NCARG_ROOT/lib/ncarg/nclex/gsun/gsn_code.ncl"
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
>>
>> hdf_file=addfile("CER_ES4_Aqua-FM3_Edition1-CV_024032.200908.hdf",
>> "r") ; Read file.
>> ; print(hdf_file) should be used to know something like hdf_file-
>> >Albedo__875
>>
>> data = hdf_file->Albedo__875
>>
>> data!0="lat"
>> data!1="lon"
>>
>> lat=hdf_file->Colatitude__875(:,0)
>> lon=hdf_file->Longitude__875(0,:)
>>
>> lat = 90. -lat
>> lon = where(lon.gt.180,lon-360,lon)
>>
>> lat@units="degrees_north"
>> lon@units="degrees_east"
>>
>> data&lat=lat
>> data&lon=lon
>>
>> xwks=gsn_open_wks("pdf","a") ; open workstation
>>
>> setvalues NhlGetWorkspaceObjectId() ; make maximum filesize larger
>> "wsMaximumSize" : 200000000
>> end setvalues
>> res=True ; plot mods desired
>>
>> res@cnFillOn=True ; enable contour fill
>> res@gsnMaximize=True; make plot large
>> res@gsnPaperOrientation = "portrait" ; force portrait orientation
>> res@cnLinesOn=False ; turn off contour lines
>> res@cnLineLabelsOn = False; turn off contour line labels
>> res@gsnSpreadColors=True ; use the entire color spectrum
>> res@cnFillMode="RasterFill" ; faster
>> res@lbOrientation = "vertical" ; vertical labels
>> res@cnMissingValFillPattern = 0 ; missing value pattern is set to
>> "SolidFill"
>> res@cnMissingValFillColor=0; white color for missing values
>> res@lbLabelAutoStride=True ; ensure labels do not overlap
>> res@gsnAddCyclic=False
>>
>> gsn_define_colormap(xwks,"BlAqGrYeOrReVi200") ; define colormap
>>
>> res@tiMainString = "CER_ES4_Aqua-FM3_Edition1-CV_024032.200908.hdf"
>> res@gsnLeftString = "FIELD NAME: Albedo"
>> res@gsnRightString = "UNITS: " + hdf_file->Albedo__875@units
>>
>> plot=gsn_csm_contour_map_ce(xwks,data,res) ; plot on world map first
>>
>> delete(plot) ; cleaning up resources used
>> delete(xwks)
>> delete(data)
>> delete(res)
>> delete(hdf_file)
>> end
>>
>> Best,
>> Yi
>>
>> On Tue, Jun 29, 2010 at 2:56 PM, Mary Haley <haley@ucar.edu> wrote:
>> You set sfXArray incorrectly and you didn't set sfYArray. You need
>> both of them:
>>
>> res@sfXArray = lon
>> res@sfYArray =colat
>>
>> The sfYArray array must be latitude values, and the sfXArray array
>> must be longitude values.
>>
>> However, as I pointed out before, your longitude values are all the
>> same, and NCL cannot contour data whose X or Y range is constant.
>>
>> --Mary
>>
>>
>>
>> On Jun 29, 2010, at 12:10 PM, Yi Wang wrote:
>>
>>> Hi Mary,
>>>
>>> Thanks for your help.
>>>
>>> Yes, I just used
>>>
>>> hdf_file=addfile("CER_ES4_Aqua-FM3_Edition1-CV_024032.200908.hdf",
>>> "r")
>>> print(hdf_file)
>>> to print out all the data.
>>>
>>> And I found:
>>>
>>> float Net_radiant_flux__899 ( 2_5_deg_zonal_colat_zones )
>>> _FillValue : 3.402823e+38
>>> valid_range : ( -200, 200 )
>>> long_name : 2.5 Degree Zonal, Monthly (Day), Total-sky Averages
>>> units : Watts per square meter
>>> hdf_name : Net radiant flux
>>> hdf_group : 2.5 Degree Zonal/Monthly (Day) Averages/Total-Sky
>>> hdf_group_id : 899
>>>
>>> and
>>>
>>> float Longitude__899 ( 2_5_deg_zonal_colat_zones )
>>> _FillValue : 3.402823e+38
>>> valid_range : ( 0, 360 )
>>> long_name : 2.5 Degree Zonal
>>> units : degrees
>>> hdf_name : Longitude
>>> hdf_group : 2.5 Degree Zonal/Monthly (Day) Averages/Total-Sky
>>> hdf_group_id : 899
>>>
>>> So I am sure this Longitude__899 corresponds to
>>> Net_radiant_flux__899 which is I want, and both of them belong to
>>> hdf_group : 2.5 Degree Zonal/Monthly (Day) Averages/Total-Sky.
>>>
>>> Anyway, I change my codes to this:
>>>
>>> load "$NCARG_ROOT/lib/ncarg/nclex/gsun/gsn_code.ncl"
>>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
>>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
>>>
>>> begin
>>>
>>> hdf_file=addfile("CER_ES4_Aqua-FM3_Edition1-CV_024032.200908.hdf",
>>> "r") ; Read file.
>>> ;print(hdf_file)
>>>
>>> data = hdf_file->Net_radiant_flux__899
>>>
>>> lat = 90. - hdf_file->Colatitude__899
>>> lat!0 = "lat"
>>> lat@units = "degrees_north"
>>> data!0 = "lat"
>>> data&lat = lat
>>>
>>> xwks=gsn_open_wks("pdf","a") ; open workstation
>>>
>>> setvalues NhlGetWorkspaceObjectId() ; make maximum filesize larger
>>> "wsMaximumSize" : 200000000
>>> end setvalues
>>>
>>> res=True ; plot mods desired
>>>
>>> res@sfXArray = lat
>>>
>>> res@cnFillOn=True ; enable contour fill
>>> res@gsnMaximize=True; make plot large
>>> res@gsnPaperOrientation = "portrait" ; force portrait orientation
>>> res@cnLinesOn=False ; turn off contour lines
>>> res@cnLineLabelsOn = False; turn off contour line labels
>>> res@gsnSpreadColors=True ; use the entire color spectrum
>>> res@cnFillMode="RasterFill" ; faster
>>> res@lbOrientation = "vertical" ; vertical labels
>>> res@cnMissingValFillPattern = 0 ; missing value pattern is set to
>>> "SolidFill"
>>> res@cnMissingValFillColor = 0; white color for missing values
>>> res@lbLabelAutoStride=True ; ensure labels do not overlap
>>>
>>> gsn_define_colormap(xwks,"BlAqGrYeOrReVi200") ; define colormap
>>>
>>> res@tiMainString = "CER_ES4_Aqua-FM3_Edition1-CV_024032.200908.hdf"
>>> res@gsnLeftString = "FIELD NAME: Net radiant flux"
>>> res@gsnRightString = "UNITS: " + hdf_file-
>>> >Net_radiant_flux__899@units
>>> res@gsnLeftStringFontHeightF=10 ; make text smaller
>>> res@gsnRightStringFontHeightF=10
>>> res@tiYAxisString = "Net radiant flux" ; create axis strings
>>> res@tiXAxisString = "latitude"
>>> res@tmYLFormat = "f" ; no unnecessary zeros
>>>
>>> plot=gsn_csm_contour(xwks,data,res) ; plot on world map first
>>>
>>> delete(plot) ; cleaning up resources used
>>> delete(xwks)
>>> delete(data)
>>> delete(res)
>>> delete(hdf_file)
>>> end
>>>
>>>
>>> But it still report me the following message:
>>>
>>> (0) Error: scalar_field: If the input data is 1-dimensional, you
>>> must set sfXArray and sfYArray to 1-dimensional arrays of the same
>>> length.warning:create: Bad HLU id passed to create, ignoring it
>>>
>>> Thanks a lot.
>>>
>>> Best,
>>> Yi
>>>
>>> On Tue, Jun 29, 2010 at 11:01 AM, Mary Haley <haley@ucar.edu> wrote:
>>> Yi,
>>>
>>> In order to plot random data, you must provide X, Y, Z 1D data Yis
>>> that are all the same length.
>>>
>>> Please see this page for examples on contouring 1D data:
>>>
>>> http://www.ncl.ucar.edu/Applications/contour1d.shtml
>>>
>>> I see that you attempted to do this (I think) with the following
>>> code:
>>>
>>> data@lat=nlat ; lat is reserved name
>>> data@lon=mlon ; lon is reserved name
>>>
>>> Setting "lat" and "lon" attributes has no meaning for the
>>> gsn_csm_xxx scripts. You may be thinking of "lat2d" and "lon2d",
>>> which do have
>>> some meaning, but these are for if you have 2D lat/lon coordinate
>>> arrays.
>>>
>>> With 1D data, you need to set the resources sfXArray and sfYArray
>>> to the corresponding 1D arrays for X and Y.
>>>
>>> I tried this with your code:
>>>
>>> res@sfXArray = lon
>>> res@sfYArray = colat
>>>
>>> but it failed because your "lon" values are all equal to 180.
>>>
>>> By the way, you have this code:
>>>
>>> nlat=new( (/n/), float )
>>> mlon=new( (/n/), float )
>>>
>>> do i = 0, n-1
>>> nlat(i) = 90. - colat(i)
>>> end do
>>>
>>> do i = 0, n-1
>>> mlon(i) = lon(i)
>>> if (mlon(i).gt.180)
>>> mlon(i) = mlon(i) - 360.
>>> end if
>>> end do
>>>
>>>
>>> You don't need to have do loops to accomplish all this. You can
>>> simply do this:
>>>
>>> nlat = 90. - colat
>>> mlon = where(lon.gt.180,lon-360,lon)
>>>
>>> You will still have a problem with "mlon" however, because it is
>>> still all equal to the same value. Are you sure that
>>> "Longitude__899" has the correct values on the file?
>>>
>>> --Mary
>>>
>>> On Jun 29, 2010, at 8:52 AM, Yi Wang wrote:
>>>
>>>> Hi Friends,
>>>>
>>>> I made some codes (in
>>>> CER_ES4_Aqua_FM3_Edition1_CV_024032_200908_Net_radiant_flux_2_5_deg_zon
>>>> .ncl, see attachment) to plot CER_ES4_Aqua-FM3_Edition1-
>>>> CV_024032.200908.hdf ( ftp://ftp.hdfgroup.uiuc.edu/pub/outgoing/veer/MAP_DATA/files/CERES/CER_ES4_Aqua-FM3_Edition1-CV_024032.200908.hdf
>>>> ).
>>>>
>>>> But I got the following message:
>>>> Error: scalar_field: If the input data is 1-dimensional, you must
>>>> set sfXArray and sfYArray to 1-dimensional arrays of the same
>>>> length. warning:create: Bad HLU id passed to create, ignoring it
>>>>
>>>> What should I do? Thanks a lot.
>>>>
>>>> Best,
>>>> Yi
>>>> <
>>>> CER_ES4_Aqua_FM3_Edition1_CV_024032_200908_Net_radiant_flux_2_5_deg_zon
>>>> .ncl>_______________________________________________
>>>> 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 Jun 30 10:20:22 2010

This archive was generated by hypermail 2.1.8 : Fri Jul 02 2010 - 07:45:13 MDT