Support the Arctic Sea Ice Forum and Blog

Author Topic: Creating Animated GIFs  (Read 78974 times)

uniquorn

  • Nilas ice
  • Posts: 2476
    • View Profile
  • Liked: 1341
  • Likes Given: 221
Re: Creating Animated GIFs
« Reply #100 on: July 06, 2019, 03:44:13 PM »
Let me know if you keep getting stuck in the same place. It's easy to miss out a step when writing instructions. Adjusting contrast before rgb compose may have a more striking effect, but only you know what you're aiming for :)

petm

  • Grease ice
  • Posts: 675
    • View Profile
  • Liked: 330
  • Likes Given: 27
Re: Creating Animated GIFs
« Reply #101 on: July 22, 2019, 01:47:22 AM »
Following up on: https://forum.arctic-sea-ice.net/index.php/topic,2591.msg214848.html#msg214848 . Not sure if this is the best thread for this, since I actually just use EZGif's website to make the GIFs once I've created the images, but it can always be moved if appropriate...

Repeating the summary from the thread above:
Quote
I do it using the imageJ API (Java code), basically by: for each day, reading in the 5 preceding days' images, converting each pixel color to a concentration value based on the Bremen key, taking the median for each pixel, then creating a new image. (Actually, the algorithm is easily changed -- 5 day median is quite conservative.)

The code is a bit of a hack, so I'll just post some snippets:

0. Make a key to convert colors to concentrations. The key was made by using the ImageJ GUI to manually pick indices corresponding to each color in the key of one particular image. (ImageJ LUT objects store pixel values as a 1d array; indices refer to that array.)
Quote
int[] concBuckets = {10, 20, 30, 40, 50, 60, 70, 80, 85, 90, 95, 99,100};
int[] indices = {14, 84, 92,104,110,105, 80,100,124,170, 79,177,174}; 
for (int i=0; i<concBuckets.length; i++) {
   this.rgbToConc.put(
      this.keyImage.getProcessor().getLut().getRGB(indices), concBuckets);
}

For each day do all of the following steps:
Quote
for (int n=0; n < this.nDays; n++) { ... }

1. Download the needed number of preceding images (e.g. five, if making a trailing 5-day median) from their URLs or get from cache if already downloaded. URLs are similar to (substitute the dates):
 - https://seaice.uni-bremen.de/data/amsr2/asi_daygrid_swath/n6250/2017/jul/Arctic/asi-AMSR2-n6250-20170731-v5_nic.png
Quote
ImagePlus image = null;
String filename = this.getFilename(date, bremenVersion);
File file = new File(this.cacheDir + filename);
if (file.exists()) {
            System.out.println("Loading image from file: " + this.cacheDir + filename);
            image = new ImagePlus(this.cacheDir + filename);
} else {
            String url = this.getUrl(date, filename);
            System.out.println("Downloading image from web: " + url);
            image = new ImagePlus(url);
}

2. For each preceding image, convert the colors to concentrations using the key.
Quote
int[] conc = new int[this.len];
LUT lut = ip.getLut();
byte[] pixels = (byte[]) ip.getPixels();
for (int y=0; y < ip.getHeight(); y++) {
            for (int x=0; x < ip.getWidth(); x++) {
                int i = x + y * ip.getWidth();
                int rgb = lut.getRGB(pixels);
                if (this.rgbToConc.containsKey(rgb)){
                    conc = Integer.parseInt(this.rgbToConc.get(rgb).toString());
                } else {
                    conc = Integer.MAX_VALUE;
                }
            }
}

3. Use this set of concentrations to calculate the output values; e.g. for median (i.e. quartile = 2):
Quote
for (int i=0; i<this.len; i++) {
            int filteredC = this.concentrations.get(0);
            int[] values = new int[this.concentrations.size()];
            for (int z=0; z<values.length; ++z) {
                values[z] = this.concentrations.get(z);
            }
            Arrays.sort(values);
            if (values.length % 2 == 0) {
                throw new RuntimeException("Can't use quartile for even number of ice concentrations.");
            } else {
                int q1 = values.length/4;   // for values.length == 5, q1 == 1 (floor of 1.25)
                filteredC = values[q1*quartile];
            }
            this.filteredConcs = filteredC;
}

4. Finally, convert the concentrations back into RGB color values and use that as the pixel array to generate a new image.

5. Now I have a set of images, each being the (e.g.) 5-day trailing median. I just use EZGif online to convert them to an animation. To use a different algorithm, just change step 3.

« Last Edit: July 22, 2019, 02:05:58 AM by petm »

uniquorn

  • Nilas ice
  • Posts: 2476
    • View Profile
  • Liked: 1341
  • Likes Given: 221
Re: Creating Animated GIFs
« Reply #102 on: July 22, 2019, 10:41:18 PM »
thanks petm, useful stuff

Sterks

  • Guest
Re: Creating Animated GIFs
« Reply #103 on: July 25, 2019, 09:46:01 PM »
Following up on: https://forum.arctic-sea-ice.net/index.php/topic,2591.msg214848.html#msg214848 . Not sure if this is the best thread for this, since I actually just use EZGif's website to make the GIFs once I've created the images, but it can always be moved if appropriate...

Repeating the summary from the thread above:
Quote
I do it using the imageJ API (Java code), basically by: for each day, reading in the 5 preceding days' images, converting each pixel color to a concentration value based on the Bremen key, taking the median for each pixel, then creating a new image. (Actually, the algorithm is easily changed -- 5 day median is quite conservative.)

The code is a bit of a hack, so I'll just post some snippets:

I don’t think I have the Java skills to achieve this in a reasonable time. Thank you anyway and hope you post more filtered gifs when you find the time. I really enjoy them, I don’t think five day average is conservative, actually it leaves the shortest characteristic time that makes sense. Weather patterns change with that pace usually, not faster.

petm

  • Grease ice
  • Posts: 675
    • View Profile
  • Liked: 330
  • Likes Given: 27
Re: Creating Animated GIFs
« Reply #104 on: August 08, 2019, 01:50:40 AM »
Oof, it turns out I made an error in calculating the index for getting median values from a sorted array. The calculation was only correct for 5-day medians (zero-based index 2). For 3-day medians it was returning the minimum (index 0; should be index 1).

However, this may have been a fortunate error, as it turns out that I actually like the minimum algorithm. It's not conservative, but if it's true that the biggest artifacts are clouds, then this does the best job of eliminating them. On the other hand, maybe it overestimates the amount of melt too much?

Attached is a gif that cycles through each index for today's result. Index 0 is minimum, 2 is median, 4 is maximum, and 1 and 3 are intermediate (something like Q1 and Q3).

Click to animate.

Any comments?

uniquorn

  • Nilas ice
  • Posts: 2476
    • View Profile
  • Liked: 1341
  • Likes Given: 221
Re: Creating Animated GIFs
« Reply #105 on: August 08, 2019, 02:03:59 AM »
Any comments?
Run all 5 over the last 5years and anecdotally compare them to available clear worldview days. Then satisfy yourself which is best. I'll be very grateful :)

petm

  • Grease ice
  • Posts: 675
    • View Profile
  • Liked: 330
  • Likes Given: 27
Re: Creating Animated GIFs
« Reply #106 on: August 08, 2019, 02:05:09 AM »
Any comments?
Run all 5 over the last 5years and anecdotally compare them to available clear worldview days. Then satisfy yourself which is best. I'll be very grateful :)

Good idea. I'd be interested to see as well. It'll have to wait for the weekend though...

uniquorn

  • Nilas ice
  • Posts: 2476
    • View Profile
  • Liked: 1341
  • Likes Given: 221
Re: Creating Animated GIFs
« Reply #107 on: August 08, 2019, 02:10:28 AM »
well, maybe not 5yrs

petm

  • Grease ice
  • Posts: 675
    • View Profile
  • Liked: 330
  • Likes Given: 27
Re: Creating Animated GIFs
« Reply #108 on: August 08, 2019, 02:13:30 AM »
lol  :D

I'll find some good examples and see if there's a clear trend.

El Cid

  • Nilas ice
  • Posts: 1103
    • View Profile
  • Liked: 444
  • Likes Given: 87
Re: Creating Animated GIFs
« Reply #109 on: August 08, 2019, 08:06:50 AM »
If you find out which one is best, please tell us about it and you could also post it on the main thread as it is important and educative

uniquorn

  • Nilas ice
  • Posts: 2476
    • View Profile
  • Liked: 1341
  • Likes Given: 221
Re: Creating Animated GIFs
« Reply #110 on: August 08, 2019, 12:08:04 PM »
Thinking about it overnight, a median has its uses but I prefer the detail of the daily. Weather artifacts are easy to see in an animation and add further information.

uniquorn

  • Nilas ice
  • Posts: 2476
    • View Profile
  • Liked: 1341
  • Likes Given: 221

uniquorn

  • Nilas ice
  • Posts: 2476
    • View Profile
  • Liked: 1341
  • Likes Given: 221
Re: Creating Animated GIFs
« Reply #112 on: May 30, 2020, 02:47:28 PM »
forgot about sst in post above but it doesn't matter now...
Quote
Real-time, global, sea surface temperature (RTG_SST_HR) analysis
ATTENTION! This product was discontinued on Feb. 11, 2020


Posting this method from A-Team for future reference
Quote
split nullschool montage into rgb components to get the high velocity component of the 70 hPa winds (the red channel), then overlay as ‘lighten only’.
best viewed full screen

blumenkraft

  • Young ice
  • Posts: 4898
  • Fans of Hans Ø Club - circa 2018
    • View Profile
  • Liked: 1669
  • Likes Given: 2814
Re: Creating Animated GIFs
« Reply #113 on: May 30, 2020, 03:09:37 PM »
Wow, that's amazing!

I do see some correlation.
"Is a thin line 'tween heaven and here" - Bubbles

uniquorn

  • Nilas ice
  • Posts: 2476
    • View Profile
  • Liked: 1341
  • Likes Given: 221
Re: Creating Animated GIFs
« Reply #114 on: June 08, 2020, 09:16:19 PM »
Reverse engineering Wipneus' piomas mp4, 1979-2018 to get daily png files (well, every 5days).
ffmpeg -i piomas.mp4 frame%04d.png
creates 2,920 frames, ~1GB, gifs might be smaller.




Freegrass

  • Nilas ice
  • Posts: 1282
  • None but our self can free our minds
    • View Profile
  • Liked: 474
  • Likes Given: 596
Re: Creating Animated GIFs
« Reply #115 on: June 08, 2020, 09:44:22 PM »
forgot about sst in post above but it doesn't matter now...
Quote
Real-time, global, sea surface temperature (RTG_SST_HR) analysis
ATTENTION! This product was discontinued on Feb. 11, 2020


Posting this method from A-Team for future reference
Quote
split nullschool montage into rgb components to get the high velocity component of the 70 hPa winds (the red channel), then overlay as ‘lighten only’.
best viewed full screen
I love those ASCAT animations. It would be great if we could overlay Nullschool wind graphics over that ice movement...
If every 8 year old in the world is taught meditation, we will eliminate violence from the world within one generation.

uniquorn

  • Nilas ice
  • Posts: 2476
    • View Profile
  • Liked: 1341
  • Likes Given: 221
Re: Creating Animated GIFs
« Reply #116 on: June 08, 2020, 11:27:52 PM »
Ideally, read this whole thread but...
Start here for background info on ascat.

Then scroll down to here for shorter instructions except that ospo doesn't appear to have the files anymore.
At the moment they can be downloaded  from
https://manati.star.nesdis.noaa.gov/ascat_images/ice_image/msfa-NHe-a-2020159.sir.gif
Change the day numbers.

Once you have a nice ascat ani you can move on to gimp for nullschool overlays.

Freegrass

  • Nilas ice
  • Posts: 1282
  • None but our self can free our minds
    • View Profile
  • Liked: 474
  • Likes Given: 596
Re: Creating Animated GIFs
« Reply #117 on: June 08, 2020, 11:37:32 PM »
Thanks Uniquorn. I'll try to figure it out later.  :)
If every 8 year old in the world is taught meditation, we will eliminate violence from the world within one generation.

Freegrass

  • Nilas ice
  • Posts: 1282
  • None but our self can free our minds
    • View Profile
  • Liked: 474
  • Likes Given: 596
Re: Creating Animated GIFs
« Reply #118 on: August 12, 2020, 10:10:03 AM »
My GIMP skills are very limited, and so I would love to learn more.

The way I make my forecast GIFs is very easy.
  • I make one screenshot and throw it away. Because the first screenshot of the day doesn't get a number and thus ends up as the last file.
  • I open Nullschool, go back 3 or 6 hours depending on the hour, and I take 41 screenshots. Make sure you select UTC time instead of local time! Set Nullschool to your prefered view, and bookmark it so you always get the same view when you open it.
  • I open GIMP and I open the screenshot as layers.
  • After all the screenshots are imported, I use the fixed crop tool to cut out the area I want.
  • I make 5 copies of the last layer to add a pause in the GIF.
  • I scale the gif to 800 by 450.
  • Export as GIF by adding .gif to the file name. In pop-up window I select interlace (not sure why. Is that good?) I deselect comment. Select animation. Leave loop forever selected. Delay to 130. Select use delay for all frames. Leave last one unselected. Click export.
  • Done
Those are my skills. So now how do I add a layer to that with the ice?
If every 8 year old in the world is taught meditation, we will eliminate violence from the world within one generation.

be cause

  • Nilas ice
  • Posts: 1313
    • View Profile
  • Liked: 567
  • Likes Given: 417
Re: Creating Animated GIFs
« Reply #119 on: August 12, 2020, 10:34:34 AM »
BLUMENKRAFT SEEMS TO HAVE ALL THE NECESSARY SKILLS TO HELP YOU .. B.C.
2007 + 5 = 2012 + 4 = 2016 + 3 = 2019 + 2 = 2021 
 (phew)