Pyephem: Precession not being applied correctly in epoch calculation? - pyephem

I have very recently downloaded pyephem. I like the user interface a lot.
However, I am getting very flaky results from it, specifically when I try to obtain the estimates of a star's declination at some point in the past. I have used exactly the code associated with the Thuban/Polaris example described in http://rhodesmill.org/brandon/projects/pyephem-manual.html#FixedObjects,Precession,andEpochs and I get completely different results. I am wondering if there is something else that needs to be added to my script to make things work, or if there is a new bug in pyephem.
My script looks like this:
import ephem
import ephem.stars
polaris = ephem.readdb("Polaris,f|M|F7,2:31:48.704,89:15:50.72,2.02,2000")
polaris.compute()
thuban = ephem.readdb("Thuban,f|V|A0,14:4:23.3,64:22:33,3.65,2000")
thuban.compute()
print 'my result for current polaris dec',polaris.dec
print 'webpage result 89:15:50.73\n'
print 'my result for current thuban dec',thuban.dec
print 'webpage result 64:22:32.99\n'
polaris.compute(epoch='-2800')
print 'my result for polaris dec in -2800',polaris.dec
print 'webpage result 63:33:17.63\n'
thuban.compute(epoch='-2800')
print 'my result for thuban dec in -2800',thuban.dec
print 'webpage result 89:54:34.97\n'
Running it produces the following output. I can understand why the first two comparisons are slightly different (the example on the web page was created in the recent past), but you can see that the declination did not change between the current date and epoch -2800 for either star, but in the example on the web page the declination changes a great deal for both stars between the two epochs:
my result for current polaris dec 89:19:19.5
webpage result 89:15:50.73
my result for current thuban dec 64:18:39.5
webpage result 64:22:32.99
my result for polaris dec in -2800 89:19:19.5
webpage result 63:33:17.63
my result for thuban dec in -2800 64:18:39.5
webpage result 89:54:34.97

The .dec attribute is auto-adjusted in several ways that would have interfered with the tutorial's attempt to show how precession works, so — if you will look carefully at the tutorial's code — I think you will find that it always asks for the .a_dec the “astrometric declination” of Polaris and Thuban. If you will make this slight spelling correction to your own code above by adding a_ to the front of the attribute name, then I think you will find that your printed answers agree with those printed in the tutorial!

Related

How to find the column of the number that you're looking for?

After I watched a video about finding back a number with random numbers (Video link, if you want to know), I tried to make a sheets program for it. When I was trying to find out how much does it take to get back to a number, I have no idea on which function to use. In order to find how much "tries" to get back to a number. I tried =FIND and =HLOOKUP and it failed because it has multiple same numbers.
Example:
[1 needs 3 tries to get back to 1, so the result should be 3. Same thing with 2, but it needs 17 tries.
Here's the link of the google sheet
try something like this:
=IFERROR(IF($B7=INDEX($B$7:$B, MATCH(B7, ROW($A$7:$A)-(ROW($A$7)-1), 0)),,
INDEX($B$7:$B, MATCH(B7, ROW($A$7:$A)-(ROW($A$7)-1), 0))))
spreadsheet demo

Alpha Vantage error when symbol has digits

I'm trying to get quotes for an Australian stock with ticker A200.AX (aka A200.AUS) from Alpha Vantage.
I have no issues getting other symbols from the AX market, e.g.:
https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=ETHI.AUS&apikey=demo
...returns data as expected
However when a symbol has digit(s) in it, it seems to return an error:
https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=A200.AUS&apikey=demo
Invalid API call. Please retry or visit the documentation (https://www.alphavantage.co/documentation/) for TIME_SERIES_INTRADAY.
Same result for F100.AUS
I checked to make sure the ticker was valid: A200.AUS shows up if I search for it:
https://www.alphavantage.co/query?function=SYMBOL_SEARCH&keywords=A200.AUS&apikey=demo
I'm aware of some questions related to URL encoding, but I can't see any URL special characters in A200.AUS . Besides, using the search endpoint works with the ticker passed on literally.
Does anyone know how to download this stock's information or what I'm doing wrong?
Your use of the search endpoint is great, however A200.AUS is an ETF. Alpha Vantage has some ETFs, but currently, only 100% supports stocks.

Coldfusion Hash SHA-1 Doesnt look the same as the sample

Im working on a script to hash a "fingerprint" for communicating with the secure Pay Direct Post API.
The issue I have is im trying to create a SHA-1 String that matches the sample code provided so that i can ensure things get posted accurately.
the example Sha-1 string appears encoded like
01a1edbb159aa01b99740508d79620251c2f871d
However my string when converted appears as
7871D5C9A366339DA848FC64CB32F6A9AD8FCADD
completely different...
my code for this is as follows..
<cfset variables.finger_print = "ABC0010|txnpassword|0|Test Reference|1.00|20110616221931">
<cfset variables.finger_print = hash(variables.finger_print,'SHA-1')>
<cfoutput>
#variables.finger_print#
</cfoutput>
Im using Coldfusion 8 to do this
it generates a 40 character hash, but i can see its generating completely different strings.
Hopefully someone out there has done this before and can point me in the right direction...
thanks in advance
** EDIT
The article for creating the Hash only contains the following information.
Example: Setting the fingerprint Fields joined with a | separator:
ABC0010|txnpassword|0|Test Reference|1.00|20110616221931
SHA1 the above string: 01a1edbb159aa01b99740508d79620251c2f871d
When generating the above example string using coldfusion hash it turns it into this
7871D5C9A366339DA848FC64CB32F6A9AD8FCADD
01a1edbb159aa01b99740508d79620251c2f871d
Sorry, but I do not see how the sample string could possibly produce that result given that php, CF and java all say otherwise. I suspect an error in the documentation. The one thing that stands out is the use of "txnpassword" instead of a sample value, like with the other fields. Perhaps they used a different value to produce the string and forgot to plug it into the actual example?
Update:
Example 5.2.1.12, on page 27, makes more sense. Ignoring case, the results from ColdFusion match exactly. I noticed the description also mentions something about a summarycode value, which is absent from the example in section 3.3.6. So that tends to support the theory of documentation error with the earlier example.
Code:
<cfset input = "ABC0010|mytxnpasswd|MyReference|1000|201105231545|1">
<cfoutput>#hash(input, "sha-1")#</cfoutput>
Result:
3F97240C9607E86F87C405AF340608828D331E10

How do I Benchmark RESTful Service with Variable Parameters?

I'm currently working on benchmarking a RESTful service I've made, and part of that is making sure it runs in a reasonable amount of times for a large array of parameters. For example, let's say I have RESTful API of the form some_site.com/item?item_id=y. In that case to be sure my service is working as fast as I'd like it to work, I'd want to try out many values for y one by one, preferably coming from some text file. I can't figure out any way of doing this in ab or httperf. I'm open to using a different benchmarking program if I have, but would prefer something simple and light. What I want to do seems like something pretty standard, so I'm guessing there must already be a program that let's me do it, but an hour or so of googling hasn't gotten me an answer. Ideas?
Answer: Jmeter (which is apparently awesome). This faq explains how to do it. Hopefully this helps someone else, as it took me like a day of searching to figure this out.
I have just had some good experience with using JavaScript (via BSF/Rhino) in JMeter.
I have put one thread group in my test plan and stick a 'Simple Controller' with two elements under it - 'HTTP Request' sampler and 'BSF PreProcessor'.
Set BSF language to 'javascript' and either type the code into the text box or point it to a file (use full path or relative to CWD of JMeter process).
/* Since `Math.random()` gives us float, we use `java.util.Random()`
* see: http://docs.oracle.com/javase/7/docs/api/java/util/Random.html */
var Random = new Packages.java.util.Random();
var min = 10-1;
var max = 2;
var maxLines = (min)+Random.nextInt(max-min);
var s = '';
for (var d = 0; d <= maxLines; d++) {
s += d.toString()+','+Random.nextInt(1000).toString()+'\n';
}
// s => '0,312\n1,104\n2,608\n'
vars.put('PAYLOAD', s);
Now I can refer to ${PAYLOAD} in the HTTP request!
You can generate JSON, but you will need to upgrade jakarta-jmeter-2.5.1/lib/js-1.6R5.jar with the newest version of Rhino to get JSON.stringify and JSON.parse. That worked perfectly for me also, though I thought I'd put a simple example here.
You can use BSF pre-processor for URL params as well, just set another variable with vars.put('X', 'some value') and pass it as ${X} in the request parameter.
This blog post helped quite a bit, by the way.

After querying DB I can't print data as well as text anymore to browser

I'm in a web scripting class, and honestly and unfortunately, it has come second to my networking and design and analysis classes. Because of this I find I encounter problems that may be mundane but can't find the solution to it easily.
I am writing a CGI form that is supposed to work with a MySQL DB. I can insert and delete into the DB just fine. My problem comes when querying the DB.
My code compiles fine and I don't get errors when trying to "display" the info in the DB through the browser but the data and text doesn't in fact display. The code in question is here:
print br, 'test';
my $dbh = DBI->connect("DBI:mysql:austinc4", "*******", "*******", {RaiseError => 1} );
my $usersstatement = "select * from users";
my $projstatment = "select * from projects";
# Get the handle
my $userinfo = $dbh->query($usersstatement);
my $projinfo = $dbh->query($projstatement);
# Fetch rows
while (#userrow = $userinfo->fetchrow()) {
print $userrow[0], br;
}
print 'end';
This code is in an if statement that is surrounded by the print header, start_html, form, /form, end_html. I was just trying to debug and find out what was happening and printed the statements test and end. It prints out test but doesn't print out end. It also doesn't print out the data in my DB, which happens to come before I print out end.
What I believe I am doing is:
Connecting to my DB
Forming a string the contains the command/request to the DB
Getting a handle for my query I perform on the DB
Fetching a row from my handle
Printing the first field in the row I fetched from my table
But I don't see why my data wouldn't print out as well as the end text. I looked in DB and it does in fact contain data in the DB and the table that I am trying to get data from.
This one has got me stumped, so I appreciate any help. Thanks again. =)
Solution:
I was using a that wasn't supported by the modules I was including. This leads me to another question. How can I detect errors like this? My program does in fact compile correctly and the webpage doesn't "break". Aside from me double checking that all the methods I do use are valid, do I just see something like text not being displayed and assume that an error like this occurred?
Upon reading the comments, the reason your program is broken is because query() does not execute an SQL query. Therefore you are probably calling an undefined subroutine unless this is a wrapper you have defined elsewhere.
Here is my original posting of helpful hints, which still apply:
I hope you have use CGI, use DBI, etc... and use CGI::Carp and use strict;
Look in /var/log/apache2/access.log or error.log for the bugs
Realize that the first thing a CGI script prints MUST be a valid header or the web server and browser become unhappy and often nothing else displays.
Because of #3 print the header first BEFORE you do anything, especially before you connect to the database where the script may die or print something else because otherwise the errors or other messages will be emitted before the header.
If you still don't see an error go back to #2.
CGIs that use CGI.pm can be run from a command line in a terminal session without going through the webserver. This is also a good way to debug.