Exemplo n.º 1
0
def search_position(**kwargs):
    '''
    Query based on position and time (+/- 1 day):

    http://asterank.com/api/skymorph/search_position?<params>
    ra	Right ascension (HMS)
    Dec	Declination (DMS)
    time	Date and time (UTC)
    per_date	Perihelion date ([M]JD or ISO)
    om	Longitude of ascending node (deg)
    w	Argument of perihelion (deg)
    i	Inclination (deg)
    H	Absolute magnitude

    '''

    base_url = "http://asterank.com/api/skymorph/search_position?"

    for key in kwargs:
        base_url += str(key) + "=" + kwargs[key] + "&"

        # remove the unnecessary & at the end
    base_url = base_url[:-1]

    return dispatch_http_get(base_url)
Exemplo n.º 2
0
def search_orbit(**kwargs):
    '''
    Query based on orbital elements:

    http://asterank.com/api/skymorph/search_orbit?<params>
    epoch	Epoch ([M]JD or ISO)
    ecc	eccentricity
    per	Perihelion distance (AU)
    per_date	Perihelion date ([M]JD or ISO)
    om	Longitude of ascending node (deg)
    w	Argument of perihelion (deg)
    i	Inclination (deg)
    H	Absolute magnitude

    '''

    base_url = "http://asterank.com/api/skymorph/search_orbit?"

    for key in kwargs:
        base_url += str(key) + "=" + kwargs[key] + "&"

        # remove the unnecessary & at the end
    base_url = base_url[:-1]

    return dispatch_http_get(base_url)
Exemplo n.º 3
0
def maas_latest():
    """
    will return a JSON object for the latest report:

{
    "report": {
        "terrestrial_date": "2013-05-01", 
        "sol": 261, 
        "ls": 310.5, 
        "min_temp": -69.75, 
        "min_temp_fahrenheit": -93.55, 
        "max_temp": -4.48, 
        "max_temp_fahrenheit": 23.94, 
        "pressure": 868.05, 
        "pressure_string": "Higher", 
        "abs_humidity": null, 
        "wind_speed": null, 
        "wind_direction": "--", 
        "atmo_opacity": "Sunny", 
        "season": "Month 11", 
        "sunrise": "2013-05-01T11:00:00Z", 
        "sunset": "2013-05-01T22:00:00Z"
    }
}

    """
    base_url = "http://marsweather.ingenology.com/v1/latest/"

    return dispatch_http_get(base_url)
Exemplo n.º 4
0
def getjp2header(Id):
    '''
    GET /api/v1/getJP2Header/


    Get the XML header embedded in a JPEG2000 image. Includes the FITS header as well as a section of Helioviewer-specific metadata.

    Request Parameters:

    Parameter	Required	Type	Example	Description
    id	Required	number	7654321	Unique JP2 image identifier.
    callback	Optional	string		Wrap the response object in a function call of your choosing.

    Example (A):

    string (XML)

    Example Request:

    http://helioviewer.org/api/v1/getJP2Header/?id=7654321
    '''
    base_url = 'http://helioviewer.org/api/v1/getJP2Header/?'

    if not isinstance(Id, int):
        raise ValueError("The Id argument should be an int, ignoring it")
    else:
        base_url += "id=" + str(Id)

    return dispatch_http_get(base_url)
Exemplo n.º 5
0
def apod(date=None, concept_tags=None):
    '''
    HTTP REQUEST

    GET https://api.nasa.gov/planetary/apod

    QUERY PARAMETERS

    Parameter	Type	Default	Description
    date	YYYY-MM-DD	today	The date of the APOD image to retrieve
    concept_tags	bool	False	Return an ordered dictionary of concepts from the APOD explanation
    api_key	string	DEMO_KEY	api.nasa.gov key for expanded usage
    EXAMPLE QUERY

    https://api.nasa.gov/planetary/apod?concept_tags=True&api_key=DEMO_KEY
    '''
    base_url = "https://api.nasa.gov/planetary/apod?"

    if date:
        try:
            vali_date(date)
            base_url += "date=" + date + "&"
        except:
            raise ValueError("Incorrect date format, should be YYYY-MM-DD")
    if concept_tags == True:
        base_url += "concept_tags=True" + "&"

    req_url = base_url + "api_key=" + nasa_api_key()

    return dispatch_http_get(req_url)
Exemplo n.º 6
0
def maas_latest():
    '''
    will return a JSON object for the latest report:

{
    "report": {
        "terrestrial_date": "2013-05-01", 
        "sol": 261, 
        "ls": 310.5, 
        "min_temp": -69.75, 
        "min_temp_fahrenheit": -93.55, 
        "max_temp": -4.48, 
        "max_temp_fahrenheit": 23.94, 
        "pressure": 868.05, 
        "pressure_string": "Higher", 
        "abs_humidity": null, 
        "wind_speed": null, 
        "wind_direction": "--", 
        "atmo_opacity": "Sunny", 
        "season": "Month 11", 
        "sunrise": "2013-05-01T11:00:00Z", 
        "sunset": "2013-05-01T22:00:00Z"
    }
}

    '''
    base_url = 'http://marsweather.ingenology.com/v1/latest/'

    return dispatch_http_get(base_url)
Exemplo n.º 7
0
def getjp2header(Id):
    '''
    GET /api/v1/getJP2Header/


    Get the XML header embedded in a JPEG2000 image. Includes the FITS header as well as a section of Helioviewer-specific metadata.

    Request Parameters:

    Parameter	Required	Type	Example	Description
    id	Required	number	7654321	Unique JP2 image identifier.
    callback	Optional	string		Wrap the response object in a function call of your choosing.

    Example (A):

    string (XML)

    Example Request:

    http://helioviewer.org/api/v1/getJP2Header/?id=7654321
    '''
    base_url = 'http://helioviewer.org/api/v1/getJP2Header/?'

    if not isinstance(Id, int):
        raise ValueError("The Id argument should be an int, ignoring it")
    else:
        base_url += "id=" + str(Id)

    return dispatch_http_get(base_url)
Exemplo n.º 8
0
def apod(date=None, concept_tags=None):
    '''
    HTTP REQUEST

    GET https://api.data.gov/nasa/planetary/apod

    QUERY PARAMETERS

    Parameter	Type	Default	Description
    date	YYYY-MM-DD	today	The date of the APOD image to retrieve
    concept_tags	bool	False	Return an ordered dictionary of concepts from the APOD explanation
    api_key	string	DEMO_KEY	api.data.gov key for expanded usage
    EXAMPLE QUERY

    https://api.data.gov/nasa/planetary/apod?concept_tags=True&api_key=DEMO_KEY
    '''
    base_url = "http://api.data.gov/nasa/planetary/apod?"

    if date:
        try:
            vali_date(date)
            base_url += "date=" + date + "&"
        except:
            raise ValueError("Incorrect date format, should be YYYY-MM-DD")
    if concept_tags == True:
        base_url += "concept_tags=True" + "&"

    req_url = base_url + "api_key=" + nasa_api_key()

    return dispatch_http_get(req_url)
Exemplo n.º 9
0
def techport(Id):
    '''
    In order to use this capability, queries can be issued to the system with the following URI
    format:
    GET /xml-api/id_parameter
    Parameter Required? Value Description
    id_parameter Yes Type: String
    Default: None
    The id value of the TechPort record.
    TechPort values range from 0-20000.
    Not all values will yield results. Id
    values can be obtained through the
    standard TechPort search feature and
    are visible in the website URLs, e.g.
    http://techport.nasa.gov/view/0000,
    where 0000 is the id value.
    Example usage:
    http://techport.nasa.gov/xml-api/4795
    Output: The output of this query is an XML file with all field data of the TechPort record. 
    '''

    base_url = 'http://techport.nasa.gov/xml-api/'

    if not isinstance(Id, str):
        raise ValueError("The Id arg you provided is not the type of str")
    else:
        base_url += Id

    return dispatch_http_get(base_url)
Exemplo n.º 10
0
def exoplanets():
    '''
    gets all exoplanets in json
    '''

    base_url = "http://star-api.herokuapp.com/api/v1/exo_planets"

    return dispatch_http_get(base_url)
Exemplo n.º 11
0
def stars():
    '''
    This endpoint gets you a list of all stars in json
    '''

    base_url = "http://star-api.herokuapp.com/api/v1/stars"

    return dispatch_http_get(base_url)
Exemplo n.º 12
0
def local_group_of_galaxies():
    '''
    gets a local group of galaxies in json
    '''

    base_url = "http://star-api.herokuapp.com/api/v1/local_groups"

    return dispatch_http_get(base_url)
Exemplo n.º 13
0
def star_clusters():
    '''
    retrieves all open star clusters in json
    '''

    base_url = "http://star-api.herokuapp.com/api/v1/open_cluster"

    return dispatch_http_get(base_url)
Exemplo n.º 14
0
def space_events(lon=None, lat=None, limit=None, date=None):
    '''
    
    lat & lon expect decimal latitude and longitude values. (Required)
    elevation assumes meters. (Optional)
    limit assumes an integer. Default is 5. (Optional)
    date expects an ISO 8601 formatted date. (Optional)
    '''

    base_url = 'http://api.predictthesky.org/?'

    if not lon or not lat:
        raise ValueError(
            "space_events endpoint expects lat and lon, type has to be float. Call the method with keyword args. Ex : lon=100.75, lat=1.5"
        )
    else:
        try:
            validate_float(lon, lat)
            # Floats are entered/displayed as decimal numbers, but your computer
            # (in fact, your standard C library) stores them as binary.
            # You get some side effects from this transition:
            # >>> print len(repr(0.1))
            # 19
            # >>> print repr(0.1)
            # 0.10000000000000001
            # Thus using decimal to str transition is more reliant
            lon = decimal.Decimal(lon)
            lat = decimal.Decimal(lat)
            base_url += "lon=" + str(lon) + "&" + "lat=" + str(lat)
        except:
            raise ValueError(
                "space_events endpoint expects lat and lon, type has to be float. Call the method with keyword args. Ex : lon=100.75, lat=1.5"
            )

    if date:
        try:
            validate_iso8601(date)
            base_url += "&" + 'date=' + date
        except:
            raise ValueError(
                "Your date input is not in iso8601 format. ex: 2014-01-01T23:59:59"
            )

    if limit:
        if not isinstance(limit, int):
            logger.error(
                "The limit arg you provided is not the type of int, ignoring it"
            )
        base_url += "&" + "limit=" + str(limit)

    return dispatch_http_get(base_url)
Exemplo n.º 15
0
def address(address=None, begin=None, end=None):
    '''
    HTTP REQUEST

    GET https://api.data.gov/nasa/planetary/earth/temperature/address

    QUERY PARAMETERS

    Parameter	Type	Default	Description
    text	string	n/a	Address string
    begin	int	1880	beginning year for date range, inclusive
    end	int	2014	end year for date range, inclusive
    api_key	string	DEMO_KEY	api.data.gov key for expanded usage
    EXAMPLE QUERY

    https://api.data.gov/nasa/planetary/earth/temperature/address?text=1800 F Street, NW, Washington DC&begin=1990
    '''
    base_url = "http://api.data.gov/nasa/planetary/earth/temperature/address?"

    if not address:
        raise ValueError(
            "address is missing, which is mandatory. example : 1800 F Street, NW, Washington DC")
    elif not isinstance(address, str):
        try:
            address = str(address)
        except:
            raise ValueError("address has to be type of string")
    else:
        base_url += "text=" + address + "&"

    if not begin:
        raise ValueError(
            "Begin year is missing, which is mandatory. Format : YYYY")
    else:
        try:
            validate_year(begin)
            base_url += "begin=" + begin + "&"
        except:
            raise ValueError("Incorrect begin year format, should be YYYY")

    if end:
        try:
            validate_year(end)
            base_url += "end=" + end + "&"
        except:
            raise ValueError("Incorrect end year format, should be YYYY")

    req_url = base_url + "api_key=" + nasa_api_key()

    return dispatch_http_get(req_url)
Exemplo n.º 16
0
def search_star_cluster(cluster):
    '''
    It is also possible to query the star clusters by label, here is an example of querying for the star cluster labeled Berkeley 59

    http://star-api.herokuapp.com/api/v1/open_cluster/Berkeley 59
    '''

    base_url = "http://star-api.herokuapp.com/api/v1/open_cluster/"

    if not isinstance(cluster, str):
        raise ValueError("The cluster arg you provided is not the type of str")
    else:
        base_url += cluster

    return dispatch_http_get(base_url)
Exemplo n.º 17
0
def search_star(star):
    '''
    It is also possible to query the stars by label, here is an example of querying for the star labeled as Sun.

    http://star-api.herokuapp.com/api/v1/stars/Sun
    '''

    base_url = "http://star-api.herokuapp.com/api/v1/stars/"

    if not isinstance(star, str):
        raise ValueError("The star arg you provided is not the type of str")
    else:
        base_url += star

    return dispatch_http_get(base_url)
Exemplo n.º 18
0
def search_local_galaxies(galaxy):
    '''
    It is also possible to query the local galaxies by label, here is an example of querying for the local galaxy labeled  IC 10

    http://star-api.herokuapp.com/api/v1/local_groups/IC 10
    '''

    base_url = "http://star-api.herokuapp.com/api/v1/local_groups/"

    if not isinstance(galaxy, str):
        raise ValueError("The galaxy arg you provided is not the type of str")
    else:
        base_url += galaxy

    return dispatch_http_get(base_url)
Exemplo n.º 19
0
def search_target_obj(target):
    '''
    Query for a specific target:

    http://asterank.com/api/skymorph/search?<params>
    target	Target object (lookup in MPC).
    '''
    base_url = "http://asterank.com/api/skymorph/search?"

    if not isinstance(target, str):
        raise ValueError("The target arg you provided is not the type of str")
    else:
        base_url += "target=" + target

    return dispatch_http_get(base_url)
Exemplo n.º 20
0
def search_exoplanet(exoplanet):
    '''
    It is also possible to query the exoplanets by label, here is an example of querying for the exoplanet labeled as 11 Com

    http://star-api.herokuapp.com/api/v1/exo_planets/11 Com
    '''

    base_url = "http://star-api.herokuapp.com/api/v1/exo_planets/"

    if not isinstance(exoplanet, str):
        raise ValueError(
            "The exoplanet arg you provided is not the type of str")
    else:
        base_url += exoplanet

    return dispatch_http_get(base_url)
Exemplo n.º 21
0
def space_events(lon=None, lat=None, limit=None, date=None):
    '''
    
    lat & lon expect decimal latitude and longitude values. (Required)
    elevation assumes meters. (Optional)
    limit assumes an integer. Default is 5. (Optional)
    date expects an ISO 8601 formatted date. (Optional)
    '''

    base_url = 'http://api.predictthesky.org/?'

    if not lon or not lat:
        raise ValueError(
            "space_events endpoint expects lat and lon, type has to be float. Call the method with keyword args. Ex : lon=100.75, lat=1.5")
    else:
        try:
            validate_float(lon, lat)
            # Floats are entered/displayed as decimal numbers, but your computer 
            # (in fact, your standard C library) stores them as binary. 
            # You get some side effects from this transition:
            # >>> print len(repr(0.1))
            # 19
            # >>> print repr(0.1)
            # 0.10000000000000001
            # Thus using decimal to str transition is more reliant
            lon = decimal.Decimal(lon)
            lat = decimal.Decimal(lat)
            base_url += "lon=" + str(lon) + "&" + "lat=" + str(lat)
        except:
            raise ValueError(
                "space_events endpoint expects lat and lon, type has to be float. Call the method with keyword args. Ex : lon=100.75, lat=1.5")

    if date:
        try:
            validate_iso8601(date)
            base_url += "&" + 'date=' + date
        except:
            raise ValueError(
                "Your date input is not in iso8601 format. ex: 2014-01-01T23:59:59")

    if limit:
        if not isinstance(limit, int):
            logger.error(
                "The limit arg you provided is not the type of int, ignoring it")
        base_url += "&" + "limit=" + str(limit)

    return dispatch_http_get(base_url)
Exemplo n.º 22
0
def patents(query=None, concept_tags=None, limit=None):
    '''
    HTTP REQUEST

    GET https://api.data.gov/nasa/patents

    QUERY PARAMETERS

    Parameter	Type	Default	Description
    query	string	None	Search text to filter results
    concept_tags	bool	False	Return an ordered dictionary of concepts from the patent abstract
    limit	int	all	number of patents to return
    api_key	string	DEMO_KEY	api.data.gov key for expanded usage
    EXAMPLE QUERY

    https://api.data.gov/nasa/patents/content?query=temperature&limit=5&api_key=DEMO_KEY

    '''
    base_url = "http://api.data.gov/nasa/patents/content?"

    if not query:
        raise ValueError("search query is missing, which is mandatory.")
    elif not isinstance(query, str):
        try:
            query = str(query)
        except:
            raise ValueError("query has to be type of string")
    else:
        base_url += "query=" + query + "&"

    if concept_tags == True:
        base_url += "concept_tags=True" + "&"

    if limit:
        if not isinstance(limit, int):
            logger.error(
                "The limit arg you provided is not the type of int, ignoring it"
            )

        base_url += "limit=" + str(limit) + "&"

    req_url = base_url + "api_key=" + nasa_api_key()

    return dispatch_http_get(req_url)
Exemplo n.º 23
0
def patents(query=None, concept_tags=None, limit=None):
    '''
    HTTP REQUEST

    GET https://api.nasa.gov/patents

    QUERY PARAMETERS

    Parameter	Type	Default	Description
    query	string	None	Search text to filter results
    concept_tags	bool	False	Return an ordered dictionary of concepts from the patent abstract
    limit	int	all	number of patents to return
    api_key	string	DEMO_KEY	api.nasa.gov key for expanded usage
    EXAMPLE QUERY

    https://api.nasa.gov/patents/content?query=temperature&limit=5&api_key=DEMO_KEY

    '''
    base_url = "https://api.nasa.gov/patents/content?"

    if not query:
        raise ValueError("search query is missing, which is mandatory.")
    elif not isinstance(query, str):
        try:
            query = str(query)
        except:
            raise ValueError("query has to be type of string")
    else:
        base_url += "query=" + query + "&"

    if concept_tags == True:
        base_url += "concept_tags=True" + "&"

    if limit:
        if not isinstance(limit, int):
            logger.error(
                "The limit arg you provided is not the type of int, ignoring it")

        base_url += "limit=" + str(limit) + "&"

    req_url = base_url + "api_key=" + nasa_api_key()

    return dispatch_http_get(req_url)
Exemplo n.º 24
0
def asterank(query=None, limit=None):
    '''
    Format
    Requests are of the form:

    http://asterank.com/api/asterank?query={query}&limit={limit}
    Response data formats are largely derived from NASA/JPL's Small Body Database query browser. Exceptions to this are the delta-v field (dv), the mass field (GM), and the normalized spectral type field (spec). Additional Asterank scores are included: closeness, price ($), and overall score.

    Sample Request
    This request returns an asteroid with a roughly circular orbit, low inclination, and semi-major axis less than 1.5 AU:

    /api/asterank?query={"e":{"$lt":0.1},"i":{"$lt":4},"a":{"$lt":1.5}}&limit=1

    '''

    base_url = "http://asterank.com/api/asterank?"

    if query:
        try:
            query = json.dumps(query)

            base_url += "query=" + query + "&"
        except:
            raise ValueError("query= param is not valid json.")
    else:
        raise ValueError(
            "query= param is missing, expecting json data format.")

    if limit:
        if not isinstance(limit, int):
            logger.error(
                "The limit arg you provided is not the type of int, ignoring it"
            )
        base_url += "limit=" + str(limit)
    else:
        raise ValueError("limit= param is missing, expecting int")

    return dispatch_http_get(base_url)
Exemplo n.º 25
0
def maas_archive(begin, end):
    '''
    This returns a collection of JSON objects for every weather report available for October 2012:

{
    "count": 29, 
    "next": "http://marsweather.ingenology.com/v1/archive/?terrestrial_date_end=2012-10-31&terrestrial_date_start=2012-10-01&page=2", 
    "previous": null, 
    "results": [
        ...
    ]
}
    '''

    base_url = 'http://marsweather.ingenology.com/v1/archive/?'
    try:
        vali_date(begin)
        vali_date(end)
        base_url += 'terrestrial_date_start=' + begin + "&" + 'terrestrial_date_end=' + end
    except:
        raise ValueError("Incorrect date format, should be YYYY-MM-DD")

    return dispatch_http_get(base_url)
Exemplo n.º 26
0
def maas_archive(begin, end):
    """
    This returns a collection of JSON objects for every weather report available for October 2012:

{
    "count": 29, 
    "next": "http://marsweather.ingenology.com/v1/archive/?terrestrial_date_end=2012-10-31&terrestrial_date_start=2012-10-01&page=2", 
    "previous": null, 
    "results": [
        ...
    ]
}
    """

    base_url = "http://marsweather.ingenology.com/v1/archive/?"
    try:
        vali_date(begin)
        vali_date(end)
        base_url += "terrestrial_date_start=" + begin + "&" + "terrestrial_date_end=" + end
    except:
        raise ValueError("Incorrect date format, should be YYYY-MM-DD")

    return dispatch_http_get(base_url)
Exemplo n.º 27
0
def asterank(query=None, limit=None):
    '''
    Format
    Requests are of the form:

    http://asterank.com/api/asterank?query={query}&limit={limit}
    Response data formats are largely derived from NASA/JPL's Small Body Database query browser. Exceptions to this are the delta-v field (dv), the mass field (GM), and the normalized spectral type field (spec). Additional Asterank scores are included: closeness, price ($), and overall score.

    Sample Request
    This request returns an asteroid with a roughly circular orbit, low inclination, and semi-major axis less than 1.5 AU:

    /api/asterank?query={"e":{"$lt":0.1},"i":{"$lt":4},"a":{"$lt":1.5}}&limit=1

    '''

    base_url = "http://asterank.com/api/asterank?"

    if query:
        try:
            query = json.dumps(query)

            base_url += "query=" + query + "&"
        except:
            raise ValueError("query= param is not valid json.")
    else:
        raise ValueError(
            "query= param is missing, expecting json data format.")

    if limit:
        if not isinstance(limit, int):
            logger.error(
                "The limit arg you provided is not the type of int, ignoring it")
        base_url += "limit=" + str(limit)
    else:
        raise ValueError("limit= param is missing, expecting int")

    return dispatch_http_get(base_url)
Exemplo n.º 28
0
def assets(lon=None, lat=None, begin=None, end=None):
    '''
    HTTP REQUEST

    GET https://api.data.gov/nasa/planetary/earth/assets

    QUERY PARAMETERS

    Parameter	Type	Default	Description
    lat	float	n/a	Latitude
    lon	float	n/a	Longitude
    begin	YYYY-MM-DD	n/a	beginning of date range
    end	        YYYY-MM-DD	today	end of date range
    api_key	string	DEMO_KEY	api.data.gov key for expanded usage
    EXAMPLE QUERY

    https://api.data.gov/nasa/planetary/earth/assets?lon=100.75&lat=1.5&begin=2014-02-01&api_key=DEMO_KEY
    '''
    base_url = "http://api.data.gov/nasa/planetary/earth/assets?"

    if not lon or not lat:
        raise ValueError(
            "assets endpoint expects lat and lon, type has to be float. Call the method with keyword args. Ex : lon=100.75, lat=1.5"
        )
    else:
        try:
            validate_float(lon, lat)
            # Floats are entered/displayed as decimal numbers, but your computer
            # (in fact, your standard C library) stores them as binary.
            # You get some side effects from this transition:
            # >>> print len(repr(0.1))
            # 19
            # >>> print repr(0.1)
            # 0.10000000000000001
            # Thus using decimal to str transition is more reliant
            lon = decimal.Decimal(lon)
            lat = decimal.Decimal(lat)
            base_url += "lon=" + str(lon) + "&" + "lat=" + str(lat) + "&"
        except:
            raise ValueError(
                "assets endpoint expects lat and lon, type has to be float. Call the method with keyword args. Ex : lon=100.75, lat=1.5"
            )

    if not begin:
        raise ValueError(
            "Begin date is missing, which is mandatory. Format : YYYY-MM-DD")
    else:
        try:
            vali_date(begin)
            base_url += "begin=" + begin + "&"
        except:
            raise ValueError("Incorrect date format, should be YYYY-MM-DD")

    if end:
        try:
            vali_date(end)
            base_url += "end=" + end + "&"
        except:
            raise ValueError("Incorrect date format, should be YYYY-MM-DD")

    req_url = base_url + "api_key=" + nasa_api_key()

    return dispatch_http_get(req_url)
Exemplo n.º 29
0
def getjp2image(date,
                sourceId=None,
                observatory=None,
                instrument=None,
                detector=None,
                measurement=None):
    '''
    Helioviewer.org and JHelioviewer operate off of JPEG2000 formatted image data generated from science-quality FITS files. Use the APIs below to interact directly with these intermediary JPEG2000 files.
    
    Download a JP2 image for the specified datasource that is the closest match in time to the `date` requested.

    Either `sourceId` must be specified, or the combination of `observatory`, `instrument`, `detector`, and `measurement`.

    Request Parameters:

    Parameter	Required	Type	Example	Description
    date	Required	string	2014-01-01T23:59:59Z	Desired date/time of the JP2 image. ISO 8601 combined UTC date and time UTC format.
    sourceId	Optional	number	14	Unique image datasource identifier.
    observatory	Optional	string	SDO	Observatory name.
    instrument	Optional	string	AIA	Instrument name.
    detector	Optional	string	AIA	Detector name.
    measurement	Optional	string	335	Measurement name.
    jpip	Optional	boolean	false	Optionally return a JPIP URI instead of the binary data of the image itself.
    json	Optional	boolean	false	Optionally return a JSON object.


    EXAMPLE: http://helioviewer.org/api/v1/getJP2Image/?date=2014-01-01T23:59:59Z&sourceId=14&jpip=true
    '''

    base_url = 'http://helioviewer.org/api/v1/getJP2Image/?'
    req_url = ''

    try:
        validate_iso8601(date)
        if not date[-1:] == 'Z':
            date += 'Z'
        base_url += 'date=' + date
    except:
        raise ValueError(
            "Your date input is not in iso8601 format. ex: 2014-01-01T23:59:59"
        )

    if sourceId:
        if not isinstance(sourceId, int):
            logger.error("The sourceId argument should be an int, ignoring it")
        else:
            base_url += "sourceId=" + str(sourceId) + "&"

    if observatory:
        if not isinstance(observatory, str):
            logger.error(
                "The observatory argument should be a str, ignoring it")
        else:
            base_url += "observatory=" + observatory + "&"

    if instrument:
        if not isinstance(instrument, str):
            logger.error(
                "The instrument argument should be a str, ignoring it")
        else:
            base_url += "instrument=" + instrument + "&"
    if detector:
        if not isinstance(detector, str):
            logger.error("The detector argument should be a str, ignoring it")
        else:
            base_url += "detector=" + detector + "&"

    if measurement:
        if not isinstance(measurement, str):
            logger.error(
                "The measurement argument should be a str, ignoring it")
        else:
            base_url += "measurement=" + detector + "&"

    req_url += base_url + "jpip=true"

    return dispatch_http_get(req_url)
Exemplo n.º 30
0
def imagery(lon=None, lat=None, dim=None, date=None, cloud_score=None):
    '''
    # ----------QUERY PARAMETERS----------

    # Parameter	Type	Default	Description
    # lat	float	n/a	Latitude
    # lon	float	n/a	Longitude
    # dim	float	0.025	width and height of image in degrees
    # date	YYYY-MM-DD  today	date of image ----if not supplied, then the most recent image (i.e., closest to today) is returned
    #cloud_score	bool	False	calculate the percentage of the image covered by clouds
    #api_key	string	vDEMO_KEY	api.nasa.gov key for expanded usage

    # ---------EXAMPLE QUERY--------

    # https://api.nasa.gov/planetary/earth/imagery?lon=100.75&lat=1.5&date=2014-02-01&cloud_score=True&api_key=DEMO_KEY

    '''

    base_url = "https://api.nasa.gov/planetary/earth/imagery?"

    if not lon or not lat:
        raise ValueError(
            "imagery endpoint expects lat and lon, type has to be float. Call the method with keyword args. Ex : lon=100.75, lat=1.5")
    else:
        try:
            validate_float(lon, lat)
            # Floats are entered/displayed as decimal numbers, but your computer 
            # (in fact, your standard C library) stores them as binary. 
            # You get some side effects from this transition:
            # >>> print len(repr(0.1))
            # 19
            # >>> print repr(0.1)
            # 0.10000000000000001
            # Thus using decimal to str transition is more reliant
            lon = decimal.Decimal(lon)
            lat = decimal.Decimal(lat)
            base_url += "lon=" + str(lon) + "&" + "lat=" + str(lat) + "&"
        except:
            raise ValueError(
                "imagery endpoint expects lat and lon, type has to be float. Call the method with keyword args. Ex : lon=100.75, lat=1.5")

    if dim:
        try:
            validate_float(dim)
            dim = decimal.Decimal(dim)
            base_url += "dim=" + str(dim) + "&"
        except:
            raise ValueError("imagery endpoint expects dim to be a float")

    if date:
        try:
            vali_date(date)
            base_url += "date=" + date + "&"
        except:
            raise ValueError("Incorrect date format, should be YYYY-MM-DD")

    if cloud_score == True:
        base_url += "cloud_score=True" + "&"

    req_url = base_url + "api_key=" + nasa_api_key()

    return dispatch_http_get(req_url)
Exemplo n.º 31
0
def imagery(lon=None, lat=None, dim=None, date=None, cloud_score=None):
    '''
    # ----------QUERY PARAMETERS----------

    # Parameter	Type	Default	Description
    # lat	float	n/a	Latitude
    # lon	float	n/a	Longitude
    # dim	float	0.025	width and height of image in degrees
    # date	YYYY-MM-DD  today	date of image ----if not supplied, then the most recent image (i.e., closest to today) is returned
    #cloud_score	bool	False	calculate the percentage of the image covered by clouds
    #api_key	string	vDEMO_KEY	api.data.gov key for expanded usage

    # ---------EXAMPLE QUERY--------

    # https://api.data.gov/nasa/planetary/earth/imagery?lon=100.75&lat=1.5&date=2014-02-01&cloud_score=True&api_key=DEMO_KEY

    '''

    base_url = "http://api.data.gov/nasa/planetary/earth/imagery?"

    if not lon or not lat:
        raise ValueError(
            "imagery endpoint expects lat and lon, type has to be float. Call the method with keyword args. Ex : lon=100.75, lat=1.5"
        )
    else:
        try:
            validate_float(lon, lat)
            # Floats are entered/displayed as decimal numbers, but your computer
            # (in fact, your standard C library) stores them as binary.
            # You get some side effects from this transition:
            # >>> print len(repr(0.1))
            # 19
            # >>> print repr(0.1)
            # 0.10000000000000001
            # Thus using decimal to str transition is more reliant
            lon = decimal.Decimal(lon)
            lat = decimal.Decimal(lat)
            base_url += "lon=" + str(lon) + "&" + "lat=" + str(lat) + "&"
        except:
            raise ValueError(
                "imagery endpoint expects lat and lon, type has to be float. Call the method with keyword args. Ex : lon=100.75, lat=1.5"
            )

    if dim:
        try:
            validate_float(dim)
            dim = decimal.Decimal(dim)
            base_url += "dim=" + str(dim) + "&"
        except:
            raise ValueError("imagery endpoint expects dim to be a float")

    if date:
        try:
            vali_date(date)
            base_url += "date=" + date + "&"
        except:
            raise ValueError("Incorrect date format, should be YYYY-MM-DD")

    if cloud_score == True:
        base_url += "cloud_score=True" + "&"

    req_url = base_url + "api_key=" + nasa_api_key()

    return dispatch_http_get(req_url)
Exemplo n.º 32
0
def getjp2image(date,
                sourceId=None,
                observatory=None,
                instrument=None,
                detector=None,
                measurement=None):
    '''
    Helioviewer.org and JHelioviewer operate off of JPEG2000 formatted image data generated from science-quality FITS files. Use the APIs below to interact directly with these intermediary JPEG2000 files.
    
    Download a JP2 image for the specified datasource that is the closest match in time to the `date` requested.

    Either `sourceId` must be specified, or the combination of `observatory`, `instrument`, `detector`, and `measurement`.

    Request Parameters:

    Parameter	Required	Type	Example	Description
    date	Required	string	2014-01-01T23:59:59Z	Desired date/time of the JP2 image. ISO 8601 combined UTC date and time UTC format.
    sourceId	Optional	number	14	Unique image datasource identifier.
    observatory	Optional	string	SDO	Observatory name.
    instrument	Optional	string	AIA	Instrument name.
    detector	Optional	string	AIA	Detector name.
    measurement	Optional	string	335	Measurement name.
    jpip	Optional	boolean	false	Optionally return a JPIP URI instead of the binary data of the image itself.
    json	Optional	boolean	false	Optionally return a JSON object.


    EXAMPLE: http://helioviewer.org/api/v1/getJP2Image/?date=2014-01-01T23:59:59Z&sourceId=14&jpip=true
    '''

    base_url = 'http://helioviewer.org/api/v1/getJP2Image/?'
    req_url = ''

    try:
        validate_iso8601(date)
        if not date[-1:] == 'Z':
            date += 'Z'
        base_url += 'date=' + date
    except:
        raise ValueError(
            "Your date input is not in iso8601 format. ex: 2014-01-01T23:59:59")

    if sourceId:
        if not isinstance(sourceId, int):
            logger.error("The sourceId argument should be an int, ignoring it")
        else:
            base_url += "sourceId=" + str(sourceId) + "&"

    if observatory:
        if not isinstance(observatory, str):
            logger.error(
                "The observatory argument should be a str, ignoring it")
        else:
            base_url += "observatory=" + observatory + "&"

    if instrument:
        if not isinstance(instrument, str):
            logger.error(
                "The instrument argument should be a str, ignoring it")
        else:
            base_url += "instrument=" + instrument + "&"
    if detector:
        if not isinstance(detector, str):
            logger.error("The detector argument should be a str, ignoring it")
        else:
            base_url += "detector=" + detector + "&"

    if measurement:
        if not isinstance(measurement, str):
            logger.error(
                "The measurement argument should be a str, ignoring it")
        else:
            base_url += "measurement=" + detector + "&"

    req_url += base_url + "jpip=true"

    return dispatch_http_get(req_url)
Exemplo n.º 33
0
def assets(lon=None, lat=None, begin=None, end=None):
    '''
    HTTP REQUEST

    GET https://api.nasa.gov/planetary/earth/assets

    QUERY PARAMETERS

    Parameter	Type	Default	Description
    lat	float	n/a	Latitude
    lon	float	n/a	Longitude
    begin	YYYY-MM-DD	n/a	beginning of date range
    end	        YYYY-MM-DD	today	end of date range
    api_key	string	DEMO_KEY	api.nasa.gov key for expanded usage
    EXAMPLE QUERY

    https://api.nasa.gov/planetary/earth/assets?lon=100.75&lat=1.5&begin=2014-02-01&api_key=DEMO_KEY
    '''
    base_url = "https://api.nasa.gov/planetary/earth/assets?"

    if not lon or not lat:
        raise ValueError(
            "assets endpoint expects lat and lon, type has to be float. Call the method with keyword args. Ex : lon=100.75, lat=1.5")
    else:
        try:
            validate_float(lon, lat)
            # Floats are entered/displayed as decimal numbers, but your computer 
            # (in fact, your standard C library) stores them as binary. 
            # You get some side effects from this transition:
            # >>> print len(repr(0.1))
            # 19
            # >>> print repr(0.1)
            # 0.10000000000000001
            # Thus using decimal to str transition is more reliant
            lon = decimal.Decimal(lon)
            lat = decimal.Decimal(lat)
            base_url += "lon=" + str(lon) + "&" + "lat=" + str(lat) + "&"
        except:
            raise ValueError(
                "assets endpoint expects lat and lon, type has to be float. Call the method with keyword args. Ex : lon=100.75, lat=1.5")

    if not begin:
        raise ValueError(
            "Begin date is missing, which is mandatory. Format : YYYY-MM-DD")
    else:
        try:
            vali_date(begin)
            base_url += "begin=" + begin + "&"
        except:
            raise ValueError("Incorrect date format, should be YYYY-MM-DD")

    if end:
        try:
            vali_date(end)
            base_url += "end=" + end + "&"
        except:
            raise ValueError("Incorrect date format, should be YYYY-MM-DD")

    req_url = base_url + "api_key=" + nasa_api_key()

    return dispatch_http_get(req_url)