<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Eat your greens! &#187; yql</title>
	<atom:link href="http://eatyourgreens.org.uk/category/yql/feed" rel="self" type="application/rss+xml" />
	<link>http://eatyourgreens.org.uk</link>
	<description>Actually, I am a rocket scientist</description>
	<lastBuildDate>Mon, 22 Aug 2011 16:53:00 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Get excited and make things with science</title>
		<link>http://eatyourgreens.org.uk/archives/2010/06/get-excited-and-make-things-with-science.html</link>
		<comments>http://eatyourgreens.org.uk/archives/2010/06/get-excited-and-make-things-with-science.html#comments</comments>
		<pubDate>Fri, 25 Jun 2010 00:30:46 +0000</pubDate>
		<dc:creator>Jim O'Donnell</dc:creator>
				<category><![CDATA[astronomy]]></category>
		<category><![CDATA[geekage]]></category>
		<category><![CDATA[yql]]></category>

		<guid isPermaLink="false">http://eatyourgreens.org.uk/?p=631</guid>
		<description><![CDATA[Last weekend, 19th &#38; 20th June 2010, saw the first Science Hack Day at the Guardian offices in London. Jeremy Keith organised a venue, food and drink and sponsorship for around 100 people to spend two days building small science projects. Saturday morning saw a series of short talks to introduce the event,  give people [...]]]></description>
			<content:encoded><![CDATA[<p>Last weekend, 19th &amp; 20th June 2010, saw the first <a href="http://sciencehackday.com">Science Hack Day</a> at <a href="http://guardian.co.uk">the Guardian</a> offices in London. <a href="http://adactio.com">Jeremy Keith</a> organised <a href="http://adactio.com/journal/1674/">a venue, food and drink and sponsorship</a> for around 100 people to spend two days building small science projects. Saturday morning saw a series of short talks to introduce the event,  give people some ideas of what they might make, and what tools were available to help them make it. 24 hours of hacking and building followed, with presentations and prizes for the best hacks on Sunday afternoon. Ed Gomez has a great <a href="http://lcogt.net/en/blog/egomez/science-hack-day">write-up of the hack day</a> itself, and the winning hacks. My personal favourites were the Aurorascope, which shows auroral activity by lighting up LEDs inside a ball representing the Earth, and <a href="http://randomorbit.net">Random Orbit</a>, a RESTful service to track satellites in real time.</p>
<p>I was asked by Jeremy to give one of the talks at the beginning of the hack day, so I chatted a bit about the work we&#8217;ve done with <a href="http://astrometry.net">astrometry.net</a> to tag Flickr photos with their celestial locations — astrotagging.</p>
<h3><span id="more-631"></span>Introducing astrotags</h3>
<p>At the <a href="http://www.nmm.ac.uk/places/royal-observatory/">Royal Observatory, Greenwich</a>, we&#8217;ve set up a Flickr group for our photography competition, <a href="http://flickr.com/groups/astrophoto">Astronomy Photographer of the Year</a>. Photos in the group are being scanned by the <a href="http://http://www.nmm.ac.uk/visit/exhibitions/astronomy-photographer-of-the-year/astro-robot/">astrometry.net bot</a>, which identifies stars in a photo then solves for celestial coordinates by comparison with a reference catalogue. Astrometry.net leaves a comment on each photo, listing the coordinates of the image and the names of objects within the field of view. The comments are relatively easy to parse, and I&#8217;ve written a <a href="/archives/2010/01/generating-astrotags-for-flickr-photos.html">small utility</a> to extract information from commented photos. However, this is the sort of problem that&#8217;s ideally suited to <a href="http://www.flickr.com/groups/api/discuss/72157594497877875/">machine tags</a> so we asked astrometry.net to add tags to photos in our group using the astro: prefix. The tags are:</p>
<dl>
<dt>astro:RA</dt>
<dd>Right Ascension of the centre of the photo.</dd>
<dt>astro:dec</dt>
<dd>Declination of the centre of the photo.</dd>
<dt>astro:orientation</dt>
<dd>Orientation of the photo from North, in degrees.</dd>
<dt>astro:fieldsize</dt>
<dd>Angular extent of the photo, East-West × North-South.</dd>
<dt>astro:name</dt>
<dd>Named objects in the field. One tag per name.</dd>
</dl>
<p>Some good examples of tagged photos are:</p>
<ul>
<li><a href="http://www.flickr.com/photos/36418300@N02/3362016992/">Horsehead Nebula</a></li>
<li><a href="http://www.flickr.com/photos/strongman/3476473934/">Eta Carina Nebula</a></li>
<li><a href="http://www.flickr.com/photos/31557673@N05/2955988513/">Summer Triangle and Milky Way</a></li>
</ul>
<p>The simplest way to get at these machine tags and use them in your own applications is with <a href="http://developer.yahoo.com/yql/">YQL</a>, which allows you to query the flickr search and photo info APIs using a simple, SQL-like syntax. To make life easier, I&#8217;ve written a <a href="http://developer.yahoo.com/yql/guide/yql-opentables-chapter.html">YQL open table</a>, <a href="http://github.com/yql/yql-tables/blob/master/flickr/flickr.photos.astro.xml">flickr.photos.astro</a>, which can be queried to return a feed of astronomical coordinates and info for a set of Flickr photos.</p>
<pre class="brush: sql; title: ; notranslate">select * from flickr.photos.astro where astro_name = 'Horsehead Nebula'</pre>
<p>That query, for example, returns <a href="http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20flickr.photos.astro%20where%20astro_name%3D'Horsehead%20Nebula'&amp;diagnostics=true&amp;env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys">a feed of photos tagged astro:name=&#8217;Horsehead Nebula&#8217;</a>. For some other examples, have a look at my post on <a href="/archives/2009/12/searching-astroname-with-yql.html">searching astro:name with YQL</a>.</p>
<h3>My hack</h3>
<p>Astrometry.net have <a href="http://www.flickr.com/photos/tags/Astrometrydotnet%3Astatus%3Dsolved/">solved almost 7,000 photos</a> on Flickr, but only <a href="http://www.flickr.com/photos/tags/astro:ra=">around 600 of those</a> have been tagged with astro: machine tags. For my hack, I decided to try making a YQL table based on screen-scraping Flickr for information left by the astrometry.net robot. I took the code from my <a href="/testapps/yql/astrotagger.html">astrotagging web form</a> and put together <a href="http://github.com/eatyourgreens/yql-tables/blob/master/flickr/flickr.photos.astrometry.xml">flickr.photos.astrometry</a>, a YQL open table that can parse astrometry information from Flickr comments. The input parameter is a Flickr photo page URL, so a query looks like</p>
<pre class="brush: sql; title: ; notranslate">select * from flickr.photos.astrometry where url = 'http://www.flickr.com/photos/dangerous_astro/4722913544/'</pre>
<p>This returns <a href="http://query.yahooapis.com/v1/public/yql?q=use%20%27http%3A%2F%2Fgithub.com%2Featyourgreens%2Fyql-tables%2Fraw%2Fmaster%2Fflickr%2Fflickr.photos.astrometry.xml%27%3B%20select%20*%20from%20flickr.photos.astrometry%20where%20url%20%3D%20%27http://www.flickr.com/photos/dangerous_astro/4722913544/%27&amp;diagnostics=true">a feed of the coordinates and names</a> found on that page.</p>
<p>To demo this, I hacked together a little javascript <a href="http://eatyourgreens.org.uk/yql/scihackday.html?text=rosette+nebula">astronomy photo search engine</a>. You pass in a search query in the URL:</p>
<p><a href="http://eatyourgreens.org.uk/yql/scihackday.html?text=milky+way">http://eatyourgreens.org.uk/yql/scihackday.html?text=milky+way</a></p>
<p>That text is then used to run a Flickr search and grab up to 30 photos, shown as thumbnails. The search is limited to photos which have been solved by astrometry.net, and we also request the photographer&#8217;s name so that we can credit them:</p>
<pre class="brush: sql; title: ; notranslate">select * from flickr.photos.search(30) where text = 'milky way' and extras='owner_name' and machine_tags = 'Astrometrydotnet:status=solved'</pre>
<p>If you don&#8217;t pass in a search query, we instead return the 30 most recent photos solved by astrometry.net.</p>
<pre class="brush: sql; title: ; notranslate">select * from flickr.photos.search(30) where extras='owner_name' and machine_tags = 'Astrometrydotnet:status=solved'</pre>
<p>When you select a thumbnail, by clicking on it, another YQL query is run against flickr.photos.astrometry to return the coordinates and names for that photo. The coordinates are used to plot the photo on a map of the sky, while the names are listed as links so that you can go on to search for pictures of specific objects in the field of view.</p>
<p>It&#8217;s quite a simple little bit of code, but hopefully it shows how useful YQL can be for accessing structured data on the web, even when that data is in HTML or plain text. If anyone does use it to build anything, Astronomy Photographer of the Year has <a href="http://www.nmm.ac.uk/visit/exhibitions/astronomy-photographer-of-the-year/showcase/">a showcase page</a> for mashups built using the Flickr astrometry data.</p>
]]></content:encoded>
			<wfw:commentRss>http://eatyourgreens.org.uk/archives/2010/06/get-excited-and-make-things-with-science.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Generating astrotags for Flickr photos</title>
		<link>http://eatyourgreens.org.uk/archives/2010/01/generating-astrotags-for-flickr-photos.html</link>
		<comments>http://eatyourgreens.org.uk/archives/2010/01/generating-astrotags-for-flickr-photos.html#comments</comments>
		<pubDate>Sun, 03 Jan 2010 12:46:06 +0000</pubDate>
		<dc:creator>Jim O'Donnell</dc:creator>
				<category><![CDATA[astronomy]]></category>
		<category><![CDATA[geekage]]></category>
		<category><![CDATA[yql]]></category>

		<guid isPermaLink="false">http://eatyourgreens.org.uk/?p=603</guid>
		<description><![CDATA[In December, I talked at London Web Standards about tagging astronomy photos with position and name information. I mentioned that around 400 photos have been tagged already on Flickr but this is only a tiny fraction of the 4,900 photos that have been solved by astrometry.net. It would be great if the remaining 4,500 photos [...]]]></description>
			<content:encoded><![CDATA[<p>In December, I talked at <a href="http://londonwebstandards.org/">London Web Standards </a>about <a href="http://eatyourgreens.org.uk/archives/2009/12/london-web-standards-introducing-astrotags.html">tagging astronomy photos with position and name information</a>. I mentioned that <a href="http://www.flickr.com/photos/tags/astro:ra=">around 400 photos</a> have been tagged already on Flickr but this is only a tiny fraction of the 4,900 photos that have been <a href="http://www.flickr.com/photos/tags/Astrometrydotnet%3Astatus%3Dsolved/">solved by astrometry.net</a>. It would be great if the remaining 4,500 photos could also be tagged, and it ought to be straightforward to generate tags for those photos too. Inspired by the <a href="http://inaturalist.org/taxa/flickr_tagger?taxon_id=4981">iNaturalist Taxonomic Tagging Tool</a>, I&#8217;ve written a little <a href="http://eatyourgreens.org.uk/testapps/yql/astrotagger.html">astrotagging form for Flickr photos</a>.</p>
<p>When the <a href="http://astrometry.net">astrometry.net</a> robot solves a photo on Flickr, it leaves a comment identifying the coordinates of the photo and listing the names of objects in the field.</p>
<blockquote cite="http://www.flickr.com/photos/eatyourgreens/4182924966/comment72157623004301204/">
  <p>Hello, this is the blind astrometry solver.
  Your results are:<br/>
   (RA, Dec) center:(82.4668973542,
  6.33857270637) degrees<br/>
  (RA, Dec) center (H:M:S,
  D:M:S):(05:29:52.055, +6:20:18.862)<br/>
  Orientation:161.45 deg E of N<br/>
  <br/>
  Pixel scale:67.93 arcsec/pixel<br/>
  <br/>
  Parity:Reverse (&#8220;Left-handed&#8221;)<br/>
  Field size :53.14 x 39.85 degrees<br/>
  <br/>
  Your field contains:<br/>
  The star Rigel (&beta;Ori)<br/>
  The star Betelgeuse (&alpha;Ori)<br/>
  The star Aldebaran (&alpha;Tau)<br/>
  The star Bellatrix (&gamma;Ori)<br/>
  The star Alnilam (&epsilon;Ori)<br/>
  The star Alhena (&gamma;Gem)<br/>
  The star Alnitak (&zeta;Ori)<br/>
  The star Saiph (&kappa;Ori)<br/>
  The star Mintaka (&delta;Ori)<br/>
  The star Cursa (&beta;Eri)<br/>
  IC 2118 / IC 2118 / Witch Head nebula<br/>
  NGC 1976 / NGC 1976 / Great Nebula in Orion
  / M 42<br/>
  NGC 1990 / NGC 1990<br/>
  IC 434 / IC 434 / Horsehead nebula<br/>
  IC 443 / IC 443<br/>
  NGC 2264 / NGC 2264 / Christmas Tree cluster
  / Cone nebula<br/>
  <br/>
  <a rel="nofollow" href="http://www.worldwidetelescope.org/wwtweb/ShowImage.aspx?reverseparity=False&amp;scale=67.93&amp;name=Orion,+Taurus+and+Gemini&amp;imageurl=http://farm3.static.flickr.com/2689/4182924966_9a291b6c39_o.jpg&amp;credits=Jim+O'Donnell+(Attribution-NonCommercial-ShareAlike+License)&amp;creditsUrl=http://creativecommons.org/licenses/by-nc-sa/2.0/&amp;ra=82.4668973542&amp;y=1056&amp;x=1408&amp;rotation=161.45&amp;dec=6.33857270637&amp;thumb=http://farm3.static.flickr.com/2689/4182924966_89b3009869_t.jpg">View in World Wide Telescope</a><br/>
  <br/>
  &#8212;&#8211;<br/>
  If you would like to have other images
  solved, please submit them to the <a href="http://www.flickr.com/groups/astrometry">astrometry group</a>.
  																<br/>

  								<small>
  									Posted 3 weeks ago.
  									( <a class="Plain" href="/photos/eatyourgreens/4182924966/comment72157623004301204/">permalink</a>
  														| <a class="Plain" href="/photos/eatyourgreens/4182924966/deletecomment72157623004301204/">delete</a>
  																)
  								</small>
  								</p>
</blockquote>
<p>These comments are always in the same format, so it&#8217;s straightforward to parse them and extract the astrometry metadata as a list of tags. I&#8217;ve written a small form which does this, using <abbr title="Yahoo! Query Language">YQL</abbr> to grab the comments from a Flickr photo then parsing them using standard <abbr title="Document Object Model">DOM</abbr> traversal and manipulation methods.</p>
<p>If you have a photo which has been solved, generating tags is straightforward. Copy the address of a Flickr photo page into the <a href="http://eatyourgreens.org.uk/testapps/yql/astrotagger.html">tagging form</a> and press the big blue &#8216;Get astrotags&#8217; button. The script should find the comment from astrometry.net and print out the tags for celestial coordinates and names, which you can then paste into the &#8216;Add a tag&#8217; form on Flickr.</p>
<p>The code to do this is fairly simple, and reproduced below. After initialising the page, we can take advantage of YQL&#8217;s HTML parser to fetch all of the comments for a Flickr photo page by selecting all paragraphs inside divs with a class of &#8216;comment-content&#8217; at that URL.</p>
<pre class="brush: sql; title: ; notranslate">
select * from html where url='http://www.flickr.com/photos/eatyourgreens/4182924966/' and xpath='//div[@class=&quot;comment-content&quot;]/p'
</pre>
<p>We then loop through the results of this query, looking for paragraphs which contain the text &#8216;blind astrometry solver&#8217;. If we have a match, we add this paragraph to the DOM so we can parse it with standard DOM methods. The code then loops through the child nodes of the comment paragraph, running regular expression matches against any text nodes it finds to extract the coordinates of the photo. </p>
<p>Names are slightly more tricky. For those, we grab every line of text between &#8216;Your field contains:&#8217; and the line &#8216;&#8212;&#8211;&#8217; above the signature, strip out whitespace, split each line on &#8216;/&#8217; to get individual names and store these in an associative array, keyed on name to remove duplicates. That done, we can then just loop through the arrays of coordinates and names and print them out.</p>
<p>Here&#8217;s the full code:</p>
<pre class="brush: jscript; title: ; notranslate">
 var url = &quot;http://www.flickr.com/photos/skiwalker79/4174398309&quot;;
 var comment_holder;
 var position_output;
 var names_output;
 
 function init() {
   var url_input = document.getElementById('photoURL');
   var url_button = document.getElementById('updateURL');
   
   comment_holder = document.getElementById('comment');
   position_output = document.getElementById('position');
   names_output = document.getElementById('names');
   
   url_input.disabled = false;
   url_input.value = url;
   url_button.disabled = false;
   position_output.disabled = false;
   names_output.disabled = false;
   
   addEvent(url_button, 'click', function(e) {
     getFlickrPhotoComments(url_input.value);
     return false;
   });
   addEvent(url_input, 'focus', function(e) {
     url_input.select();
   });
   addEvent(position_output, 'focus', function(e) {
     position_output.select();
   });
   addEvent(names_output, 'focus', function(e) {
     names_output.select();
   });
   
   // Mark up nodes which this script updates as
   // ARIA live regions.
   comment_holder.setAttribute('aria-live', 'polite');
   position_output.setAttribute('aria-live', 'polite');
   names_output.setAttribute('aria-live', 'polite');
   
   getFlickrPhotoComments(url);    
 }

 function getFlickrPhotoComments(url) {

   // YQL query to get all comments from a Flickr photo page.
   var yql = &quot;select * from html where url='&quot;+url+&quot;' and xpath='//div[@class=\&quot;comment-content\&quot;]/p'&quot;;
   var yql_url = 'http://query.yahooapis.com/v1/public/yql?q='+escape(yql)+'&amp;format=xml&amp;callback=getAstrometryComment&amp;diagnostics=false';
   position_output.value = '';
   names_output.value = '';
   comment_holder.innerHTML = 'Looking up '+url;
   makeYQLRequest(yql_url);
 }
 
 function makeYQLRequest(yql_url) {
   var script=document.getElementById('yqlscript');
   var newscript=document.createElement('script');
   newscript.type = 'text/javascript';
   newscript.src=yql_url;
   newscript.id='yqlscript';
   document.getElementsByTagName(&quot;body&quot;)[0].removeChild(script);
   document.getElementsByTagName(&quot;body&quot;)[0].appendChild(newscript);
 }

function getAstrometryComment(data) {
  var results = data.results;
  
  var comment = 'Sorry, that photo has not been solved by &lt;a href=&quot;http://astrometry.net&quot;&gt;astrometry.net&lt;/a&gt;.';
  for (var i in results) {
    var text = results[i];
    // Comments left by the solver contain the text 'blind astrometry solver'.
    if(text.match(/blind astrometry solver/gi)) {
      comment = text;
    }
  }
  parseComment(comment);
  
}

function parseComment(comment) {
  var astro = {};
  var names = {};
  var parsing_names = false;
  
  comment_holder.innerHTML = comment;
  var children = comment_holder.firstChild.childNodes;
  
  for (var i in children) {
    var child = children[i];
    var text = '';
    text = child.data;
    
    if (text) {
      if (text.match(/(RA, Dec)/g) &amp;&amp; text.match(/degrees/g)) {
        text=text.match(/[-0-9\.]+/g);
        astro.RA = text[0];
        astro.Dec = text[1];
      } else if (text.match(/Orientation/g)) {
        text = text.match(/[-0-9\.]+/g);
        astro.orientation = text[0];
      } else if (text.match(/Pixel scale/g)) {
        text = text.match(/[0-9\.]+/g);
        astro.pixelScale = text[0];
      } else if(text.match(/Field size/g)) {
        text = text.match(/[0-9\.]+ x [0-9\.]+ (degrees|arcminutes|arcseconds)/g);
        astro.fieldsize = text[0];
      } else if(text.match(/Your field contains:/g)) {
        parsing_names = true;
      } else if (text.match(/-----/g)) {
        parsing_names = false;
      }

      if (parsing_names) {
        names = addNames(names, text);
      }
      
    }
  }

  renderPositionTags(astro);
  
  renderNameTags(names);
  
  if (astro.RA) {
    position_output.focus();
  }
}

function addNames(names, text) {
  
 text = trim(text);
 text = text.split('/');
 for (var j in text) {
   var name = text[j];
   name = trim(name);
   if (name &amp;&amp; name !='Your field contains:'){
     names[name] = name;
   }
 }
 return names;
}

function renderPositionTags(astro) {
  
  position_output.value = '';
   for (var tag in astro) {
     position_output.value += 'astro:'+tag+'=&quot;'+astro[tag]+'&quot; ';
   } 
}

function renderNameTags(names) {

  names_output.value = '';
   for (var name in names) {
     names_output.value += 'astro:name=&quot;'+name+'&quot; '
   }
}

function trim(text) {
  // Trim leading and trailing whitespace from a string.
  text = text.replace(/^\s+/, '');
  text = text.replace(/\s+$/,'');
  return text;
}

function addEvent(obj, evType, fn) {
  if (obj.addEventListener) {
    obj.addEventListener(evType, fn, false);
    return true;
  } else if (obj.attachEvent) {
    var r = obj.attachEvent(&quot;on&quot; + evType, fn);
    return r;
  } else {
    return false;
  }
}
</pre>]]></content:encoded>
			<wfw:commentRss>http://eatyourgreens.org.uk/archives/2010/01/generating-astrotags-for-flickr-photos.html/feed</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Searching astro:name with YQL</title>
		<link>http://eatyourgreens.org.uk/archives/2009/12/searching-astroname-with-yql.html</link>
		<comments>http://eatyourgreens.org.uk/archives/2009/12/searching-astroname-with-yql.html#comments</comments>
		<pubDate>Sat, 19 Dec 2009 22:59:53 +0000</pubDate>
		<dc:creator>Jim O'Donnell</dc:creator>
				<category><![CDATA[astronomy]]></category>
		<category><![CDATA[geekage]]></category>
		<category><![CDATA[yql]]></category>

		<guid isPermaLink="false">http://eatyourgreens.org.uk/archives/2009/12/searching-astroname-with-yql.html</guid>
		<description><![CDATA[Searching astro:name with YQL, originally uploaded by Eat your greens!. The YQL team announced personal URLs for queries this week. I&#8217;ve used the new feature to set up a shortcut for looking up photos of astronomical objects by name. The URL is: http://queries.yahooapis.com/v1/public/yql/eatyourgreens/astrolookup?name=M+42 You can set the name parameter in the URL to change the [...]]]></description>
			<content:encoded><![CDATA[<p><a title="photo sharing" href="http://www.flickr.com/photos/eatyourgreens/4198668956/"><img style="border: solid 2px #000000;" src="http://farm3.static.flickr.com/2797/4198668956_e6490091f7.jpg" alt="" /></a></p>
<p style="font-size: 0.8em; margin-top: 0px;"><a href="http://www.flickr.com/photos/eatyourgreens/4198668956/">Searching astro:name with YQL</a>, originally uploaded by <a href="http://www.flickr.com/people/eatyourgreens/">Eat your greens!</a>.</p>
<p>The <abbr title="Yahoo! Query Language">YQL</abbr> team announced <a href="http://developer.yahoo.net/blog/archives/2009/12/yql_gets_personal_urls_and_more_cache_control.html">personal URLs for queries</a> this week. I&#8217;ve used the new feature to set up a shortcut for looking up photos of astronomical objects by name. The URL is:</p>
<p><a href="http://queries.yahooapis.com/v1/public/yql/eatyourgreens/astrolookup?name=M+42">http://queries.yahooapis.com/v1/public/yql/eatyourgreens/astrolookup?name=M+42</a></p>
<p>You can set the <code>name</code> parameter in the URL to change the name of the object you are looking for. I&#8217;ve also set up <a href="http://eatyourgreens.org.uk/testapps/yql/astronamesearch.html?name=Horsehead+nebula">a demo page</a> to render results from this query. The URL is:</p>
<p><a href="http://eatyourgreens.org.uk/testapps/yql/astronamesearch.html?name=Horsehead+nebula">http://eatyourgreens.org.uk/testapps/yql/astronamesearch.html?name=Horsehead+nebula</a></p>
<p>Again, change the <code>name</code> parameter in the URL to lookup different objects. Note that it looks for an exact match with the <code>astro:name</code> machine tag, so looking up stars is cumbersome:</p>
<p><a href="http://eatyourgreens.org.uk/testapps/yql/astronamesearch.html?name=the%20star%20deneb%20%28%CE%B1cyg%29">http://eatyourgreens.org.uk/testapps/yql/astronamesearch.html?name=the+star+deneb+(&alpha;cyg)</a></p>
<p><strong>Update:</strong> it seems Flickr&#8217;s machine tag search can match just the first part of a tag, so you can search for stars by supplying the first part of the tag&#8217;s value.</p>
<p><a href="http://eatyourgreens.org.uk/testapps/yql/astronamesearch.html?name=the+star+deneb">http://eatyourgreens.org.uk/testapps/yql/astronamesearch.html?name=the+star+deneb</a></p>
<p>I&#8217;ve also made some changes to <a href="http://github.com/eatyourgreens/yql-tables/blob/master/flickr/flickr.photos.astro.xml"><code>flickr.photos.astro</code></a> in order to enable faster searching by name. Use <code>astro_name</code> in a query to find objects by matching on <code>astro:name</code>:</p>
<pre class="brush: sql; title: ; notranslate">
select * from flickr.photos.astro where astro_name = 'M 31'
</pre>
<p>or use <code>text</code> to run a Flickr text search across photo descriptions and titles:</p>
<pre class="brush: sql; title: ; notranslate">
select * from flickr.photos.astro where text = 'orion'
</pre>
<p>If you want to see what values have been used for <code>astro:name</code> on Flickr, I recommend <a href="http://husk.org/code/machine-tag-browser.html#tag=astro:name">Paul Mison&#8217;s excellent machine tag browser</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://eatyourgreens.org.uk/archives/2009/12/searching-astroname-with-yql.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>London web standards: Introducing astrotags</title>
		<link>http://eatyourgreens.org.uk/archives/2009/12/london-web-standards-introducing-astrotags.html</link>
		<comments>http://eatyourgreens.org.uk/archives/2009/12/london-web-standards-introducing-astrotags.html#comments</comments>
		<pubDate>Tue, 15 Dec 2009 00:18:37 +0000</pubDate>
		<dc:creator>Jim O'Donnell</dc:creator>
				<category><![CDATA[astronomy]]></category>
		<category><![CDATA[geekage]]></category>
		<category><![CDATA[yql]]></category>

		<guid isPermaLink="false">http://eatyourgreens.org.uk/?p=530</guid>
		<description><![CDATA[Here are the slides from my talk at the December LWS meetup &#8211; Introducing astrotags: astrometry, machine tags and YQL (20MB pdf). The examples and demos should all be in the YQL category on this blog. If you&#8217;re interested in the nuts and bolts of the automated astrometry robot, I recommend having a look at [...]]]></description>
			<content:encoded><![CDATA[<p>Here are the slides from my talk at the December LWS meetup &#8211; <a href="/pdf/astrotags.pdf">Introducing astrotags: astrometry, machine tags and YQL</a>  (20MB pdf). The examples and demos should all be in the <a href="/category/yql">YQL category</a> on this blog.</p>
<p>If you&#8217;re interested in the nuts and bolts of the automated astrometry robot, I recommend having a look at <a href="http://astrometry.net">astrometry.net</a> and reading <a href="http://cosmo.nyu.edu/hogg/research/2006/09/28/astrometry_google.pdf">Making the sky searchable: Fast geometric hashing for automated astrometry</a>.</p>
]]></content:encoded>
			<wfw:commentRss>http://eatyourgreens.org.uk/archives/2009/12/london-web-standards-introducing-astrotags.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Look out honey cos I&#8217;m using technology</title>
		<link>http://eatyourgreens.org.uk/archives/2009/11/look-out-honey-cos-im-using-technology.html</link>
		<comments>http://eatyourgreens.org.uk/archives/2009/11/look-out-honey-cos-im-using-technology.html#comments</comments>
		<pubDate>Mon, 02 Nov 2009 22:20:17 +0000</pubDate>
		<dc:creator>Jim O'Donnell</dc:creator>
				<category><![CDATA[geekage]]></category>
		<category><![CDATA[yql]]></category>

		<guid isPermaLink="false">http://eatyourgreens.org.uk/?p=488</guid>
		<description><![CDATA[My last post gave some examples of YQL queries that could be used to access the data for the Science Museum&#8217;s Cosmic Collections competition. Looking at XML feeds is pretty dry, though, so I thought it would be fun to put together a demo which uses a YQL query to visualise the data. I&#8217;ve also [...]]]></description>
			<content:encoded><![CDATA[<p>My last post gave some examples of <abbr title="Yahoo Query Language">YQL</abbr> queries that could be used to access the data for the Science Museum&#8217;s <a href="http://www.sciencemuseum.org.uk/visitmuseum/galleries/cosmos_and_culture/mash-up_competition.aspx">Cosmic Collections competition</a>. Looking at XML feeds is pretty dry, though, so I thought it would be fun to put together a demo which uses a YQL query to visualise the data. I&#8217;ve also been looking at <a href="http://raphaeljs.com">Raphaël </a>recently, a small library for working with <abbr title="Scalable Vector Graphics">SVG</abbr> in web pages. Inspired by the <a href="http://www.flickr.com/photos/eatyourgreens/4037719269/">Royal Observatory&#8217;s Flickr touchscreen</a>, and knowing next to nothing about either<a href="http://jquery.com"> jQuery</a> or SVG, I wrote some quick code with jQuery and Raphaël to display photos of the Science Museum objects as a pile of polaroid photos.</p>
<p>Here&#8217;s the code, with some explanation in the comments that hopefully shows how to extract the Science Museum data from the query results and do something useful with it. The event handling code seems a little dodgy to me ( I really know very little about SVG or jQuery) but seems to work in Opera, Firefox and Safari. You can try it on <a href="http://eatyourgreens.org.uk/yql/coscultcom.html">the demo page</a>. Click to pick up a photo and move it. Click again to drop it.</p>
<p><strong>A small update:</strong> Here&#8217;s <a href="http://eatyourgreens.org.uk/yql/coscultcom2.html">a second demo</a> using drag-and-drop instead of mouse clicks. I&#8217;ve also added the <code>focusable</code> attribute to the SVG rectangles, to make them accessible from the keyboard. This only seems to work in Opera.</p>
<pre class="brush: jscript; title: ; notranslate">
// URL of the environment file, which points to the URL
// of the nmsi.cosmosculture YQL table definition.
var env = 'http://eatyourgreens.org.uk/yql/nmsi.env';
// YQL query to select everything from the Cosmic Collections dataset.
// Change this query to change the objects displayed in the page.
var yql = &quot;select * from nmsi.cosmosculture&quot;;
// Example alternate query - fetch everything linked to the Moon
// var yql = &quot;select * from nmsi.cosmosculture where LinkedCelestialBodies.CelestialBody.CommonName = 'Moon'&quot;;

// Encode the query and env file URL in a call to the YQL web service.
// Specify JSON as the return format.
var url = 'http://query.yahooapis.com/v1/public/yql?q='+ encodeURIComponent(yql) + '&amp;env='+encodeURIComponent(env)+'&amp;diagnostics=false&amp;format=json&amp;callback=?';

// Set a canvas for Raphael to draw on.
var height = 600;
var width = 800;
var paper = Raphael('canvas', width, height);

// Set some global variables to use when we are dragging elements around the canvas.
var startx = 0;
var starty = 0;
var dragging = false;
var draggedSet = null;

// Call the YQL web service and pass the json result to a callback function
$.getJSON(url, function(json){
//  Get the array of museum objects from the query result.
	var items = json.query.results.MuseumObject;
// Loop through the items array
	$.each(items, function(i, item) {
// Ignore items which don't have a photo
		if(item.Image.Source){
			var src = item.Image.Source;
// The smallest available image size is 'Inline'.
			src = src.replace(&quot;Medium&quot;,&quot;Inline&quot;);
			src = 'http://www.sciencemuseum.org.uk'+src;
// Generate a random x,y position for the photo
 			var x = 10 + (width-110) * Math.random();
 			var y = 10 + (height-110) * Math.random();
// Generate a random angle between 350 and 10 degrees.
 			var rot = 10*Math.random();
 			if(Math.random() &amp;lt; 0.5) rot = 360-rot;
// Each photo is built from a set consisting of a white rectangle and the photo
 				var s = paper.set();
 				s.push(paper.rect(x,y,110,140).attr('fill','white'),paper.image(src, x+5, y+5, 100, 100));
// Rotate the set by our random angle
 				s.rotate(rot);
// When the set is clicked, if already dragging, drop the photo.
// Otherwise, bring to the front and store the mouse
// coordinates for future use.
 				s.click(function(e) {
 					if (dragging) {
 						dragging=false;
 					}else {
 						dragging = true;
 						startx = e.clientX;
 						starty = e.clientY;
 						s.toFront();
 						draggedSet = s;
 					}
 				});
// Listen for mouse movement on the document.
// If dragging, move the dragged set to the
// x,y coordinates of the mouse.
// Store the current coordinates for the start
// of the next move.
 				document.onmousemove = function(e){
 					if(dragging) {
 						dx = e.clientX - startx;
 						dy = e.clientY - starty;

 						for (var j=0; j &amp;lt; 2; j++) {
 							var node = draggedSet[j];
 							node.attr({x: node.attr('x')+dx, y: node.attr('y')+dy});
 						}

 						startx = e.clientX;
 						starty = e.clientY;
 					}
 				};
 			}
 		});
})
</pre>
]]></content:encoded>
			<wfw:commentRss>http://eatyourgreens.org.uk/archives/2009/11/look-out-honey-cos-im-using-technology.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Science Museum Cosmic Collections competition</title>
		<link>http://eatyourgreens.org.uk/archives/2009/10/science-museum-cosmic-collections-competition.html</link>
		<comments>http://eatyourgreens.org.uk/archives/2009/10/science-museum-cosmic-collections-competition.html#comments</comments>
		<pubDate>Sun, 25 Oct 2009 13:52:51 +0000</pubDate>
		<dc:creator>Jim O'Donnell</dc:creator>
				<category><![CDATA[geekage]]></category>
		<category><![CDATA[yql]]></category>

		<guid isPermaLink="false">http://eatyourgreens.org.uk/?p=471</guid>
		<description><![CDATA[The Science Museum have launched their Cosmic Collections website competition. They are offering two £1,000 prizes for web mashups built using their data describing the objects in the Cosmos &#38; Culture gallery. The deadline for entries is 28th November 2009. Full details are available on the competition web page. There&#8217;s also a Yahoo! Developer Network [...]]]></description>
			<content:encoded><![CDATA[<p>The Science Museum have launched their <a href="http://www.sciencemuseum.org.uk/visitmuseum/galleries/cosmos_and_culture/mash-up_competition.aspx">Cosmic Collections website competition</a>. They are offering two £1,000 prizes for web mashups built using their data describing the objects in the <a href="http://www.sciencemuseum.org.uk/visitmuseum/galleries/cosmos_and_culture.aspx">Cosmos &amp; Culture gallery</a>. The deadline for entries is 28th November 2009. Full details are available on the competition web page. There&#8217;s also a <a href="http://developer.yahoo.net/blog/archives/2009/10/a_new_api_and_h.html">Yahoo! Developer Network interview with Mia Ridge</a> about the competition.</p>
<p>The data has been released using a fairly simple API, so I&#8217;ve drafted a <a href="http://eatyourgreens.org.uk/yql/nmsi.cosmosculture.xml">YQL open table definition</a> for it. You can use it to retrieve the full dataset:</p>
<pre class="brush: sql; title: ; notranslate">use &quot;http://eatyourgreens.org.uk/yql/nmsi.cosmosculture.xml&quot;;
select * from nmsi.cosmosculture</pre>
<p><a href="http://query.yahooapis.com/v1/public/yql?q=use%20%22http%3A%2F%2Featyourgreens.org.uk%2Fyql%2Fnmsi.cosmosculture.xml%22%3B%0Aselect%20*%20from%20nmsi.cosmosculture&amp;format=xml&amp;env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys">Try it</a></p>
<p>or retrieve an individual item, given the accession number:</p>
<pre class="brush: sql; title: ; notranslate">use &quot;http://eatyourgreens.org.uk/yql/nmsi.cosmosculture.xml&quot;;
select * from nmsi.cosmosculture where AccessionNumber = '1923-668';</pre>
<p><a href="http://query.yahooapis.com/v1/public/yql?q=use%20%22http%3A%2F%2Featyourgreens.org.uk%2Fyql%2Fnmsi.cosmosculture.xml%22%3B%0Aselect%20*%20from%20nmsi.cosmosculture%20where%20AccessionNumber%20%3D%20'1923-668'%3B&amp;format=xml&amp;env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys">Try it</a></p>
<p>You can also use YQL&#8217;s own filtering operators to restrict the result set. For example, get items for a particular place:</p>
<pre class="brush: sql; title: ; notranslate">use &quot;http://eatyourgreens.org.uk/yql/nmsi.cosmosculture.xml&quot;;
select * from nmsi.cosmosculture
where LinkedPlaces.Place.PlaceName like '%Italy%'</pre>
<p><a href="http://query.yahooapis.com/v1/public/yql?q=use%20%22http%3A%2F%2Featyourgreens.org.uk%2Fyql%2Fnmsi.cosmosculture.xml%22%3B%0Aselect%20*%20from%20nmsi.cosmosculture%20where%20LinkedPlaces.Place.PlaceName%20like%20'%25Italy%25'&amp;format=xml&amp;env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys">Try it</a></p>
<p>The <a href="http://cosmiccollections.pbworks.com/">competition wiki</a> has a page describing the <a href="http://cosmiccollections.pbworks.com/Cosmic-Collections-API">catalogue fields</a> returned by the API.</p>
]]></content:encoded>
			<wfw:commentRss>http://eatyourgreens.org.uk/archives/2009/10/science-museum-cosmic-collections-competition.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>YQL updates for nmm.collections</title>
		<link>http://eatyourgreens.org.uk/archives/2009/10/yql-updates-for-nmm-collections.html</link>
		<comments>http://eatyourgreens.org.uk/archives/2009/10/yql-updates-for-nmm-collections.html#comments</comments>
		<pubDate>Thu, 22 Oct 2009 22:14:54 +0000</pubDate>
		<dc:creator>Jim O'Donnell</dc:creator>
				<category><![CDATA[geekage]]></category>
		<category><![CDATA[yql]]></category>

		<guid isPermaLink="false">http://eatyourgreens.org.uk/?p=452</guid>
		<description><![CDATA[I&#8217;ve made a couple of updates to the National Maritime Museum YQL tables, to hopefully make it a little easier to search the NMM collections with YQL. Firstly, I&#8217;ve added a new input parameter, sortby, to nmm.collections.search, which specifies the field used to sort search results. Possible values are objectid, title, maker, year, updated. You [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve made a couple of updates to the National Maritime Museum YQL tables, to hopefully make it a little easier to search the NMM collections with <a href="http://developer.yahoo.com/yql/">YQL</a>.</p>

<p>Firstly, I&#8217;ve added a new input parameter, <code>sortby</code>, to <code>nmm.collections.search</code>, which specifies the field used to sort search results. Possible values are <code>objectid, title, maker, year, updated</code>. You can also specify <code>sortby = 'rank'</code> to order results by relevance for free text searches. So, for example, you can get the most recently updated records from the art collection with the following query:</p>

<pre class="brush: sql; title: ; notranslate">select * from nmm.collections.search
where category = 'art' and searchterm = '' and sortby='updated'</pre>
<a href="http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20nmm.collections.search%0Awhere%20category%20%3D%20'art'%20and%20searchterm%3D''%20and%20sortby%3D'updated'&amp;format=xml&amp;env=http%3A%2F%2Fwww.nmm.ac.uk%2Fcollections%2Fexperiments%2Fyql%2Fnmm.env">Try it</a>

<p>Secondly, I&#8217;ve set up an XML feed to look up entries in the authority tables, and a corresponding YQL table <code>nmm.collections.authorities</code>. So, rather than having to know that the Aquitania is entry 21209 in the vessels authority, you can look up its entry with:</p>

<pre class="brush: sql; title: ; notranslate">select * from nmm.collections.authorities
where authority = 'vessels' and title = 'Aquitania'</pre>
<a href="http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20nmm.collections.authorities%20where%20authority%20%3D%20'vessels'%20and%20title%20%3D%20'Aquitania'&amp;format=xml&amp;env=http%3A%2F%2Fwww.nmm.ac.uk%2Fcollections%2Fexperiments%2Fyql%2Fnmm.env">Try it</a>

<p>This is most useful when doing search for objects linked to a particular authority record, as you can join the two <code>nmm.collections</code> tables. For example, to search for art by the painter Charles Pears, you could try the query:</p>

<pre class="brush: sql; title: ; notranslate">select * from nmm.collections.search
where searchterm='' and (authority,category) in
(select authority,id from nmm.collections.authorities
where authority = 'people' and title = 'pears')</pre>
<a href="http://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20nmm.collections.search%0Awhere%20searchterm%3D''%0Aand%20(authority%2Ccategory)%20in%20%0A(select%20authority%2Cid%20from%20nmm.collections.authorities%0Awhere%20authority%20%3D%20'people'%20and%20title%20%3D%20'pears')%0A&amp;format=xml&amp;env=http%3A%2F%2Fwww.nmm.ac.uk%2Fcollections%2Fexperiments%2Fyql%2Fnmm.env">Try it</a>

<p>The <a href="http://github.com/yql/yql-tables/tree/master/nmm/">new YQL table definitions</a> are available on github, and will hopefully be available to use in the YQL console soon. I&#8217;ve set up a<a href="http://www.nmm.ac.uk/collections/experiments/yql/badge.html"> javascript demo page</a> where developers can test YQL queries against the NMM collections. There&#8217;s also a page of <a href="http://www.nmm.ac.uk/collections/feeds/docs/">documentation about the NMM&#8217;s collections feeds</a>, with some sample YQL queries for developers.</p>]]></content:encoded>
			<wfw:commentRss>http://eatyourgreens.org.uk/archives/2009/10/yql-updates-for-nmm-collections.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Searching the sky with YQL Execute</title>
		<link>http://eatyourgreens.org.uk/archives/2009/05/searching-the-sky-with-yql-execute.html</link>
		<comments>http://eatyourgreens.org.uk/archives/2009/05/searching-the-sky-with-yql-execute.html#comments</comments>
		<pubDate>Mon, 11 May 2009 22:45:42 +0000</pubDate>
		<dc:creator>Jim O'Donnell</dc:creator>
				<category><![CDATA[astronomy]]></category>
		<category><![CDATA[geekage]]></category>
		<category><![CDATA[yql]]></category>

		<guid isPermaLink="false">http://eatyourgreens.org.uk/?p=411</guid>
		<description><![CDATA[Astro location search with YQL execute, originally uploaded by eat your greens. I was fortunate enough to win one of the prizes at Open Hack London this weekend. I ported the javascript from my astronomy photo browser to YQL Execute, creating a new open data table which returns celestial coordinates for astrotagged flickr photos. Essentially, [...]]]></description>
			<content:encoded><![CDATA[<div style="text-align: left; padding: 3px;"><a title="photo sharing" href="http://www.flickr.com/photos/eatyourgreens/3528192730/"><img style="border: 2px solid #000000;" src="http://farm4.static.flickr.com/3572/3528192730_354929ee9e.jpg" alt="" width="500" height="256" /></a></p>
<p><span style="font-size: 0.8em; margin-top: 0px;"><a href="http://www.flickr.com/photos/eatyourgreens/3528192730/">Astro location search with YQL execute</a>, originally uploaded by <a href="http://www.flickr.com/people/eatyourgreens/">eat your greens</a>.</span></div>
<p>I was fortunate enough to win one of the prizes at <a href="http://openhacklondon.pbwiki.com/">Open Hack London</a> this weekend. I ported the javascript from my <a href="http://eatyourgreens.org.uk/archives/2009/03/google-sky-photo-browser.html">astronomy photo browser</a> to <a href="http://developer.yahoo.com/yql/guide/yql-execute-chapter.html">YQL Execute</a>, creating a new open data table which returns celestial coordinates for astrotagged flickr photos. Essentially, my hack extends the flickr API to, hopefully, enable location-based searching in the sky.</p>
<p>Since I only wrote my hack in about an hour, during breakfast on Sunday, I returned to it this evening and finished it off. I&#8217;ve defined an open data table at <a href="http://eatyourgreens.org.uk/yql/flickr.photos.astro.xml">http://eatyourgreens.org.uk/yql/flickr.photos.astro.xml</a> which returns all machine tag info in the astro: namespace for the 50 most recently tagged photos. For convenience, it also returns the photo owner, title, url and root url for thumbnail images.</p>
<p>There is a demo, where you can try searching based on Right Ascension and Declination (both expressed in degrees). Please try it out and leave feedback in the comments here.</p>
<p>Demo URL: <a href="http://eatyourgreens.org.uk/testapps/yql/locationsearch.html">http://eatyourgreens.org.uk/testapps/yql/locationsearch.html</a></p>
<h3>Example queries</h3>
<p>The Carina Nebula</p>
<pre><code>        select * from flickr.photos.astro
        where ra &gt; 155 and ra &lt; 165
        and dec &gt; -65 and dec &lt; -55</code></pre>
<p>The Orion Nebula and surroundings</p>
<pre><code>        select * from flickr.photos.astro
        where ra &gt; 70 and ra &lt; 100
        and dec &gt; -20 and dec &lt; 10</code></pre>
<p>Get lots of photos of Orion (may be slow)</p>
<pre><code>        select * from flickr.photos.astro(0,200)
        where ra &gt; 70 and ra &lt; 100
        and dec &gt; -20 and dec &lt; 10</code></pre>
<p>Find nebulae from the New General Catalogue (names beginning NGC)</p>
<pre><code>      select * from flickr.photos.astro
      where name like 'NGC%'
</code></pre>
<p>Find nebulae from the Messier catalogue (names beginning with M )</p>
<pre><code>     select id, title, url, imgroot, username, ra, dec, fov, orientation, name
      from flickr.photos.astro(40)
      where name like 'M %'</code></pre>
<p>Find all photos of the Rosette nebula</p>
<pre><code>      select * from flickr.photos.astro(0,200)
        where name = 'Rosette nebula'</code></pre>
<p>Explicitly declare all the table columns</p>
<pre><code>      select id, title, url, imgroot, username, ra, dec, fov, orientation, name
      from flickr.photos.astro</code></pre>
]]></content:encoded>
			<wfw:commentRss>http://eatyourgreens.org.uk/archives/2009/05/searching-the-sky-with-yql-execute.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Building a KML feed with YQL and coldfusion</title>
		<link>http://eatyourgreens.org.uk/archives/2009/04/building-a-kml-feed-with-yql-and-coldfusion.html</link>
		<comments>http://eatyourgreens.org.uk/archives/2009/04/building-a-kml-feed-with-yql-and-coldfusion.html#comments</comments>
		<pubDate>Fri, 24 Apr 2009 09:46:21 +0000</pubDate>
		<dc:creator>Jim O'Donnell</dc:creator>
				<category><![CDATA[astronomy]]></category>
		<category><![CDATA[geekage]]></category>
		<category><![CDATA[yql]]></category>

		<guid isPermaLink="false">http://eatyourgreens.org.uk/archives/2009/04/building-a-kml-feed-with-yql-and-coldfusion.html</guid>
		<description><![CDATA[4 views of Comet Lulin, originally uploaded by eat your greens. Following on from my javascript photo browser, for viewing astronomy photos in Google sky, I&#8217;ve written a feed to display Astronomy Photographer of the Year (APY) photos in Google Earth. The address is http://www.nmm.ac.uk/collections/feeds/apyKML.cfm That link should open in Google Earth. If it doesn&#8217;t, [...]]]></description>
			<content:encoded><![CDATA[<div style="text-align: left; padding: 3px;"><a title="photo sharing" href="http://www.flickr.com/photos/eatyourgreens/3449685017/"><img style="border: solid 2px #000000;" src="http://farm4.static.flickr.com/3655/3449685017_ff7063a34c.jpg" alt="" /></a>
<p style="font-size: 0.8em; margin-top: 0px;"><a href="http://www.flickr.com/photos/eatyourgreens/3449685017/">4 views of Comet Lulin</a>, originally uploaded by <a href="http://www.flickr.com/people/eatyourgreens/">eat your greens</a>.</p>

</div>
<p>Following on from my javascript photo browser, for viewing astronomy photos in Google sky, I&#8217;ve written a feed to display <a href="http://www.nmm.ac.uk/astrophoto">Astronomy Photographer of the Year</a> (APY) photos in Google Earth. The address is <a href="http://www.nmm.ac.uk/collections/feeds/apyKML.cfm">http://www.nmm.ac.uk/collections/feeds/apyKML.cfm
</a> That link should open in Google Earth. If it doesn&#8217;t, add it manually in Google Earth via &#8216;Add &gt; Network Link&#8217; (some browsers save the KML feed rather than opening it).</p>

<p>If you&#8217;re interested in seeing how the feed is generated, have a look at <a href="http://www.nmm.ac.uk/collections/feeds/apyKML.txt">the source code</a>. I&#8217;ll also go through the code here to try and explain how it works. I&#8217;ve written it in coldfusion, but it should be straightforward to rewrite in any other server-side language.</p><span id="more-349"></span>

<p>First we define a YQL query to retrieve 30 photos from the <a href="http://www.flickr.com/groups/astrophoto">APY Flickr group</a> (group ID 973956@N23). We select only photos tagged with <code>'astro:RA='</code> to make sure we only get photos tagged with positions by the <a href="http://astrometry.net">astrometry.net</a> robot. We then encode the query in a URL and get the data, as xml, using cfhttp.</p>
<pre><code>
&lt;cfset yql = "select farm, server, id, secret, title, urls.url.content, tags.tag.raw
		from flickr.photos.info
		where (tags.tag.raw like 'astro:%')
		and photo_id in (
			select id from flickr.photos.search(30)
			where group_id='973956@N23'
			and machine_tags='astro:RA='
		)
"&gt;
&lt;cfset yqlURL = "http://query.yahooapis.com/v1/public/yql?q=#URLEncodedFormat(yql)#&amp;format=xml"&gt;
&lt;!--- Get our results as XML for better performance.. ---&gt;
&lt;cfhttp url="#yqlURL#" redirect="no" /&gt;
</code></pre>
<p>The YQL query returns XML that looks something like the following fragment, one photo element, with title and urls, for each returned tag.</p>
<pre><code>
&lt;results&gt;
	&lt;photo farm="4" id="3465625670" secret="95d665362f" server="3495"&gt;
		&lt;title&gt;M42VMC-NS&lt;/title&gt;
		&lt;tags&gt;
		    &lt;tag raw="astro:RA=83.8283780568"/&gt;
		&lt;/tags&gt;
		&lt;urls&gt;
		    &lt;url&gt;http://www.flickr.com/photos/36672102@N07/3465625670/&lt;/url&gt;
		&lt;/urls&gt;
	&lt;/photo&gt;
	&lt;photo farm="4" id="3465625670" secret="95d665362f" server="3495"&gt;
		&lt;title&gt;M42VMC-NS&lt;/title&gt;
		&lt;tags&gt;
		    &lt;tag raw="astro:Dec=-5.41730075227"/&gt;
		&lt;/tags&gt;
		&lt;urls&gt;
		    &lt;url&gt;http://www.flickr.com/photos/36672102@N07/3465625670/&lt;/url&gt;
		&lt;/urls&gt;
	&lt;/photo&gt;
	</code></pre>
<p>First we parse the output of the YQL query and create a new structure, <code>photos</code>, which will hold one element for each photo, keyed on photo id. We get an array of photo elements by selecting all the children of <code>query.results</code> and loop through this array. If we are dealing with a new photo id, we store it and create a new photo hash to hold the properties of this photo. At the end of this loop, we aim to have each photo stored as a hash with properties <code>photo.title</code>, <code>photo.url</code> etc. <code>photo.imgroot</code> holds the root URL used to construct links to the thumbnail images on Flickr.</p>
<pre><code>
	rawData = XmlParse(cfhttp.FileContent);
	//array of results is now in rawdata.query.results.XmlChildren
	results = rawData.query.results.XmlChildren;
	//fun with Java - arrays are easier to loop through if you use their Iterator object.
	iterator = results.Iterator();
	//photos will hold our parsed photo data
	photos = StructNew();
	//loop through YQL results, parse and store photo data in photos, keyed on photo id.
	while (iterator.HasNext()) {
		result = iterator.Next();
		id = result.XmlAttributes.id;
		if(not structKeyExists(photos, id)) {
			photos[id] = structNew();
			photos[id]['name'] = ArrayNew(1);
			p = photos[id];
			p.title = result.title.XmlText;
			p.url = result.urls.url.XmlText;
			p.imgroot = "http://farm
						#result.XmlAttributes.farm#
						.static.flickr.com/
						#result.XmlAttributes.server#/
						#id#_#result.XmlAttributes.secret#";
		}
</code></pre>
<p>Parsing the values of the machine tags requires a little bit of extra work. The values we want are stored in the raw attribute for each tag. We split the value on = to get the tag name and value, then split the tag name on : and discard the namespace prefix. The results are stored in our new photo hash as <code>photo[tagname] = value</code>. <code>astro:name</code> and <code>astro:fieldsize</code> require slightly different treatment from the other machine tags. There may be several <code> astro:name</code> tags in a single photo, so we store <code>photo.name</code> as an array. <code>astro:fieldsize</code>, which may be in degrees, arcmins or arcsecs, is converted to <code>x</code> and <code>y</code> values in degrees and stored in <code>photo.fov.x</code> and <code>photo.fov.y</code>.</p>
<pre><code>
		tag = result.tags.tag.XMLAttributes.raw;
			//split machine tag name and value
			tmp = ListToArray(tag, '=');
			//discard namespace from tag name by splitting tmp[1] on :
			// store data as o[predicate] = value eg. o[id].RA = 85.123456
			tagname = ListToArray(tmp[1],':');
			tagname = tagname[2];
			if (tagname eq 'name') {
				ArrayAppend(p['name'],tmp[2]);
			} else {
				p[tagname] = tmp[2];
			}
			//fieldsize is a string in degrees, arcminutes or arcseconds.
			//We will standardise on a value in degrees.
			if (tmp[1] eq 'astro:fieldsize') {
			//convert fieldsize string into a numeric value in degrees.
				tmp = ListToArray(p.fieldsize,' ');
				p.fov = structNew();
				p.fov.x = tmp[1];
				p.fov.y = tmp[3];
				if (tmp[4] eq 'arcminutes') {
					p.fov.x = p.fov.x/60;
					p.fov.y = p.fov.y/60;
				}
				if (tmp[4] eq 'arcseconds') {
					p.fov.x = p.fov.x/3600;
					p.fov.y = p.fov.y/3600;
				}
			}
		}
</code></pre>
<p>Having parsed the YQL results into a more manageable array of photos, the final step is loop through the photos and generate latitude, longitude, range, rotation and field boundaries for each that we can use in a KML photo overlay. Equations for latitude, longitude and range are taken from <a href="http://code.google.com/apis/kml/documentation/kmlsky.html">Sky data in KML</a>. Unfortunately, there isn&#8217;t much documentation explaining the boundaries of photo overlays, but I found by trial and error that we can set the north–south distance to our vertical field in degrees. The east–west distance is the horizontal field corrected by a factor of <code>cos(lat)</code>. Note that this works regardless of whether north–south is vertical or horizontal in the photo.</p>
<pre><code>
//for each photo, convert machine tag values into numbers used by Google Earth overlays.
		for (id in photos) {
			p = photos[id];
			p.lat = p.Dec;
			p.long = p.RA - 180;
			beta = max(p.fov.x,p.fov.y) * 6.28/360;
		    p.range = 1.5 *6378000 *(1.1917536 * sin(beta/2) - cos(beta/2) + 1);
			p.rotation = 180-p.orientation;
			latField = p.fov.y;
			longField = p.fov.x/cos(p.lat * 6.28/360);
			p.north = p.lat + latField/2;
			p.south = p.lat - latField/2;
			p.east = p.long + longField/2;
			p.west = p.long - longField/2;

		}
</code></pre>
<p>That done, we can generate a KML feed by looping through the <code>photos</code> array and printing the photo properties into the appropriate elements of a KML template.</p>
<pre><code>
	&lt;?xml version="1.0" encoding="UTF-8"?&gt;
	&lt;kml xmlns="http://www.opengis.net/kml/2.2" hint="target=sky"&gt;
	  &lt;Document&gt;
	  &lt;name&gt;Astronomy Photographer of the Year&lt;/name&gt;
	  &lt;cfloop collection="#photos#" item="id"&gt;
	  &lt;cfoutput&gt;
	    &lt;GroundOverlay&gt;
		&lt;name&gt;#XMLFormat(photos[id].title)#&lt;/name&gt;
		&lt;color&gt;b8ffffff&lt;/color&gt;
	    &lt;LookAt&gt;
	      &lt;longitude&gt;#photos[id].long#&lt;/longitude&gt;
	      &lt;latitude&gt;#photos[id].lat#&lt;/latitude&gt;
	      &lt;altitude&gt;0&lt;/altitude&gt;
	      &lt;range&gt;#photos[id].range#&lt;/range&gt;
	      &lt;tilt&gt;0&lt;/tilt&gt;
	      &lt;heading&gt;#photos[id].rotation#&lt;/heading&gt;
	    &lt;/LookAt&gt;
		&lt;Icon&gt;
			&lt;href&gt;#photos[id].imgroot#.jpg&lt;/href&gt;
		&lt;/Icon&gt;
		&lt;LatLonBox&gt;
			&lt;north&gt;#photos[id].north#&lt;/north&gt;
			&lt;south&gt;#photos[id].south#&lt;/south&gt;
			&lt;east&gt;#photos[id].east#&lt;/east&gt;
			&lt;west&gt;#photos[id].west#&lt;/west&gt;
	        &lt;rotation&gt;#photos[id].rotation#&lt;/rotation&gt;
		&lt;/LatLonBox&gt;
	&lt;/GroundOverlay&gt;
	    &lt;/cfoutput&gt;
	   &lt;/cfloop&gt;
	  &lt;/Document&gt;
	&lt;/kml&gt;
</code></pre>
<p>A quick footnote about performance. My first version of this code got the YQL results as JSON, but I found that decoding the JSON response was taking around 30 or 40s. Parsing XML, on the other hand, takes around 2 or 3s. So I switched to XML even though the code for processing the XML results was somewhat uglier. I think this is down to CFJSON&#8217;s decode function making heavy use of regular expressions, which slows it right down when dealing with large or complicated JSON responses.</p>]]></content:encoded>
			<wfw:commentRss>http://eatyourgreens.org.uk/archives/2009/04/building-a-kml-feed-with-yql-and-coldfusion.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Google sky photo browser</title>
		<link>http://eatyourgreens.org.uk/archives/2009/03/google-sky-photo-browser.html</link>
		<comments>http://eatyourgreens.org.uk/archives/2009/03/google-sky-photo-browser.html#comments</comments>
		<pubDate>Sun, 15 Mar 2009 19:13:51 +0000</pubDate>
		<dc:creator>Jim O'Donnell</dc:creator>
				<category><![CDATA[astronomy]]></category>
		<category><![CDATA[geekage]]></category>
		<category><![CDATA[yql]]></category>

		<guid isPermaLink="false">http://eatyourgreens.org.uk/archives/2009/03/google-sky-photo-browser.html</guid>
		<description><![CDATA[Google sky experiment, originally uploaded by eat your greens. Just a brief update on my previous post. I&#8217;ve now hacked together an astronomy photo browser which displays Flickr photos directly in Google Sky. Requires you to have the Google Earth plugin installed.]]></description>
			<content:encoded><![CDATA[<div style="text-align: left; padding: 3px;">
<a href="http://www.flickr.com/photos/eatyourgreens/3354448363/" title="photo sharing"><img src="http://farm4.static.flickr.com/3204/3354448363_281e77eee7.jpg" style="border: solid 2px #000000;" alt="" /></a><br />
<br />
<span style="font-size: 0.8em; margin-top: 0px;"><a href="http://www.flickr.com/photos/eatyourgreens/3354448363/">Google sky experiment</a>, originally uploaded by <a href="http://www.flickr.com/people/eatyourgreens/">eat your greens</a>.</span>
</div>
<p>
Just a brief update on my previous post. I&#8217;ve now hacked together <a href="http://eatyourgreens.org.uk/testapps/yql/overlay2.html">an astronomy photo browser</a> which displays Flickr photos directly in Google Sky. Requires you to have the Google Earth plugin installed.</p>
]]></content:encoded>
			<wfw:commentRss>http://eatyourgreens.org.uk/archives/2009/03/google-sky-photo-browser.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

