80
80
:py:class:`InCodeGridAttributeStorage`
81
81
Subclass of AbstractInCodeAttributeStorage, manages grids
82
82
83
-
84
-
85
83
"""
86
84
85
+ import numpy
86
+ import inspect
87
+
87
88
from amuse .support .methods import AbstractCodeMethodWrapper
88
89
from amuse .units import nbody_system
89
90
from amuse .units import units
92
93
from amuse .support .core import late
93
94
from amuse .support import exceptions
94
95
95
- import numpy
96
- import inspect
97
-
98
96
from amuse .datamodel import parameters
99
97
from amuse .datamodel import base
100
98
from amuse .datamodel import Particles , ParticlesSuperset
@@ -178,7 +176,7 @@ def check_arguments(self, storage, attributes_to_return, *indices):
178
176
"getter method {0} cannot handle arrays" .format (self .method )
179
177
)
180
178
elif self .method_is_code :
181
- if not self .method .legacy_specification is None :
179
+ if self .method .legacy_specification is not None :
182
180
if not (
183
181
self .method .legacy_specification .can_handle_array
184
182
or self .method .legacy_specification .must_handle_array
@@ -398,13 +396,13 @@ def convert_attributes_and_values_to_list_and_keyword_arguments(
398
396
for index , x in enumerate (list_arguments ):
399
397
if x is not_set_marker :
400
398
name_of_attribute = self .attribute_names [index ]
401
- if not name_of_attribute in self .optional_attribute_names :
399
+ if name_of_attribute not in self .optional_attribute_names :
402
400
missing_attributes .append (name_of_attribute )
403
401
else :
404
402
default_argument_found = True
405
403
elif default_argument_found :
406
404
name_of_attribute = self .attribute_names [index ]
407
- if not name_of_attribute in self .optional_attribute_names :
405
+ if name_of_attribute not in self .optional_attribute_names :
408
406
raise exceptions .AmuseException (
409
407
"Optional before required arguments"
410
408
)
@@ -520,14 +518,12 @@ def set_attribute_values_async(self, storage, attributes, values, *indices):
520
518
521
519
class NewParticleMethod (ParticleSetAttributesMethod ):
522
520
"""
523
- Instances wrap a method to create particles. The method may
524
- take attributes values to set initial values on
525
- the created particles.
521
+ Instances wrap a method to create particles. The method may take attributes
522
+ values to set initial values on the created particles.
526
523
527
- The new particle functions work a lot like
528
- the set attribute methods, only the new particle
529
- function is supposed to return an array
530
- of the indices of the created particles.
524
+ The new particle functions work a lot like the set attribute methods, only
525
+ the new particle function is supposed to return an array of the indices of
526
+ the created particles.
531
527
532
528
.. code-block:: python
533
529
@@ -549,7 +545,7 @@ def add_entities(self, attributes, values):
549
545
return indices
550
546
551
547
552
- class ParticleQueryMethod ( object ) :
548
+ class ParticleQueryMethod :
553
549
"""
554
550
Instances wrap a function that can take one or more arguments
555
551
and returns an index (or a list of indices, if the arguments are
@@ -598,19 +594,18 @@ def apply_for_superset(self, particles, *args, **kwargs):
598
594
return ParticlesSuperset (subset_results )
599
595
600
596
601
- class ParticleSpecificSelectMethod ( object ) :
597
+ class ParticleSpecificSelectMethod :
602
598
"""
603
- Instances wrap a function that can take a particle index
604
- and returns one or more indices
605
- (but a limited and fixed number of indices). This method is most
606
- useful to return links between particles (subparticles or
607
- nearest neighbors)
599
+ Instances wrap a function that can take a particle index and returns one or
600
+ more indices (but a limited and fixed number of indices). This method is
601
+ most useful to return links between particles (subparticles or nearest
602
+ neighbors)
608
603
609
604
.. code-block:: python
610
605
611
- output_index = instance.get_nearest_neigbord (input_index)
606
+ output_index = instance.get_nearest_neighbor (input_index)
612
607
613
- The idex or indices are converted to a particle subset.
608
+ The index or indices are converted to a particle subset.
614
609
"""
615
610
616
611
def __init__ (self , method , names = (), public_name = None ):
@@ -640,22 +635,22 @@ def apply_on_all(self, particles):
640
635
641
636
return result
642
637
643
- def apply_on_one (self , set , particle ):
644
- index = set ._private .attribute_storage .get_indices_of (particle .key )
638
+ def apply_on_one (self , particleset , particle ):
639
+ index = particleset ._private .attribute_storage .get_indices_of (particle .key )
645
640
646
641
result = self .method (index )
647
642
648
- keys = set ._private .attribute_storage ._get_keys_for_indices_in_the_code (result )
643
+ keys = particleset ._private .attribute_storage ._get_keys_for_indices_in_the_code (result )
649
644
650
645
result = []
651
646
return particle .as_set ()._subset (keys )
652
647
653
648
654
649
class ParticleMethod (AbstractCodeMethodWrapper ):
655
650
"""
656
- Instances wrap a function that returns quanties given particle
657
- indices and optional arguments. Instances have a lot in common
658
- with attribute getters, but can take extra arguments.
651
+ Instances wrap a function that returns quantities given particle indices
652
+ and optional arguments. Instances have a lot in common with attribute
653
+ getters, but can take extra arguments.
659
654
660
655
.. code-block:: python
661
656
@@ -673,13 +668,13 @@ def apply_on_all(self, particles, *list_arguments, **keyword_arguments):
673
668
)
674
669
return self .method (all_indices , * list_arguments , ** keyword_arguments )
675
670
676
- def apply_on_one (self , set , particle , * list_arguments , ** keyword_arguments ):
671
+ def apply_on_one (self , particleset , particle , * list_arguments , ** keyword_arguments ):
677
672
storage = particle .particles_set ._private .attribute_storage
678
673
index = storage .get_indices_of ([particle .key ])
679
674
return self .method (index [0 ], * list_arguments , ** keyword_arguments )
680
675
681
676
682
- class ParticleSetSelectSubsetMethod ( object ) :
677
+ class ParticleSetSelectSubsetMethod :
683
678
"""
684
679
Generic method to query and retrieve particles from the
685
680
set. This selection can have up to tree stages:
@@ -720,7 +715,7 @@ def __init__(
720
715
721
716
def apply_on_all (self , particles , * list_arguments , ** keyword_arguments ):
722
717
query_identifiers = None
723
- if not self .set_query_arguments_method is None :
718
+ if self .set_query_arguments_method is not None :
724
719
query_identifiers = self .set_query_arguments_method (
725
720
* list_arguments , ** keyword_arguments
726
721
)
@@ -730,7 +725,7 @@ def apply_on_all(self, particles, *list_arguments, **keyword_arguments):
730
725
elif not hasattr (query_identifiers , "__iter__" ):
731
726
query_identifiers = (query_identifiers ,)
732
727
733
- if not self .get_number_of_particles_in_set_method is None :
728
+ if self .get_number_of_particles_in_set_method is not None :
734
729
number_of_particles_in_set = self .get_number_of_particles_in_set_method (
735
730
* query_identifiers
736
731
)
@@ -747,7 +742,7 @@ def apply_on_all(self, particles, *list_arguments, **keyword_arguments):
747
742
return particles ._subset (keys )
748
743
749
744
750
- class ParticlesAddedUpdateMethod ( object ) :
745
+ class ParticlesAddedUpdateMethod :
751
746
def __init__ (
752
747
self ,
753
748
get_number_of_particles_added_method = None ,
@@ -758,7 +753,7 @@ def __init__(
758
753
759
754
def apply_on_all (self , particles , * list_arguments , ** keyword_arguments ):
760
755
query_identifiers = None
761
- if not self .set_query_arguments_method is None :
756
+ if self .set_query_arguments_method is not None :
762
757
query_identifiers = self .set_query_arguments_method (
763
758
* list_arguments , ** keyword_arguments
764
759
)
@@ -768,7 +763,7 @@ def apply_on_all(self, particles, *list_arguments, **keyword_arguments):
768
763
elif not hasattr (query_identifiers , "__iter__" ):
769
764
query_identifiers = (query_identifiers ,)
770
765
771
- if not self .get_number_of_particles_in_set_method is None :
766
+ if self .get_number_of_particles_in_set_method is not None :
772
767
number_of_particles_in_set = self .get_number_of_particles_in_set_method (
773
768
* query_identifiers
774
769
)
@@ -785,7 +780,7 @@ def apply_on_all(self, particles, *list_arguments, **keyword_arguments):
785
780
return particles ._subset (keys )
786
781
787
782
788
- class ParticleGetIndexMethod ( object ) :
783
+ class ParticleGetIndexMethod :
789
784
"""
790
785
Instances return the index of a particle in the code
791
786
"""
@@ -805,10 +800,9 @@ def get_attribute_values(self, storage, attributes_to_return, *indices):
805
800
806
801
class AbstractInCodeAttributeStorage (base .AttributeStorage ):
807
802
"""
808
- Abstract base storage for incode attribute storage.
809
- It provides functions to handle getters and setters of
810
- attributes but not for creating or deleting of particles as
811
- this differs between grids and particle sets.
803
+ Abstract base storage for incode attribute storage. It provides functions
804
+ to handle getters and setters of attributes but not for creating or
805
+ deleting of particles as this differs between grids and particle sets.
812
806
813
807
"""
814
808
@@ -870,7 +864,7 @@ def select_getters_for(self, attributes):
870
864
871
865
if set_of_attributes :
872
866
raise exceptions .AmuseException (
873
- "Do not have attributes {0}" . format ( sorted (set_of_attributes ))
867
+ f "Do not have attributes { sorted (set_of_attributes )} "
874
868
)
875
869
876
870
return result
@@ -961,7 +955,7 @@ def add_particles_to_store(self, keys, attributes=[], values=[]):
961
955
index = 0
962
956
for key in keys :
963
957
if key in self .mapping_from_particle_key_to_index_in_the_code :
964
- raise Exception ("particle with same key added twice: {0}" . format ( key ) )
958
+ raise Exception (f "particle with same key added twice: { key } " )
965
959
self .mapping_from_particle_key_to_index_in_the_code [key ] = indices [index ]
966
960
self .mapping_from_index_in_the_code_to_particle_key [indices [index ]] = key
967
961
index = index + 1
@@ -1422,17 +1416,16 @@ def get_defined_settable_attribute_names(self):
1422
1416
return sorted (self .writable_attributes )
1423
1417
1424
1418
1425
- class ParticleSpecificSelectSubsetMethod ( object ) :
1419
+ class ParticleSpecificSelectSubsetMethod :
1426
1420
"""
1427
1421
Instances wrap a function that can take a particle index, plus a list
1428
- offset and returns one index. This method is most
1429
- useful to return links between particles (subparticles or
1430
- nearest neighbors). Instances also need a function to get
1431
- the number of links.
1422
+ offset and returns one index. This method is most useful to return links
1423
+ between particles (subparticles or nearest neighbors). Instances also need
1424
+ a function to get the number of links.
1432
1425
1433
1426
.. code-block:: python
1434
1427
1435
- output_index = instance.get_nearest_neigbors (index_of_the_particle, input_index)
1428
+ output_index = instance.get_nearest_neighbors (index_of_the_particle, input_index)
1436
1429
1437
1430
The index or indices are converted to a particle subset.
1438
1431
"""
@@ -1451,14 +1444,14 @@ def apply_on_all(self, particles):
1451
1444
"Getting all links to other particles from all particles in a set is not implemented yet"
1452
1445
)
1453
1446
1454
- def apply_on_one (self , set , particle ):
1455
- from_indices = set ._private .attribute_storage .get_indices_of (
1447
+ def apply_on_one (self , particleset , particle ):
1448
+ from_indices = particleset ._private .attribute_storage .get_indices_of (
1456
1449
[
1457
1450
particle .key ,
1458
1451
]
1459
1452
)
1460
1453
1461
- if not self .get_number_of_particles_in_set_method is None :
1454
+ if self .get_number_of_particles_in_set_method is not None :
1462
1455
number_of_particles_in_set = self .get_number_of_particles_in_set_method (
1463
1456
from_indices
1464
1457
)[0 ]
@@ -1470,6 +1463,6 @@ def apply_on_one(self, set, particle):
1470
1463
index = self .method ()
1471
1464
indices = [index ]
1472
1465
1473
- keys = set ._private .attribute_storage ._get_keys_for_indices_in_the_code (indices )
1466
+ keys = particleset ._private .attribute_storage ._get_keys_for_indices_in_the_code (indices )
1474
1467
1475
1468
return particle .as_set ()._subset (keys )
0 commit comments