Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Wearing a different hat I do the odd spot of astronomy observation. One of the observation areas I'm interested in is recording data for microlensing events which can be used for discovering exoplanets. Detected candidate events are published in various places around the internet, but a chunk of digging and analysis is required to find events that are interesting to observe "tonight". The following code scrapes one of the sites and uses heuristics involving the brightness of the event and various other parameters to choose and prioritize interesting current events from the thousand or so listed.

use strict; use warnings; use File::Copy; use HTML::Tree; use Astro::Time qw(); my $nowJD = Astro::Time::mjd2jd(Astro::Time::now2mjd()); my $root = HTML::TreeBuilder->new_from_url( ''); my @elements = $root->guts(); my @tables = $root->find('table'); my @rows = $tables[-1]->find('tr'); my @events; for my $row (@rows) { my @cells = $row->find('td'); my $flag = shift @cells; my ( $event, $field, $starNo, $ra, $dec, $tmaxHJD, $tmaxUT, $tau, $Umin, $Amax, $Dmag, $fbl, $ibl, $i0 ) = map {$_->as_text()} @cells; next if !$event || !$flag->find('img') || $Amax < 20; my $delta = abs($nowJD - $tmaxHJD); my $minMag = $i0 - $Dmag; next if $tau > 300 || $delta > $tau || $minMag > 16; $delta ||= 0.0001; $Umin ||= 0.0001; my $tRoot = $delta / $tau; my $uNow = sqrt($Umin * $Umin + $tRoot * $tRoot); my $aNow = ($uNow * $uNow + 2) / ($uNow * sqrt($uNow * $uNow + 4)) +; my $magNow = $i0 - 5 * log($aNow) / log(100); next if $magNow > 17; $magNow = sprintf "%.4f", $magNow; push @events, [$event, $tmaxUT, $tRoot, $tau, $ra, $dec, $Dmag, $m +agNow, $i0]; } for my $eventData (sort {$a->[2] <=> $b->[2]} @events) { my ($event, $tmaxUT, $tRoot, $tau, $ra, $dec, $Dmag, $magNow, $i0) + = map {s/^\s+|\s+$//g; $_} @$eventData; my $minMag = sprintf "%.3f", $i0 - $Dmag; print <<EVENT; $event: peak at $tmaxUT (tau $tau) RA $ra Dec $dec Mag $i0 - $minMag ( +now $magNow) EVENT }

Run at 6:29 UT 2017/08/24 printed:

2017-BLG-1600: peak at 2017-08-25.34 (tau 9.350) RA 17:43:38.19 Dec -2 +6:54:38.8 Mag 16.982 - 6.688 (now 14.6269) 2017-BLG-0019: peak at 2017-06-22.58 (tau 134.989) RA 17:52:18.74 Dec +-33:00:04.0 Mag 14.798 - 11.277 (now 13.8859)
Premature optimization is the root of all job security

In reply to Searching for exoplanets by GrandFather

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others making s'mores by the fire in the courtyard of the Monastery: (3)
    As of 2018-08-16 02:44 GMT
    Find Nodes?
      Voting Booth?
      Asked to put a square peg in a round hole, I would:

      Results (166 votes). Check out past polls.