[ncl-talk] convert the double missing_value to float one

Rick Brownrigg brownrig at ucar.edu
Mon Jun 19 09:38:03 MDT 2017


Hi,

I'm having trouble reproducing the situation. However, you have these lines:

   p8 at missing_value=doubletofloat(p8 at missing_value)

   p8 at _FillValue = p8 at missing_value

   delete(p8 at missing_value)

In my tests, it was possible to delete the missing_value attribute first,
and then reassign it as a float value.  Note that the line:

p8 at missing_value=doubletofloat(p8 at missing_value)

would not work, because as written, the missing_value is of type double,
and even through doubletofloat() would return a float, the assignment would
coerce it back to double.  I think you need to delete the attribute and
recreate it.

Rick


On Mon, Jun 19, 2017 at 1:04 AM, Beáta Szabó-Takács <szabo.b at czechglobe.cz>
wrote:

> Dear NCL Users,
>
>
>
> I would like to create a taylor_metrics_table where the missing values are
> denoted by -999. This part of script is:
>
>
>
>   season    = (/ "DJF","JJA" /)
>
>   nSeason   = dimsizes(season)
>
>
>
>   table     = new ( (/nCase,nSeason,nSource/), typeof(ratio) )
>
>   table(0,:,:) = (/CA_bias, CA_biasn/)
>
>   table(1,:,:) = (/CB_bias, CB_biasn/)
>
>   table(2,:,:) = (/CC_bias, CC_biasn/)
>
>   table(3,:,:) = (/CD_bias, CD_biasn/)
>
>
>
>
>
>   tt_opt        = True
>
>   tt_opt at tableTitle  =  "Bias(%)"
>
>   tt_opt at pltType= "png"                  ; "eps" [default], "pdf", "ps"
>
>                                          ; "png", "gif" [if you have
> ImageMajik 'convert']
>
> ;  tt_opt at color0 = "palegreen2"
>
> ;  tt_opt at color1 = "tomato2"
>
>   tt_opt at color0 = "white"
>
>   tt_opt at color1 = "white"
>
>
>
>
>
>   taylor_metrics_table("taylor_bias_dry", source, case ,season, table,
> tt_opt)
>
>
>
> I have some netcdf files where the precipitation (pr) values are float
> data type, but the _FillValue and missing_value are double. I tried convert
> these data to float with:
>
>
>
> ncap2 -s 'pr=float(pr)' CM5A-MR_RCA4_dry_power_sm.nc
> CM5A-MR_RCA4_dry_power_sm2.nc
>
>
>
> It converted the _FillValue to float but the missing_value are still
> double:
>
> netcdf CM5A-MR_RCA4_dry_power_sm2 {
>
> dimensions:
>
>         time = UNLIMITED ; // (4 currently)
>
>         latitude = 201 ;
>
>         longitude = 464 ;
>
> variables:
>
>         float pr(time, latitude, longitude) ;
>
>                 pr:_FillValue = -999.f ;
>
>                 pr:cell_methods = "time: mean" ;
>
>                 pr:long_name = "precipitation" ;
>
>                 pr:missing_value = -999. ;
>
>                 pr:standard_name = "precipitation_flux" ;
>
>                 pr:units = "mm" ;
>
>         float longitude(longitude) ;
>
>                 longitude:standard_name = "longitude" ;
>
>                 longitude:long_name = "longitude" ;
>
>                 longitude:units = "degrees_east" ;
>
>                 longitude:axis = "X" ;
>
>         float latitude(latitude) ;
>
>                 latitude:standard_name = "latitude" ;
>
>                 latitude:long_name = "latitude" ;
>
>                 latitude:units = "degrees_north" ;
>
>                 latitude:axis = "Y" ;
>
>         double time(time) ;
>
>                 time:standard_name = "time" ;
>
>                 time:long_name = "time" ;
>
>                 time:units = "days since 1949-12-1 00:00:00" ;
>
>                 time:calendar = "standard" ;
>
>                 time:axis = "T" ;
>
>
>
> The resulted table is attached. In the table the missing values are
> denoted by double values in CD_biasn despite the fact  that the printed
> CD_biasn contains _FillValues:
>
>
>
> Variable: CD_biasn
>
> Type: float
>
> Total Size: 20 bytes
>
>             5 values
>
> Number of Dimensions: 1
>
> Dimensions and sizes:   [5]
>
> Coordinates:
>
> Number Of Attributes: 1
>
>   _FillValue :  -999
>
> (0)     -999
>
> (1)     -4.541727
>
> (2)     12.45617
>
> (3)     10.47692
>
> (4)     -999
>
>
>
> I also tried to convert the missing values to float type by ncl
> doubletofloat function but it does not work:
>
>
>
> p8 at missing_value=doubletofloat(p8 at missing_value)
>
>    p8 at _FillValue = p8 at missing_value
>
>    delete(p8 at missing_value)
>
>
>
> fatal:Type Mismatch: The type of missing value could not be converted to
> type of variable (p8)
>
>
>
>    p8_out = addfile("p8.nc","c")
>
>    p8_out ->p8 = p8
>
>
>
>
>
> ncdump -h p8.nc
>
> netcdf p8 {
>
> dimensions:
>
>         time = 4 ;
>
>         latitude = 201 ;
>
>         longitude = 464 ;
>
> variables:
>
>         float p8(time, latitude, longitude) ;
>
>                 p8:_FillValue = -999.f ;
>
>                 p8:cell_methods = "time: mean" ;
>
>                 p8:long_name = "precipitation" ;
>
>                 p8:missing_value = -999. ;
>
>                 p8:standard_name = "precipitation_flux" ;
>
>                 p8:units = "mm" ;
>
>         double time(time) ;
>
>                 time:standard_name = "time" ;
>
>                 time:long_name = "time" ;
>
>                 time:units = "days since 1949-12-1 00:00:00" ;
>
>                 time:calendar = "standard" ;
>
>                 time:axis = "T" ;
>
>         float latitude(latitude) ;
>
>                 latitude:standard_name = "latitude" ;
>
>                 latitude:long_name = "latitude" ;
>
>                 latitude:units = "degrees_north" ;
>
>                 latitude:axis = "Y" ;
>
>         float longitude(longitude) ;
>
>                 longitude:standard_name = "longitude" ;
>
>                 longitude:long_name = "longitude" ;
>
>                 longitude:units = "degrees_east" ;
>
>                 longitude:axis = "X" ;
>
> }
>
>
>
>
>
> Can someone suggest me a solution?
>
> Thank you for your help in advance!
>
> Kind regards,
>
> Beata
>
>
>
> _______________________________________________
> 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/20170619/b3337dd0/attachment.html 


More information about the ncl-talk mailing list