Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Animated Heatmap

by marioroy (Prior)
on Aug 24, 2019 at 23:14 UTC ( [id://11104965]=note: print w/replies, xml ) Need Help??


in reply to Animated Heatmap

Hi,

On the Mac side, I needed to install library dependencies. Thus, installed extra to cover GIF, PNG, JPEG, and TIFF at least :)

$ brew install giflib libpng libjpeg libtiff freetype $ cpanm Imager -n $ cpanm Imager::File::GIF -n $ cpanm Imager::File::PNG -n $ cpanm Imager::File::JPEG -n $ cpanm Imager::File::TIFF -n $ cpanm Imager::Heatmap -n

I tried your example using MCE::Map. It was cool seeing the output from 1 to 90 go by swiftly. So here it is, a parallel demonstration.

#!/usr/bin/env perl ## # https://www.perlmonks.org/?node_id=11104262 # # 100 simultaneous supernovae collapse into a supermassive blackhole! # This makes a pretty picture by incrementing the sigma values on the # sample data resulting in an animated GIF. Please feel free to hack # it up and post your version! ## use strict; use warnings; use Imager::Heatmap; use MCE::Map; my $filename = 'heatmapa.gif'; my @insert = sample_data(); my @images = (); $| = 1; print "Generating GIF frame "; MCE::Map->init( max_workers => 20, chunk_size => 1, init_relay => '' ); my @data = mce_map { my $x = $_; my $hmap = Imager::Heatmap->new( xsize => 300, ysize => 300, xsigma => $x, ysigma => $x, ); $hmap->insert_datas(@insert); $hmap = $hmap->draw; my $data; $hmap->write(data => \$data, type => 'tiff'); # calling relay so orderly print output MCE::relay { print "$x " }; $data; } [ 1 .. 90 ]; MCE::Map->finish; print "done!\n"; Imager->write_multi({ file => $filename, transp => 'none', gif_loop => 0, }, map { Imager->read_multi(data => \$_) } @data); print "Saved $filename\n"; sub sample_data { my @insert = (); while (<DATA>) { chomp; push @insert, [ split /\s/ ] } return @insert } __DATA__ ...

Regards, Mario

Replies are listed 'Best First'.
Re^2: Animated Heatmap
by marioroy (Prior) on Aug 24, 2019 at 23:17 UTC

    MCE::Map constructs the MCE object internally. The following is a parallel demonstration using the core MCE API.

    #!/usr/bin/env perl ## # https://www.perlmonks.org/?node_id=11104262 # # 100 simultaneous supernovae collapse into a supermassive blackhole! # This makes a pretty picture by incrementing the sigma values on the # sample data resulting in an animated GIF. Please feel free to hack # it up and post your version! ## use strict; use warnings; use Imager::Heatmap; use MCE; my $filename = 'heatmapa.gif'; my @insert = sample_data(); my @images = (); $| = 1; print "Generating GIF frame "; my @data; MCE->new( max_workers => 20, input_data => [ 1 .. 90 ], chunk_size => 1, init_relay => '', gather => sub { my ($chunk_id) = @_; $data[ $chunk_id - 1 ] = $_[1]; }, user_func => sub { my $x = $_; my $hmap = Imager::Heatmap->new( xsize => 300, ysize => 300, xsigma => $x, ysigma => $x, ); $hmap->insert_datas(@insert); $hmap = $hmap->draw; my $data; $hmap->write(data => \$data, type => 'tiff'); # calling relay so orderly print output MCE::relay { print "$x "; MCE->gather(MCE->chunk_id, $data); }; } )->run; print "done!\n"; Imager->write_multi({ file => $filename, transp => 'none', gif_loop => 0, }, map { Imager->read_multi(data => \$_) } @data); print "Saved $filename\n"; sub sample_data { my @insert = (); while (<DATA>) { chomp; push @insert, [ split /\s/ ] } return @insert } __DATA__ ...

    Regards, Mario

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11104965]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-03-29 09:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found