# ----------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

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)