# ----------------------------------------------------------------------------------------
# This table provides a mapping from the grib2io's shortName attr to CF standard name
# and cell method.
# ----------------------------------------------------------------------------------------
table_shortname_to_cf = {
    'ABSV': {'cf_standard_name': 'atmosphere_absolute_vorticity', 'cf_cell_methods': None},
    'DEN': {'cf_standard_name': 'air_density', 'cf_cell_methods': None},
    'DEPR': {'cf_standard_name': 'dew_point_depression', 'cf_cell_methods': None},
    'DPT': {'cf_standard_name': 'dew_point_temperature', 'cf_cell_methods': None},
    'DZDT': {'cf_standard_name': 'upward_air_velocity', 'cf_cell_methods': None},
    'EPOT': {'cf_standard_name': 'equivalent_potential_temperature', 'cf_cell_methods': None},
    'GP': {'cf_standard_name': 'geopotential', 'cf_cell_methods': None},
    'HGT': {'cf_standard_name': 'geopotential_height', 'cf_cell_methods': None},
    'DIST': {'cf_standard_name': 'unknown', 'cf_cell_methods': None},
    'LAPR': {'cf_standard_name': 'air_temperature_lapse_rate', 'cf_cell_methods': None},
    'MIXR': {'cf_standard_name': 'humidity_mixing_ratio', 'cf_cell_methods': None},
    'POT': {'cf_standard_name': 'air_potential_temperature', 'cf_cell_methods': None},
    'PRES': {'cf_standard_name': 'air_pressure', 'cf_cell_methods': None},
    'PRMSL': {'cf_standard_name': 'air_pressure_at_mean_sea_level', 'cf_cell_methods': None},
    'PTEND': {'cf_standard_name': 'tendency_of_air_pressure', 'cf_cell_methods': None},
    'PVORT': {'cf_standard_name': 'atmosphere_potential_vorticity', 'cf_cell_methods': None},
    'RELV': {'cf_standard_name': 'atmosphere_relative_vorticity', 'cf_cell_methods': None},
    'RH': {'cf_standard_name': 'relative_humidity', 'cf_cell_methods': None},
    'SPFH': {'cf_standard_name': 'specific_humidity', 'cf_cell_methods': None},
    'STRM': {'cf_standard_name': 'atmosphere_streamfunction', 'cf_cell_methods': None},
    'TMAX': {'cf_standard_name': 'air_temperature', 'cf_cell_methods': 'time: maximum'},
    'TMIN': {'cf_standard_name': 'air_temperature', 'cf_cell_methods': 'time: minimum'},
    'MAXRH': {'cf_standard_name': 'relative_humidity', 'cf_cell_methods': 'time: maximum'},
    'MINRH': {'cf_standard_name': 'relative_humidity', 'cf_cell_methods': 'time: minimum'},
    'TMP': {'cf_standard_name': 'air_temperature', 'cf_cell_methods': None},
    'CAPE': {'cf_standard_name': 'atmosphere_convective_available_potential_energy', 'cf_cell_methods': None},
    'CEIL': {'cf_standard_name': 'unknown', 'cf_cell_methods': None},
    'ICSEV': {'cf_standard_name': 'unknown', 'cf_cell_methods': None},
    'ICPRB': {'cf_standard_name': 'unknown', 'cf_cell_methods': None},
    'SIPD': {'cf_standard_name': 'unknown', 'cf_cell_methods': None},
    'ELLINX': {'cf_standard_name': 'unknown', 'cf_cell_methods': None},
    'TURB': {'cf_standard_name': 'unknown', 'cf_cell_methods': None},
    'CLOUDBASE': {'cf_standard_name': 'cloud_base_altitude', 'cf_cell_methods': None},
    'DRYTPROB': {'cf_standard_name': 'unknown', 'cf_cell_methods': None},
    'TSTM': {'cf_standard_name': 'thunderstorm_probability', 'cf_cell_methods': None},
    'TRWSPD': {'cf_standard_name': 'unknown', 'cf_cell_methods': None},
    'TRWDIR': {'cf_standard_name': 'unknown', 'cf_cell_methods': None},
    'VRATE': {'cf_standard_name': 'unknown', 'cf_cell_methods': None},
    'RETOP': {'cf_standard_name': 'unknown', 'cf_cell_methods': None},
    'MIXHT': {'cf_standard_name': 'unknown', 'cf_cell_methods': None},
    'PWTHER': {'cf_standard_name': 'unknown', 'cf_cell_methods': None},
    'MAXREF': {'cf_standard_name': 'equivalent_reflectivity_factor', 'cf_cell_methods': None},
    'SNOWLR': {'cf_standard_name': 'unknown', 'cf_cell_methods': None},
    'SNOWLVL': {'cf_standard_name': 'unknown', 'cf_cell_methods': None},
    'ASNOW': {'cf_standard_name': 'thickness_of_snowfall_amount', 'cf_cell_methods': None},
    'FICEAC': {'cf_standard_name': 'unknown', 'cf_cell_methods': None},
    'APTMP': {'cf_standard_name': 'apparent_air_temperature', 'cf_cell_methods': None},
    'UGRD': {'cf_standard_name': 'eastward_wind', 'cf_cell_methods': None},
    'VAPP': {'cf_standard_name': 'water_vapor_partial_pressure_in_air', 'cf_cell_methods': None},
    'VGRD': {'cf_standard_name': 'northward_wind', 'cf_cell_methods': None},
    'VPOT': {'cf_standard_name': 'atmosphere_velocity_potential', 'cf_cell_methods': None},
    'VTMP': {'cf_standard_name': 'virtual_temperature', 'cf_cell_methods': None},
    'VVEL': {'cf_standard_name': 'lagrangian_tendency_of_air_pressure', 'cf_cell_methods': None},
    'VUCSH': {'cf_standard_name': 'eastward_wind_shear', 'cf_cell_methods': None},
    'VVCSH': {'cf_standard_name': 'northward_wind_shear', 'cf_cell_methods': None},
    'WDIR': {'cf_standard_name': 'wind_from_direction', 'cf_cell_methods': None},
    'WIND': {'cf_standard_name': 'wind_speed', 'cf_cell_methods': None},
    'GUST': {'cf_standard_name': 'wind_speed_of_gust', 'cf_cell_methods': None},
    'WTMP': {'cf_standard_name': 'sea_water_temperature', 'cf_cell_methods': None},
    'ACPCP': {'cf_standard_name': 'lwe_thickness_of_convective_precipitation_amount', 'cf_cell_methods': 'time: sum'},
    'PTYPE': {'cf_standard_name': 'predominant_precipitation_type_at_surface', 'cf_cell_methods': None},
    'APCP': {'cf_standard_name': 'lwe_thickness_of_precipitation_amount', 'cf_cell_methods': 'time: sum'},
    'CICE': {'cf_standard_name': 'atmosphere_cloud_ice_content', 'cf_cell_methods': None},
    'CWAT': {'cf_standard_name': 'atmosphere_cloud_condensate_content', 'cf_cell_methods': None},
    'EVP': {'cf_standard_name': 'water_evaporation_flux', 'cf_cell_methods': 'time: mean'},
    'HCDC': {'cf_standard_name': 'high_type_cloud_area_fraction', 'cf_cell_methods': None},
    'LCDC': {'cf_standard_name': 'low_type_cloud_area_fraction', 'cf_cell_methods': None},
    'MCDC': {'cf_standard_name': 'medium_type_cloud_area_fraction', 'cf_cell_methods': None},
    'NCPCP': {'cf_standard_name': 'lwe_thickness_of_large_scale_precipitation_amount', 'cf_cell_methods': 'time: sum'},
    'PRATE': {'cf_standard_name': 'precipitation_flux', 'cf_cell_methods': None},
    'PWAT': {'cf_standard_name': 'atmosphere_water_vapor_content', 'cf_cell_methods': None},
    'SNOC': {'cf_standard_name': 'lwe_thickness_of_convective_snowfall_amount', 'cf_cell_methods': 'time: sum'},
    'SNOL': {'cf_standard_name': 'lwe_thickness_of_large_scale_snowfall_amount', 'cf_cell_methods': 'time: sum'},
    'TCDC': {'cf_standard_name': 'cloud_area_fraction', 'cf_cell_methods': None},
    'WEASD': {'cf_standard_name': 'lwe_thickness_of_surface_snow_amount', 'cf_cell_methods': 'time: sum'},
    'LAND': {'cf_standard_name': 'land_area_fraction', 'cf_cell_methods': None},
    'SFCR': {'cf_standard_name': 'surface_roughness_length', 'cf_cell_methods': None},
    'SNOD': {'cf_standard_name': 'surface_snow_thickness', 'cf_cell_methods': None},
    'SNOM': {'cf_standard_name': 'surface_snow_melt_flux', 'cf_cell_methods': 'time: mean'},
    'SOILM': {'cf_standard_name': 'soil_moisture_content', 'cf_cell_methods': None},
    'TSOIL': {'cf_standard_name': 'soil_temperature', 'cf_cell_methods': None},
    'VEG': {'cf_standard_name': 'vegetation_area_fraction', 'cf_cell_methods': None},
    'WATR': {'cf_standard_name': 'runoff_flux', 'cf_cell_methods': 'time: mean'},
    'ALBDO': {'cf_standard_name': 'surface_albedo', 'cf_cell_methods': None},
    'DLWRF': {'cf_standard_name': 'surface_downwelling_longwave_flux_in_air', 'cf_cell_methods': 'time: mean'},
    'DSWRF': {'cf_standard_name': 'surface_downwelling_shortwave_flux_in_air', 'cf_cell_methods': 'time: mean'},
    'GRAD': {'cf_standard_name': 'surface_downwelling_shortwave_flux_in_air', 'cf_cell_methods': 'time: mean'},
    'LHTFL': {'cf_standard_name': 'surface_upward_latent_heat_flux', 'cf_cell_methods': 'time: mean'},
    'NLWRS': {'cf_standard_name': 'surface_net_downward_longwave_flux', 'cf_cell_methods': 'time: mean'},
    'NLWRT': {'cf_standard_name': 'toa_net_downward_longwave_flux', 'cf_cell_methods': 'time: mean'},
    'NSWRS': {'cf_standard_name': 'surface_net_downward_shortwave_flux', 'cf_cell_methods': 'time: mean'},
    'NSWRT': {'cf_standard_name': 'toa_net_downward_shortwave_flux', 'cf_cell_methods': 'time: mean'},
    'SHTFL': {'cf_standard_name': 'surface_upward_sensible_heat_flux', 'cf_cell_methods': 'time: mean'},
    'ULWRF': {'cf_standard_name': 'surface_upwelling_longwave_flux_in_air', 'cf_cell_methods': 'time: mean'},
    'USWRF': {'cf_standard_name': 'surface_upwelling_shortwave_flux_in_air', 'cf_cell_methods': 'time: mean'},
    'DSLM': {'cf_standard_name': 'sea_surface_height_above_sea_level', 'cf_cell_methods': None},
    'HTSGW': {'cf_standard_name': 'sea_surface_wave_significant_height', 'cf_cell_methods': None},
    'ICEC': {'cf_standard_name': 'sea_ice_area_fraction', 'cf_cell_methods': None},
    'ICETK': {'cf_standard_name': 'sea_ice_thickness', 'cf_cell_methods': None},
    'SALTY': {'cf_standard_name': 'sea_water_salinity', 'cf_cell_methods': None},
    'SWELL': {'cf_standard_name': 'sea_surface_swell_wave_significant_height', 'cf_cell_methods': None},
    'SWDIR': {'cf_standard_name': 'sea_surface_swell_wave_from_direction', 'cf_cell_methods': None},
    'SWPER': {'cf_standard_name': 'sea_surface_swell_wave_period', 'cf_cell_methods': None},
    'UOGRD': {'cf_standard_name': 'eastward_sea_water_velocity', 'cf_cell_methods': None},
    'VOGRD': {'cf_standard_name': 'northward_sea_water_velocity', 'cf_cell_methods': None},
    'WTMP': {'cf_standard_name': 'sea_water_temperature', 'cf_cell_methods': None},
    'WVDIR': {'cf_standard_name': 'sea_surface_wind_wave_from_direction', 'cf_cell_methods': None},
    'WVHGT': {'cf_standard_name': 'sea_surface_wind_wave_significant_height', 'cf_cell_methods': None},
    'WVPER': {'cf_standard_name': 'sea_surface_wind_wave_period', 'cf_cell_methods': None},
    'TOZNE': {'cf_standard_name': 'atmosphere_mole_content_of_ozone', 'cf_cell_methods': None},
    'VIS': {'cf_standard_name': 'visibility_in_air', 'cf_cell_methods': None},
}

# ----------------------------------------------------------------------------------------
# A dictionary to map GRIB2 Code Table 4.7 (Derived Forecast) to their equivalent 
# CF Convention cell_methods.
# ----------------------------------------------------------------------------------------
table_4_7_cf = {
    0: {'cf_cell_methods': 'time: mean'},
    1: {'cf_cell_methods': 'time: mean (comment: weighted)'},
    2: {'cf_cell_methods': 'time: standard_deviation (comment: with respect to cluster mean)'},
    3: {'cf_cell_methods': 'time: standard_deviation (comment: normalized)'},
    4: {'cf_cell_methods': 'time: standard_deviation'},
    5: {'cf_cell_methods': None}, # No direct CF equivalent
    6: {'cf_cell_methods': 'time: mean (comment: of cluster members)'},
    7: {'cf_cell_methods': 'time: range (comment: interquartile)'},
    8: {'cf_cell_methods': 'time: minimum'},
    9: {'cf_cell_methods': 'time: maximum'},
    10: {'cf_cell_methods': 'time: variance'},
    192: {'cf_cell_methods': 'time: mode'},
    193: {'cf_cell_methods': None}, # No direct CF equivalent
    194: {'cf_cell_methods': 'time: median'},
    195: {'cf_cell_methods': None}, # No direct CF equivalent
    197: {'cf_cell_methods': None}, # No direct CF equivalent
    198: {'cf_cell_methods': None}, # Not a cell method
    199: {'cf_cell_methods': None}, # No direct CF equivalent
    200: {'cf_cell_methods': 'time: mean'},
    201: {'cf_cell_methods': None}, # No direct CF equivalent
    202: {'cf_cell_methods': None}, # No direct CF equivalent
    203: {'cf_cell_methods': None}, # No direct CF equivalent
    204: {'cf_cell_methods': None}, # No direct CF equivalent
    255: {'cf_cell_methods': None}, # Represents a missing value
}
