#!/usr/bin/env python
#
# grib_checker.py checks Checks whatever you want to check in your life
#
# AUTHOR: BSC-CNS I. CERNICHARO
#

import sys
import numpy as np

def return_coords_bounds(msg):
    keys = msg.keys()
    
    lat0 = 'latitudeOfFirstGridPointInDegrees'
    lat1 = 'latitudeOfLastGridPointInDegrees'
    lon0 = 'longitudeOfFirstGridPointInDegrees'
    lon1 = 'longitudeOfLastGridPointInDegrees'
    
    conditional = lon0 in keys and lat0 in keys and lon1 in keys and lat1 in keys

    if conditional:
        lat = msg['latitudes']
        bounds_lat = [
            msg[lat0],
            msg[lat1]
        ]

        lon = msg['longitudes']
        bounds_lon = [
            msg[lon0],
            msg[lon1]
        ]

        return [
            max(bounds_lat),
            min(bounds_lat),
            max(lat),
            min(lat),
            max(bounds_lon),
            min(bounds_lon),
            max(lon),
            min(lon),
        ]           

    else:
        gridtype = msg["gridType"]
        
        if gridtype == "lambert":
            return None
            
        else:
            return "Error"
    
def return_values_bounds(msg):
    vals = msg['values']
    return [
        msg[ 'maximum'],
        msg['minimum'],
        msg['average'],
        max(vals),
        min(vals),
        np.mean(vals),
    ]

def return_metadata(msg):
    keys = msg.keys()
    return keys

if __name__ == "__main__":
    sys.exit()