JiaweiZhuang / xESMF

Universal Regridder for Geospatial Data
http://xesmf.readthedocs.io/
MIT License
269 stars 49 forks source link

Print Statement Suppression #77

Closed jejjohnson closed 4 years ago

jejjohnson commented 4 years ago

Hi,

First of all, I really like this package. Thank you for making it easier for beginners to use regrid functions without all of the boilerplate stuff that's needed. Super useful.

I was wondering if there was a way to suppress the print statements of the regridding method? Perhaps we can add a verbose argument if such a way doesn't already exists?

Example

Code snippet to reproduce

reference_ds = gpp_data_low
method = 'nearest_s2d'

# initialize regridder
regridder = xe.Regridder(
    gpp_data_hi,       # DataArray to be converted
    gpp_data_low,      # reference DataArray
    method=method,
)

# regrid new dataset
gpp_new = regridder(gpp_data_hi.compute())

Output

Overwrite existing file: nearest_s2d_432x936_144x312.nc 
 You can set reuse_weights=True to save computing time.

Expected Behavior

Nothing unless prompted.

System information

Please complete the following information:

JiaweiZhuang commented 4 years ago

Glad that you find xesmf useful!

One possible fix is to change print to warnings.warn, which can be disabled by warnings.filters.

Such printing will no longer exist with the new regridder save-load API #75, so the current sub-optimal API is probably not worth fixing...

jejjohnson commented 4 years ago

Thank you for the response! I agree; since the API will change then it's probably not worth fixing.

Thank you again!

hdrake commented 4 years ago

I found this as a neat temporary solution for suppressing print statements from regridder until the API changes go through.