Skip to content

Commit

Permalink
change argument name to spatial_conditions_for_subset
Browse files Browse the repository at this point in the history
It is perhaps a bit long winded, but its meaning is clear.

Croaks if the old keyword of spatial_condition is passed to Biodiverse::Randomise::run_analysis().

Update tests to match.

Fixes #605
  • Loading branch information
shawnlaffan committed Jul 21, 2016
1 parent 487c152 commit a45b1ff
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
18 changes: 13 additions & 5 deletions lib/Biodiverse/Randomise.pm
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,11 @@ sub run_randomisation {
$self->set_default_args (function => $function, args_hash => \%args);
}
$self->set_analysis_args (\%args);

# dirty hack for short term back compat
#$args{spatial_conditions_for_subset} //= $args{spatial_condition};
croak "spatial_condition argument is deprecated - use spatial_conditions_for_subset\n"
if defined $args{spatial_condition};

my $rand_object = $self->initialise_rand (%args);

Expand Down Expand Up @@ -736,7 +741,7 @@ sub _get_randomised_basedata {
my $bd = $args{basedata_ref} || $self->get_param ('BASEDATA_REF');

# do we have one or more valid conditions which imply a subset is needed?
my $check = join '', map {$_ // ''} ($args{spatial_conditions}, $args{definition_query}, $args{spatial_condition});
my $check = join '', map {$_ // ''} ($args{spatial_conditions_for_subset}, $args{definition_query});
$check =~ s/\s//g;

if (length $check) {
Expand Down Expand Up @@ -1990,7 +1995,7 @@ sub get_metadata_get_rand_structured_subset {
my $parameters = [];

my $spatial_condition_param = bless {
name => 'spatial_condition',
name => 'spatial_conditions_for_subset',
label_text => "Spatial condition\nto define subsets",
default => '', #' ' x 30, # add spaces to get some widget width
type => 'spatial_conditions',
Expand Down Expand Up @@ -2037,9 +2042,12 @@ sub get_rand_structured_subset {
if (!$sp) {
my $name = "get nbrs for rand_structured_subset, $time" . $self->get_name;
$sp = $bd->add_spatial_output (name => $name);

my $sp_conditions = $args{spatial_conditions} || [$args{spatial_condition}];


my $sp_conditions = $args{spatial_conditions_for_subset};
if (ref ($sp_conditions // '') ne 'ARRAY') {
$sp_conditions = [$sp_conditions];
}

# Check the sp conditions
# If we get only whitespace and comments then default to selecting all groups
my $sp_check_text = $sp_conditions->[0];
Expand Down
26 changes: 17 additions & 9 deletions t/28-Randomisation.t
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ sub test_rand_structured_subset_richness_same {
iterations => 3,
seed => $prng_seed,
return_rand_bd_array => 1,
spatial_condition => 'sp_block(size => 1000000)',
spatial_condition_for_subsets => 'sp_block(size => 1000000)',
definition_query => $def_query,
);

Expand Down Expand Up @@ -638,7 +638,7 @@ sub test_rand_labels_all_constant {
iterations => 2,
seed => $prng_seed,
return_rand_bd_array => 1,
#spatial_condition => 'sp_block(size => 1000000)',
#spatial_conditions_for_subset => 'sp_block(size => 1000000)',
labels_not_to_randomise => $labels_not_to_randomise,
);

Expand Down Expand Up @@ -691,7 +691,7 @@ sub test_rand_labels_constant {
iterations => 2,
seed => $prng_seed,
return_rand_bd_array => 1,
spatial_condition => 'sp_block(size => 1000000)',
spatial_conditions_for_subset => 'sp_block(size => 1000000)',
labels_not_to_randomise => $labels_not_to_randomise,
);

Expand Down Expand Up @@ -755,7 +755,7 @@ sub test_rand_constant_labels_differing_input_methods {
iterations => 1,
seed => $prng_seed,
return_rand_bd_array => 1,
spatial_condition => 'sp_block(size => 1000000)',
spatial_conditions_for_subset => 'sp_block(size => 1000000)',
);

my $rand_object_a = $bd->add_randomisation_output (name => $rand_name . '_a');
Expand Down Expand Up @@ -1172,7 +1172,7 @@ sub node_calcs_gave_expected_results {

sub test_group_properties_reassigned_subset_rand {
my %args = (
spatial_condition => 'sp_block (size => 1000000)',
spatial_conditions_for_subset => 'sp_block (size => 1000000)',
);

# get a basedata aftr we have run some tests on it first
Expand Down Expand Up @@ -1223,7 +1223,11 @@ sub test_group_properties_reassigned {

$sp->run_analysis (
calculations => [qw /calc_gpprop_stats/],
spatial_conditions => [$args{spatial_condition} // 'sp_self_only()'],
spatial_conditions => [
$args{spatial_condition}
// $args{spatial_conditions_for_subset}
// 'sp_self_only()'
],
);

my %prop_handlers = (
Expand Down Expand Up @@ -1264,7 +1268,7 @@ sub test_group_properties_reassigned {
}

sub test_label_properties_reassigned_with_condition {
test_label_properties_reassigned (spatial_condition => 'sp_block (size => 300000)');
test_label_properties_reassigned (spatial_conditions_for_subset => 'sp_block (size => 300000)');
}

sub test_label_properties_reassigned {
Expand Down Expand Up @@ -1292,7 +1296,11 @@ sub test_label_properties_reassigned {

$sp->run_analysis (
calculations => [qw /calc_lbprop_stats/],
spatial_conditions => [$args{spatial_condition} // 'sp_self_only()'],
spatial_conditions => [
$args{spatial_condition}
// $args{spatial_conditions_for_subset}
// 'sp_self_only()',
],
);

my %prop_handlers = (
Expand Down Expand Up @@ -1785,7 +1793,7 @@ sub test_spatial_allocation_order_fails {

my $rand_bd_array = $rand->run_analysis (
%rand_func_args,
spatial_condition => '$x == $nbr_x',
spatial_conditions_for_subset => '$x == $nbr_x',
);
my $rand_bd = $rand_bd_array->[0];

Expand Down

0 comments on commit a45b1ff

Please sign in to comment.