From 54e26e906dc821af3522170fbf2003e30415c504 Mon Sep 17 00:00:00 2001 From: Steven Rieder Date: Fri, 14 Jun 2024 15:06:44 +0200 Subject: [PATCH 1/6] split off astronomical constants from units --- src/amuse/units/astronomical_constants.py | 19 +++++++++++++++++++ src/amuse/units/units.py | 23 ++++++++++++----------- 2 files changed, 31 insertions(+), 11 deletions(-) create mode 100644 src/amuse/units/astronomical_constants.py diff --git a/src/amuse/units/astronomical_constants.py b/src/amuse/units/astronomical_constants.py new file mode 100644 index 0000000000..1b9c285ca0 --- /dev/null +++ b/src/amuse/units/astronomical_constants.py @@ -0,0 +1,19 @@ +""" +Series of astronomical constants, which are in turn used by the units of the +same names. +""" + +import numpy as np +from amuse.units.si import m, kg +from amuse.units.derivedsi import W, km + +au = 149597870691.0 | m +parsec = au / np.tan(np.pi / (180 * 60 * 60)) +lightyear = 9460730472580.8 | km +Lsun = 3.839e26 | W +Msun = 1.98892e30 | kg +Rsun = 6.955e8 | m +Mjupiter = 1.8987e27 | kg +Rjupiter = 71492.0 | km +Mearth = 5.9722e24 | kg +Rearth = 6371.0088 | km # IUGG mean radius diff --git a/src/amuse/units/units.py b/src/amuse/units/units.py index eeab5a068f..22b7a100c4 100644 --- a/src/amuse/units/units.py +++ b/src/amuse/units/units.py @@ -4,6 +4,7 @@ import numpy from . import constants +from . import astronomical_constants from . import quantities # The two imports below are to explicitly expose everything directly used in @@ -43,20 +44,20 @@ # astronomical units angstrom = named("angstrom", "angstrom", 1e-10 * m) -au = named("astronomical unit", "au", 149597870691.0 * m) -aud = named("au per day", "aud", 149597870691.0 * m / day) -parsec = named("parsec", "parsec", au / numpy.tan(numpy.pi / (180 * 60 * 60))) +au = named("astronomical unit", "au", astronomical_constants.au.as_unit()) +aud = named("au per day", "aud", astronomical_constants.au.as_unit() / day) +parsec = named("parsec", "parsec", astronomical_constants.parsec.as_unit()) kpc = named("kilo parsec", "kpc", 10**3 * parsec) Mpc = named("mega parsec", "Mpc", 10**6 * parsec) Gpc = named("giga parsec", "Gpc", 10**9 * parsec) -lightyear = named("light year", "ly", 9460730472580.8 * km) -LSun = named("solar luminosity", "LSun", 3.839e26 * W) -MSun = named("solar mass", "MSun", 1.98892e30 * kg) -RSun = named("solar radius", "RSun", 6.955e8 * m) -MJupiter = named("jupiter mass", "MJupiter", 1.8987e27 * kg) -RJupiter = named("jupiter radius", "RJupiter", 71492.0 * km) -MEarth = named("earth mass", "MEarth", 5.9722e24 * kg) -REarth = named("earth radius", "REarth", 6371.0088 * km) # IUGG mean radius +lightyear = named("light year", "ly", astronomical_constants.lightyear.as_unit()) +LSun = named("solar luminosity", "LSun", astronomical_constants.Lsun.as_unit()) +MSun = named("solar mass", "MSun", astronomical_constants.Msun.as_unit()) +RSun = named("solar radius", "RSun", astronomical_constants.Rsun.as_unit()) +MJupiter = named("jupiter mass", "MJupiter", astronomical_constants.Mjupiter.as_unit()) +RJupiter = named("jupiter radius", "RJupiter", astronomical_constants.Rjupiter.as_unit()) +MEarth = named("earth mass", "MEarth", astronomical_constants.Mearth.as_unit()) +REarth = named("earth radius", "REarth", astronomical_constants.Rearth.as_unit()) kyr = named("kilo year", "kyr", 1000 * yr) myr = named("million year", "Myr", 1000000 * yr) gyr = named("giga (billion) year", "Gyr", 1000000000 * yr) From 3f661afea3ae6e7a4d6d05b98d093a91d19d749e Mon Sep 17 00:00:00 2001 From: Steven Rieder Date: Mon, 8 Jul 2024 12:56:31 +0200 Subject: [PATCH 2/6] Lightyear is a physical constant (julianyr * lightspeed), not astronomical --- src/amuse/units/amuse_2010/__init__.py | 1 + src/amuse/units/{ => amuse_2010}/astronomical_constants.py | 2 +- src/amuse/units/{constants.py => physical_constants.py} | 0 src/amuse/units/units.py | 3 ++- 4 files changed, 4 insertions(+), 2 deletions(-) create mode 100644 src/amuse/units/amuse_2010/__init__.py rename src/amuse/units/{ => amuse_2010}/astronomical_constants.py (93%) rename src/amuse/units/{constants.py => physical_constants.py} (100%) diff --git a/src/amuse/units/amuse_2010/__init__.py b/src/amuse/units/amuse_2010/__init__.py new file mode 100644 index 0000000000..066260ae03 --- /dev/null +++ b/src/amuse/units/amuse_2010/__init__.py @@ -0,0 +1 @@ +# constants as originally defined/used in AMUSE diff --git a/src/amuse/units/astronomical_constants.py b/src/amuse/units/amuse_2010/astronomical_constants.py similarity index 93% rename from src/amuse/units/astronomical_constants.py rename to src/amuse/units/amuse_2010/astronomical_constants.py index 1b9c285ca0..febd7145ac 100644 --- a/src/amuse/units/astronomical_constants.py +++ b/src/amuse/units/amuse_2010/astronomical_constants.py @@ -7,9 +7,9 @@ from amuse.units.si import m, kg from amuse.units.derivedsi import W, km + au = 149597870691.0 | m parsec = au / np.tan(np.pi / (180 * 60 * 60)) -lightyear = 9460730472580.8 | km Lsun = 3.839e26 | W Msun = 1.98892e30 | kg Rsun = 6.955e8 | m diff --git a/src/amuse/units/constants.py b/src/amuse/units/physical_constants.py similarity index 100% rename from src/amuse/units/constants.py rename to src/amuse/units/physical_constants.py diff --git a/src/amuse/units/units.py b/src/amuse/units/units.py index 22b7a100c4..f4f158e0aa 100644 --- a/src/amuse/units/units.py +++ b/src/amuse/units/units.py @@ -4,6 +4,7 @@ import numpy from . import constants +from . import physical_constants from . import astronomical_constants from . import quantities @@ -50,7 +51,7 @@ kpc = named("kilo parsec", "kpc", 10**3 * parsec) Mpc = named("mega parsec", "Mpc", 10**6 * parsec) Gpc = named("giga parsec", "Gpc", 10**9 * parsec) -lightyear = named("light year", "ly", astronomical_constants.lightyear.as_unit()) +lightyear = named("light year", "ly", (physical_constants.c * julianyr).as_unit()) LSun = named("solar luminosity", "LSun", astronomical_constants.Lsun.as_unit()) MSun = named("solar mass", "MSun", astronomical_constants.Msun.as_unit()) RSun = named("solar radius", "RSun", astronomical_constants.Rsun.as_unit()) From e8563b881281c6472e82474e6e3811cefcdfdfed Mon Sep 17 00:00:00 2001 From: Steven Rieder Date: Mon, 8 Jul 2024 12:57:17 +0200 Subject: [PATCH 3/6] sanitize test_pickle, *don't* import * from modules! causes clashes between units/constants. --- .../test/suite/core_tests/test_pickle.py | 73 +++++++++++-------- 1 file changed, 43 insertions(+), 30 deletions(-) diff --git a/src/amuse/test/suite/core_tests/test_pickle.py b/src/amuse/test/suite/core_tests/test_pickle.py index eff6d02817..6b88398006 100644 --- a/src/amuse/test/suite/core_tests/test_pickle.py +++ b/src/amuse/test/suite/core_tests/test_pickle.py @@ -1,37 +1,30 @@ -from amuse.test import amusetest - +import subprocess import pickle +import sys +import os -from amuse.support.exceptions import AmuseException +from amuse.test import amusetest -from amuse.units import core from amuse.units import si from amuse.units import nbody_system -from amuse.units import generic_unit_system from amuse.units.quantities import zero -from amuse.units.units import * -from amuse.units.constants import * +from amuse.units.units import m, km, kg, parsec, stellar_type from amuse.datamodel import Particles, parameters -import subprocess -import pickle -import sys -import os - class TestPicklingOfUnitsAndQuantities(amusetest.TestCase): def test1(self): - km = 1000 * m - self.assertEqual(1000, km.value_in(m)) - pickled_km = pickle.dumps(km) - unpickled_km = pickle.loads(pickled_km) - self.assertEqual(1000, unpickled_km.value_in(m)) + kilometer = 1000 * m + self.assertEqual(1000, kilometer.value_in(m)) + pickled_kilometer = pickle.dumps(kilometer) + unpickled_kilometer = pickle.loads(pickled_kilometer) + self.assertEqual(1000, unpickled_kilometer.value_in(m)) def test2(self): - km = 1000 * m - quantity = 12.0 | km + kilometer = 1000 * m + quantity = 12.0 | kilometer self.assertEqual(12000, quantity.value_in(m)) pickled_quantity = pickle.dumps(quantity) unpickled_quantity = pickle.loads(pickled_quantity) @@ -81,7 +74,9 @@ def test8(self): def test9(self): quantity = 1.3 | nbody_system.time - path = os.path.abspath(os.path.join(self.get_path_to_results(), "test9.pickle")) + path = os.path.abspath( + os.path.join(self.get_path_to_results(), "test9.pickle") + ) with open(path, "wb") as stream: pickle.dump(quantity, stream) @@ -89,7 +84,12 @@ def test9(self): pythonpath = os.pathsep.join(sys.path) env = os.environ.copy() env['PYTHONPATH'] = pythonpath - code = "import pickle;stream = open('{0}', 'rb'); print(str(pickle.load(stream)));stream.close()".format(path) + code = ( + f"import pickle;" + f"stream = open('{path}', 'rb');" + f"print(str(pickle.load(stream)));" + f"stream.close()" + ) process = subprocess.Popen([ sys.executable, @@ -100,18 +100,28 @@ def test9(self): ) unpickled_quantity_string, error_string = process.communicate() self.assertEqual(process.returncode, 0) - self.assertEqual(str(quantity), unpickled_quantity_string.strip().decode('utf-8')) + self.assertEqual( + str(quantity), + unpickled_quantity_string.strip().decode('utf-8') + ) def test10(self): quantity = 1 | parsec - path = os.path.abspath(os.path.join(self.get_path_to_results(), "test10.pickle")) + path = os.path.abspath( + os.path.join(self.get_path_to_results(), "test10.pickle") + ) with open(path, "wb") as stream: pickle.dump(quantity, stream) pythonpath = os.pathsep.join(sys.path) env = os.environ.copy() env['PYTHONPATH'] = pythonpath - code = "import pickle;stream = open('{0}', 'rb'); print(str(pickle.load(stream)));stream.close()".format(path) + code = ( + f"import pickle;" + f"stream = open('{path}', 'rb');" + f"print(str(pickle.load(stream)));" + f"stream.close()" + ) process = subprocess.Popen([ sys.executable, @@ -122,7 +132,10 @@ def test10(self): ) unpickled_quantity_string, error_string = process.communicate() self.assertEqual(process.returncode, 0) - self.assertEqual(str(quantity), unpickled_quantity_string.strip().decode('utf-8')) + self.assertEqual( + str(quantity), + unpickled_quantity_string.strip().decode('utf-8') + ) def test11(self): value = 1 | stellar_type @@ -175,7 +188,7 @@ def test4(self): self.assertEqual(unpickled_particles.center_of_mass(), [2, 3, 0] | m) -class BaseTestModule(object): +class BaseTestModule: def before_get_parameter(self): return @@ -202,13 +215,13 @@ def set_test(self, value): self.x = value o = TestModule() - set = parameters.Parameters([definition,], o) - set.test_name = 10 | m + paramset = parameters.Parameters([definition,], o) + paramset.test_name = 10 | m self.assertEqual(o.x, 10 | m) - self.assertEqual(set.test_name, 10 | m) + self.assertEqual(paramset.test_name, 10 | m) - memento = set.copy() + memento = paramset.copy() self.assertEqual(memento.test_name, 10 | m) pickled_memento = pickle.dumps(memento) From 34651808bd6fb588bbd2a043000692e0ae662329 Mon Sep 17 00:00:00 2001 From: Steven Rieder Date: Mon, 8 Jul 2024 12:59:39 +0200 Subject: [PATCH 4/6] I know, importing *... but here no better way to do it. --- src/amuse/units/astronomical_constants.py | 10 ++++++++++ src/amuse/units/constants.py | 2 ++ 2 files changed, 12 insertions(+) create mode 100644 src/amuse/units/astronomical_constants.py create mode 100644 src/amuse/units/constants.py diff --git a/src/amuse/units/astronomical_constants.py b/src/amuse/units/astronomical_constants.py new file mode 100644 index 0000000000..5582189738 --- /dev/null +++ b/src/amuse/units/astronomical_constants.py @@ -0,0 +1,10 @@ +""" +Series of astronomical constants, which are in turn used by the units of the +same names. +""" + +# Until we have a way to select a system of constants, use the originally +# defined values. Later, we should have a way to select between different +# constants definitions. + +from amuse.units.amuse_2010.astronomical_constants import * diff --git a/src/amuse/units/constants.py b/src/amuse/units/constants.py new file mode 100644 index 0000000000..f44ee928f4 --- /dev/null +++ b/src/amuse/units/constants.py @@ -0,0 +1,2 @@ +from .physical_constants import * +from .astronomical_constants import * From a95b3e51547f47cf186a6f8d6e1db725f0942d57 Mon Sep 17 00:00:00 2001 From: Steven Rieder Date: Mon, 8 Jul 2024 13:01:25 +0200 Subject: [PATCH 5/6] rewrite/modernise nist.py. I think the NIST_URL is no longer operational, but manual downloading and passing the filename works. --- src/amuse/units/nist.py | 207 ++++++++++++++++++++++++++-------------- 1 file changed, 134 insertions(+), 73 deletions(-) diff --git a/src/amuse/units/nist.py b/src/amuse/units/nist.py index b57817efeb..ade920ebfd 100644 --- a/src/amuse/units/nist.py +++ b/src/amuse/units/nist.py @@ -1,3 +1,5 @@ +import sys + import urllib.request, urllib.error, urllib.parse, urllib.request, urllib.parse, urllib.error import difflib import os.path @@ -9,18 +11,18 @@ from amuse.units import derivedsi NIST_URL = "http://132.229.222.6:9000/nistdata" -MESSAGE = \ -""" -#This is an auto generated file, do not change manually. Instead if you want to add constants -#or change them, change the nist.txt file and run nist.py +MESSAGE = """\"\"\" +Physical constants +\"\"\" +# This is an auto generated file, do not change manually. Instead if you want +# to add constants or change them, change the nist.txt file and run nist.py import numpy -from amuse.units.si import * -from amuse.units.derivedsi import * +from amuse.units.si import m, kg, s, A, K, mol, none +from amuse.units.derivedsi import Hz, MHz, sr, N, Pa, J, W, F, C, V, T, ohm, S, Wb """ -ADDITIONAL_DERIVED_CONSTANTS = \ -""" +ADDITIONAL_DERIVED_CONSTANTS = """ pi = numpy.pi hbar = h / (2.0 * numpy.pi) four_pi_stefan_boltzmann = 4.0 * numpy.pi * Stefan_hyphen_Boltzmann_constant @@ -31,9 +33,12 @@ eps = numpy.finfo(numpy.double).eps precision = int(numpy.log10(2/eps)) """ -class GetConstantsFromFiles(object): - - def __init__(self): + + +class GetConstantsFromFiles: + + def __init__(self, filename="nist.txt"): + self.nist_filename = filename self.nist_table = "" self.local_table = "" self.translator_table = [] @@ -45,88 +50,107 @@ def get_table_from_url(self): f.close() def save_table_as(self, filename): - f = open(os.path.join(self.directory, 'nist.txt'), 'w') + f = open(os.path.join(self.directory, self.nist_filename), "w") f.write(self.nist_table) f.close() - + def get_table_from_file(self): - f = open(os.path.join(self.directory, 'nist.txt'), 'r') # CODATA 2006, for CODATA 2010 use 'nist2010.txt' - self.nist_table = f.read() - f.close() + f = open( + os.path.join(self.directory, self.nist_filename), "r" + ) # CODATA 2006, for CODATA 2010 use 'nist2010.txt' + self.nist_table = f.read() + f.close() def check_current_file_with_table(self): - md5sum_local = md5() - md5sum_local.update(self.local_table) - md5sum_local_val = md5sum_local.hexdigest() - md5sum_wgot = md5() - md5sum_wgot.update(self.nist_table) - md5sum_wgot_val = md5sum_wgot.hexdigest() - return md5sum_local_val == md5sum_wgot_val + md5sum_local = md5() + md5sum_local.update(self.local_table) + md5sum_local_val = md5sum_local.hexdigest() + md5sum_wgot = md5() + md5sum_wgot.update(self.nist_table) + md5sum_wgot_val = md5sum_wgot.hexdigest() + return md5sum_local_val == md5sum_wgot_val def compare_char_by_char(self): - self.nist_table.lstrip('\n') - mydiff = difflib.unified_diff(self.nist_table.splitlines(1), self.local_table.splitlines(1)) + self.nist_table.lstrip("\n") + mydiff = difflib.unified_diff( + self.nist_table.splitlines(1), self.local_table.splitlines(1) + ) for i in list(mydiff): print(i) - + def get_translator(self): - f = open(os.path.join(self.directory, 'translator.txt'), 'r') + f = open(os.path.join(self.directory, "translator.txt"), "r") lines = f.readlines() for i, s in enumerate(lines): - cols = s.split(',') + cols = s.split(",") self.translator_table.append(cols) - f.close() + f.close() + -class Constants(object): - def __init__(self): - self.I = GetConstantsFromFiles() - #I.get_table_from_url() +class Constants: + def __init__(self, filename="nist.txt"): + self.I = GetConstantsFromFiles(filename=filename) + # I.get_table_from_url() self.I.get_table_from_file() self.table = self.I.nist_table self.I.get_translator() self.translator = self.I.translator_table self.nistfile = MESSAGE - + self.nisttable = [] self.nisttablederivedunits = [] self.nisttablenoneunits = [] self.nisttablebaseunits = [] self.nisttabledependingunits = [] - self.siunits = dir(si)+dir(derivedsi) - + self.siunits = dir(si) + dir(derivedsi) + def test_regexp(self, regexp): - lines =self.table.splitlines(1) - for i,line in enumerate(lines): - if i>80: + lines = self.table.splitlines(1) + for i, line in enumerate(lines): + if i > 80: break print(re.findall(regexp, line)) def translate(self, to_translate): list = [s[1] for s in self.translator if to_translate == s[0]] if list == []: - return to_translate.lstrip(' ') + return to_translate.lstrip(" ") else: - return list[0].strip('\n') + return list[0].strip("\n") def list_constants(self): - error =[] + error = [] value = [] name = [] unit = [] - lines =self.table.splitlines(1) + lines = self.table.splitlines(1) for n, line in enumerate(lines): if "----------------------" in line: number_of_header_lines = n + 1 break firstline = lines[number_of_header_lines] - namestr_length = len(firstline) - len(firstline[firstline.find(" "):].lstrip()) - column_index_of_uncertainty = len(firstline) - len(firstline[namestr_length+21+firstline[namestr_length+21:].find(" "):].lstrip()) - column_index_of_unit = len(firstline) - len(firstline[column_index_of_uncertainty+21+firstline[column_index_of_uncertainty+21:].find(" "):].lstrip()) + print() + print(firstline) + namestr_length = len(firstline) - len( + firstline[firstline.find(" ") :].lstrip() + ) + column_index_of_uncertainty = len(firstline) - len( + firstline[ + namestr_length + 21 + firstline[namestr_length + 21 :].find(" ") : + ].lstrip() + ) + column_index_of_unit = len(firstline) - len( + firstline[ + column_index_of_uncertainty + + 21 + + firstline[column_index_of_uncertainty + 21 :].find(" ") : + ].lstrip() + ) for i in lines[number_of_header_lines:]: namestr = i[0:namestr_length] @@ -134,68 +158,105 @@ def list_constants(self): marker2 = column_index_of_unit while 1: - if i[marker1-1]=='\x20': + if i[marker1 - 1] == "\x20": break else: - marker1+=1 + marker1 += 1 while 1: - if i[marker2-1]=='\x20': + try: + if i[marker2 - 1] == "\x20": + break + else: + marker2 += 1 + except: break - else: - marker2+=1 + # print(f"i (length {len(i)}): {i}") + # print(f"marker2: {marker2}") + # sys.exit() - nrs=[] + nrs = [] nrs.append(i[namestr_length:marker1]) nrs.append(i[marker1:marker2]) unitstr = i[marker2:] - - unitstr = unitstr.strip().replace(' ','*').replace('^','**') - new_name = self.translate(namestr.rstrip(' ').replace(' ','_').replace('.','').replace('{','X').replace('}','X').replace('(','X').replace(')','X').replace('-','_hyphen_').replace(',','_and_').replace('/','_div_')) - error.append(nrs[1].replace(' ','')) - if len(unitstr)==1: + unitstr = unitstr.strip().replace(" ", " * ").replace("^", "**") + + new_name = self.translate( + namestr.rstrip(" ") + .replace(" ", "_") + .replace(".", "") + .replace("{", "X") + .replace("}", "X") + .replace("(", "X") + .replace(")", "X") + .replace("-", "_hyphen_") + .replace(",", "_and_") + .replace("/", "_div_") + ) + error.append(nrs[1].replace(" ", "")) + if len(unitstr) == 1: this_unit = "none\n" else: this_unit = unitstr - self.nisttable.append([new_name, float(i[namestr_length:marker1].replace(' ','').replace('...','')), unitstr]) + self.nisttable.append( + [ + new_name, + float( + i[namestr_length:marker1].replace(" ", "").replace("...", "") + ), + unitstr, + ] + ) def sort_units(self): for entry in self.nisttable: if entry[2] in self.siunits: self.nisttablebaseunits.append(entry) - elif entry[2] == '': + elif entry[2] == "": self.nisttablenoneunits.append(entry) - elif set(re.split('[*/^]',re.sub('\*\*-?[0-9.]*','',entry[2]))).issubset(set(self.siunits)): + elif set(re.split("[*/^]", re.sub("\*\*-?[0-9.]*", "", entry[2]))).issubset( + set(self.siunits) + ): self.nisttablederivedunits.append(entry) else: self.nisttabledependingunits.append(entry) - + def print_list_of_units(self, unitlist): for name, value, unit in unitlist: - self.nistfile += ("{0} = {1} | {2}\n".format(name, value, unit or "none")) + self.nistfile += "{0} = {1} | {2}\n".format(name, value, unit or "none") def generate_constants(self): self.list_constants() self.sort_units() - self.nistfile += "#BASE UNITS***********************************************\n" + self.nistfile += "# BASE UNITS***********************************************\n" self.print_list_of_units(self.nisttablebaseunits) - self.nistfile += "#DERIVED UNITS***********************************************\n" + self.nistfile += ( + "# DERIVED UNITS***********************************************\n" + ) self.print_list_of_units(self.nisttablederivedunits) - self.nistfile += "#RATIOS ***********************************************\n" + self.nistfile += "# RATIOS ***********************************************\n" self.print_list_of_units(self.nisttablenoneunits) - self.nistfile += "#DERIVED CONSTANTS***********************************************" + self.nistfile += ( + "# DERIVED CONSTANTS***********************************************" + ) self.nistfile += ADDITIONAL_DERIVED_CONSTANTS - self.nistfile += '#DROPPED UNITS***********************************************\n"""' + self.nistfile += ( + '# DROPPED UNITS***********************************************\n"""' + ) self.print_list_of_units(self.nisttabledependingunits) - self.nistfile +='"""\n' + self.nistfile += '"""\n' - - f = open(os.path.join(self.I.directory, 'constants.py'), 'w') + f = open(os.path.join(self.I.directory, "constants.py"), "w") f.write(self.nistfile) f.close() -if __name__ == "__main__": - print("Generating constants.py...", end=' ') - Constants().generate_constants() + +if __name__ == "__main__": + if len(sys.argv) > 1: + filename = sys.argv[1] + else: + filename = "nist.txt" + print("Generating constants.py...", end=" ") + Constants(filename=filename).generate_constants() print(" done!") From 9d20f4f8907ebfe20371b9d72377a0c13a827714 Mon Sep 17 00:00:00 2001 From: Steven Rieder Date: Mon, 8 Jul 2024 13:02:17 +0200 Subject: [PATCH 6/6] small updates --- src/amuse/units/quantities.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/amuse/units/quantities.py b/src/amuse/units/quantities.py index 8bb0bd43ea..f4df1c72a4 100644 --- a/src/amuse/units/quantities.py +++ b/src/amuse/units/quantities.py @@ -103,7 +103,7 @@ def is_vector(self): return False def __repr__(self): - return "quantity<" + str(self) + ">" + return f"quantity<{self}>" def __add__(self, other): if self.unit.is_zero(): @@ -1199,7 +1199,7 @@ def __str__(self): return self.unit.value_to_string(self.value) def __repr__(self): - return f"quantity<{str(self.value)} - {str(self)}>" + return f"quantity<{self.value} - {self}>" def as_vector_with_length(self, length): return VectorQuantity(numpy.array([self.value] * length), self.unit)