Re: [gdal-dev] BandWriteArray and FlushCache question

2009-01-19 Thread Frank Warmerdam

Gong, Shawn (Contractor) wrote:

hi list,

I recently upgraded to gdal 1.6.0 and found that one Python function 
that used to work in 1.4.4 no longer works.


The purpose of function was to read in a band, perform matrix 
manipulation (in this case, subtract a baseline) and resave.


The error that I am getting is that in the new dataset the last hundreds 
of lines DN are written zero. If I take out the last line 
“self.balanced_ds.FlushCache()” then the entire dataset is written as 
zeros.  None of errors would happen in gdal 1.4.4.


Is there any changes in gdal 1.6.0 w.r.t. FlushCache() ?  What is the 
right way to perform this?

...

for block in range( nblocks ):

first_line = RCS_PROC_STEP*block

if block == nblocks - 1:

nlines = ysize - first_line

  

datablock = gdalnumeric.BandReadAsArray( bandobj, 0, first_line, 
xsize, nlines )


datablock = datablock - baseline

gdalnumeric.BandWriteArray( bandobj, 
datablock.astype(gdalnumeric.Int16), 0, first_line )


bandobj.FlushCache()

self.balanced_ds.FlushCache()


Shawn,

I'm not sure of any reason the script shouldn't work properly.  But I
will note that aspects of the TIFF file are only written out when the
file is closed.  You may find it helpful to do "self.balanced_ds = None"
at the end so that python will release the dataset and it can be closed.

I'm not sure of what environment you are running your script in.  Normally
at script end this would happen anyways.

Best regards,
--
---+--
I set the clouds in motion - turn up   | Frank Warmerdam, warmer...@pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush| Geospatial Programmer for Rent

___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/gdal-dev


RE: [gdal-dev] BandWriteArray and FlushCache question

2009-01-19 Thread Gong, Shawn (Contractor)
thanks Frank.

adding "self.balanced_ds = None" seems to do the trick.


Shawn



-Original Message-
From: gdal-dev-boun...@lists.osgeo.org
[mailto:gdal-dev-boun...@lists.osgeo.org] On Behalf Of Frank Warmerdam
Sent: Monday, January 19, 2009 4:03 PM
To: Gong, Shawn (Contractor)
Cc: gdal-dev@lists.osgeo.org
Subject: Re: [gdal-dev] BandWriteArray and FlushCache question

Gong, Shawn (Contractor) wrote:
> hi list,
> 
> I recently upgraded to gdal 1.6.0 and found that one Python function 
> that used to work in 1.4.4 no longer works.
> 
> The purpose of function was to read in a band, perform matrix 
> manipulation (in this case, subtract a baseline) and resave.
> 
> The error that I am getting is that in the new dataset the last
hundreds 
> of lines DN are written zero. If I take out the last line 
> "self.balanced_ds.FlushCache()" then the entire dataset is written as 
> zeros.  None of errors would happen in gdal 1.4.4.
> 
> Is there any changes in gdal 1.6.0 w.r.t. FlushCache() ?  What is the 
> right way to perform this?
...
> for block in range( nblocks ):
> 
> first_line = RCS_PROC_STEP*block
> 
> if block == nblocks - 1:
> 
> nlines = ysize - first_line
> 
>   
> 
> datablock = gdalnumeric.BandReadAsArray( bandobj, 0, first_line, 
> xsize, nlines )
> 
> datablock = datablock - baseline
> 
> gdalnumeric.BandWriteArray( bandobj, 
> datablock.astype(gdalnumeric.Int16), 0, first_line )
> 
> bandobj.FlushCache()
> 
> self.balanced_ds.FlushCache()

Shawn,

I'm not sure of any reason the script shouldn't work properly.  But I
will note that aspects of the TIFF file are only written out when the
file is closed.  You may find it helpful to do "self.balanced_ds = None"
at the end so that python will release the dataset and it can be closed.

I'm not sure of what environment you are running your script in.
Normally
at script end this would happen anyways.

Best regards,
-- 
---+
--
I set the clouds in motion - turn up   | Frank Warmerdam,
warmer...@pobox.com
light and sound - activate the windows | http://pobox.com/~warmerdam
and watch the world go round - Rush| Geospatial Programmer for Rent

___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/gdal-dev
___
gdal-dev mailing list
gdal-dev@lists.osgeo.org
http://lists.osgeo.org/mailman/listinfo/gdal-dev