hughesadam_87 54 Junior Poster

I'm not sure but I'm guessing that something like that would differ for each device, and of course there's the possibility that it may have a domain-specific like language connected to it. I'm intrigued by the idea though. Not to digress but on a semi-related topic I recently came across this http://pyrorobotics.org/

That is interesting. I guess I'm somewhat disheartened to find that out, but it does make sense that a developer would only write system-specific code for a device. One way I can probably do it is that spectrometers can output files in real time. I'm sure I can write a program in python to monitor the output directory, grab the new data files, append them to a large matrix, replot etc...

hughesadam_87 54 Junior Poster

Hey everyone,

I've been using python quite a bit to develop scientific applications. As of late, the Enthought Tool Suite is proving to be one of the handiest set of development tools out there.

One question I have is, with commercial software, I often see the ability to plugin output for a device. For example, my OceanOptics spectrometer comes bundled with software which allows real-time interaction with the experimental data.

I would like to write program that have such functionality in python. I don't really understand; however, at what level one tends to begin including such additions (low-level vs. high-level). Does anyone know where I could find a general tutorial for such matters?

hughesadam_87 54 Junior Poster

Thanks for the help guys. The method that Griboullis suggested seems to work with my code as it is. The other method doesn't work, but it's because I am using Tkinter and all of the pre-defined control variables produce this error:

Exception _tkinter.TclError: 'can\'t unset "PY_VAR1386": no such variable' in <bound method IntVar.__del__ of <Tkinter.IntVar instance at 0xc297e2c>> ignored

This is probably my fault, since I don't have a strong grasp on inheritance so I don't really know what I'm doing. Thanks both of you for your help.

hughesadam_87 54 Junior Poster

Thanks a lot guys. Let me play with the suggestions you've posted and see if I can get my stuff straightened out.

hughesadam_87 54 Junior Poster

You are calling the __init__ of inherited class in beginning of child __init__ , aren't you? Could you post restricted example with only the problem behaviour?

Thanks tony. I don't quite understand what that means. Can you post a quick metacode example, and then I'll put it into my code and post the restricted example? Sorry for my idiocy.

hughesadam_87 54 Junior Poster

Hey everyone, this should be simple, but I keep running into errors so help is greatly appreciated.

I have a large class, call it class A, which has several methods. Most of these methods modify data.

ClassA()
def __init(X,Y,Z)
...
..

def data_mod1():
...

def data_mod2():
...

I'm dealing with a large GUI program, which has several connected buttons. Therefore, I have another class to do nothing but handle button operations. Most of these operations are stylistic (changing colors and names). For example:

class Button_manager()

def color_style1():
....

def attribute_style1():
....

Here is the issue. At some point, it is advantageous to change the data at the level of the button_manager. Therefore, I need to borrow a method from ClassA. For example, the method

def data_mod1():

Ought to be callable from the button_manager or ClassA. I can't for the life of me get this to work though. I've tried following example on inheritance and stuff, but because the Button_Manager class is called through ClassA, it seems to give me issues. Basically, how do I load Button_Manager to share this method.

hughesadam_87 54 Junior Poster

Hmm I don't know much about heatmaps in matplotlib, but to make 1d, you may need to just make a 2d heatmap which has a very narrow height dimension.

http://stackoverflow.com/questions/2369492/generate-a-heatmap-in-matplotlib-using-a-scatter-data-set

hughesadam_87 54 Junior Poster

Which solution did you end up using to make the exe

hughesadam_87 54 Junior Poster

Can you be more specific about exactly what you want to plot. You have a list of numbers. You wanted to do some operations, like normalization and stuff... after you did all of these, what would you be left with? Strictly an array of numbers still?

hughesadam_87 54 Junior Poster

320.2e18

hughesadam_87 54 Junior Poster

Hey everyone,

I'm checking some bessel functions in python using mathematica, and I can't find anything online about how to import values into python with exponentials.

I know how to values with exponents. For example:

x=2032.43 * 10 **23

However, when I read in a data file, say with one column of values such as the one above, such a notation is not recognized by:

f=open('data.dat', 'r')
     for line in f:
         print float(line)

I've also tried other notations. What is the correct notation? Thanks

hughesadam_87 54 Junior Poster

Hey all,

After beating my head against the wall with this, I decided to post.

I'm using f2py, a wrapper to call Fortran routines from python. I can't use it because my current version of gcc does not support f2py. According to a posted solution, I have to edit my python Makefile such that:


"edit the variable BASECFLAGS to exclude -Wno-long-double" .

In the makefile, I've found the variable:

OPT=		-DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes
BASECFLAGS=	 -fno-strict-aliasing
CFLAGS=		$(BASECFLAGS) $(OPT) $(EXTRA_CFLAGS)

But have no damn idea how to exclude -wno-long-double.

Any help would be so appreciated.

But

hughesadam_87 54 Junior Poster

Enthought emailed me and said it's not supported.

hughesadam_87 54 Junior Poster

Hey everyone, I've tried extensively to find a thread like this already, so I hope it's not a repose.

Basically, I have a program with a nice GUI (Tkinter) which has a frame which takes in matplotlib figures. I am able to connect the plots to the Tkinter frame this way:

def graph_area(self, frame):
		'''Used to store parameters'''
		self.graphframe = Frame(frame)
		self.graphframe.pack(side = RIGHT)
		self.f = Figure(figsize=(5,4), dpi=100)
		self.ax1 = self.f.add_subplot(111)
		self.canvas = FigureCanvasTkAgg(self.f, self.graphframe)
		self.canvas.get_tk_widget().pack(side=TOP, fill=BOTH, expand=1)

This works very nicely; however, I would really like to have the flexibility to incorporate mlab plots into this frame interchangably. Basically, the pylab canvas is plugged right into the tkinter frame; hwoever, I don't know of a way to do with with mlab. There is some documentation how to embed mlab into a Wx or Qt program, as well as how to customize mlab call backs.

http://github.enthought.com/mayavi/mayavi/building_applications.html

Unfortunately, these don't explain if tkinter explicitly has any support for such an application. I suppose I could run the mlab programs in popup windows which aren't integrated into the frames directly; however, this is not preferred. Any help would be so greatly appreciated.

hughesadam_87 54 Junior Poster
hughesadam_87 54 Junior Poster

Hey everyone,

I'm making a data analysis suite in python, and want to construct a custom event handler which will reset the axis based on the data in the current subplot. To do so, I need the event handler to know what data is currently in the subplot. The matplotlib Axes and Axis classes are good at telling you the data limits in the entire plot, but not when the plot is zoomed in.

So for example, if my data runs from -100,100 on the x-axis, and I zoom into a window of -50,50, I need a command that will return the subset of the data within these boundaries. Then I can redraw the plot so that it effectively has the same width of the data curves. Essentially, this will autoscale the axis to optimally view the data.

I can't seem to find anything like this, and was going to try to write a custom routine to do this, but wanted to make sure no one knew of one already.

Thanks

hughesadam_87 54 Junior Poster

Hi all,

I have built a small event handler to zoom in on a graph on pyplot figure, and then I use the builtin pickline event handler to select a line. I plot multiple lines from a large dataset of ordered series, so when I choose one, I need my program to recognize which column of the original data array this is coming from. Because I'm zoomed in, when I perform the following metaoperation

thisline = event.artist
xdata, ydata = thisline.get_data()

The xdata and ydata are now subsets of the full curve, because I've zoomed in, the full data set is not being shown in the figure. What I'd like to do is
have thisline.get_data() return some sort of identifier so I know immediately which column of the full data matrix I am in.

If there is no built-in way to do it, I need to think of a clever way to take a subset of the ydata for example:

ydata=[100.4, 104.2, 503.4, 980.0]

And figure out to which column this belongs in my original array. I don't want to reinvent the wheel on this, as it seems that a very pythonic solution is lurking somewhere.

hughesadam_87 54 Junior Poster

Thanks alot I will try it!

hughesadam_87 54 Junior Poster

I'm not so great at explaining all the nuts and bolts of classes, and probably have some bad habits, but I've fixed your code so that it at least works:

class OffSwitch:
    def __init__(self):
        self.keycheck='off'

    def turnOff(self, key):
	print key, 'hi'
        if key==self.keycheck:
            SystemExit
        else:
            print('will continue')


switchword=str(raw_input('Enter a word: ') )

foo=OffSwitch()
foo.turnOff(switchword)

First, I changed your class declaration to class Offswitch: instead of Offswitch(object). I don't know why you need to put the object there, maybe there's a good reason, but it's not necessary.

Second, I changed your switchword call so that it knew to make your input a string. Again, your syntax may be fine, but this is how I do it.

Lastly, and importantly, the code works when you initialize the class before calling its methods. I made a class instance by using:

foo=OffSwitch()

Now, the variable foo, is the instance of your class. Basically, foo is a variable just waiting around for you to run the class methods. I'm no expert, but I think you always need to first instatiate a class like this before you run its methods. To run methods, the syntax is:

foo.turnOff(switchword)
hughesadam_87 54 Junior Poster

Hi,

That game sounds like a good motivator to get started. I wrote a text-based rock paper scissor game to learn early on.

Your best bet is really not a book, but a good online tutorial. I don't remember the ones I followed; however, this one looks good.

http://docs.python.org/release/2.5.2/tut/tut.html

Read along, slowly, and do every single example you find. Soon you'll understand how to do what you want. Also, since you're interested in games, once you're comfortable with basic operations in python, consider learning how to make graphical user interfaces in tandem. That way, you'll acquire both skill sets; however, keep in mind that GUI's are more difficult to write because they require a good intuition about python structures in general, so don't get frustrated at first.

I'd recommend tkinter as your GUI development toolkit:

http://www.pythonware.com/library/tkinter/introduction/

hughesadam_87 54 Junior Poster

Hey everyone,

I'm in the process of writing a data analysis program with a full GUI. The program is turning out to be quite useful for the spectral analysis we do in our lab, so I'd like to share it with my colleagues. Perhaps if it catches on, I would share it with a more general audience.

My concern is that most people I work with don't use python, and really don't have much programming experience. Therefore, if I told them to download python version 2.6, then get the matplotlib, scipy, numpy, gtk etc... packages, and then open a terminal, and type "python foo.py", all of this would turn them off. They are used to downloading a program, double clicking an icon, and having it install.

I realize that this type of simple installation is perhaps impossible, but I don't know a good alternative. Is it possibly to package all the necessary elements to make it simple for a novice to install and run your programs? Or is it possible to make an object file, for example, so that the user doesn't ever have to install python/python packages at all?

hughesadam_87 54 Junior Poster

Hey everyone.

I have a matrix of matricies. Basically, I have a 3 dimensional matrix object which stores i 2-d arrays. For example:

M=(i,j,k)
A= M[1,:,:] = (j, k)
B= M[2, :, :] = (j', k')
etc..

Now, what is want to do is actually do the entire product (A*B*C...); however, I don't really have a good way to store these variables dynamically. For example, if in one run I have 8 2-d arrays, and in the next run I have 6 2-d arrays, I have no idea how to dynamically change a product from an 8-element product to a 6-element product.

Let me know if I've made my problem clear.

hughesadam_87 54 Junior Poster

Thanks. Good call

hughesadam_87 54 Junior Poster

Hey guys,

I am writing a GUI program, and one of the routines requires that I choose a file to be my data file. If the data file is chosen correctly, then my program will send it to a subroutine which will perform a bunch of methods and ultimately construct a large matrix and return it.

Obviously, a user can import the wrong file, and when my subroutines act on this, then they are going to error. Because the user can import a bunch of different wrong files, I can't anticipate what error will present itself. For example, IndexError vs. ValueError. Therefore, I'd like to do something like is presented in the following metacode:

Imported file = f

Try:
  Run subroutines on f
Except AllErrorsImaginable:
  Run some complaint statement

Basically, I can't think of a better way of doing this without just putting every error type in the ``AllErrorsImaginable'' block. This doesn't seem very elegant. Any tips?

hughesadam_87 54 Junior Poster

What do you mean random vector? Is this a vector in a mathematical sense, or do you mean an array/list? Also, what's random about it? The entries?

hughesadam_87 54 Junior Poster
hughesadam_87 54 Junior Poster

I should point out that in theory, this should work for all toplevel windows. So if I made a completely new window, I'd like to be able to import these class files to customize it so it looks exactly how I want.

hughesadam_87 54 Junior Poster

Hey everyone,

I'm getting familiar with TkInter, and while it's a cool program, I'm having a hell of a time with keeping all the classes straight. As of now, I'm trying to build a program with a menubar and some other widgets. I can get the program working if I call it through the main program:

root = Tk()

meninst = Menu(root) #All properties of the menu are designed in this block
root.config(menu=meninst)
filemenu=Menu(meninst)
etc...

mainloop()

Now, that's all fine, but what I'd really prefer to do is have a class file, say "Menu style A.py", which I can simply pass root to, and then all the menus and things will appear. I've seen some documentation for this with the widgets; however, I'm not really sure how to do it with my root window. Any help would be great.

hughesadam_87 54 Junior Poster

Thanks. Yeah, I saw this demo on the matplotlib archives. One thing I'm having trouble with is finding good documentation on these backends, like FigureCanvasTkAgg. Who actually releases these programs?

hughesadam_87 54 Junior Poster

Hello all,

Following the guide on sourceforge, I've created several pyplot programs which have nice event handling. I'm able to press keys on my keyboard and the plots advance and change. The backend for this program is GTKagg. There are several instances where I can change parameters in the plot interactively. For example, if I press r, the data will begin at 0. I am able to successfully interact through the terminal; that is, I press a button and the terminal prompts me for a value before it begins running the next iteration of the code. What I can't find is if it's possible to add a small box on the pyplot figure itself which will allow me to easily put in these parameters, instead of going through the terminal.

For example, a box stays open and if I enter a number, it plots a new graph. This is easily done through the terminal, but I'm confused on how to incorporate the GUI right into the pyplot program. Is there support for this already?

hughesadam_87 54 Junior Poster

Anyway, I think the solution I'm going to make is this:

In my Masterarray class, I'm going to just put an if statement. If a keyword is specified, it will make the matrix of type A. If not, then type B. This seems like maybe the best solution, although I thought it was kind of a novice approach.

hughesadam_87 54 Junior Poster

Both of these suggestions were certainly helpful, but the information I could find on them seems pretty abstract. Sort of the kind of thing you'd study for a test in a programming class.

Let me put the questions this way and maybe the best solution will present itself:

If you have a code that is built around manipulating a matrix. Say you had 50 different functions that can operate on this matrix. You also have a very stable main program where everything is called in a nice sequence. Now, you decide you want to do the same thing on a new matrix. You can't just change the main program calls for the new matrix since it's already very elegant. Then all I need is one line that basically says (If choice A, make matrix A. If choice B, make matrix B), and then the rest of the code should operate on either matrix.

hughesadam_87 54 Junior Poster

So since posting this, a colleague pointed out that this is polymorphism. I'll try to read up on that and see if I can solve the problem. If you guys have anything to add, would still certainly be glad to hear it.

hughesadam_87 54 Junior Poster

Hey guys,

Couldn't find the answer to this question in any old threads, probably because I don't know the terminology involved well enough.

I have a program which takes in data and writes it into a numpy array at the beginning of a pipeline. I use a class called Masterarray to take in the data and form it into an array.

Now I need to add the ability to take in the data and return a modified, but similar array. The new array, call it Darkarray, has all of the same dimensions and properties as the Masterarray, but the values are changed. To make this easy on myself, I set darkarray as an inheritance class so that my metacode looks like:

class Masterarray:
   def __init__(self, inlist, x_col, dark_col, ref_col):  
       ......
       ......
   def fcn1: 
       ......
   def fcn2:
       ......

class Dynamic_dark(Masterarray):
      	def __init__(self, inlist, x_col, dark_col, ref_col, sstart, ssend, lstart, lend):
        ......
        ......

My problem is that I have these functions, fcn1 fcn2 etc... that do very simple things, like return columns, rows and other simple operations. Since my inherited class, dynamic_dark is an array of equal dimensions, I thought I could just have these functions be inherited as well. But in my main program, when I call fcn1 or fcn2 even after instantiating the Dynamic_dark class, it returns values for these based on the original class. How do you inherit functions so to speak so that I can call them same function for either array?

hughesadam_87 54 Junior Poster

Are you thinking along the line of a record structure?
You can easily set those up with a Python class.

I don't really know what this is. I ended up with a solution that works; although I'm not sure it is the best solution. What I ended up doing was writing a class that takes in the number of iterations that will be ran in a given execution, and assigns a properly sized numpy array to hold each result from each function. Therefore, I have all the data stored in large arrays at the end of the runs. These can then be exported into plotting programs to make animations or still-framed plots, can be output to files etc... My main goal was to have all the information stored in one place, so that I could manipulate as necessary from this one large class instance.

hughesadam_87 54 Junior Poster

http://gentry.metr.ou.edu/~bfiedler/byteofpython/class-and-object-vars.html

This link seems pretty much what I want to do; however, instead of "population", I'd like this to be several arrays. I will try to work through this example. If you foresee a problem, please let me know.

THanks.

hughesadam_87 54 Junior Poster

Hey fellows,

I've created a fairly large math suite for my spectrometer research, which is basically a set of programs that does several math operations, generates plots etc...

It's beginning to get pretty bulky, and seems like it would benefit from a nice class; wherein, I could store all the data into one set and then can update the class in the future rather than one function then another etc...

Here's my question/problem:

I import a large data set in which each column is a time trial. Let's say I have 100 time trials. I can run my analysis on this file one column at a time, generating 100 plots, 100 output files, 100 result pages etc... or I can, say, average every 5 runs, resulting in 20 of each of the aforementioned results. In many instances, I have to look at the data each way over and over, so it's very inefficient for me to format the data in the preprocessing.

The way it looks computationally is that I want to make a class file that takes in several numpy arrays. Each array corresponds to the result of one of my math functions. Let's say I have three functions, func1, func2, func 3, and each outputs a different. Depending on my needs, I may need to make 100 of each of these arrays, or only 50 each, or 20 each. In each run, I will always make the same number of arrays for all …

hughesadam_87 54 Junior Poster

Thanks this is great!

hughesadam_87 54 Junior Poster

Hello all,

I've tried to find this problem in past threads, so sorry if this is a repost.

I have a large file with regular data. The file is too large for me to open it all at once, so I need to split it into evenly (preferred) spaced output files with some regular name.

So if my full file is called 'bigfile.txt' I want to output:

subfile_1.txt, subfile_2.txt etc... where each subfile has a user-determined number of lines (say 100k). Also, if this program gets to the end of bigfile, what do you recommend I do so that it doesn't error, since the last subfile probably won't be exactly 100k lines?

Thanks.

hughesadam_87 54 Junior Poster

One with regex.

import re

data = '''\
Correct for Detector Non-linearity: No (USB2E7196)
Correct for Stray Light: No (USB2E7196)
Number of Pixels in Processed Spectrum: 2048
>>>>>Begin Processed Spectral Data<<<<<
339.09 0.00
339.48 184.72
339.86 186.46
340.24 187.76
340.63 189.11
341.01 190.97
...
...
1023.36 196.86
1023.65 196.36
>>>>>End Processed Spectral Data<<<<<'''

r = re.compile(r'(\d+\..+)')
for match in r.finditer(data):
    print match.group()

'''Output-->
339.09 0.00
339.48 184.72
339.86 186.46
340.24 187.76
340.63 189.11
341.01 190.97
1023.36 196.86
1023.65 196.36
'''

Thanks. Can you explain this one a bit? I don't understand exactly what the re.compile() is doing.

hughesadam_87 54 Junior Poster

Another way in spirit of Python philosophy of duck typing, the line is correct it succeeds to become to floating point values:

import pretty
files =  ['testdata.txt', 'testdata2.txt']
values = []
perline = 2
for fn in files:
    with open(fn) as this_file:
        for line in this_file:
            try:
                value = map(float, line.strip().split())
                if len(value) == perline:
                    values.append(value)
            except ValueError as e:
                # debug
                print 'Dumped: %s'%line,
                pass

pretty.printer(values)
                    
            
""" output:
Dumped: SpectraSuite Data File
Dumped: ++++++++++++++++++++++++++++++++++++
Dumped: Date: Fri Feb 25 13:43:55 EST 2011
Dumped: User: group
Dumped: Dark Spectrum Present: No
Dumped: Reference Spectrum Present: No
Dumped: Number of Sampled Component Spectra: 1
Dumped: Spectrometers: USB2E7196
Dumped: Integration Time (usec): 11000 (USB2E7196)
Dumped: Spectra Averaged: 500 (USB2E7196)
Dumped: Boxcar Smoothing: 0 (USB2E7196)
Dumped: Correct for Electrical Dark: No (USB2E7196)
Dumped: Strobe/Lamp Enabled: No (USB2E7196)
Dumped: Correct for Detector Non-linearity: No (USB2E7196)
Dumped: Correct for Stray Light: No (USB2E7196)
Dumped: Number of Pixels in Processed Spectrum: 2048
Dumped: >>>>>Begin Processed Spectral Data<<<<<
Dumped: >>>>>End Processed Spectral Data<<<<<
Dumped: #comment

  [
    [339.09, 0.0], 
    [339.48, 184.72], 
    [339.86, 186.46], 
    [340.24, 187.76], 
    [340.63, 189.11], 
    [341.01, 190.97], 
    [1023.36, 196.86], 
    [1023.65, 196.36], 
    [339.09, 0.0], 
    [339.48, 184.72], 
    [339.86, 186.46], 
    [340.24, 187.76], 
    [340.63, 189.11], 
    [341.01, 190.97], 
    [1023.36, 196.86], 
    [1023.65, 196.36]]
"""

Input is what you gave to us, and copy of it without beginning and end part, a comment added.
Pretty is my pretty printer module posted in code snippets in DaniWeb. If you do not us it you can mange with pprint or simple for loop.

This is …

hughesadam_87 54 Junior Poster

Nice stuff but what is the benefit of this app. In real life situation? Can you give more light?

Sure.

When I do measurements in the lab, I get a lot of datasets which are more or less similar sets of curves. Some of the statistical analysis that we do on the curves depends on both the effect of each curve individually and the total number of curves used. Therefore, in some analysis, I may import 3 out of 10 curves. In other analysis, I import 7 curves, etc...

Additionally, I have programs that can further concatenate the data to consolidate it into one data set. So for example, I can use the program mentioned above to import three data sets, then use other programs to concatenate them and output (if desirable), write them into an array for NP analysis, etc...

Basically, anytime a program would benefit from a file_list import, in which the files vary in number and location on the HDD, this is a quick way to import them.

hughesadam_87 54 Junior Poster

This code is horrible. You're saying that the code would fail if the header is different or non existent, but in order to write the code, we must know the different possible formats of your files. So what are these possible formats ?

I don't understand the if not re.match("#", line) . Why is it here ? Also there must be only 1 call to open() in your function.

Sometimes the files do not have headers, but have the same type of data. I wanted to incorporate this into the code you wrote, so that if the header isn't there, it still reads the data.

Any ideas?

The re.match(#) is in case I ever put comments at the beginning of my file, but is not necessary.

hughesadam_87 54 Junior Poster

I like this solution. However, I noticed if the file itself does not have a header, then this program won't recognize it. I've written your code here into a function called 'import data'. Since I have files that have headers and files that dont, I was thinking something like this:

try:
(if first line is composed of digits)
print lines
else:
call import data (the code you wrote)


What would be the best syntax for the try statement do you think? I was thinking of doing what the poster above said:

if line[0].isdigit():

What do you think?

Here's how I implemented it:

def import_data(file):
	'''Reads in list of files and stores data in an array'''
	f=open(file, 'r')	
	line=f.readline()
	if not re.match("#", line): 
		if not line[0].isdigit():       #If first line is a letter, cut the header out

		#######Cut's out header above and below the defined statements; so not very modular
			def not_is_begin(line):
				return not line.startswith(">>>>>Begin Processed Spectral Data<<<<<")   #CUTS THE HEADER
			def not_is_end(line):
				return not line.startswith(">>>>>End Processed Spectral Data<<<<<")
			lines=itt.dropwhile(not_is_begin, open(file))
			lines = itt.islice(lines, 1, None)
			lines = itt.takewhile(not_is_end, lines)

			for line in lines:
				line=line.strip()
				sline=line.split()
				print sline
		#######
		if line[0].isdigit():      #If first line is a number, just go on and 
			for line in f:		
				line=line.strip()
				sline=line.split()
				print sline

Let me know if you guys see anymore improvements. As of now, it would fail if the header didn't have the key strings that >>>>Begin spectra data<<< etc... and would fail if the header itself began with …

hughesadam_87 54 Junior Poster

Using the itertools module

import itertools as itt

def not_is_begin(line):
    return not line.startswith(">>>>>Begin Processed Spectral Data<<<<<")

def not_is_end(line):
    return not line.startswith(">>>>>End Processed Spectral Data<<<<<")

lines = itt.dropwhile(not_is_begin, open(FILENAME))
lines = itt.islice(lines, 1, None)
lines = itt.takewhile(not_is_end, lines)

for line in lines:
    print line

!

I like this solution. However, I noticed if the file itself does not have a header, then this program won't recognize it. I've written your code here into a function called 'import data'. Since I have files that have headers and files that dont, I was thinking something like this:

try:
(if first line is composed of digits)
print lines
else:
call import data (the code you wrote)


What would be the best syntax for the try statement do you think? I was thinking of doing what the poster above said:

if line[0].isdigit():

What do you think?

hughesadam_87 54 Junior Poster

I wrote a program that interactively allows you to import files directly from your HDD into another python program. When building a new program, you simply call my program, navigator, and it lets you choose a directory and it prints out a numbered list of file:

file a 1
file b 2
file c 3

Then you pick the files you want by number. Say 1 2, then these files are immediately loaded into the program from which you've called this. I wrote this because I do a lot of data analysis in which I need to import many different data files of varying number, and wanted a modular way to do this.

If this is useful, I can post it, but my current version might only work on windows because I've used colors.

Can someone tell me if a program like this already exists?

hughesadam_87 54 Junior Poster

penguin,

One thing you should be careful of when posting in this forum is that not everyone knows the context of your problem. Python is a multi-dimensional language which can be used to do anything from writing letters to solving partial differential equations. As such, when posting, you need to to outline a proper context for your problem and show some effort to have solved it. I don't think most people on this forum are likely to be biologists with the same background as you, so you should do the following:

Post a sample of your data, in this case DNA sequence data.
Explain what it is you are trying to do. In this case, I think many people on this forum will easily understand what an open reading frame is without the biological context.
Third, and probably key, is to demonstrate that you have put in some effort on your own to solve the problem, so that you don't give off the vibe that you want someone else to do the work for you.

You may also consider looking into the BioPython addon, which is a free package for Bio analysis which may already have this feature built in. If not, then post more information here and we can help.

TrustyTony commented: Good balance of expression! Continue same way! +3
hughesadam_87 54 Junior Poster

Thanks guys. These suggestions were all helpful and I believe I will have this working momentarily.

hughesadam_87 54 Junior Poster

I have a series of data files with large headers. Here is an example:

SpectraSuite Data File
++++++++++++++++++++++++++++++++++++
Date: Fri Feb 25 13:43:55 EST 2011
User: group
Dark Spectrum Present: No
Reference Spectrum Present: No
Number of Sampled Component Spectra: 1
Spectrometers: USB2E7196
Integration Time (usec): 11000 (USB2E7196)
Spectra Averaged: 500 (USB2E7196)
Boxcar Smoothing: 0 (USB2E7196)
Correct for Electrical Dark: No (USB2E7196)
Strobe/Lamp Enabled: No (USB2E7196)
Correct for Detector Non-linearity: No (USB2E7196)
Correct for Stray Light: No (USB2E7196)
Number of Pixels in Processed Spectrum: 2048
>>>>>Begin Processed Spectral Data<<<<<
339.09 0.00
339.48 184.72
339.86 186.46
340.24 187.76
340.63 189.11
341.01 190.97
...
...
1023.36 196.86
1023.65 196.36
>>>>>End Processed Spectral Data<<<<<

I've highlighted the heading and footer in red. What I would like to do is have a code completely crop these sections. I have done some RE matching, but don't know what is the best way to identify the entire line as a string. Is there a simple, smart way to do this?

Thanks.

hughesadam_87 54 Junior Poster

If this question is phyton related, best put it on the Phyton forum.

Wow, didn't realize I put it here. Well, I solved it so any admin is free to delete, or let it die.

Sorry.