diff --git a/requirements.txt b/requirements.txt index 738931a..8b5a93f 100644 --- a/requirements.txt +++ b/requirements.txt @@ -11,6 +11,7 @@ Jinja2==2.9.5 Markdown==2.6.8 MarkupSafe==1.0 python-slugify==1.2.4 +requests==2.19.1 ## SECOND LEVEL DEPS diff --git a/spec/example_votable.xml b/spec/example_votable.xml new file mode 100644 index 0000000..483df98 --- /dev/null +++ b/spec/example_votable.xml @@ -0,0 +1,396 @@ + + + Planetary aurorae are powerful emissions radiated from auroral + regions of magnetized planets by accelerated charged particles, in a + wide range of wavelengths (from radio to X-rays). The UV range in + particular is adequate to measure collisionaly excited transitions of + H and H2, the dominant species in the upper atmosphere of giant + planets, produced by precipitating auroral particles, and benefits a + good angular resolution. Auroral UV observations therefore provide a + rich source of informations on planetary atmospheres and + magnetospheres. They also offer a unique diagnostic to remotely probe + the solar wind activity throughout the heliosphere. from Laurent Lamy + + + + EPN-TAP + + + + Planetary aurorae are powerful emissions radiated from auroral + regions of magnetized planets by accelerated charged particles, in + a + wide range of wavelengths (from radio to X-rays). The UV range in + particular is adequate to measure collisionaly excited transitions + of + H and H2, the dominant species in the upper atmosphere of giant + planets, produced by precipitating auroral particles, and benefits + a + good angular resolution. Auroral UV observations therefore provide + a + rich source of informations on planetary atmospheres and + magnetospheres. They also offer a unique diagnostic to remotely + probe + the solar wind activity throughout the heliosphere. from Laurent + Lamy + + this + research have been made using APIS database by LaurentLamy + Lesia-Observatoire de Paris + + plasma in + planetary atmosphere. + + Query successful + + For advice on how to cite the resource(s) that contributed to this + result, see + http://voparis-tap-planeto.obspm.fr:80/tableinfo/apis.epn_core + + + plasma in planetary atmosphere. + + Granule unique identifier, provides direct + access + + + + Group identifier, identical for similar data + products + + + + Identical for data products related to the same + original data + + + + Organization of the data product (from enumerated + list) + + + + Name of target (IAU standard) + + + type of target from enumerated list + + + Acquisition start time (in JD) + + + Acquisition stop time (in JD) + + + Min time sampling step + + + Max time sampling step + + + Min integration time + + + Max integration time + + + Min spectral range (frequency) + + + Max spectral range (frequency) + + + min spectral sampling step (as frequency) + + + + max pectral sampling step (as frequency) + + + + Min spectral resolution (as frequency) + + + + Max spectral resolution (as frequency) + + + + Min (westernmost) longitude on planetary surface + + + + Max (easternmost) longitude on planetary surface + + + + Min latitude on planetary surface + + + Max latitude on planetary surface + + + Min of third coordinate (altitude) + + + Max of third coordinate (altitude) + + + Min resolution on longitude + + + Max resolution on longitude + + + Min resolution on latitude + + + Max resolution on latitude + + + Min resolution in third coordinate + + + Max resolution in third coordinate + + + Defines the nature of coordinates (from enumerated + list) + + + + Min incidence angle (solar zenith angle) + + + + Max incidence angle (solar zenith angle) + + + + Min emergence angle + + + Max emergence angle + + + Min phase angle + + + Max phase angle + + + Standard name of the observatory or spacecraft + + + + Standard name of instrument + + + UCD(s) defining the nature of measurements + + + + URL of the data files. + + + file format type. + + + Estimate file size in kB. + + + + Level of calibration (CODMAC level) + + + + publiher of the ressource + + + Extra: bibliograpic reference + + + Title of the ressourcee + + + region of interest from a predifine list + + + + Secondary name (can be standard name of region of + interest) + + + + Right ascention + + + Declination + + + Start of public period + + + + Creation date of entry + + + + Date of last modification of entry + + + + STC-S region + + + URL of a thumbnail image + + + Link to a web page providing more details on the + granule + + + + Observing mode + + + Detector name + + + Optical element name + + + Filter name + + + Position angle of image y axis + + + Measurement unit + + + Proposal identifier + + + + Proposal principal investigator + + + Proposal title + + + spatial resolution per pixel or platescale + + + + Name of the observational campaign + + + Apparent radius of the target + + + North pole position angle with respect to + celestial north pole + + + + Primary observed hemisphere + + + Secondary observed hemisphere + + + + +
+
+
+ diff --git a/web/run.py b/web/run.py index 7b50eb3..5b5d728 100755 --- a/web/run.py +++ b/web/run.py @@ -9,6 +9,8 @@ import random import tarfile import time import urllib +import requests + from csv import writer as csv_writer from math import sqrt, isnan from os import environ, remove as removefile @@ -338,6 +340,92 @@ def get_active_targets(): return [t for t in all_targets if not ('locked' in t and t['locked'])] +def retrieve_auroral_emissions(target_name): + """ + Work In Progress. + :param target_name: You should probably not let users choose this value, + as our sanitizing for ADQL may not be 100% safe. + Use values from YAML configuration, instead. + Below is a list of the ids we found to be existing. + > SELECT DISTINCT target_name FROM apis.epn_core + - Mars + - MERCURY + - Jupiter + - Titan + - Io + - VENUS + - Ganymede + - Uranus + - Callisto + - Europa + - Saturn + :return: + """ + api_url = "http://voparis-tap.obspm.fr/__system__/tap/run/tap/sync" + d_started_at = datetime.datetime.now() + t_started_at = time.mktime(d_started_at.timetuple()) - 3600 * 24 * 365 * 10 # fixme + # t_started_at = 1 + d_stopped_at = datetime.datetime.now() + t_stopped_at = time.mktime(d_stopped_at.timetuple()) + + def to_jday(timestamp): + return timestamp / 86400.0 + 2440587.5 + + query = """ +SELECT + time_min, + time_max, + thumbnail_url, + external_link +FROM apis.epn_core +WHERE target_name='{target_name}' +AND dataproduct_type='im' +AND time_min > {jday_start} +AND time_min < {jday_stop} +ORDER BY time_min, granule_gid +""".format( + target_name=target_name.replace("'", "\\'"), + jday_start=to_jday(t_started_at), + jday_stop=to_jday(t_stopped_at) + ) + +# query = """ +# SELECT DISTINCT target_name FROM apis.epn_core +# """ + + try: + response = requests.post(api_url, { + 'REQUEST': 'doQuery', + 'LANG': 'ADQL', + 'QUERY': query, + 'TIMEOUT': '30', + 'FORMAT': 'VOTable/td' + }) + + response_xml = response.text + + import xml.etree.ElementTree as ET + root = ET.fromstring(response_xml) + namespaces = {'vo': 'http://www.ivoa.net/xml/VOTable/v1.3'} + rows_xpath = "./vo:RESOURCE/vo:TABLE/vo:DATA/vo:TABLEDATA/vo:TR" + rows = [] + for row in root.findall(rows_xpath, namespaces): + rows.append({ + 'time_min': row[0].text, + 'time_max': row[1].text, + 'thumbnail_url': row[2].text, + 'external_link': row[3].text, + }) + + # print(rows) + return rows + except Exception as e: + print("Failed to retrieve auroral emissions :") + print(e) + + # print(query) + + def retrieve_amda_netcdf(orbiter, what, started_at, stopped_at): """ Handles remote querying AMDA's API for URLs, and then downloading, -- libgit2 0.21.2