[ncl-talk] sub: read ascii error
Dennis Shea
shea at ucar.edu
Tue Mar 30 16:52:36 MDT 2021
@dale zuri <dalezuri at gmail.com>
As noted, you must provide more information. ncl-talk should not have to
determine the structure of your data.
The *readAsciiTable* assumes that each column contains separate variables.
The avhrr_seaice file's columns are not separate values.
ngrid_pts=720*1440 = 1036800
It turns out there are 2 grids
The file structure is:
[1] header line with two values: 720 1440
[2] nlat=720 latitude values [left to right]
[3] mlon=1440 longitude values
[4] 2 successive grids of nlat*mlon values
The first line:
1 720 1440
The columns are not separate variables. Rather, going left to right, these
are the 720 latitude grid coordinates.
2 -89.8750 -89.6250 -89.3750 -89.1250 -88.8750
-88.6250
3 -88.3750 -88.1250 -87.8750 -87.6250 -87.3750
-87.1250
[snip]
61 -1.37500 -1.12500 -0.875000 -0.625000 -0.375000
-0.125000
62 0.125000 0.375000 0.625000 0.875000 1.12500
1.37500
[snip]
120 87.1250 87.3750 87.6250 87.8750 88.1250
88.3750
121 88.6250 88.8750 89.1250 89.3750 89.6250
89.8750
Followed immediately, by 1440 longitude grid coordinates:
122 0.125000 0.375000 0.625000 0.875000 1.12500
1.37500
123 1.62500 1.87500 2.12500 2.37500 2.62500
2.87500
[snip]
360 357.125 357.375 357.625 357.875 358.125
358.375
361 358.625 358.875 359.125 359.375 359.625
359.875
Then the data values. Likely, -9999.00 is an _FillValue (missing value)
362 -9999.00 -9999.00 -9999.00 -9999.00 -9999.00
-9999.00
363 -9999.00 -9999.00 -9999.00 -9999.00 -9999.00
-9999.00
[snip
The first non-missing values are at:
11279 -9999.00 -9999.00 -9999.00 -9999.00 -9999.00
-9999.00
11280 -9999.00 -9999.00 -9999.00 -9999.00 -9999.00
73.1283
11281 72.8258 72.7936 71.9907 71.9810 71.5007
71.5007
11282 70.9247 70.9355 71.1821 71.1821 71.2308
71.2523
[snip]
11293 89.3143 89.4753 89.5369 89.2018 88.8201
88.7093
11294 89.1968 -9999.00 -9999.00 -9999.00 -9999.00
-9999.00
11295 -9999.00 -9999.00 -9999.00 -9999.00 -9999.00
-9999.00
[snip]
11532 65.7548 66.1178 66.4644 87.9502 88.4724
88.9699
11533 89.3143 89.4753 89.5369 89.2018 88.8201
88.7093
11534 89.1968 -9999.00 -9999.00 -9999.00 -9999.00
-9999.00
=============================================================
diri = "./"
fili = "avhrr_seaice"
pthi = diri + fili
data = asciiread(pthi,-1,"float")
nlat = 720
mlon = 1440
nStrt = (nlat+mlon) + 2 ; 2160 lat/lon values +2: first
line: 720,1440
print("nStrt="+nStrt)
seaice = onedtond( data(nStrt:), (/2,nlat,mlon/)) ; skip the 1st 2162
values
lat = latGlobeFo(nlat, "lat", "latitude", "degrees_north")
lon = lonGlobeFo(mlon, "lon", "longitude", "degrees_east")
printVarSummary(lat)
printVarSummary(lon)
seaice!0 = "season"
seaice!1 = "lat"
seaice&lat = lat
seaice!2 = "lon"
seaice&lon = lon
seaice at long_name = "Seaice"
seaice at units = "%"
seaice at _FillValue = -9999.0
printVarSummary(seaice)
printMinMax(seaice,0)
~
~
On Tue, Mar 30, 2021 at 1:51 PM Alessandra Giannini via ncl-talk <
ncl-talk at mailman.ucar.edu> wrote:
>
> ok, thanks. more questions —
>
> So, “data” is a matrix of dimensions 345960 by 6.
>
> 1) what is the 6 dimension? what are the 6 "fields"?
>
> 2) regarding the 345960 dimension —
> nlat x nlon = 720x1440 = 1036800, which is larger than 345960.
> So, each one of the 6 dimensions cannot be a map, given the nlat and nlon
> dimension you specify.
>
> I give up!
>
>
>
>
>
> On Mar 30, 2021, at 2:41 PM, dale zuri via ncl-talk <
> ncl-talk at mailman.ucar.edu> wrote:
>
>
>
> ---------- Forwarded message ---------
> From: dale zuri <dalezuri at gmail.com>
> Date: Tue, Mar 30, 2021 at 12:36 PM
> Subject: Re: [ncl-talk] sub: read ascii error
> To: Alessandra Giannini <alesall at iri.columbia.edu>
>
>
> Hi,
> Thanks for your response.
> Variable: data
> Type: float
> Total Size: 8303040 bytes
> 2075760 values
> Number of Dimensions: 2
> Dimensions and sizes: [345960] x [6]
> Coordinates:
> Number Of Attributes: 1
>
> On Tue, Mar 30, 2021 at 12:00 PM Alessandra Giannini <
> alesall at iri.columbia.edu> wrote:
>
>>
>>
>> Hi there,
>>
>> can you print out:
>>
>> printVarSummary(data)
>>
>> ?
>>
>> are lat and lon really included in the matrix called “data”?
>> The way you define “templat” and “templon”, they should have the same
>> dimension. (Is said dimension nlat x nlon?)
>>
>> At any rate, lon and lat should be 1-dimensional.
>>
>> Rule #0 of ncl-talk is that you should have an idea of the structure of
>> your data…
>> Maybe you do, but you are not telling us!
>>
>> warm regards, alessandra
>>
>>
>>
>>
>>
>> On Mar 30, 2021, at 1:45 PM, dale zuri via ncl-talk <
>> ncl-talk at mailman.ucar.edu> wrote:
>>
>> Hi Adam,
>> I would appreciate any help to plot this ASCII data.
>>
>> Thanks
>> DZ
>>
>>
>> ---------- Forwarded message ---------
>> From: dale zuri <dalezuri at gmail.com>
>> Date: Tue, Mar 30, 2021 at 10:24 AM
>> Subject: sub: read ascii error
>> To: Ncl-talk <ncl-talk at ucar.edu>
>>
>>
>> Dear NCL user,
>> I would appreciate any help to plot this data. I'm getting this error.
>>
>> Thanks in advance
>> DZ
>>
>> fatal:Variable (lat) is undefined
>> fatal:["Execute.c":8637]:Execute: Error occurred at or near line 18 in
>> file test.ncl
>>
>>
>>
>>
>> begin
>> nlat=720
>> nlon=1440
>>
>> ncol = 6
>> nhead = 1
>>
>> fname = "avhrr_seaice"
>> data = readAsciiTable("avhrr_seaice", ncol, "float", nhead)
>> temp12D = onedtond(data(2,:),(/nlat,nlon/)) ; convert 1D array to a 2D
>> array
>> temp22D = onedtond(data(3,:),(/nlat,nlon/)) ; convert 1D array to a 2D
>> array
>> templat = data(0,:) ; convert 1D array to a 2D array
>> templon = data(1,:) ; convert 1D array to a 2D array
>> ; Assign named dimensions
>> temp12D!0 = "lat"
>> temp12D!1 = "lon"
>> temp12D&lat = templat ; assign coord variables
>> temp12D&lon = templon
>> temp22D!0 = "lat"
>> temp22D!1 = "lon"
>> temp22D&lat = templat ; assign coord variables
>> temp22D&lon = templon
>> temp12D&lat at units = "degrees_north"
>> temp12D&lon at units = "degrees_east"
>> temp22D&lat at units = "degrees_north"
>> temp22D&lon at units = "degrees_east"
>> ; Assign coordinate variables
>> printVarSummary(temp12D)
>> printVarSummary(temp22D)
>>
>> wks = gsn_open_wks("x11","test") ; send graphics to PNG file
>>
>> plot = new(2,graphic)
>> cmap = read_colormap_file("UKM_hadcrut"); choose colormap
>> ;
>>
>> res = True ; plot mods desired
>> res at cnFillOn = True ; turn on color
>> ;res at mpShapeMode = "FreeAspect"
>> res at vpWidthF = 0.3
>> res at vpHeightF = 0.2
>> ; res at cnFillPalette 2 = "grads_rainbow" ; choose colormap
>> res at cnFillPalette = cmap ; choose colormap
>> res at gsnPolar = "NH" ; specify the hemisphere
>> res at gsnDraw = False
>> res at gsnFrame = False
>> res at gsnTickMarksOn = False
>> res at mpMinLatF = 50 ; specify min lat
>> ; res at mpMinLatF = minlatt ; specify min lat
>> ;res at mpMaxLatF = maxlatt
>> res at trGridType = "TriangularMesh"
>> res at cnLinesOn = False ; True is default
>> ;res at mpFillOn = False ; turns off continent gray
>> res at cnLineLabelsOn = False ; True is default
>> res at mpGridAndLimbOn = False
>> res at mpLabelFontHeightF = "22"
>> res at mpPerimLineThicknessF = 2
>> res at mpOutlineOn = True
>> ; res at mpLandFillColor = "tan"
>> ;res at tiMainString = ""+type+"-"+mon+""
>> res at lbLabelBarOn = False ; turn off individual lb's
>>
>> res at gsnLeftString = "" ; no titles
>> res at gsnRightString = ""
>> res at tiXAxisString = ""
>> res at tiYAxisString = ""
>> res at cnLevelSelectionMode = "ManualLevels" ; set manual contour
>> levels
>> res at cnMinLevelValF = 0;0 ; set min contour level
>> res at cnMaxLevelValF = 100 ;6 ; set max contour
>> level
>> res at cnLevelSpacingF = 10;0.5 ; set contour spacing
>>
>>
>> ;res at lbOrientation = "Horizontal"
>> ;res at lbLabelFontHeightF = 0.014
>> ;res at lbLabelFont = "22"
>> ; res at lbTitleString = ""+type+""
>> ; res at lbTitleString = " (deg C)" ; bar title
>> ; res at lbTitlePosition = "Right" ; title
>> location
>> ; res at lbTitleDirection = "Across" ; letter
>> angle
>> ; res at lbTitleAngleF = 90. ; title
>> angle
>> ; res at lbTitleFontHeightF = 0.02 ; font
>> height
>> res at gsnStringFont = "helvetica-bold" ; will be used for
>> gsnCenterString later
>> res at gsnCenterStringFontHeightF = 0.014
>> res at gsnCenterString = "NDJFM"
>> plot(0) = gsn_csm_contour_map_polar(wks,temp12D(:,0),res)
>> res at gsnCenterString = "JJAS"
>> plot(1) = gsn_csm_contour_map_polar(wks,temp22D(:,1),res)
>> ;********************************
>> ;;;;;Contour plot;;;;;;;;;;;;;;;
>> ;********************************
>> ; panel plot only resources
>> ;********************************
>> ; panel plot only resources
>> ; panel plot only resources
>> resP = True ; modify the panel plot
>> resP at gsnMaximize = True ; large format
>> resP at gsnPanelLabelBar = True ; add common colorbar
>> resP at lbLabelFontHeightF = 0.012
>> resP at gsnPanelBottom = 0.2;;;increases figure size
>> ; shrink panel plot by setting bottom edge of plot
>> resP at gsnPanelTop = 0.9 ; shrink panel plot by
>> setting top edge of plot
>> resP at pmLabelBarWidthF = 0.50 ; make thinner/small
>> number
>> ; resP at pmLabelBarHeightF = 0.05
>> resP at pmLabelBarHeightF = 0.08
>> resP at pmLabelBarOrthogonalPosF = -0.016
>> ; resP at gsnPanelYWhiteSpacePercent = 5. ; increase spacing
>> along Y-axis between panel plots
>> resP at gsnPanelYWhiteSpacePercent = 2;;increases the figure size
>> ; increase spacing along Y-axis between panel plots
>> res at lbLabelFontHeightF = 0.018
>> resP at lbLabelFont = "22"
>> ; resP at lbTitleString = ""+tic+""
>> resP at cnLinesOn = False ; turn off contour lines
>> resP at lbLabelFont = "helvetica-bold" ; add common colorbar
>> resP at lbTitleFont = "helvetica-bold" ; add common colorbar
>> resP at lbTitleFontHeightF= .015 ; make title smaller
>> resP at cnLineLabelsOn = False
>> resP at txFontHeightF = 0.03
>> resP at txFont = "helvetica-bold"
>>
>> gsn_panel(wks,plot,(/1,2/),resP)
>> ;---This will maximize the size of all the paneled stuff.
>> ;end do
>>
>> end
>> _______________________________________________
>> ncl-talk mailing list
>> ncl-talk at mailman.ucar.edu
>> List instructions, subscriber options, unsubscribe:
>> https://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>
>>
>> _______________________________________________
> ncl-talk mailing list
> ncl-talk at mailman.ucar.edu
> List instructions, subscriber options, unsubscribe:
> https://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
> _______________________________________________
> 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/20210330/133575f1/attachment.html>
More information about the ncl-talk
mailing list