visualdatatools.com Forum Index visualdatatools.com
Discussion for DataTank and DataGraph
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Writing DataTank objects from Python

 
Post new topic   Reply to topic    visualdatatools.com Forum Index -> Using External Programs
View previous topic :: View next topic  
Author Message
Adam



Joined: 01 Dec 2006
Posts: 61
Location: Sequim, WA

PostPosted: Mon Mar 08, 2010 2:09 pm    Post subject: Writing DataTank objects from Python Reply with quote

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 Smile.
Back to top
View user's profile Send private message
Adam



Joined: 01 Dec 2006
Posts: 61
Location: Sequim, WA

PostPosted: Thu Mar 11, 2010 6:53 pm    Post subject: Reply with quote

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 Smile. 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
View user's profile Send private message
Adam



Joined: 01 Dec 2006
Posts: 61
Location: Sequim, WA

PostPosted: Thu Jun 10, 2010 10:14 pm    Post subject: Reply with quote

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
View user's profile Send private message
Adam



Joined: 01 Dec 2006
Posts: 61
Location: Sequim, WA

PostPosted: Thu Dec 09, 2010 11:22 pm    Post subject: Reply with quote

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 Smile.
Back to top
View user's profile Send private message
Adam



Joined: 01 Dec 2006
Posts: 61
Location: Sequim, WA

PostPosted: Mon Feb 14, 2011 3:48 pm    Post subject: Reading support Reply with quote

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 Very Happy.
Back to top
View user's profile Send private message
Adam Maxwell



Joined: 23 Feb 2014
Posts: 4

PostPosted: Sun Feb 23, 2014 2:29 am    Post subject: New location Reply with quote

I've created a GitHub repository for my datatank_py project, which is still being developed.

https://github.com/amaxwell/datatank_py

More high level objects have been added since I last posted, and a few changes have been made for compatibility with those. You can now create a fair number of 2D/3D grid-based objects from Python.

If you have improvements or fixes, feel free to issue a pull request on GitHub.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    visualdatatools.com Forum Index -> Using External Programs All times are GMT - 3 Hours
Page 1 of 1

 
Jump to:  
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