Skip to content

Instantly share code, notes, and snippets.

@run4flat
Forked from jberger/gist:3012794
Created June 28, 2012 21:10
Show Gist options
  • Save run4flat/3013911 to your computer and use it in GitHub Desktop.
Save run4flat/3013911 to your computer and use it in GitHub Desktop.
PGPS gaussian width app
#!/usr/bin/env perl
use strict;
use warnings;
use PDL;
use PDL::Image2D;
use PDL::Fit::Gaussian;
use Prima;
use PDL::Graphics::Prima::Simple -sequential;
my $file = shift;
analyze($file);
sub analyze {
my $file = shift;
my $pdl = rfits $file;
my ($x_dim, $y_dim) = $pdl->dims;
my ($val, $max_x, $max_y) = $pdl->max2d_ind;
plot(
-data => ds::Grid(
$pdl,
x_bounds => [1,$x_dim],
y_bounds => [1,$y_dim],
plotType => pgrid::Matrix(
palette => pal::BlackToWhite,
),
),
-max => ds::Pair(
$max_x, $max_y,
plotTypes => ppair::Crosses,
colors => pdl(255, 0, 0)->rgb_to_color,
),
onMouseClick => sub {
my ($self, $button, undef, $x, $y) = @_;
return unless $button & mb::Left;
$x = int $self->x->pixels_to_reals($x);
$y = int $self->y->pixels_to_reals($y); #-- #highlight fix
xy_fit($pdl, $x, $y);
$self->get_parent->close;
},
onKeyDown => sub {
my $self = shift;
xy_fit($pdl,$max_x,$max_y);
$self->get_parent->close;
},
);
}
sub xy_fit {
my ($pdl, $x, $y) = @_;
my $x_lineout = $pdl->slice(",($y)");
my $y_lineout = $pdl->slice("($x),");
my (undef, undef, $fwhm_x) = fitgauss1d(
$x_lineout->sequence * 5.4,
$x_lineout,
);
my (undef, undef, $fwhm_y) = fitgauss1d(
$y_lineout->sequence * 5.4,
$y_lineout,
);
print "X: $fwhm_x, Y: $fwhm_y\n";
return ($fwhm_x, $fwhm_y);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment