[Tutor] Appending an extra column in a data file

Andre' Walker-Loud walksloud at gmail.com
Wed Apr 10 21:14:29 CEST 2013


Hi Sayan,

> Is it that? We can have different plots and hence animation from a single data file.Very good!...if you have some time in your disposal, it will be kind of you to illumine in this matter...may be some useful link will do.
> 
> I have written this small code from scratch,there's no 'get it to work' business...:)
> 
> Here is the total code...not attaching as you might have problem opening random files from internet....:)

I will leave the complete code snippet for the list memory.
A couple things.

With the code you have now, you do not even have to save any files.  You can simply implant the plotting into the initial while loop.  Right now, your saved files serve only as a temporary holding file for the data you had just created.  Since your initial data is not read from another file, but simply generated in your code, there is no reason to write any thing to disk, except the figures you are saving.

One thing to notice, your "t" and "i" while loops iterate over different counters.  You have
	t = t + 0.01
	i = i + 0.001
so your second loop will produce many calls that don't match anything (the files you created don't exist).

The previous error is because the pp_za and pv_za are already 1D numpy arrays of dimension 999.  That is why combining them with a single float, "np.array([pp_za,pv_za,t])", did not work - the dimension of "pp_za" and "t" don't match, so writing them with numpy.savetxt() gave an error.

How do you want to include the "t" information in the figure?
Do you want to make different plots with a time axis?  Or, it sounds like you are talking about a 3D plot?

If you want to store the time with the data, then make a t_array like so

''' inside your t while loop '''
# make an array filled with ones the same dimension as your pp_init, and then multiply each entry by "t"
t_array = t * numpy.ones_like(pp_init) 

''' then pack your data as '''
np.array([pp_za,pv_za,t_array])

but to have a single data file containing all of this:

t_array = np.arange(0,1,.001) # initialize all the times you care about
pp_init = np.linspace(0,1.99799799,999)  #just taking from your code
# initialize an array of zeros
# first dimension spans time
# second dimension is 3 to store value of pp_za, pv_za, t
# third dimension is actual length of data
all_data = np.zeros([len(t_array),3,len(pp_init)]) 

for i,t in enumerate(t_array):
    # make your pp_za and pv_za as in your code
    t_tmp = t * numpy.ones_like(pp_init)
    all_data[i] = np.array([pp_za,pv_za,t])


'''
now you have a single object (np.array) which contains all of your data.
You could either make each of the figures in the above loop, or you can use a second loop to make them.
I see Oscar has given you some advice on the plotting - so you could use this single object and his example to do what you want.


Andre




More information about the Tutor mailing list