Turning off automatic prints from writeProduct()

Hi, simple question. Whenever I use writeProduct in snappy it automatically prints 100% done. This gets annoying since I’m going to write thousands of files. Is there a way to “mute” it? :slight_smile:

Edit I switched to using WriteOp after this, so the 100% done is gone but now instead I get things like:

INFO: org.esa.snap.core.gpf.common.WriteOp: Start writing product Subset_Subset_S1A_IW_GRDH_1SDH_20141107T045909_20141107T045934_003171_003A68_12E5_Orb_NR_Cal_Spk to data\s1_output\1415336349_56.9491_56.991_19.1516_19.2277
INFO: org.esa.snap.core.gpf.common.WriteOp: End writing product 1415336349_56.9491_56.991_19.1516_19.2277 to data\s1_output\1415336349_56.9491_56.991_19.1516_19.2277
INFO: org.esa.snap.core.gpf.common.WriteOp: Time: 0,022 s total, 0,054 ms per line, 0,000135 ms per pixel

is there a way to get rid of these? My question still remains for GPF.createProduct() as I realized later

Yes, this should be possible. I haven’t executed the following, but I think it will work.
I’m not sure if the NullOutputStream is accessible from Python, but it should.
This will disable any output.

System = jpy.get_type('java.lang.System')
PrintStream = jpy.get_type('java.io.PrintStream')
NullStream = jpy.get_type('org.apache.commons.io.output.NullOutputStream')

## disable System.out
System.setOut(new PrintStream(new NullStream ()))
## optionally disable System.err too
System.setErr(new PrintStream(new NullStream ()))

You can also disable only the logging (for your WriteOp case)
The following code should do it.

Logger = jpy.get_type('java.util.logging.Logger')
Level = jpy.get_type('java.util.logging.Level')
Logger.getLogger('').setLevel(Level.OFF)
snappy.SystemUtils.LOG.setLevel(Level.OFF)

Thank you Marco! This worked perfectly.

However, I have now started to encounter the memory issues I have read about on the forum from a couple of years ago. Has there been any updates regarding these issues? Here are some of the posts that I am referring to.

In my project I have to subdivide my image into thousands of smaller images (400x400) pixels and write these using WriteOp. I am currently creating the subsets using

def create_subset(source, x, y, x_offset, y_offset, copy_boolean):
    parameters = HashMap()
    parameters.put('copyMetadata', copy_boolean)
    parameters.put('region', '%s, %s, %s, %s' % (x, y, x_offset, y_offset))

    return GPF.createProduct("Subset", parameters, source)

and then writing them using

write_op = WriteOp(subset, File(output_name), 'GeoTIFF')
write_op.writeProduct(ProgressMonitor.NULL)
write_op.dispose()

I have seen the possible workaround using subprocesses, but I am mainly curious if there has been any general progress regarding this. Thank you!

In this direction no progress was made. It also depends which output format and input format you are using. It is not only snappys fault.

An additional hint. when you are done with one input product you can call
product.dispose(). This might help to reduce this issue.