pytroll / pytroll-examples

Collection of examples for pytroll satellite data processing
GNU General Public License v3.0
76 stars 34 forks source link

Add Introduction to MTSAT readers #8

Closed sfinkens closed 5 years ago

sfinkens commented 5 years ago

Belongs to https://github.com/pytroll/satpy/pull/524

mraspaud commented 5 years ago

I found this tool a while ago https://github.com/arve0/ipynbcompress. I had to tweak it a bit, but it's quite nice to reduce the size of the notebook (mostly images). Maybe it should be tested on this ?

sfinkens commented 5 years ago

For sure! I will have a look

mraspaud commented 5 years ago

Here are the changes I had to make to the ipynbcompress code to make it work:

--- a/ipynbcompress/ipynbcompress.py
+++ b/ipynbcompress/ipynbcompress.py
@@ -53,6 +53,10 @@ def compress(filename, output_filename=None, img_width=2048, img_format='png'):
                     new_size = [int(s*factor+0.5) for s in img.size]
                     img = img.resize(new_size)
                 out = BytesIO()
+                if img.mode == 'RGBA':
+                    bgimg = Image.new('RGBA', new_size, (255, 255, 255, 255))
+                    bgimg.paste(img, mask=img)
+                    img = bgimg.convert('RGB')
                 img.save(out, img_format)
                 out.seek(0)
                 mime = 'image/' + img_format
diff --git a/scripts/ipynb-compress b/scripts/ipynb-compress
index 5304001..9c0e2c5 100755
--- a/scripts/ipynb-compress
+++ b/scripts/ipynb-compress
@@ -1,7 +1,8 @@
 #!/usr/bin/env python
 # encoding: utf-8

-import climate
+#import climate
+import sys
 from ipynbcompress import compress
 from hurry.filesize import size, verbose
 from tempfile import mkstemp
@@ -9,11 +10,7 @@ from shutil import copyfile
 from os import close, remove
 from sys import exit

-@climate.annotate(
-    img_width=('image width', 'option', 'w'),
-    img_format=('image compression; png or jpeg', 'option', 'f')
-)
-def main(filename, output_filename=None, img_width=2048, img_format='png'):
+def main(filename, output_filename=None, img_width=2048, img_format='jpg'):
     """Compress images in IPython notebooks.

     filename : Notebook to compress. Will take any notebook format.
@@ -60,4 +57,5 @@ def main(filename, output_filename=None, img_width=2048, img_format='png'):
         print('ipynb-compress: error: %s file not found' % filename)

 if __name__ == '__main__':
-    climate.call(main)
+    #climate.call(main)
+    main(sys.argv[1])
diff --git a/setup.py b/setup.py
index 628e07c..afb0a9a 100755
--- a/setup.py
+++ b/setup.py
@@ -32,7 +32,7 @@ setup(
         'Pillow',
         'jsonschema',
         'ipython',
-        'climate',
+        #'climate',
         'hurry.filesize'
     ],
     license='MIT',
sfinkens commented 5 years ago

@mraspaud Perfect, thanks!

sfinkens commented 5 years ago

@mraspaud Ok, done! Compressed the GOES & MTSAT introductions and reduced the image size of the corresponding mosaics. Total size is now 2MB less than the current master.

mraspaud commented 5 years ago

Perfect, thanks a lot!