-
Notifications
You must be signed in to change notification settings - Fork 48
Programming guidelines
-
Comment your code: Especially the docstring on top of each class definition is important in a double sense. Apart from providing some documentation about the class, this docstring is evaluated through [PyRAT's help system](Help system). If it is not present, or contains only little information, also the command
help
in [CLI mode](Batch mode commands) and the help buttons in [GUI mode](Pyrat gui) won't supply a lot of information. -
Stickly follow the Python coding style: If you don't know, have a look at PEP 8 -- Style Guide for Python Code. As a user of PyCharm it's pretty simple to follow most of the rules: just use
Code->Reformat code
orCtrl-Alt-L
from time to time.
PyRAT uses automatic multiprocessing while running its workers. This implies that debugging routines can be quite tricky: possible bugs and breakpoints in spawned processes are not easy (or impossible) to catch and to analyse. It is therefore recommended not to use multiprocessing while implementing new functionality. There are several possibilities to achieve this:
-
Run PyRAT in debug mode
In debug mode, additional output is printed to the console, multiprocessing is switched off and error handling is reverted to Python default. Debug mode is started by launching PyRAT with the
-d / --debug
flag:
pyrat.run --debug
Alternatively, at the beginning of your own PyRAT scripts, use pyrat_init(debug=True)
instead of pyrat_init()
-
Switch on debug mode during script exection
To move from normal mode to debug mode, use
pyrat._debug = True
the following code will run in debug mode. Switch it off in the same way.
-
Tell your class not to use multiprocessing
In the constructor of your class, you have two possibilies to change multiprocessing behaviour:
self.nthreads = 1
will switch off multiprocessing, but will still use blockprocessing in the main thread. Note that your code will run slower (no multiprocessing) - do not forget to enable multiprocessing again when your code is ready.
self.blockprocess = False
will switch off blockprocessing entirely, together with multiprocessing. Memory consumption will be higher, since the entire layer will be transfered to your class.
PyRAT uses azimuth blockprocessing as default, with a blocksize of 128 pixels. Some routines do not allow blockprocessing, some will need range blocks instead. Blockprocessing can be influenced by the following parameters:
-
Switch off blockprocessing:
As said before, use
self.blockprocess = False
in the constructor not to use blockprocessing.
- Change blocksize:
self.blocksize = 512
will change the blocksize to another value. If you want instead to change the default, use for example
pyrat.Worker.blocksize = 512
- Use vertical blocks
self.vblocks = True
in the constructor. Set it back to false to return to horizontal blocks.
- Set block overlap
self.blockoverlap = N
in the constructor (default=0) sets the number of overlap between neighbouring blocks. Must be set in all classes, which require a filter discard at the block boundaries.