Graph.pm (PDL-2.076) | : | Graph.pm (PDL-2.077) | ||
---|---|---|---|---|
skipping to change at line 15 | skipping to change at line 15 | |||
use PDL::LiteF; # XXX F needed? | use PDL::LiteF; # XXX F needed? | |||
use fields qw(Data DataBind UnBound DefaultAxes Axis ); | use fields qw(Data DataBind UnBound DefaultAxes Axis ); | |||
sub add_dataseries { | sub add_dataseries { | |||
my($this,$data,$name) = @_; | my($this,$data,$name) = @_; | |||
if(!defined $name) { | if(!defined $name) { | |||
$name = "Data0"; | $name = "Data0"; | |||
while(defined $this->{Data}{$name}) {$name++;} | while(defined $this->{Data}{$name}) {$name++;} | |||
} | } | |||
$this->{Data}{$name} = $data; | $this->{Data}{$name} = $data; | |||
$this->{DataBind}{$name} = []; | $this->{DataBind}{$name} = []; | |||
$this->{UnBound}{$name} = 1; | $this->{UnBound}{$name} = 1; | |||
$this->add_object($data); | $this->add_object($data); | |||
$this->changed(); | $this->changed(); | |||
return $name; | return $name; | |||
} | } | |||
sub bind_data { | sub bind_data { | |||
my($this,$dser,$axes,$axis) = @_; | my($this,$dser,$axes,$axis) = @_; | |||
push @{$this->{DataBind}{$dser}},[$axis,$axes]; | push @{$this->{DataBind}{$dser}},[$axis,$axes]; | |||
delete $this->{UnBound}{$dser}; | delete $this->{UnBound}{$dser}; | |||
$this->changed(); | $this->changed(); | |||
} | } | |||
skipping to change at line 71 | skipping to change at line 68 | |||
} | } | |||
for(values %{$this->{Axis}}) { | for(values %{$this->{Axis}}) { | |||
$_->finish_scale(); | $_->finish_scale(); | |||
} | } | |||
} | } | |||
# use Data::Dumper; | # use Data::Dumper; | |||
sub get_points { | sub get_points { | |||
my($this,$name) = @_; | my($this,$name) = @_; | |||
# print Dumper($this->{Axis}); | # print Dumper($this->{Axis}); | |||
my $d = $this->{Data}{$name}->get_points(); | my $d = $this->{Data}{$name}->get_points(); | |||
my @ddims = $d->dims; shift @ddims; | my @ddims = $d->dims; shift @ddims; | |||
my $p = PDL->zeroes(&PDL::float(),3,@ddims); | my $p = PDL->zeroes(&PDL::float(),3,@ddims); | |||
my $pnew; | my $pnew; | |||
for(@{$this->{DataBind}{$name}}) { | for(@{$this->{DataBind}{$name}}) { | |||
defined($this->{Axis}{$_->[0]}) or die("Axis not defined: $_->[0] "); | defined($this->{Axis}{$_->[0]}) or die("Axis not defined: $_->[0] "); | |||
# Transform can return the same or a different ndarray. | # Transform can return the same or a different ndarray. | |||
$pnew = $this->{Axis}{$_->[0]}->transform($p,$d,$_->[1]); | $pnew = $this->{Axis}{$_->[0]}->transform($p,$d,$_->[1]); | |||
$p = $pnew; | $p = $pnew; | |||
} | } | |||
return $pnew; | return $pnew; | |||
skipping to change at line 119 | skipping to change at line 114 | |||
my($this,$name,$axes) = @_; | my($this,$name,$axes) = @_; | |||
$this->{Axis}{Default} = $this->{Axis}{$name}; | $this->{Axis}{Default} = $this->{Axis}{$name}; | |||
$this->{DefaultAxes} = $axes; | $this->{DefaultAxes} = $axes; | |||
} | } | |||
sub changed {} | sub changed {} | |||
package PDL::Graphics::TriD::EuclidAxes; | package PDL::Graphics::TriD::EuclidAxes; | |||
sub new { | sub new { | |||
my($type) = @_; bless {Names => [qw(X Y Z)]},$type; | my($type) = @_; bless {Names => [qw(X Y Z)]},$type; | |||
} | } | |||
sub init_scale { | sub init_scale { | |||
my($this) = @_; | my($this) = @_; | |||
$this->{Scale} = []; | $this->{Scale} = undef; | |||
} | } | |||
sub add_scale { | sub add_scale { | |||
my($this,$data,$inds) = @_; | my($this,$data,$inds) = @_; | |||
my $i = 0; | $data = $data->dice_axis(0, $inds); | |||
for(@$inds) { | my $to_minmax = $data->clump(1..$data->ndims-1); # xyz,... | |||
my $d = $data->slice("($_)"); | $to_minmax = $to_minmax->glue(1, $this->{Scale}); # include old min/max | |||
my $max = $d->max; | my ($mins, $maxes) = $to_minmax->transpose->minmaxover; # each is xyz | |||
my $min = $d->min; | $this->{Scale} = PDL->pdl($mins, $maxes); # xyz,minmax | |||
if(!defined $this->{Scale}[$i]) { | ||||
$this->{Scale}[$i] = [$min,$max]; | ||||
} else { | ||||
if($min < $this->{Scale}[$i][0]) { | ||||
$this->{Scale}[$i][0] = $min; | ||||
} | ||||
if($max > $this->{Scale}[$i][1]) { | ||||
$this->{Scale}[$i][1] = $max; | ||||
} | ||||
} | ||||
$i++; | ||||
} | ||||
} | } | |||
sub finish_scale { | sub finish_scale { | |||
my($this) = @_; | my($this) = @_; | |||
# Normalize the smallest differences away. | # Normalize the smallest differences away. | |||
for(@{$this->{Scale}}) { | my ($min, $max) = $this->{Scale}->dog; | |||
if(abs($_->[0] - $_->[1]) < 0.000001) { | my $diff = $max - $min; | |||
$_->[1] = $_->[0] + 1; | my ($got_smalldiff, $got_bigdiff) = PDL::which_both(abs($diff) < 1e-6); | |||
} else { | $max->dice_axis(0, $got_smalldiff) .= $min->dice_axis(0, $got_smalldiff) + 1; | |||
my $shift = ($_->[1]-$_->[0])*0.05; | my ($min_big, $max_big, $shift) = map $_->dice_axis(0, $got_bigdiff), $min, $m | |||
$_->[0] -= $shift; | ax, $diff; | |||
$_->[1] += $shift; | $shift = $shift * 0.05; # don't mutate | |||
} | $min_big -= $shift, $max_big += $shift; | |||
} | ||||
} | } | |||
# Add 0..1 to each axis. | # Add 0..1 to each axis. | |||
sub transform { | sub transform { | |||
my($this,$point,$data,$inds) = @_; | my($this,$point,$data,$inds) = @_; | |||
my $i = 0; | my ($min, $max) = map $this->{Scale}->slice("0:$#$inds,$_"), 0, 1; | |||
for(@$inds) { | (my $tmp = $point->slice("0:$#$inds")) += | |||
(my $tmp = $point->slice("($i)")) += | ($data->dice_axis(0, $inds) - $min) / ($max - $min); | |||
($data->slice("($_)") - $this->{Scale}[$i][0]) / | return $point; | |||
($this->{Scale}[$i][1] - $this->{Scale}[$i][0]) ; | ||||
$i++; | ||||
} | ||||
return $point; | ||||
} | } | |||
# | ||||
# projects from the sphere to a cylinder | # projects from the sphere to a cylinder | |||
# | ||||
package PDL::Graphics::TriD::CylindricalEquidistantAxes; | package PDL::Graphics::TriD::CylindricalEquidistantAxes; | |||
use PDL::Core ''; | use PDL::Core ''; | |||
sub new { | sub new { | |||
my($type) = @_; | my($type) = @_; | |||
bless {Names => [qw(LON LAT Pressure)]},$type; | bless {Names => [qw(LON LAT Pressure)]},$type; | |||
} | } | |||
sub init_scale { | sub init_scale { | |||
my($this) = @_; | my($this) = @_; | |||
$this->{Scale} = []; | $this->{Scale} = []; | |||
} | } | |||
sub add_scale { | sub add_scale { | |||
my($this,$data,$inds) = @_; | my($this,$data,$inds) = @_; | |||
my $i = 0; | my $i = 0; | |||
for(@$inds) { | for(@$inds) { | |||
my $d = $data->slice("($_)"); | my $d = $data->slice("($_)"); | |||
my $max = $d->max; | my $max = $d->max->sclr; | |||
my $min = $d->min; | my $min = $d->min->sclr; | |||
if($i==1){ | if($i==1){ | |||
if($max > 89.9999 or $min < -89.9999){ | if($max > 89.9999 or $min < -89.9999){ | |||
barf "Error in Latitude $max $min\n"; | barf "Error in Latitude $max $min\n"; | |||
} | } | |||
} | } | |||
elsif($i==2){ | elsif($i==2){ | |||
$max = 1012.5 if($max<1012.5); | $max = 1012.5 if($max<1012.5); | |||
$min = 100 if($min>100); | $min = 100 if($min>100); | |||
} | } | |||
if(!defined $this->{Scale}[$i]) { | if(!defined $this->{Scale}[$i]) { | |||
$this->{Scale}[$i] = [$min,$max]; | $this->{Scale}[$i] = [$min,$max]; | |||
} else { | } else { | |||
if($min < $this->{Scale}[$i][0]) { | if($min < $this->{Scale}[$i][0]) { | |||
$this->{Scale}[$i][0] = $min; | $this->{Scale}[$i][0] = $min; | |||
} | } | |||
if($max > $this->{Scale}[$i][1]) { | if($max > $this->{Scale}[$i][1]) { | |||
$this->{Scale}[$i][1] = $max; | $this->{Scale}[$i][1] = $max; | |||
} | } | |||
} | } | |||
$i++; | $i++; | |||
} | } | |||
# $this->{Center} = [$this->{Scale}[0][0]+($this->{Scale}[0][1]-$this->{Scale}[ | ||||
0][0])/2, | ||||
# $this->{Scale}[1][0]+($this->{Scale}[1][1]-$this->{Scale}[1] | ||||
[0])/2]; | ||||
# | ||||
# Should make the projection center an option | # Should make the projection center an option | |||
# | ||||
$this->{Center} = [$this->{Scale}[0][0]+($this->{Scale}[0][1]-$this->{Scale}[0 ][0])/2, | $this->{Center} = [$this->{Scale}[0][0]+($this->{Scale}[0][1]-$this->{Scale}[0 ][0])/2, | |||
0]; | 0]; | |||
} | } | |||
sub finish_scale { | sub finish_scale { | |||
my($this) = @_; | my($this) = @_; | |||
my @dist; | my @dist; | |||
# Normalize the smallest differences away. | # Normalize the smallest differences away. | |||
for(@{$this->{Scale}}) { | for(@{$this->{Scale}}) { | |||
if(abs($_->[0] - $_->[1]) < 0.000001) { | if(abs($_->[0] - $_->[1]) < 0.000001) { | |||
$_->[1] = $_->[0] + 1; | $_->[1] = $_->[0] + 1; | |||
} | } | |||
push(@dist,$_->[1]-$_->[0]); | push(@dist,$_->[1]-$_->[0]); | |||
} | } | |||
# for the z coordiniate reverse the min and max values | # for the z coordinate reverse the min and max values | |||
my $max = $this->{Scale}[2][0]; | my $max = $this->{Scale}[2][0]; | |||
if($max < $this->{Scale}[2][1]){ | if($max < $this->{Scale}[2][1]){ | |||
$this->{Scale}[2][0] = $this->{Scale}[2][1]; | $this->{Scale}[2][0] = $this->{Scale}[2][1]; | |||
$this->{Scale}[2][1] = $max; | $this->{Scale}[2][1] = $max; | |||
} | } | |||
# Normalize longitude and latitude scale | # Normalize longitude and latitude scale | |||
if($dist[1] > $dist[0]){ | if($dist[1] > $dist[0]){ | |||
$this->{Scale}[0][0] -= ($dist[1]-$dist[0])/2; | $this->{Scale}[0][0] -= ($dist[1]-$dist[0])/2; | |||
$this->{Scale}[0][1] += ($dist[1]-$dist[0])/2; | $this->{Scale}[0][1] += ($dist[1]-$dist[0])/2; | |||
}elsif($dist[0] > $dist[1] && $dist[0]<90){ | }elsif($dist[0] > $dist[1] && $dist[0]<90){ | |||
$this->{Scale}[1][0] -= ($dist[0]-$dist[1])/2; | $this->{Scale}[1][0] -= ($dist[0]-$dist[1])/2; | |||
$this->{Scale}[1][1] += ($dist[0]-$dist[1])/2; | $this->{Scale}[1][1] += ($dist[0]-$dist[1])/2; | |||
}elsif($dist[0] > $dist[1]){ | }elsif($dist[0] > $dist[1]){ | |||
$this->{Scale}[1][0] -= (90-$dist[1])/2; | $this->{Scale}[1][0] -= (90-$dist[1])/2; | |||
$this->{Scale}[1][1] += (90-$dist[1])/2; | $this->{Scale}[1][1] += (90-$dist[1])/2; | |||
} | } | |||
} | } | |||
sub transform { | sub transform { | |||
my($this,$point,$data,$inds) = @_; | my($this,$point,$data,$inds) = @_; | |||
my $i = 0; | my $i = 0; | |||
if($#$inds!=2){ | if($#$inds!=2){ | |||
barf("Wrong number of arguments to transform $this\n"); | barf("Wrong number of arguments to transform $this\n"); | |||
exit; | exit; | |||
} | } | |||
my $pio180 = 0.017453292; | my $pio180 = 0.017453292; | |||
(my $tmp1 = $point->slice("(0)")) += | (my $tmp1 = $point->slice("(0)")) += | |||
0.5+($data->slice("($inds->[0])")-$this->{Center}[0]) / | 0.5+($data->slice("($inds->[0])")-$this->{Center}[0]) / | |||
($this->{Scale}[0][1] - $this->{Scale}[0][0]) | ($this->{Scale}[0][1] - $this->{Scale}[0][0]) | |||
*cos($data->slice("($inds->[1])")*$pio180); | *cos($data->slice("($inds->[1])")*$pio180); | |||
(my $tmp2 = $point->slice("(1)")) += | (my $tmp2 = $point->slice("(1)")) += | |||
0.5+($data->slice("($inds->[1])")-$this->{Center}[1]) / | 0.5+($data->slice("($inds->[1])")-$this->{Center}[1]) / | |||
($this->{Scale}[1][1] - $this->{Scale}[1][0]); | ($this->{Scale}[1][1] - $this->{Scale}[1][0]); | |||
(my $tmp3 = $point->slice("(2)")) .= | (my $tmp3 = $point->slice("(2)")) .= | |||
log($data->slice("($inds->[2])")/1012.5)/log($this->{Scale}[2][1]/1012.5); | log($data->slice("($inds->[2])")/1012.5)/log($this->{Scale}[2][1]/1012.5); | |||
return $point; | return $point; | |||
} | } | |||
package PDL::Graphics::TriD::PolarStereoAxes; | package PDL::Graphics::TriD::PolarStereoAxes; | |||
use PDL::Core ''; | use PDL::Core ''; | |||
sub new { | sub new { | |||
my($type) = @_; | my($type) = @_; | |||
skipping to change at line 304 | skipping to change at line 264 | |||
} | } | |||
sub init_scale { | sub init_scale { | |||
my($this) = @_; | my($this) = @_; | |||
$this->{Scale} = []; | $this->{Scale} = []; | |||
} | } | |||
sub add_scale { | sub add_scale { | |||
my($this,$data,$inds) = @_; | my($this,$data,$inds) = @_; | |||
my $i = 0; | my $i = 0; | |||
for(@$inds) { | for(@$inds) { | |||
my $d = $data->slice("($_)"); | my $d = $data->slice("($_)"); | |||
my $max = $d->max; | my $max = $d->max->sclr; | |||
my $min = $d->min; | my $min = $d->min->sclr; | |||
if($i==1){ | if($i==1){ | |||
if($max > 89.9999 or $min < -89.9999){ | if($max > 89.9999 or $min < -89.9999){ | |||
barf "Error in Latitude $max $min\n"; | barf "Error in Latitude $max $min\n"; | |||
} | } | |||
} | } | |||
elsif($i==2){ | elsif($i==2){ | |||
$max = 1012.5 if($max<1012.5); | $max = 1012.5 if($max<1012.5); | |||
$min = 100 if($min>100); | $min = 100 if($min>100); | |||
} | } | |||
if(!defined $this->{Scale}[$i]) { | if(!defined $this->{Scale}[$i]) { | |||
$this->{Scale}[$i] = [$min,$max]; | $this->{Scale}[$i] = [$min,$max]; | |||
} else { | } else { | |||
if($min < $this->{Scale}[$i][0]) { | if($min < $this->{Scale}[$i][0]) { | |||
$this->{Scale}[$i][0] = $min; | $this->{Scale}[$i][0] = $min; | |||
} | } | |||
if($max > $this->{Scale}[$i][1]) { | if($max > $this->{Scale}[$i][1]) { | |||
$this->{Scale}[$i][1] = $max; | $this->{Scale}[$i][1] = $max; | |||
} | } | |||
} | } | |||
$i++; | $i++; | |||
} | } | |||
$this->{Center} = [$this->{Scale}[0][0]+($this->{Scale}[0][1]-$this->{Scale}[0 ][0])/2, | $this->{Center} = [$this->{Scale}[0][0]+($this->{Scale}[0][1]-$this->{Scale}[0 ][0])/2, | |||
$this->{Scale}[1][0]+($this->{Scale}[1][1]-$this->{Scale}[1] [0])/2]; | $this->{Scale}[1][0]+($this->{Scale}[1][1]-$this->{Scale}[1] [0])/2]; | |||
} | } | |||
sub finish_scale { | sub finish_scale { | |||
my($this) = @_; | my($this) = @_; | |||
my @dist; | my @dist; | |||
# Normalize the smallest differences away. | # Normalize the smallest differences away. | |||
for(@{$this->{Scale}}) { | for(@{$this->{Scale}}) { | |||
if(abs($_->[0] - $_->[1]) < 0.000001) { | if(abs($_->[0] - $_->[1]) < 0.000001) { | |||
$_->[1] = $_->[0] + 1; | $_->[1] = $_->[0] + 1; | |||
} | } | |||
push(@dist,$_->[1]-$_->[0]); | push(@dist,$_->[1]-$_->[0]); | |||
} | } | |||
# for the z coordiniate reverse the min and max values | # for the z coordinate reverse the min and max values | |||
my $max = $this->{Scale}[2][0]; | my $max = $this->{Scale}[2][0]; | |||
if($max < $this->{Scale}[2][1]){ | if($max < $this->{Scale}[2][1]){ | |||
$this->{Scale}[2][0] = $this->{Scale}[2][1]; | $this->{Scale}[2][0] = $this->{Scale}[2][1]; | |||
$this->{Scale}[2][1] = $max; | $this->{Scale}[2][1] = $max; | |||
} | } | |||
# Normalize longitude and latitude scale | # Normalize longitude and latitude scale | |||
if($dist[1] > $dist[0]){ | if($dist[1] > $dist[0]){ | |||
$this->{Scale}[0][0] -= ($dist[1]-$dist[0])/2; | $this->{Scale}[0][0] -= ($dist[1]-$dist[0])/2; | |||
$this->{Scale}[0][1] += ($dist[1]-$dist[0])/2; | $this->{Scale}[0][1] += ($dist[1]-$dist[0])/2; | |||
}elsif($dist[0] > $dist[1] && $dist[0]<90){ | }elsif($dist[0] > $dist[1] && $dist[0]<90){ | |||
$this->{Scale}[1][0] -= ($dist[0]-$dist[1])/2; | $this->{Scale}[1][0] -= ($dist[0]-$dist[1])/2; | |||
$this->{Scale}[1][1] += ($dist[0]-$dist[1])/2; | $this->{Scale}[1][1] += ($dist[0]-$dist[1])/2; | |||
}elsif($dist[0] > $dist[1]){ | }elsif($dist[0] > $dist[1]){ | |||
$this->{Scale}[1][0] -= (90-$dist[1])/2; | $this->{Scale}[1][0] -= (90-$dist[1])/2; | |||
$this->{Scale}[1][1] += (90-$dist[1])/2; | $this->{Scale}[1][1] += (90-$dist[1])/2; | |||
} | } | |||
} | } | |||
sub transform { | sub transform { | |||
my($this,$point,$data,$inds) = @_; | my($this,$point,$data,$inds) = @_; | |||
my $i = 0; | my $i = 0; | |||
if($#$inds!=2){ | if($#$inds!=2){ | |||
barf("Wrong number of arguments to transform $this\n"); | barf("Wrong number of arguments to transform $this\n"); | |||
exit; | exit; | |||
} | } | |||
my $pio180 = 0.017453292; | my $pio180 = 0.017453292; | |||
(my $tmp1 = $point->slice("(0)")) += | (my $tmp1 = $point->slice("(0)")) += | |||
0.5+($data->slice("($inds->[0])")-$this->{Center}[0]) / | 0.5+($data->slice("($inds->[0])")-$this->{Center}[0]) / | |||
($this->{Scale}[0][1] - $this->{Scale}[0][0]) | ($this->{Scale}[0][1] - $this->{Scale}[0][0]) | |||
*cos($data->slice("($inds->[1])")*$pio180); | *cos($data->slice("($inds->[1])")*$pio180); | |||
(my $tmp2 = $point->slice("(1)")) += | (my $tmp2 = $point->slice("(1)")) += | |||
0.5+($data->slice("($inds->[1])")-$this->{Center}[1]) / | 0.5+($data->slice("($inds->[1])")-$this->{Center}[1]) / | |||
($this->{Scale}[1][1] - $this->{Scale}[1][0]) | ($this->{Scale}[1][1] - $this->{Scale}[1][0]) | |||
*cos($data->slice("($inds->[1])")*$pio180); | *cos($data->slice("($inds->[1])")*$pio180); | |||
# Longitude transformation | # Longitude transformation | |||
# (my $tmp = $point->slice("(0)")) = | # (my $tmp = $point->slice("(0)")) = | |||
# ($this->{Center}[0]-$point->slice("(0)"))*cos($data->slice("(1)")); | # ($this->{Center}[0]-$point->slice("(0)"))*cos($data->slice("(1)")); | |||
# Latitude transformation | # Latitude transformation | |||
# (my $tmp = $point->slice("(1)")) = | # (my $tmp = $point->slice("(1)")) = | |||
# ($this->{Center}[1]-$data->slice("(1)"))*cos($data->slice("(1)")); | # ($this->{Center}[1]-$data->slice("(1)"))*cos($data->slice("(1)")); | |||
# Vertical transformation | # Vertical transformation | |||
# -7.2*log($data->slice("(2)")/1012.5 | # -7.2*log($data->slice("(2)")/1012.5 | |||
(my $tmp3 = $point->slice("(2)")) .= | (my $tmp3 = $point->slice("(2)")) .= | |||
log($data->slice("($inds->[2])")/1012.5)/log($this->{Scale}[2][1]/1012.5); | log($data->slice("($inds->[2])")/1012.5)/log($this->{Scale}[2][1]/1012.5); | |||
return $point; | return $point; | |||
} | } | |||
1; | 1; | |||
End of changes. 41 change blocks. | ||||
84 lines changed or deleted | 30 lines changed or added |