Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.

#1 June 16, 2010 17:31:53

W.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

File - .dat


Hello,

I need to leave a file tabbed, like this:http://www.srl.caltech.edu/~shane/sensitivity/asteroids/scg_8564.datFollowing piece of my code that does this: - with Django

# -----------------------------
# Import
# -----------------------------
from django.shortcuts import get_object_or_404, render_to_response
from django.http import HttpResponseRedirect
from django.http import HttpResponse
from django.template import RequestContext
from django.core.urlresolvers import reverse
from simuladores.detector.forms import Fase
from django.template import loader, Context
from django.views.generic.simple import direct_to_template
from django.forms import forms, fields
from matplotlib import use
use('Agg')
from matplotlib.pyplot import plot, savefig, setp, figure, subplot
import csv
#from struct import pack
from pylab import *
import pylab
from decimal import Decimal
import math
import matplotlib.pyplot as plt

# ------------------------------------
# A view that to show the form
# ------------------------------------
def desenha_grafico(request):

if request.method == 'POST':
form = Fase(request.POST)
if form.is_valid():
f = xrange(3000,3400)

# ------------
# S, Sfase
# ------------

Sfase=


for v in f:
# ---------------
# Sfase
# ---------------
Sfase.append(form.cleaned_data*(pow(v,2)/
pow(form.cleaned_data,2)))



# ---------------
# Plot Graph
# ---------------
fig = plt.figure()
plt.subplots_adjust(hspace=0.4)
plt.subplots_adjust(wspace=0.4)
ax = plt.subplot(2,2,1)
ax.plot(f,Sfase)
leg = ax.legend(loc="left")

setp(ax.get_xticklabels(), fontsize=8.5)
setp(ax.get_yticklabels(), fontsize=8.5)
frame = leg.get_frame()
frame.set_facecolor('white') # set the frame face color to
white

# matplotlib.text.Text instances
for t in leg.get_texts():
t.set_fontsize('9')
grid('TRUE')


savefig('C:\simuladores\detector\media\imagem.png')
writer = csv.writer(open('C:\simuladores\detector\media
\dados.dat','wb'))

writer.writerow(f)
writer.writerow(Sfase)

resultado = Fase()

# -----------------------------------
# return to template
# -----------------------------------
return render_to_response('gera_grafico.html',
{'resultado': resultado},
context_instance =
RequestContext(request))
#return render_to_response('soma.html', {'resultado':
resultado})
else:
form = Fase(request.POST)
return render_to_response('soma.html', {'form': form})

form=Fase()
return render_to_response('soma.html', {'form': form})



Following my code in the IDLE of Python


import numpy
import pylab
from pylab import *

x = arange(3000,3400)
y = -108*((x**2)/(3e14**2))

numpy.savetxt('C:\Documents and Settings\Web\dados.dat', (x,y))


However, my file dados.dat out as follows in this link, yhis out in a
single line....http://paste.pocoo.org/show/226192/As I viewthis as link:http://www.srl.caltech.edu/~shane/sensitivity/asteroids/scg_8564.dat--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

#2 June 17, 2010 17:08:33

C.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

File - .dat


If you want to get a response. Why don't you make a minimal example?
>From your email I do not understand what your problem is. I thought
you want to generate a file like the one you posted but what about all
that Django stuff?

What do you want to do? Is it correct, that you want a file with (x,y)
values in each row? Do you want to generate that file dynamically with
Django, or do you just need that file once, and the data inside won't
change? If that is the case, here is something (see below) that you
can use.

But please, write concise and think of your audience. The people on
this mailing list have no idea what you are doing and probably don't
even care unless it is either interesting or they can help you. I am
happy to help if I can but I don't want to spend time deciphering your
mail.

Best regards,
Christoph

PS:http://www.catb.org/~esr/faqs/smart-questions.html;-)

from pylab import arange
import csv
x = arange(3000, 3400)
y = x**2 #Or whatever function you choose

writer = csv.writer(open('test.dat', 'wb'), delimiter='\t')

#Here is how to do it. This is quite ugly (non-performant), you should
use the power of numpy/pylab
for i in range(len(x)):
writer.writerow((x[i], y[i]))

del writer #Closes (and thus writes) the file handler, there is
probably a nicer way of doing this.


On Jun 16, 5:31 pm, Waleria <waleriantu...@gmail.com> wrote:
> Hello,
>
> I need to leave a file tabbed, like this:
>
>http://www.srl.caltech.edu/~shane/sensitivity/asteroids/scg_8564.dat>
> Following piece of my code that does this: - with Django
>
> # -----------------------------
> # Import
> # -----------------------------
> from django.shortcuts import get_object_or_404, render_to_response
> from django.http import HttpResponseRedirect
> from django.http import HttpResponse
> from django.template import RequestContext
> from django.core.urlresolvers import reverse
> from simuladores.detector.forms import Fase
> from django.template import loader, Context
> from django.views.generic.simple import direct_to_template
> from django.forms import forms, fields
> from matplotlib import use
> use('Agg')
> from matplotlib.pyplot import plot, savefig, setp, figure, subplot
> import csv
> #from struct import pack
> from pylab import *
> import pylab
> from decimal import Decimal
> import math
> import matplotlib.pyplot as plt
>
> # ------------------------------------
> # A view that to show the form
> # ------------------------------------
> def desenha_grafico(request):
>
>     if request.method == 'POST':
>         form = Fase(request.POST)
>         if form.is_valid():
>             f = xrange(3000,3400)
>
>             # ------------
>             # S, Sfase
>             # ------------
>
>             Sfase=
>
>             for v in f:
>                 # ---------------
>                 # Sfase
>                 # ---------------
>                 Sfase.append(form.cleaned_data*(pow(v,2)/
> pow(form.cleaned_data,2)))
>
>             # ---------------
>             # Plot Graph
>             # ---------------
>             fig = plt.figure()
>             plt.subplots_adjust(hspace=0.4)
>             plt.subplots_adjust(wspace=0.4)
>             ax = plt.subplot(2,2,1)
>             ax.plot(f,Sfase)
>             leg = ax.legend(loc="left")
>
>             setp(ax.get_xticklabels(), fontsize=8.5)
>             setp(ax.get_yticklabels(), fontsize=8.5)
>             frame  = leg.get_frame()
>             frame.set_facecolor('white') # set the frame face color to
> white
>
>             # matplotlib.text.Text instances
>             for t in leg.get_texts():
>                 t.set_fontsize('9')
>             grid('TRUE')
>
>             savefig('C:\simuladores\detector\media\imagem.png')
>             writer = csv.writer(open('C:\simuladores\detector\media
> \dados.dat','wb'))
>
>             writer.writerow(f)
>             writer.writerow(Sfase)
>
>             resultado = Fase()
>
>             # -----------------------------------
>             # return to template
>             # -----------------------------------
>             return render_to_response('gera_grafico.html',
>                                       {'resultado': resultado},
>                                       context_instance =
> RequestContext(request))
>             #return render_to_response('soma.html', {'resultado':
> resultado})
>         else:
>             form = Fase(request.POST)
>             return render_to_response('soma.html', {'form': form})
>
>     form=Fase()
>     return render_to_response('soma.html', {'form': form})
>
> Following my code in the IDLE of Python
>
>     import numpy
>     import pylab
>     from pylab import *
>
>     x = arange(3000,3400)
>     y = -108*((x**2)/(3e14**2))
>
>     numpy.savetxt('C:\Documents and Settings\Web\dados.dat', (x,y))
>
> However, my file dados.dat  out as follows in this link, yhis out in a
> single line....
>
>http://paste.pocoo.org/show/226192/>
> As I viewthis as
> link:http://www.srl.caltech.edu/~shane/sensitivity/asteroids/scg_8564.dat--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to django-us...@googlegroups.com.
To unsubscribe from this group, send email to
django-users+unsubscr...@googlegroups.com.
For more options, visit this group athttp://groups.google.com/group/django-users?hl=en.

Offline

Board footer

Moderator control

Enjoy the 13th of December
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support