Tuesday, February 07, 2017

Amazon Polly Just For Laughs

If you've ever had a burning desire to create custom dialog for Consuela the housekeeper in Family Guy..

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#! /usr/bin/python
import boto3
import io
from subprocess import call

client = boto3.client('polly', region_name='us-east-1')

# aws polly describe-voices --region us-east-1|grep Name
response = client.synthesize_speech(
    OutputFormat='mp3',
    SampleRate='16000',
    Text='<speak><p>Hola. Doggie a puera!</p></speak>',
    TextType='ssml',
    VoiceId='Conchita'
)

# Access the audio stream from the response
if 'AudioStream' in response:
    sb = response.get('AudioStream')
    data = sb.read()
    fd = io.open('hello.mp3', mode='wb', closefd=True)
    fd.write(data)
    fd.close()

    call(["afplay", "hello.mp3"])

Saturday, January 21, 2017

Canon 70-200mm f/2.8L versus Pentax 200mm f/4 Super-Multi-Coated Takumar

I have compared two Canon lenses, the 10-20mm f/3.5-4.5 consumer zoom (on APS-C) and the 16-35mm f/4 L IS here. The results were predictable - the L zoom was consistently better than the consumer zoom, at about three times the cost (and increased weight).

Also, I used to collect old, Pentax screw mount manual focus lenses. These old lenses have a cult following, with various miraculous attributes being ascribed to them (glorious bokeh, an otherworldly quality of the image, etc. etc.) While some of these old lenses (particularly the old Leica lenses) do deserve the praise, I had always wondered how these old lenses compared to modern, non-consumer grade ones.

So in this post, I compare the older, non-IS Canon 70-200mm f/2.8L zoom with a decades-old, manual focus, Pentax screw mount 200mm f/4 Super-Multi-Coated Takumar. The comparison was done at f/4 (since the Pentax manual focus prime cannot open up to f/2.8) on a Canon 6D, which should have plenty of resolution. The target image was a neighboring building at (close to) infinity focus.  The Canon zoom was auto-focused, while the Pentax was manually focused using Live View (it ended up at the infinity stop anyway). Base ISO was used and a fairly high shutter speed (1/2000 second) on a tripod.

First the full image:


The highlighted areas are zoomed in (1:1) for comparison. They roughly cover the center of the frame, and the edge. The extreme edge was not used, because it turns out the Canon 70-200mm zoom is not really 200mm at the long end (it is a bit short).

Let's look at the center of the frame, where both lenses should be performing their best. The zoom is one stop down, so should show improved performance.. but it's a zoom, while the competition is a (wide-open) prime:

Canon 70-200mm f/2.8L at 200mm f/4, center:
Pentax 200mm SMC Takumar at f/4, center:
We can see that the Pentax is ever so slightly longer than the Canon, it has less contrast, and is less sharp. We're talking a $40 lens (at KEH) versus a $1300 lens. I wondered if the Pentax was not critically focused, but it was at the infinity stop, and Live View could not yield a better focus. In any case, "in the field" one would not have the luxury of tripod and Live View and would probably just use the prime at the infinity stop.

The difference is certainly obvious at pixel-peeping distances, but on a regular full-size image the two lenses would be indistinguishable.

Canon 70-200mm f/2.8L at 200mm f/4, edge:
Pentax 200mm SMC Takumar at f/4, edge:
again we can see better contrast with the Canon (better coatings perhaps) and also more detail in the fine vertical lines of the blinds. What is noteworthy is that both lenses don't really suffer much (if any) drop in resolution, going from the center of the frame to the (near) edge.

Is the $1300 Canon a better lens? of course it is - sharper, more contrast, autofocus - but is it thirty times better? that depends on the user.  If autofocus and zoom are important, then these are worth paying money for.

The Canon is quite bulky in comparison to the relatively compact Pentax prime, however.
I was whale-watching in Monterey in October 2016, and did not bring any long lenses (the Canon 70-200mm is very hard to travel with). Ended up with a lot of distant images of whales (using the 35mm end of the 16-35mm f/4L IS). At that time, I would have gladly used the small Pentax prime, in spite of all its shortcomings and non-L image quality.

In conclusion: yes, the Canon 70-200mm f/2.8L is a better lens at the 200mm end than the 1960's - 1970's Pentax 200mm f/4 Super-Multi-Coated Takumar.  But the SMC Takumar is more than good enough and I would say can more than hold its own image quality wise (so long as you don't pixel-peep at 100% magnification).










Friday, December 30, 2016

Making a Dobsonian from an Ikea Bedside Table

The Ikea RAST bedside table is cheap, made of pine, and happens to be almost a perfect fit for a typical 8" Newtonian OTA.
The upper and lower shelves just about fit an 8" OTA, and if you remove the left vertical plank in the photo above, and screw it to the back of the two shelves, you have the beginnings of a Dobsonian base.

I used an 8" f/4 Newtonian (an AT8IN actually) with its tube rings, and bolted two halves of a 12" diameter chopping board to the tube rings to serve as altitude bearings.  I had to use a number of fender washers to get the spacing right, but the diameter of the AT8IN is almost perfect for the Ikea table (about three washers were required to get the right spacing).



A significant advantage of this scheme is that by removing the trunnion bearings (which are held on with two M6 hex-head bolts on each side) and attaching a dovetail, the scope can be used for imaging.

Also, the scope has an extended-length aluminum tube of 2mm thickness, which is incredibly rigid (the original AstroTech tube was 0.8mm thick steel) while weighing the same as the original tube. In addition, because the tube is extended, focus can be achieved with a Paracorr without racking out the focuser, which improves the rigidity of the imaging train significantly.



Here's another view of the 12" diameter chopping board. I used the same type of chopping board as the azimuth base (and printed setting circles as well). It was necessary to cut V-shaped channels in the side of the Ikea bedside table to support the trunnion bearings.

The bearing surface is a rough glass fiber (FRP) strip that I purchased from AstroGoods.com and the bearings are virgin teflon blocks. The azimuth bearing surface is also an FRP strip from AstroGoods (I did not go for the vinyl LP record trick here).

I have used this setup to track Mars at 320X during the last opposition and while it's a tricky affair, it's actually usable. While the AstroTech 8" f/4 has a huge secondary, for Mars it was quite acceptable due to the small exit pupil.






I replaced the secondary collimation bolts with stainless steel M4 hardware:



There is a CatsEye hotspot on the primary mirror:



And all steel fasteners have been replaced with hex-head stainless steel hardware. Also note the seam in the faux carbon fiber covering: the aluminum tube underneath is unpainted, and I wrapped the tube in vinyl carbon fiber lookalike (used for wrapping cars).


The primary collimation locking bolts have been relocated next to the collimation knobs, and the primary support springs have been replaced with much stronger ones. This allows the Newtonian to hold collimation very well when used for imaging:


In addition, the telescope has a 2" Feathertouch focuser which is incredibly smooth and a joy to use.



I don't like to think about how much I've spent on this project in total. It is certainly several multiples of the price of a stock 8" dobsonian. However, this scope is better than a stock 8" dobsonian or a stock 8" imaging Newtonian in all possible ways.






Parsing VPC Flow Logs with Pandas

Here's a trivial code snippet to parse AWS VPC Flow Logs. This is extremely useful when setting up permissive security groups and then tightening them up later.

This script will (probably) fail if there are too many VPC flow log files (and therefore the Python interpreter would run out of memory). However it's nice to see that Pandas read_csv can read S3 URL's directly (even gzip'ped CSV files).

You can also filter for REJECT  rule and find out all the IP's that have been attempting to attack you.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from boto.s3.connection import S3Connection
import pandas as pd
import os

srcbucket = 'flowlogs-bucket-orly'
aws_access_key = 'AKIAxxx'
aws_secret_key = 'oRCIxxx'

os.environ['AWS_ACCESS_KEY_ID'] = aws_access_key
os.environ['AWS_SECRET_ACCESS_KEY'] = aws_secret_key

cols = [ 'timestamp', 'version', 'accountid', 'interfaceid', 'srcaddr', 'dstaddr', 'srcport', 'dstport', 'protocol', 'packets', 'bytes', 'start', 'end', 'action', 'logstatus']

# iterate over all the VPC flowlogs in the bucket
conn = S3Connection(aws_access_key, aws_secret_key)
bucket = conn.get_bucket(srcbucket)

count = 0
for key in bucket.list():
    keystr = key.name.encode('utf-8')
    if 'eni-' in keystr:
        s3url = 's3://' + srcbucket + '/' + keystr
        count = count + 1
        
        if (count == 1):
            df = pd.read_csv(s3url, delim_whitespace=True, header=None, names=cols, low_memory=True)
            df = df [ df['action'] == 'ACCEPT']
        else:
            df2 = pd.read_csv(s3url, delim_whitespace=True, header=None, names=cols, low_memory=True)
            df2 = df2 [ df2['action'] == 'ACCEPT']
            df = df.append(df2, ignore_index=True)
        
        print 'Processed ' + keystr

src = df.groupby(['srcaddr', 'dstaddr', 'dstport']).size().reset_index()
src.columns = [ 'srcaddr', 'dstaddr', 'dstport', 'count' ]

n = src.sort_values(by = ['count', 'srcaddr', 'dstaddr'], ascending=False)

print(n)

Tuesday, June 28, 2016

Printing Your Own Azimuth Setting Circles

If you ever are in need of printing your own azimuth setting circles, having a piece of software to generate the rule marks is very useful.

I needed to create a 360-degree paper tape to wrap around the base of my dobsonian, which had a roughly 12" diameter (I measured its circumference at 955mm).  Here's a Perl script which generates a PostScript file on STDOUT. You will need to change the circumference on line 9 (in millimeters). Then you would need a utility such as ps2pdf to convert the PostScript file to PDF and print it out (taking note when printing out to avoid scaling the file).

The script attempts to create the paper tape on a single sheet of paper, and currently will not behave properly for circumferences that exceed the size of the single sheet of paper.  I really should fix the script so that it creates more than four segments for the tape.


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#!/usr/bin/perl
#
# generate a 360-degree scale tape using postscript

use strict;
use POSIX;

# define the circumference of the circle
my $circ = 955;
my $mm_per_degree = $circ / 360;

# derivations
my $point_per_mm = 72 / 25.4;
my $point_per_degree = $point_per_mm / $mm_per_degree;

# minimum (x, y) in points (for margin)
my $minX = 36;
my $minY = 36;


# go from 0.. 360 degrees
for (my $deg = 0; $deg < 360; $deg++) {
 my $x_offset = POSIX::floor($deg / 90) * 64 + $minX;
 my $y_offset = $minY;

 my $mm = ($deg % 90) * $mm_per_degree;
 my $y = ($mm * $point_per_mm) + $y_offset;

 my $line_length = 18;
 if ($deg % 5 == 0) { $line_length = 24; }
 if ($deg % 10 == 0) { $line_length = 32; }

 my $lX = $x_offset + $line_length;
 my $tX = $x_offset + $line_length + 10;

 # estimate the length of the text label
 my $labelLen = length(sprintf("%d", $deg));
 my $tY = $y - (3 * $labelLen);

 print <<EOF;
newpath
$x_offset $y moveto
$lX $y lineto
1 setlinewidth
stroke
EOF

 # add an additional (long) line at the end and a long rule for cutting
 if ($deg % 90 == 89) {
  my $nY = (($deg % 90) + 1) * $mm_per_degree * $point_per_mm + $y_offset;
  my $lX = $x_offset + 48;

  my $cX = $x_offset + 48;

  print <<EOF;
$x_offset $nY moveto
$lX $nY lineto
1 setlinewidth
stroke

$x_offset $minY moveto
$x_offset $nY lineto
1 setlinewidth
stroke

$cX $minY moveto
$cX $nY lineto
1 setlinewidth
stroke
EOF
 }

 if ($deg % 10 == 0) {
  print <<EOF;
$tX $tY moveto
90 rotate
/Courier findfont 12 scalefont setfont
($deg) show
-90 rotate
EOF
 }
}
print "showpage";

And here's what the PDF output looks like:


Cut carefully!