Page tree
Skip to end of metadata
Go to start of metadata


The resource descriptor (RD file) can include procedure coded in python. We test here an access to a remote webservice at IMCCE to retrieve ephemeris parameters for various targets and observation dates.

A first solution was provided in EPN2020, using the SAOP interface to Miriade and the ZEEP python package.

The present solution uses the REST interface of ephemph with VOtable output. An example is provided here as a variation on the spectro_planets service (adapted from Baptiste's assessments on irtf_orton and the simpler Herschel service).

Procedure Definition

The definition of the procedure in the RD file is done using the <procDef> element. The code snippet is used for observations of any planets and satellites (and possibly small bodies).

<resource schema='spectro_planets3'>


<!--
  -- Place the <procDef> element after the <meta> elements 
  -->

	<procDef type="apply" id="ephemph">
		<setup>
			<par key="ignoreUnknowns" description="Return Nones for unknown
				objects?  (if false, ValidationErrors will be raised)">True</par>
			<par key="logUnknowns" description="Write unresolved objects 
				to the info log">False</par>

			<!-- any piece of python code to be run before the main procedure, like importing modules -->
			<code>
      			import urllib
      			import numpy as np
      			from gavo import votable
      			def get_code(tclass):
        			return {
			            'planet': 'p',
            			'star': 'p',
			            'satellite': 's',
            			'asteroid': 'a',
			            'dwarf_planet': 'dp',
            			'comet': 'c'
        			}[tclass]
			</code>
		</setup>

		<code>
			## This is the beginning of the core python code, indentation matters as in python.
 
			# Setting up request parameters (as defined on service description page)
			# NB: Here we will use the ephemph webservice with VOtable output
		    base_url = "http://vo.imcce.fr/webservices/miriade/ephemph_query.php"
      		targettot = "{}:{}".format(get_code(@target_class), @target_name)
      		#print('target:', format(targettot))
      		query_params = [
		      ('-name', targettot),
        	  ('-ep', str(@start_time)),
		      ('-observer', '500'),
		    ]

      		encoded_query = urllib.urlencode(query_params)
      		rest_query = '{}?-from=vespa&-mime=votable&-nbd=1&{}'.format(base_url, encoded_query)

			try:
				# Retrieving response from webservice
				f = urllib.urlopen(rest_query)
        		#print('return:', format(f.read()))
	        	data, metadata = votable.load(f)
   	     		#print('- query: {}'.format(rest_query))

	        	labels = [field.name for field in metadata]
        		tmp_data = dict(zip(labels, data[0]))
        		print('labels:', format(labels))
        		Long  = "SEPLong"
				# Return parameters are different for Jupiter 
        		if "Jupiter" in @target_name:
		          Long  = "SEPLong3"

	      		# Preparing output: whatever you put into the vars dictionary can be used outside the procedure
		  		#order matters (not all parameters available for all targets)
		        vars['c1min'] = tmp_data[Long]
		        vars['c2min'] = tmp_data['SEPLat']
				# Build s_region for the visible hemisphere 
		        vars['s_region'] = pgsphere.SCircle(pgsphere.SPoint.fromDegrees(float(@c1min), float(@c2min)), 89.).asPoly()
		        vars['earth_distance_min'] = tmp_data['Dg']
		        vars['sun_distance_min'] = tmp_data['Dh']
		        vars['phase_min'] = tmp_data['PhaseAngle']

			except:
        		# keep the first two for the Sun + no need to null them anyway
		        #vars['c1min'] = None
		        #vars['c2min'] = None
		        #vars['phase_min'] = None
		        print('ep "{}": pb'.format(@start_time))
		        print('name "{}": pb'.format(targettot))

		</code>
	</procDef>


<!--
  -- Any other RD stuff... 
  -->

</resource>

Using Procedures

Then to use the procedure, we use the <apply> element, with proper configuration. The procedure is used here inside a <rowmaker> element. The <bind> elements allow to link content (constant values or computed values) to input parameters.

<apply procDef="ephemph"/>
	<!-- copy single fct return value on both param of pair (optional parameters) -->	
	<map key="sun_distance_max">@sun_distance_min</map>
	<map key="earth_distance_max">@earth_distance_min</map> 

	<apply procDef="//epntap2#populate-2_0" name="fillepn">

	<!-- copy single fct return value on both param of pair (mandatory parameters) -->	
	<bind key="phase_min">@phase_min</bind>
	<bind key="phase_max">@phase_min</bind>
	<bind key="c1min">@c1min</bind>
	<bind key="c2min">@c2min</bind>
	<bind key="c1max">@c1min</bind>
	<bind key="c2max">@c2min</bind>
	<bind key="s_region">@s_region</bind>

	<!-- input parameters set with <bind> elements in <apply> element -->
	<bind key="target_name">@target_name</bind>
	<bind key="target_class">@target_class</bind>
	<bind key="time_min">dateTimeToJdn(parseISODT(@start_time))</bind>


</apply>
  • No labels
Write a comment...