Skip to content

Commit 06ef418

Browse files
authored
manual updates (#1075)
1 parent 3dde66e commit 06ef418

File tree

1 file changed

+47
-54
lines changed

1 file changed

+47
-54
lines changed

src/amuse/datamodel/incode_storage.py

Lines changed: 47 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,11 @@
8080
:py:class:`InCodeGridAttributeStorage`
8181
Subclass of AbstractInCodeAttributeStorage, manages grids
8282
83-
84-
8583
"""
8684

85+
import numpy
86+
import inspect
87+
8788
from amuse.support.methods import AbstractCodeMethodWrapper
8889
from amuse.units import nbody_system
8990
from amuse.units import units
@@ -92,9 +93,6 @@
9293
from amuse.support.core import late
9394
from amuse.support import exceptions
9495

95-
import numpy
96-
import inspect
97-
9896
from amuse.datamodel import parameters
9997
from amuse.datamodel import base
10098
from amuse.datamodel import Particles, ParticlesSuperset
@@ -178,7 +176,7 @@ def check_arguments(self, storage, attributes_to_return, *indices):
178176
"getter method {0} cannot handle arrays".format(self.method)
179177
)
180178
elif self.method_is_code:
181-
if not self.method.legacy_specification is None:
179+
if self.method.legacy_specification is not None:
182180
if not (
183181
self.method.legacy_specification.can_handle_array
184182
or self.method.legacy_specification.must_handle_array
@@ -398,13 +396,13 @@ def convert_attributes_and_values_to_list_and_keyword_arguments(
398396
for index, x in enumerate(list_arguments):
399397
if x is not_set_marker:
400398
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:
402400
missing_attributes.append(name_of_attribute)
403401
else:
404402
default_argument_found = True
405403
elif default_argument_found:
406404
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:
408406
raise exceptions.AmuseException(
409407
"Optional before required arguments"
410408
)
@@ -520,14 +518,12 @@ def set_attribute_values_async(self, storage, attributes, values, *indices):
520518

521519
class NewParticleMethod(ParticleSetAttributesMethod):
522520
"""
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.
526523
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.
531527
532528
.. code-block:: python
533529
@@ -549,7 +545,7 @@ def add_entities(self, attributes, values):
549545
return indices
550546

551547

552-
class ParticleQueryMethod(object):
548+
class ParticleQueryMethod:
553549
"""
554550
Instances wrap a function that can take one or more arguments
555551
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):
598594
return ParticlesSuperset(subset_results)
599595

600596

601-
class ParticleSpecificSelectMethod(object):
597+
class ParticleSpecificSelectMethod:
602598
"""
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)
608603
609604
.. code-block:: python
610605
611-
output_index = instance.get_nearest_neigbord(input_index)
606+
output_index = instance.get_nearest_neighbor(input_index)
612607
613-
The idex or indices are converted to a particle subset.
608+
The index or indices are converted to a particle subset.
614609
"""
615610

616611
def __init__(self, method, names=(), public_name=None):
@@ -640,22 +635,22 @@ def apply_on_all(self, particles):
640635

641636
return result
642637

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)
645640

646641
result = self.method(index)
647642

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)
649644

650645
result = []
651646
return particle.as_set()._subset(keys)
652647

653648

654649
class ParticleMethod(AbstractCodeMethodWrapper):
655650
"""
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.
659654
660655
.. code-block:: python
661656
@@ -673,13 +668,13 @@ def apply_on_all(self, particles, *list_arguments, **keyword_arguments):
673668
)
674669
return self.method(all_indices, *list_arguments, **keyword_arguments)
675670

676-
def apply_on_one(self, set, particle, *list_arguments, **keyword_arguments):
671+
def apply_on_one(self, particleset, particle, *list_arguments, **keyword_arguments):
677672
storage = particle.particles_set._private.attribute_storage
678673
index = storage.get_indices_of([particle.key])
679674
return self.method(index[0], *list_arguments, **keyword_arguments)
680675

681676

682-
class ParticleSetSelectSubsetMethod(object):
677+
class ParticleSetSelectSubsetMethod:
683678
"""
684679
Generic method to query and retrieve particles from the
685680
set. This selection can have up to tree stages:
@@ -720,7 +715,7 @@ def __init__(
720715

721716
def apply_on_all(self, particles, *list_arguments, **keyword_arguments):
722717
query_identifiers = None
723-
if not self.set_query_arguments_method is None:
718+
if self.set_query_arguments_method is not None:
724719
query_identifiers = self.set_query_arguments_method(
725720
*list_arguments, **keyword_arguments
726721
)
@@ -730,7 +725,7 @@ def apply_on_all(self, particles, *list_arguments, **keyword_arguments):
730725
elif not hasattr(query_identifiers, "__iter__"):
731726
query_identifiers = (query_identifiers,)
732727

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:
734729
number_of_particles_in_set = self.get_number_of_particles_in_set_method(
735730
*query_identifiers
736731
)
@@ -747,7 +742,7 @@ def apply_on_all(self, particles, *list_arguments, **keyword_arguments):
747742
return particles._subset(keys)
748743

749744

750-
class ParticlesAddedUpdateMethod(object):
745+
class ParticlesAddedUpdateMethod:
751746
def __init__(
752747
self,
753748
get_number_of_particles_added_method=None,
@@ -758,7 +753,7 @@ def __init__(
758753

759754
def apply_on_all(self, particles, *list_arguments, **keyword_arguments):
760755
query_identifiers = None
761-
if not self.set_query_arguments_method is None:
756+
if self.set_query_arguments_method is not None:
762757
query_identifiers = self.set_query_arguments_method(
763758
*list_arguments, **keyword_arguments
764759
)
@@ -768,7 +763,7 @@ def apply_on_all(self, particles, *list_arguments, **keyword_arguments):
768763
elif not hasattr(query_identifiers, "__iter__"):
769764
query_identifiers = (query_identifiers,)
770765

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:
772767
number_of_particles_in_set = self.get_number_of_particles_in_set_method(
773768
*query_identifiers
774769
)
@@ -785,7 +780,7 @@ def apply_on_all(self, particles, *list_arguments, **keyword_arguments):
785780
return particles._subset(keys)
786781

787782

788-
class ParticleGetIndexMethod(object):
783+
class ParticleGetIndexMethod:
789784
"""
790785
Instances return the index of a particle in the code
791786
"""
@@ -805,10 +800,9 @@ def get_attribute_values(self, storage, attributes_to_return, *indices):
805800

806801
class AbstractInCodeAttributeStorage(base.AttributeStorage):
807802
"""
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.
812806
813807
"""
814808

@@ -870,7 +864,7 @@ def select_getters_for(self, attributes):
870864

871865
if set_of_attributes:
872866
raise exceptions.AmuseException(
873-
"Do not have attributes {0}".format(sorted(set_of_attributes))
867+
f"Do not have attributes {sorted(set_of_attributes)}"
874868
)
875869

876870
return result
@@ -961,7 +955,7 @@ def add_particles_to_store(self, keys, attributes=[], values=[]):
961955
index = 0
962956
for key in keys:
963957
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}")
965959
self.mapping_from_particle_key_to_index_in_the_code[key] = indices[index]
966960
self.mapping_from_index_in_the_code_to_particle_key[indices[index]] = key
967961
index = index + 1
@@ -1422,17 +1416,16 @@ def get_defined_settable_attribute_names(self):
14221416
return sorted(self.writable_attributes)
14231417

14241418

1425-
class ParticleSpecificSelectSubsetMethod(object):
1419+
class ParticleSpecificSelectSubsetMethod:
14261420
"""
14271421
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.
14321425
14331426
.. code-block:: python
14341427
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)
14361429
14371430
The index or indices are converted to a particle subset.
14381431
"""
@@ -1451,14 +1444,14 @@ def apply_on_all(self, particles):
14511444
"Getting all links to other particles from all particles in a set is not implemented yet"
14521445
)
14531446

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(
14561449
[
14571450
particle.key,
14581451
]
14591452
)
14601453

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:
14621455
number_of_particles_in_set = self.get_number_of_particles_in_set_method(
14631456
from_indices
14641457
)[0]
@@ -1470,6 +1463,6 @@ def apply_on_one(self, set, particle):
14701463
index = self.method()
14711464
indices = [index]
14721465

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)
14741467

14751468
return particle.as_set()._subset(keys)

0 commit comments

Comments
 (0)