Re: Problem writing masked array to netcdf

From: David Brown <dbrown_at_nyahnyahspammersnyahnyah>
Date: Mon Mar 26 2012 - 12:57:31 MDT

Hi Daniel,
I am not sure is happening here, but the PyNIO interface does not have a 'seek' method so I do not understand how that could possibly come into play. I think the best thing would be for you to upload your script and whatever input data file(s) it depends on, so that we can take a look. Thank you. Please upload to ftp.cgd.ucar.edu
login as anonymous with email as password
cd incoming
put the files

Then let me know the file names because this ftp site directory has 'ls' turned off for security reasons.
 -dave

On Mar 26, 2012, at 11:09 AM, Daniel Gilmore wrote:

> I think I may have figured out what is happening here.
>
> I've noticed in a few of my scripts, I have to close and re-open the grib2 file prior to reading new messages. I'm not sure why this is happening, or why a fix like grib2fh.seek(0) doesn't work. When I applied that fix to this code, the data reads cleanly and writes cleanly to the file.
>
> This isn't the first issue I've noticed with the file pointer in a grib2 file that was opened using PyNio, so you guys might have a bug. I'm using version 1.3.0b5.
>
> Dan
>
> On Fri, Mar 23, 2012 at 10:06 AM, Daniel Gilmore <daniel.gilmore@noaa.gov> wrote:
> Good morning.
>
> (I originally wrote this and it ended up mixed in with another thread, so I'm breaking it out into its own message. Sorry about the mix up.)
>
> I'm having an issue writing masked data to a netcdf file. I've read this section and applied the work-around to my code. The code to read and write the data looks like this:
>
> v = self.grib2fh.variables[grib2var]
> mv = v[:].data
> self.ncfh.variables[cdfvar].assign_value(mv)
>
> ...where grib2var is the grib2 variable name and cdfvar the corresponding cf-compliant variable name.
>
> When I read the value from the grib2 file, the data retrieved appears correct, but when I write to and then retrieve the data from the netcdf file, the data is all fill values and none of the data looks like it was written. I'm including the arrays for both below.
>
> Any thoughts?
>
> --------------------------------------------------------------
>
> (Pdb) self.grib2fh.variables[grib2var][:].data[0][186]
> array([ 1.00000002e+20, 1.00000002e+20, 1.00000002e+20,
> - - - repeated missing value data omitted for bevity - - -
> 1.00000002e+20, 1.00000002e+20, 1.00000002e+20,
> 1.00000002e+20, 1.00000002e+20, 1.00000002e+20,
> 1.00000002e+20, 1.00000002e+20, 2.84769989e+02,
> 2.84540009e+02, 2.84299988e+02, 2.89919983e+02,
> 2.90049988e+02, 2.90209991e+02, 2.90389984e+02,
> 2.90579987e+02, 2.90769989e+02, 2.92559998e+02,
> 2.92540009e+02, 2.92479980e+02, 2.91359985e+02,
> 2.91429993e+02, 2.91440002e+02, 2.91399994e+02,
> 2.91279999e+02, 2.87149994e+02, 2.86579987e+02,
> 2.86059998e+02, 2.85669983e+02, 2.85399994e+02,
> 2.85299988e+02, 2.85320007e+02, 1.00000002e+20,
> 1.00000002e+20, 1.00000002e+20, 1.00000002e+20,
> 1.00000002e+20, 1.00000002e+20, 1.00000002e+20,
> 1.00000002e+20, 1.00000002e+20, 1.00000002e+20,
> 1.00000002e+20, 1.00000002e+20, 1.00000002e+20,
> 1.00000002e+20, 1.00000002e+20, 1.00000002e+20,
> 1.00000002e+20, 1.00000002e+20], dtype=float32)
> (Pdb) self.ncfh.variables[cdfvar][:].data[0][186]
> array([ 1.00000002e+20, 1.00000002e+20, 1.00000002e+20,
> - - - repeated missing value data omitted for brevity - - -
> 1.00000002e+20, 1.00000002e+20, 1.00000002e+20,
> 1.00000002e+20, 1.00000002e+20, 1.00000002e+20,
> 1.00000002e+20, 1.00000002e+20, 1.00000002e+20,
> 1.00000002e+20, 1.00000002e+20, 1.00000002e+20,
> 1.00000002e+20, 1.00000002e+20, 1.00000002e+20,
> 1.00000002e+20, 1.00000002e+20, 1.00000002e+20,
> 1.00000002e+20, 1.00000002e+20, 1.00000002e+20,
> 1.00000002e+20, 1.00000002e+20, 1.00000002e+20,
> 1.00000002e+20, 1.00000002e+20, 1.00000002e+20,
> 1.00000002e+20, 1.00000002e+20, 1.00000002e+20,
> 1.00000002e+20, 1.00000002e+20, 1.00000002e+20,
> 1.00000002e+20, 1.00000002e+20, 1.00000002e+20,
> 1.00000002e+20, 1.00000002e+20, 1.00000002e+20,
> 1.00000002e+20, 1.00000002e+20, 1.00000002e+20,
> 1.00000002e+20, 1.00000002e+20, 1.00000002e+20,
> 1.00000002e+20, 1.00000002e+20, 1.00000002e+20,
> 1.00000002e+20, 1.00000002e+20, 1.00000002e+20,
> 1.00000002e+20, 1.00000002e+20, 1.00000002e+20,
> 1.00000002e+20, 1.00000002e+20, 1.00000002e+20,
> 1.00000002e+20, 1.00000002e+20, 1.00000002e+20,
> 1.00000002e+20, 1.00000002e+20], dtype=float32)
>
> --
> --
> Daniel Gilmore (AceInfo Solutions)
> PGB/MDL/OST/NWS/NOAA
> Office #: SSMC2-10357
> Phone: 301.713.0224 x101
> Cell: 703.232.9603
>
>
>
> --
> --
> Daniel Gilmore (AceInfo Solutions)
> PGB/MDL/OST/NWS/NOAA
> Office #: SSMC2-10357
> Phone: 301.713.0224 x101
> Cell: 703.232.9603
> _______________________________________________
> pyngl-talk mailing list
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/pyngl-talk

_______________________________________________
pyngl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/pyngl-talk
Received on Mon Mar 26 12:57:40 2012

This archive was generated by hypermail 2.1.8 : Wed Apr 11 2012 - 14:41:42 MDT