Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Introduction to MTSAT readers #8

Merged
merged 10 commits into from
Jan 7, 2019
Merged

Conversation

sfinkens
Copy link
Member

@sfinkens sfinkens commented Dec 3, 2018

Belongs to pytroll/satpy#524

@mraspaud
Copy link
Member

mraspaud commented Dec 7, 2018

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
Copy link
Member Author

sfinkens commented Dec 7, 2018

For sure! I will have a look

@mraspaud
Copy link
Member

mraspaud commented Dec 7, 2018

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
Copy link
Member Author

sfinkens commented Dec 7, 2018

@mraspaud Perfect, thanks!

@sfinkens
Copy link
Member Author

sfinkens commented Jan 7, 2019

@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
Copy link
Member

mraspaud commented Jan 7, 2019

Perfect, thanks a lot!

@mraspaud mraspaud merged commit 4ffbdf4 into pytroll:master Jan 7, 2019
djhoese pushed a commit that referenced this pull request Aug 17, 2020
Add Introduction to MTSAT readers
djhoese pushed a commit that referenced this pull request Aug 17, 2020
Add Introduction to MTSAT readers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants