diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rwxr-xr-x | plugins/grapher.py | 50 | ||||
-rwxr-xr-x | plugins/imager.py | 44 | ||||
-rw-r--r-- | tsalis/README.md | 2 | ||||
-rw-r--r-- | tsalis/src/handler.c | 2 |
5 files changed, 84 insertions, 15 deletions
@@ -11,3 +11,4 @@ *.auto
*.exe
bin/*.png
+bin/auto/*
diff --git a/plugins/grapher.py b/plugins/grapher.py new file mode 100755 index 0000000..bd93205 --- /dev/null +++ b/plugins/grapher.py @@ -0,0 +1,50 @@ +#!/usr/bin/python +''' +This script generates a data file that can be read by gnuplot or similar +software. Columns, representing different data fields, may be generated via +command line arguments. Current available columns include: + +- current cycle: always present +- number of organisms: activate with '-o' flag + +To run it, simply call it from within the ./bin/ directory inside the SALIS +main directory, such as: + +../plugins/grapher.py -o def.sim.*.auto + +Calling this will create a single DATA file including data from all files +matching the given pattern. This file may, in turn, be passed into gnuplot +for generating graphs. +''' +import os +import sys +from ctypes import * + +current_arg = 1 +data_flags = [] + +while sys.argv[current_arg][0] == '-': + if sys.argv[current_arg] == '-o': + data_flags.append('organism_count') + print('organism count will be graphed') + else: + print('{} is not a valid flag'.format(sys.argv[current_arg])) + + current_arg += 1 + +files = sys.argv[current_arg:] +oname = 'output.data' +salis = CDLL('libsalis.so') +salis.s_getCycle.restype = c_uint +salis.s_getEpoch.restype = c_uint +salis.sp_getCount.restype = c_uint + +with open(oname, 'w') as output: + for f in files: + salis.s_load(bytes(f, 'utf-8')) + cycle = salis.s_getCycle() + epoch = salis.s_getEpoch() + date = cycle + (epoch * (2 ** 32)) + output.write('{} {}\n'.format(date, salis.sp_getCount())) + print('info of date {} added to output.data'.format(date)) + salis.s_quit() diff --git a/plugins/imager.py b/plugins/imager.py index 76d93b3..fc7d77b 100755 --- a/plugins/imager.py +++ b/plugins/imager.py @@ -1,28 +1,47 @@ -#!/usr/bin/python3 -""" -This script generates an PNG image from a SALIS save file (or a list of saved +#!/usr/bin/python +''' +This script generates a PNG image from a SALIS save file (or a list of saved files), on which each pixel corresponds to a single byte on the simulation. It's useful for identifying large scale structures and appreciating the -large-scale evolution of the world. +macro-evolution of the world. Tu run it, simply call it from within the ./bin/ directory inside the SALIS main directory, such as: -../plugins/imager.py def.sim* +../plugins/imager.py def.sim.*.auto -Calling this will create a PNG image for each file beggining with "def.sim". -""" +Calling this will create a PNG image for each file matching the given pattern. + +By default, this script ignores any existing simulation files whose name +matches an existing image on the same directory. You may force it to overwrite +existing images by passing the '-o' flag before the file list parameter. +''' +import os import sys from ctypes import * from PIL import Image -files = sys.argv[1:] -salis = CDLL("libsalis.so") + +if sys.argv[1] == '-o': + overwrite = True + files = sys.argv[2:] +else: + overwrite = False + files = sys.argv[1:] + +salis = CDLL('libsalis.so') salis.sm_getSize.restype = c_uint def makeImage(iname): - salis.s_load(bytes(iname, "utf-8")) + oname = iname + '.png' + + if not overwrite: + if os.path.isfile('./' + oname): + print(oname + ' skipped') + return + + salis.s_load(bytes(iname, 'utf-8')) lsize = int(salis.sm_getSize() ** 0.5) - image = Image.new("L", (lsize, lsize), "black") + image = Image.new('L', (lsize, lsize), 'black') pixels = image.load() for y in range(lsize): @@ -32,9 +51,8 @@ def makeImage(iname): pixels[x, y] = byte salis.s_quit() - oname = iname + ".png" image.save(oname) - print(oname + " generated") + print(oname + ' generated') for f in files: makeImage(f) diff --git a/tsalis/README.md b/tsalis/README.md index fd81a19..bb50c38 100644 --- a/tsalis/README.md +++ b/tsalis/README.md @@ -33,7 +33,7 @@ renamed and reloaded as needed. |Left arrow |Previous page | |Right arrow |Next page | |wasd |Scroll (PROCESS and WORLD page) | -|W |Scroll to top (PROCESS and WORLD page) | +|Q |Scroll to top (PROCESS and WORLD page) | |A |Scroll to left (PROCESS page) | |zx |Zoom in/out (WORLD page) | |op |Select previous/next organism | diff --git a/tsalis/src/handler.c b/tsalis/src/handler.c index e886733..f5be2c8 100644 --- a/tsalis/src/handler.c +++ b/tsalis/src/handler.c @@ -240,7 +240,7 @@ tsh_handleEvent(int event) tsp_scrollRight(); break; - case 'W': + case 'Q': tsp_scrollToTop(); break; |