 |
visualdatatools.com Discussion for DataTank and DataGraph
|
| View previous topic :: View next topic |
| Author |
Message |
Adam
Joined: 01 Dec 2006 Posts: 56 Location: Sequim, WA
|
Posted: Mon Mar 08, 2010 2:09 pm Post subject: Writing DataTank objects from Python |
|
|
Over the last few days, I've been working on a Python solution for writing .dtbin files. If anyone's interested in the work-in-progress, you can check it out with subversion:
| Code: | | svn co http://mactlmgr.googlecode.com/svn/datatank_py |
or browse the repo at http://code.google.com/p/mactlmgr/source/browse/#svn/datatank_py. This may only be a temporary home, but it was convenient.
Feedback can be sent to me directly (email address in DTDataFile.py) or posted here, but don't blame David for any bugs in it . |
|
| Back to top |
|
 |
Adam
Joined: 01 Dec 2006 Posts: 56 Location: Sequim, WA
|
Posted: Thu Mar 11, 2010 6:53 pm Post subject: |
|
|
I just realized that I can use this to implement modules, by following the conventions used for naming (Seq_Var for return variables). The great thing is that the .dtmod actually stores the script inside, so you can edit the source without recompiling or resaving the module . The creation process isn't nearly as slick as the magic Xcode project creation, though, so it may help to create a C++ project to get the variable names right.
I've posted a couple examples of how to use this to create modules (one of them works around problems linking against libDT.a on x86_64). The more basic one is http://code.google.com/p/mactlmgr/source/browse/datatank_py/examples/format_number.py, which converts a number to a string using printf-style formatting. These assume you've checked out the source to a directory searched by Python, or created a symlink so it's picked up. |
|
| Back to top |
|
 |
Adam
Joined: 01 Dec 2006 Posts: 56 Location: Sequim, WA
|
Posted: Thu Jun 10, 2010 10:14 pm Post subject: |
|
|
In case anyone's following along, I just fixed (I think) a critical bug in saving 3D arrays. Row-major vs. column-major ordering in NumPy confuses me, so any advice or checks would be welcome.
I've also added a protocol for saving high-level DTSource objects such as DTMesh2D and DTStructuredMesh3D, and have slowly been adding Python implementations of those as I've needed them (only for saving, not for computations). |
|
| Back to top |
|
 |
Adam
Joined: 01 Dec 2006 Posts: 56 Location: Sequim, WA
|
Posted: Thu Dec 09, 2010 11:22 pm Post subject: |
|
|
I've just landed a major bug fix in my DTDataFile Python code, so if you're using it, make sure to update. The short summary is that mixing reads and writes could cause file corruption under some conditions.
I noticed this while adding checks to make sure time variables are strictly increasing, as well as ensuring that your variable name time indices start at zero and are strictly increasing. Both of those have bitten me in DataTank, so now I can catch them earlier . |
|
| Back to top |
|
 |
Adam
Joined: 01 Dec 2006 Posts: 56 Location: Sequim, WA
|
Posted: Mon Feb 14, 2011 3:48 pm Post subject: Reading support |
|
|
I've started adding read support for some high-level objects, using a class method. To use it, you'd do something like
| Code: |
#!/usr/bin/python
from datatank_py.DTDataFile import DTDataFile
from datatank_py.DTBitmap2D import DTBitmap2D
input_file = DTDataFile("Input.dtbin")
bitmap = DTBitmap2D.from_data_file(input_file, "My bitmap name")
print bitmap.grid, bitmap.red, bitmap.gray
|
This allows you to read an 8-bit or 16-bit gray/color DTBitmap2D object from a .dtbin file without worrying about the underlying channel/grid variable names. As practical examples, there's now an accessor for a PIL image, and a method for saving a GeoTIFF, so dumping a DataTank drawing window as a registered raster image to share with GIS-using colleagues is now trivial . |
|
| Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|