Showing posts with label web-app-dev. Show all posts
Showing posts with label web-app-dev. Show all posts

Saturday, May 30, 2015

Moire with Spyre (a Python web framework)

By Vasudev Ram




The image above is of Uppsala Cathedral, Sweden, with its spires.

From the Spyre site:

Spyre is a Web Application Framework for providing a simple user interface for Python data projects. It is by Adam Hajari

I had come across Spyre recently via this post by Ian Oszvald:

Data Science Deployed – Opening Keynote for PyConSE 2015. More about Ian Oszvald here.

So I installed Spyre with the command:
pip install dataspyre
which in turn installed NumPy, pandas and matplotlib, all of which went through okay, though I saw some compiler / linker error messages scroll by as some compilation of C modules was happening (as part of the installation).

Then I tried it out a little, this time just using one of the simple applications on the Spyre site, without any modifications, like I sometimes do.
from spyre import server

import matplotlib.pyplot as plt
import numpy as np

class SimpleSineApp(server.App):
    title = "Simple Sine App"
    inputs = [{ "input_type":"text",
                "variable_name":"freq",
                "value":5,
                "action_id":"sine_wave_plot"}]

    outputs = [{"output_type":"plot",
                "output_id":"sine_wave_plot",
                "on_page_load":True }]

    def getPlot(self, params):
        f = float(params['freq'])
        x = np.arange(0,2*np.pi,np.pi/150)
        y = np.sin(f*x)
        fig = plt.figure()
        splt1 = fig.add_subplot(1,1,1)
        splt1.plot(x,y)
        return fig

app = SimpleSineApp()
app.launch()
As you can see, the structure / model of the code for a Spyre app does not seem to be very similar to that of, say, a Flask or a Bottle app. But then, there is no reason that it should be.
Anyway, I ran this app with the command:

python simple_sine_example.py

and then browsed to:

http://127.0.0.1:8080/

where I then gave different values for the input parameter freq, to see what would happen. I found that running it with certain values of freq created interesting Moire patterns in the output; hence the title of this post.

Here are a few screenshots below that show those moire patterns:

With freq = 764:


With freq = 472:


With freq = 475:


With freq = 479:


Notice that in some cases, such as with the values of 472, 475 and 479 for freq, the small changes between those values results in significant changes in the output image. Not only that: for 472 and 479, the images are similar (look sine-wave-y), but for 475 (which is between the other two values), the image looks almost like straight vertical lines. (It isn't, of course; it's still a sine wave, but more compressed along the horizontal axis.) I've not analyzed the reason for this in detail; something to do with the periodicity of the sine function, is my rough guess, but I have seen similar phenomena when drawing other kinds of computer graphics on the screen; those also involved trigonometric functions such as sine and cosine.

Spyre away :)

P.S. In other news, I was recently profiled in PyDev of the Week.

- Vasudev Ram - Online Python training and programming

Dancing Bison Enterprises

Signup to hear about new products or services that I create.

Posts about Python  Posts about xtopdf

Contact Page

Monday, July 11, 2011

WebStatusCodes, a web development utility by Brian Jones

By Vasudev Ram - dancingbison.com | @vasudevram | jugad2.blogspot.com

I think this tool can be useful to web developers:

WebStatusCodes - http://webstatuscodes.appspot.com/ - is a web development utility written by Brian Jones, using Google AppEngine. Excerpts from the main page of the site, which convey what it is about:

[
This was put here as a handy testing tool for apps that need to test how their code deals with various HTTP status codes, and as a very basic reference for those who know HTTP but need an occasional reminder of whether 302 or 301 is "permanent", or can't remember which code means "Not Modified".
...
Request a valid status code by putting the status code as the first part of the URL path. For example, requesting
http://webstatuscodes.appspot.com/403 will return a 403 forbidden error, and the body of the response will contain the standard message describing that response.
...
Currently, this site doesn't do anything other than return the error. 401 doesn't issue a challenge, for example.
...
This site is also a handy reference. Not only is the list of supported codes and their accompanying short  description messages in a table below (in case you *don't* know what you're looking for), but
requesting a status code in a browser includes the description in the body of the response (in case you *do* know  what you're looking for).
]

Below the last paragraph above, is a table of web (HTTP) request status codes and their accompanying short  descriptions.

Posted via email
- Vasudev Ram - Dancing Bison Enterprises