Skip to content

Commit de86dc4

Browse files
committed
Apply various easy fixes
1 parent 8c0002f commit de86dc4

23 files changed

Lines changed: 374 additions & 41 deletions
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
# -*- coding: iso-8859-1 -*-
2+
3+
"""
4+
Colour-blind proof distinct colours module, based on work by Paul Tol
5+
Pieter van der Meer, 2011
6+
SRON - Netherlands Institute for Space Research
7+
"""
8+
9+
# colour table in HTML hex format
10+
hexcols = ['#332288', '#88CCEE', '#44AA99', '#117733', '#999933', '#DDCC77',
11+
'#CC6677', '#882255', '#AA4499', '#661100', '#6699CC', '#AA4466',
12+
'#4477AA']
13+
14+
greysafecols = ['#809BC8', '#FF6666', '#FFCC66', '#64C204']
15+
16+
xarr = [[12],
17+
[12, 6],
18+
[12, 6, 5],
19+
[12, 6, 5, 3],
20+
[0, 1, 3, 5, 6],
21+
[0, 1, 3, 5, 6, 8],
22+
[0, 1, 2, 3, 5, 6, 8],
23+
[0, 1, 2, 3, 4, 5, 6, 8],
24+
[0, 1, 2, 3, 4, 5, 6, 7, 8],
25+
[0, 1, 2, 3, 4, 5, 9, 6, 7, 8],
26+
[0, 10, 1, 2, 3, 4, 5, 9, 6, 7, 8],
27+
[0, 10, 1, 2, 3, 4, 5, 9, 6, 11, 7, 8]]
28+
29+
# get specified nr of distinct colours in HTML hex format.
30+
# in: nr - number of colours [1..12]
31+
# returns: list of distinct colours in HTML hex
32+
33+
def get_distinct(nr):
34+
35+
# check if nr is in correct range
36+
37+
if nr < 1 or nr > 12:
38+
print("wrong nr of distinct colours!")
39+
return
40+
41+
# get list of indices
42+
43+
lst = xarr[nr-1]
44+
45+
# generate colour list by stepping through indices and looking them up
46+
# in the colour table
47+
48+
i_col = 0
49+
col = [0] * nr
50+
for idx in lst:
51+
col[i_col] = hexcols[idx]
52+
i_col+=1
53+
return col
54+
55+
# gets 4 colours, which also look distinct in black&white
56+
# returns: list of 4 colours in
57+
#def get_distinct_grey():
58+
59+
import sys
60+
61+
# display usage information and produce example plot.
62+
if __name__ == '__main__':
63+
import numpy as np
64+
import matplotlib.mlab as mlab
65+
import matplotlib.pyplot as plt
66+
67+
print(__doc__)
68+
print("usage examples: ")
69+
print("print distinct_colours.get_distinct(2)")
70+
print(get_distinct(2))
71+
print("print distinct_colours.greysafecols")
72+
print(greysafecols)
73+
74+
print("generating example plot: distinct_colours_example.png")
75+
plt.close()
76+
t = np.arange(0.0, 2.0, 0.01)
77+
n = 12
78+
if len(sys.argv) > 1: n = int(sys.argv[1])
79+
cols = get_distinct(n)
80+
d = 2./n
81+
for i in range(n):
82+
s = np.sin(i*d*np.pi*t)
83+
plt.plot(t, s, linewidth=2.0, c=cols[i], label=str(i))
84+
85+
plt.xlabel('time (s)')
86+
plt.ylabel('voltage (mV)')
87+
plt.title('Distinct colours example (n = '+str(n)+')')
88+
plt.grid(True)
89+
plt.legend(loc=3, ncol=2)
90+
91+
plt.savefig("distinct_colours_example.png")
92+
plt.show()

src/amuse/examples/gravity_hydro.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,12 @@ def new_option_parser():
152152
help="end time of the simulation [%default]")
153153
return result
154154

155-
if __name__ in ('__main__', '__plot__'):
155+
156+
def main():
156157
o, arguments = new_option_parser().parse_args()
157158
numpy.random.seed(123)
158159
gravity_hydro_bridge(**o.__dict__)
160+
161+
162+
if __name__ in ('__main__', '__plot__'):
163+
main()

src/amuse/examples/gravity_stellar_minimal.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -166,13 +166,13 @@ def gravity_stellar_minimal_argument_parser():
166166
return result
167167

168168

169-
def main(args):
170-
arguments = gravity_stellar_minimal_argument_parser().parse_args(args)
171-
gravity_stellar_minimal(**arguments.__dict__)
169+
def main():
170+
if shell_is_interactive():
171+
gravity_stellar_minimal({})
172+
else:
173+
arguments = gravity_stellar_minimal_argument_parser().parse_args(sys.argv[1:])
174+
gravity_stellar_minimal(**arguments.__dict__)
172175

173176

174177
if __name__ == "__main__":
175-
if shell_is_interactive():
176-
main([])
177-
else:
178-
main(sys.argv[1:])
178+
main()

src/amuse/examples/gravity_to_virial.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
"""
44
from amuse.lab import *
55
from matplotlib import pyplot
6-
from prepare_figure import single_frame, figure_frame, set_tickmarks
7-
from distinct_colours import get_distinct
6+
from amuse.examples.prepare_figure import single_frame, figure_frame, set_tickmarks
7+
from amuse.examples.distinct_colours import get_distinct
88

99
def virial_ratio_evolution(code, bodies, Q_init, t_end):
1010
dt = 0.06125 | t_end.unit

src/amuse/examples/hydrodynamics_class.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from amuse.community.fi.interface import Fi
99
from amuse.community.gadget2.interface import Gadget2
1010

11-
from cooling_class import Cooling, SimplifiedThermalModelEvolver
11+
from amuse.examples.cooling_class import Cooling, SimplifiedThermalModelEvolver
1212
# from amuse.ext.sink import SinkParticles
1313
from amuse.ext.sink import new_sink_particles
1414

src/amuse/examples/iliev_test5.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -344,11 +344,9 @@ def plots(i):
344344
aplot(i, 'mach', ((r/15, mach, 'r'),),
345345
xlim=(0., 1.), ylim=(1.e-5, 10.))
346346

347-
# main example
348-
349-
350-
if __name__ == "__main__":
351347

348+
# main example
349+
def main():
352350
N = 10000
353351
Ns = 1
354352
L = 15. | units.kpc
@@ -361,3 +359,7 @@ def plots(i):
361359
if IS_PLOT_AVAILABLE:
362360
plots(50)
363361
plots(100)
362+
363+
364+
if __name__ == "__main__":
365+
main()

src/amuse/examples/kelvin_helmholtz.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,12 @@ def plot_grid(grid):
152152
plot.imshow(rho, origin = 'lower', cmap='jet')
153153
figure.savefig('kelvin_helmholtz.png')
154154
pyplot.show()
155-
156-
if __name__ == "__main__":
155+
156+
157+
def main():
157158
grids = simulate_kelvin_helmholtz_instability(1.0 | time)
158159
plot_grid(grids[0])
160+
161+
162+
if __name__ == "__main__":
163+
main()

src/amuse/examples/list_of_examples.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
chapter_6 = ["hydro_minimal", "hydro_outflow_particles", "hydro_sink_particles", "hydro_disk_with_bump", "explode_evolved_star", "helium_star", ]
66
chapter_7 = ["rad_minimal", "radiative_h2cloud", ]
77
chapter_8 = ["gravity_stellar_minimal", "gravity_stellar_collision", "plot_fractal_clumpy_cluster", "gravity_stellar_eventdriven", "merge_two_stars_and_evolve", "merge_two_stars_sph", "gravity_kepler_disks", "basic_multiples", "kira", "lonely_planets", ]
8-
chapter_9 = ["gravity_potential", "gravity_drifter", "two_body_bridge", "three_body_bridge", "three_body_bridge_hierarchical", "gravity_hydro", "relas_gas_and_stars", "evolve_xi_tau_primary", ]
8+
chapter_9 = ["gravity_potential", "gravity_drifter", "two_body_bridge", "three_body_bridge", "three_body_bridge_hierarchical", "gravity_hydro", "relax_gas_and_stars", "evolve_xi_tau_primary", ]
99
chapter_10 = ["multiples_minimal", "kira", ]
1010
appendix_a = ["multiple_stellar_threaded", ]
1111
appendix_b = []

src/amuse/examples/make_oort_cloud.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ def main():
393393
outfile = args.outfile
394394

395395
if args.outfile is None:
396-
outfile = f"sun_and_comets_N{args:01}.amuse"
396+
outfile = f"sun_and_comets_N{args.n_comets:01}.amuse"
397397

398398
bodies = read_set_from_file(args.filename, close_file=True)
399399
stars = bodies[bodies.type == "star"]

src/amuse/examples/merge_two_stars_sph_convergence.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
from amuse.lab import *
55
from amuse.plot import plot
66
from amuse.ext.sph_to_star import convert_SPH_to_stellar_model
7-
from prepare_figure import *
8-
from distinct_colours import get_distinct
7+
from amuse.examples.prepare_figure import *
8+
from amuse.examples.distinct_colours import get_distinct
99

1010
def return_evolved_star_hydro(mass, time, Nsph):
1111
star = Particle(mass=mass)

0 commit comments

Comments
 (0)