Re: Calculate differences between two data sets

From: David Brown <dbrown_at_nyahnyahspammersnyahnyah>
Date: Thu Oct 10 2013 - 13:16:17 MDT

Hi Lifen,
I only looked into the reasons why your script was not executing. I removed the characters using a text editor. I can't remember if I used vi or emacs, but I just used normal text editing actions to delete the characters.
Perhaps you use some other text editor that doesn't show these characters. In vi or emacs it looks like this (on my Mac):

  printVarSummary(t1)
  
    t1@_FillValue = 999
    t1@missing_value = t1@_FillValue
    t1 = where(t1 .eq. 0, t1@_FillValue, t1)
  

whereas in the Mac TextEdit tool it appears like this:

같 printVarSummary(t1)
같같
    t1@_FillValue = 999
    t1@missing_value = t1@_FillValue
    t1 = where(t1 .eq. 0, t1@_FillValue, t1)
같같

1e+20 is the original _FillValue for your t2 variable. It should get propagated as the _FillValue of the result, but it appears not to be behaving correctly. I will investigate this.
Meantime, in order to work around this, assign the t2 _FillValue to the t1 variable prior to the subtraction.
Using dble2flt works for me. Here is a new version of the script that should give you what you want (although you might want to reassign the missing_value attribute to match the _FillValue -- or just delete it).

    load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"

    f1 = addfile("Regrid.Revised.nc", "r")
    f2 = addfile("regrid_2000_bcc-csm1-1.nc", "r")

    t1 = dble2flt(f1->regrid) ; t1(lat,lon)
    t2 = f2->regrid ; t2(lat,lon)
    printVarSummary(t1)
    printVarSummary(t2)

    t1@_FillValue = t2@_FillValue
    t1 = where(t1 .eq. 0, t1@_FillValue, t1)

    printMinMax(t1,0)
    printMinMax(t2,0)
    d = t2 - t1 ; difference
    copy_VarMeta (t1, d)
    d@long_name = "diff"
    printVarSummary(d)
    print("d: min="+min(d)+" max="+max(d))

    system("/bin/rm -f Diff_BCC.nc")
    fout = addfile("Diff_BCC.nc", "c") ; new netCDF file
    fout@title = "Difference"
    fout->DIFF = d

-dave

 

On Oct 9, 2013, at 9:13 PM, "Jiang, Lifen" <lfjiang@ou.edu> wrote:

> Dear Dave,
>
> Thank you for checking my data! Yes, it did the calculations. However, lat and lon were lost. I tried Dennis suggestion with "dble2flt" but still no lat and lon.
>
> And, max=1e+20 is not realistic for my data. Max value should be less than 20.
>
> In addition, I didn't find where you have modified to remove the characters but it did work. Could you please give me any clues? This is for potential use in future.
>
> Thanks again,
>
> Lifen
>
>
>
>
> From: David Brown [dbrown@ucar.edu]
> Sent: Wednesday, October 09, 2013 6:28 PM
> To: Jiang, Lifen
> Cc: ncl-talk@ucar.edu USERS
> Subject: Re: Calculate differences between two data sets
>
> Hi Lifen,
> You have non-standard characters in your source file. Character value 241 occurs about 10 times in the file. NCL can only handle standard 7-bit ascii characters. The first occurrence of these
> characters is just before the first printVarSummary call. Since NCL does not understand these characters and they are not part of the regular syntax, it just exits. I am not sure whether we can
> modify NCL to generate a warning in this case. But the fix is just to eliminate them. I am attaching a revised version of your script with these characters removed. It seems to work fine.
> -dave
> _______________________________________________
> 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 Thu Oct 10 13:16:28 2013

This archive was generated by hypermail 2.1.8 : Tue Oct 22 2013 - 10:35:27 MDT