[Kstars-devel] KDE/kdeedu/kstars/kstars/data/tools
Akarsh Simha
akarshsimha at gmail.com
Tue Jul 15 02:05:55 CEST 2008
SVN commit 832574 by asimha:
+ Deleting binary (binfiletester) that had landed on the repository by
accident
+ Replacing tycdatatomysql.pl with the version that includes
duplication for proper motion
+ Adding Perl script to parse the NOMAD catalog ASCII files.
CCMAIL: kstars-devel at kde.org
D binfiletester
AM nomaddatatomysql.pl
M +140 -15 tycdatatomysql.pl
** trunk/KDE/kdeedu/kstars/kstars/data/tools/nomaddatatomysql.pl #property svn:executable
+ *
--- trunk/KDE/kdeedu/kstars/kstars/data/tools/tycdatatomysql.pl #832573:832574
@@ -1,15 +1,18 @@
#!/usr/bin/perl
#
-# datatomysql.pl Put star data from Tycho-1 ASCII data file into a database
+# tycdatatomysql_pm.pl Put star data from Tycho-1/Tycho-2 ASCII data file into a database
#
# CAUTION: Will truncate the table supplied!
#
# NOTE: The Tycho-1 text data file should be supplied via stdin:
# use cat <tycho-1 data file> | <this script> to achieve this.
-
+#
+# This version of the script takes into account the proper motion of the star for J2000.0 +/- x millenia
use strict;
use DBI;
use HTMesh;
+use Math::Trig;
+use Math::Complex;
my $ERROR;
my @STARS;
@@ -21,9 +24,11 @@
# For database handling
my $db_db = shift;
my $db_user = shift;
-!($db_db eq "") and !($db_user eq "") or print "USAGE: " . $0 . " <database name> <MySQL Username> [[MySQL Password [Table]]\n" and exit;
+!($db_db eq "") and !($db_user eq "") or print "USAGE: " . $0 . " <database name> <MySQL Username> [[MySQL Password [Table [Millenia]]]\n" and exit;
my $db_pass = shift;
my $db_tbl = shift;
+my $pm_millenia = shift;
+($pm_millenia eq "") and $pm_millenia = 10;
if($db_tbl eq "") {
$db_tbl = "tycho"
}
@@ -49,6 +54,7 @@
`Name` varchar(70) default NULL COMMENT 'Long Name',
`GName` varchar(15) default NULL COMMENT 'Genetive Name',
`UID` int(11) NOT NULL auto_increment COMMENT 'Unique ID',
+ `Copies` tinyint(8) NOT NULL COMMENT 'Number of Copies of the star',
PRIMARY KEY (`UID`),
UNIQUE KEY `UID` (`UID`),
KEY `Trixel` (`Trixel`,`PM`,`Mag`)
@@ -66,7 +72,7 @@
my $dbh = DBI->connect("DBI:mysql:", $db_user, $db_pass, { RaiseError => 1, AutoCommit => 0 });
my @fields = qw/Trixel HD RA Dec dRA dDec PM Parallax Mag BV_Index
- Spec_Type Mult Var GName Name/;
+ Spec_Type Mult Var GName Name Copies/;
$dbh->do($db_query);
$dbh->do($db_select_query);
@@ -98,18 +104,97 @@
printf "\n";
}
- $star->{Trixel} = $mesh->lookup_name($star->{RA}, $star->{Dec});
-
- my $query ||= qq/INSERT INTO `$db_tbl` (/ .
- join(", ", map {"`$_`"} @fields) .
- qq/) VALUES (/ .
- join(", ", map {"?"} @fields) .
- qq/)/;
-
- my $sth ||= $dbh->prepare($query);
-
- $sth->execute(@$star{@fields});
+ my $_RA1 = $star->{RA} - $pm_millenia * $star->{dRA} / 3600.0;
+ my $_RA2 = $star->{RA} + $pm_millenia * $star->{dRA} / 3600.0;
+ my $_Dec1 = $star->{Dec} - $pm_millenia * $star->{dDec} / (3600.0 * cos( $star->{Dec} * 3.14159265 / 180.0 ));
+ my $_Dec2 = $star->{Dec} + $pm_millenia * $star->{dDec} / (3600.0 * cos( $star->{Dec} * 3.14159265 / 180.0 ));
+ my ( $RA1, $Dec1 ) = proper_motion_coords( $star->{RA}, $star->{Dec}, $star->{dRA}, $star->{dDec}, -$pm_millenia * 1000 );
+ my ( $RA2, $Dec2 ) = proper_motion_coords( $star->{RA}, $star->{Dec}, $star->{dRA}, $star->{dDec}, $pm_millenia * 1000 );
+
+# ( $star->{PM} > 1000.0 ) and print "$RA1, $Dec1 : $star->{RA}, $star->{Dec} : $RA2, $Dec2\n";
+
+ my $leftDec;
+ my $rightDec;
+ my $topRA;
+ my $botRA;
+
+ my $verbose = 0;
+# if( $star->{HD} == "91125" ) {
+# $verbose = 1;
+# }
+# else {
+# print $star->{HD} . "\n";
+# }
+
+ $verbose and print "(RA1, RA2, Dec1, Dec2) = ($RA1 ,$RA2 ,$Dec1 ,$Dec2 )\n";
+
+ if( $Dec1 < $Dec2 ) {
+ $leftDec = $Dec1;
+ $rightDec = $Dec2;
+ }
+ else {
+ $leftDec = $Dec2;
+ $rightDec = $Dec1;
+ }
+
+ if( $RA1 < $RA2 ) {
+ $topRA = $RA1;
+ $botRA = $RA2;
+ }
+ else {
+ $topRA = $RA2;
+ $botRA = $RA1;
+ }
+
+ $verbose and print "leftDec = $leftDec and topRA = $topRA\n";
+
+ my $epsilon = ( 90.0 / 3600.0 ) / 15.0;
+
+ $star->{originalTrixelID} = $mesh->lookup_id( $star->{RA}, $star->{Dec} );
+
+ $verbose and print "Original trixel ID = " . $star->{originalTrixelID};
+
+ my @trixels;
+ if( $star->{Name} eq "" && $star->{GName} eq "" ) {
+ my $separation = sqrt( ($botRA - $topRA) * ($botRA - $topRA) + ($leftDec - $rightDec) * ($leftDec - $rightDec) );
+ if( $separation > 50.0 / 60.0 ) {
+# $mesh->intersect_poly4( $botRA, $leftDec,
+# $botRA - $epsilon, $leftDec + $epsilon,
+# $topRA - $epsilon, $rightDec - $epsilon,
+# $topRA, $rightDec);
+ $mesh->intersect_poly4( $topRA, $rightDec,
+ $topRA - $epsilon, $rightDec - $epsilon,
+ $botRA - $epsilon, $leftDec + $epsilon,
+ $botRA, $leftDec);
+
+ @trixels = $mesh->results();
+ }
+ if( !@trixels ) {
+ @trixels = $mesh->lookup_id( $star->{RA}, $star->{Dec} );
+ }
+ }
+ else {
+ @trixels = $mesh->lookup_id( $star->{RA}, $star->{Dec} );
+ }
+
+ for(@trixels) {
+ my $tid = $_;
+ $star->{Trixel} = $mesh->id_to_name( $tid );
+ $star->{Copies} = 0;
+ if( $star->{originalTrixelID} == $tid ) {
+ $star->{Copies} = @trixels;
+ }
+ $verbose and print "Trixel = " . $star->{Trixel} . "\n";
+ my $query ||= qq/INSERT INTO `$db_tbl` (/ .
+ join(", ", map {"`$_`"} @fields) .
+ qq/) VALUES (/ .
+ join(", ", map {"?"} @fields) .
+ qq/)/;
+ my $sth ||= $dbh->prepare($query);
+ $sth->execute(@$star{@fields});
+ }
+
}
$dbh->commit();
@@ -182,3 +267,43 @@
$star->{Name} = (($line =~ s/^\s*(\S.*?)\s*$//) ? $1 : "");
return $star;
}
+
+sub proper_motion_coords {
+ my ( $ra0, $dec0, $pmRA, $pmDec, $years ) = @_;
+
+ my $theta0 = hour2rad($ra0);
+ my $lat0 = deg2rad($dec0);
+
+ my $pm = sqrt( $pmRA * $pmRA + $pmDec * $pmDec ) * $years;
+ my $dir0 = ( $pm > 0 ) ? atan2( $pmRA, $pmDec ) : atan2( -$pmRA, -$pmDec );
+ ( $pm < 0 ) and $pm = - $pm;
+# print "$pm, $dir0\n";
+
+ my $dst = milliarcsecond2rad($pm);
+
+ my $phi0 = pi/2 - $lat0;
+
+ my $lat1 = asin(sin($lat0)*cos($dst) +
+ cos($lat0)*sin($dst)*cos($dir0));
+ my $dtheta = atan2(sin($dir0)*sin($dst)*cos($lat0),
+ cos($dst)-sin($lat0)*sin($lat1));
+
+ return (rad2hour($theta0 + $dtheta), rad2deg($lat1));
+ #return (rad2milliarcsecond($dtheta) * cos($lat0),
+ # rad2milliarcsecond($lat1 - $lat0));
+}
+
+sub hour2rad {
+ return deg2rad($_[0] * 15.);
+}
+
+sub rad2hour {
+ return rad2deg($_[0]) / 15.;
+}
+
+sub milliarcsecond2rad {
+ return deg2rad( $_[0] / ( 60 * 60 * 1000));
+}
+sub rad2milliarcsecond {
+ return rad2deg( $_[0]) * ( 60 * 60 * 1000);
+}
More information about the Kstars-devel
mailing list