Help with loading an .hdr file in python

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Help with loading an .hdr file in python

thiirane
Hello,

I have a series of .hdr files (>1000) that I need to convert to .png or .bmp files so that I can merge them into a .avi or .mpeg.  I want to automate this process in the python script.  The first step is writing the script and importing into Opticks.   I have looked at other examples scripts

Here is what I have so far....

import os,sys,glob
from os.path import basename,splitext
import ctypes
import opticks.load_file = opticks._genwrap("loadFile", ctypes.c_uint32, ctypes.c_char_p, ctypes.c_int)

def main():
    files=[]
    fname=[]
    path="c:/users/russ/documents/"
    files=glob.glob("c:/users/russ/documents/*.hdr")
    fname=[splitext(basename(i))[0] for i in files]
    #print files[0]
    for i in range(0,len(files)):
        fname[i]=fname[i]+'.hdr'
    #print fname[0]
opticks.load_file(fname[0], 0)

if __name__ == '__main__':
    main()

I have successfully typed in all of the lines in the scripting window.  I have demonstrate my ability to call up any filename in my directory.  The problem comes when I attempt to load it into Opticks.  Can you offer any assistance on the proper use of the opticks._genwrap module?
Reply | Threaded
Open this post in threaded view
|

Re: Help with loading an .hdr file in python

thiirane
This post was updated on .
screen capture of Opticks scripting window I applied the commandline opticks.load_file=fname[0] and it appeared to accept it....How do I display the .hdr in Opticks as I would if I were to manually import the file?
Reply | Threaded
Open this post in threaded view
|

Re: Help with loading an .hdr file in python

tclarke
Administrator
In reply to this post by thiirane
First, the _genwrap isn't what you need..it's used to interface to the Opticks C api (not the other way around). You have a  couple of options. If you want to use python you can put in a call to the GeoTIFF exporter (see opticks.PlugIn) then just run the loop in the Python scripting window. Note that the PNG exporter is a view "snapshot" and does not simply convert the raw data.

A better option would be to skip Python and using a wizard with batch mode opticks. You add an Import Data Set item and feed it to an Export Data Set item. Set the Execution Mode to Batch then open with the Batch Wizard Editor and use Filesets to iterate files.

Likely a better option for just converting is not to use Opticks which is really more of an interactive tool and while there is batch capability, it can be a bit awkward to use. GDAL (via the gdalconvert tool) with a simple bash script would likely be much quicker to create.

----------------------
Trevor R.H. Clarke
Software Engineer, Ball Aerospace
(937)320-7087


> -----Original Message-----
> From: thiirane [mailto:[hidden email]]
> Sent: Thursday, April 10, 2014 10:57 AM
> To: [hidden email]
> Subject: [Opticks-devs] Help with loading an .hdr file in python
>
> Hello,
>
> I have a series of .hdr files (>1000) that I need to convert to .png or .bmp
> files so that I can merge them into a .avi or .mpeg.  I want to automate
> this process in the python script.  The first step is writing the script and
> importing into Opticks.   I have looked at other examples scripts
>
> Here is what I have so far....
>
> import os,sys,glob
> from os.path import basename,splitext
> import ctypes
> import opticks.load_file = opticks._genwrap("loadFile", ctypes.c_uint32,
> ctypes.c_char_p, ctypes.c_int)
>
> def main():
>     files=[]
>     fname=[]
>     path="c:/users/russ/documents/"
>     files=glob.glob("c:/users/russ/documents/*.hdr")
>     fname=[splitext(basename(i))[0] for i in files]
>     #print files[0]
>     for i in range(0,len(files)):
>         fname[i]=fname[i]+'.hdr'
>     #print fname[0]
> opticks.load_file(fname[0], 0)
>
> if __name__ == '__main__':
>     main()
>
> I have successfully typed in all of the lines in the scripting window.  I
> have demonstrate my ability to call up any filename in my directory.  The
> problem comes when I attempt to load it into Opticks.  Can you offer any
> assistance on the proper use of the opticks._genwrap module?
>
>
>
> --
> View this message in context:
> https://urldefense.proofpoint.com/v1/url?u=http://opticks-
> devs.2021163.n4.nabble.com/Help-with-loading-an-hdr-file-in-python-
> tp4653175.html&k=1GMYaKjmAz8SrwAdnQ9klA%3D%3D%0A&r=Ho639Wn0L
> QPE3P8SnMqwUA%3D%3D%0A&m=y37de6JnaynNAp75ZHbSeb2%2BOb9d6r
> aYhp5JpyTcFbI%3D%0A&s=b2c57df3c115ba6795379b76a676ae50060626bf689
> 1719020bb778fa3318ad1
> Sent from the opticks-devs mailing list archive at Nabble.com.
>
> ------------------------------------------------------------------------------
> Put Bad Developers to Shame
> Dominate Development with Jenkins Continuous Integration
> Continuously Automate Build, Test & Deployment
> Start a new project now. Try Jenkins in the cloud.
> https://urldefense.proofpoint.com/v1/url?u=http://p.sf.net/sfu/13600_Clo
> udbees&k=1GMYaKjmAz8SrwAdnQ9klA%3D%3D%0A&r=Ho639Wn0LQPE3P8
> SnMqwUA%3D%3D%0A&m=y37de6JnaynNAp75ZHbSeb2%2BOb9d6raYhp5J
> pyTcFbI%3D%0A&s=1f3ed88625e0bd1371b2dcb9401391774045a489a7f718f74
> 5f979cc52a47597
> _______________________________________________
> Opticks-devs mailing list
> [hidden email]
> https://urldefense.proofpoint.com/v1/url?u=https://lists.sourceforge.net/li
> sts/listinfo/opticks-
> devs&k=1GMYaKjmAz8SrwAdnQ9klA%3D%3D%0A&r=Ho639Wn0LQPE3P8Sn
> MqwUA%3D%3D%0A&m=y37de6JnaynNAp75ZHbSeb2%2BOb9d6raYhp5Jpy
> TcFbI%3D%0A&s=0b12083d68c780b11d26a671362fabc7cb5adea46963f81c349
> 603cf0af83f5f



This message and any enclosures are intended only for the addressee.  Please
notify the sender by email if you are not the intended recipient.  If you are
not the intended recipient, you may not use, copy, disclose, or distribute this
message or its contents or enclosures to any other person and any such actions
may be unlawful.  Ball reserves the right to monitor and review all messages
and enclosures sent to or from this email address.

------------------------------------------------------------------------------
Put Bad Developers to Shame
Dominate Development with Jenkins Continuous Integration
Continuously Automate Build, Test & Deployment
Start a new project now. Try Jenkins in the cloud.
http://p.sf.net/sfu/13600_Cloudbees
_______________________________________________
Opticks-devs mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/opticks-devs