Skip to content

Commit

Permalink
Apply black -S -l 99. Black is not mandated yet, but better try it now
Browse files Browse the repository at this point in the history
  • Loading branch information
alexamici committed May 14, 2019
1 parent 73f9f9b commit 19c0067
Show file tree
Hide file tree
Showing 25 changed files with 612 additions and 314 deletions.
39 changes: 15 additions & 24 deletions cfgrib/bindings.py
Expand Up @@ -29,8 +29,8 @@

ffi = cffi.FFI()
ffi.cdef(
pkgutil.get_data(__name__, 'grib_api.h').decode('utf-8') +
pkgutil.get_data(__name__, 'eccodes.h').decode('utf-8')
pkgutil.get_data(__name__, 'grib_api.h').decode('utf-8')
+ pkgutil.get_data(__name__, 'eccodes.h').decode('utf-8')
)


Expand Down Expand Up @@ -74,7 +74,7 @@ def __getattr__(self, attr):
""" TAF product kind """

# Constants for 'missing'
GRIB_MISSING_DOUBLE = -1e+100
GRIB_MISSING_DOUBLE = -1e100
GRIB_MISSING_LONG = 2147483647

CODES_MISSING_DOUBLE = GRIB_MISSING_DOUBLE
Expand All @@ -92,21 +92,17 @@ def __getattr__(self, attr):
CODES_TYPE_LABEL = lib.GRIB_TYPE_LABEL
CODES_TYPE_MISSING = lib.GRIB_TYPE_MISSING

KEYTYPES = {
1: int,
2: float,
3: str,
}
KEYTYPES = {1: int, 2: float, 3: str}

CODES_KEYS_ITERATOR_ALL_KEYS = 0
CODES_KEYS_ITERATOR_SKIP_READ_ONLY = (1 << 0)
CODES_KEYS_ITERATOR_SKIP_OPTIONAL = (1 << 1)
CODES_KEYS_ITERATOR_SKIP_EDITION_SPECIFIC = (1 << 2)
CODES_KEYS_ITERATOR_SKIP_CODED = (1 << 3)
CODES_KEYS_ITERATOR_SKIP_COMPUTED = (1 << 4)
CODES_KEYS_ITERATOR_SKIP_DUPLICATES = (1 << 5)
CODES_KEYS_ITERATOR_SKIP_FUNCTION = (1 << 6)
CODES_KEYS_ITERATOR_DUMP_ONLY = (1 << 7)
CODES_KEYS_ITERATOR_SKIP_READ_ONLY = 1 << 0
CODES_KEYS_ITERATOR_SKIP_OPTIONAL = 1 << 1
CODES_KEYS_ITERATOR_SKIP_EDITION_SPECIFIC = 1 << 2
CODES_KEYS_ITERATOR_SKIP_CODED = 1 << 3
CODES_KEYS_ITERATOR_SKIP_COMPUTED = 1 << 4
CODES_KEYS_ITERATOR_SKIP_DUPLICATES = 1 << 5
CODES_KEYS_ITERATOR_SKIP_FUNCTION = 1 << 6
CODES_KEYS_ITERATOR_DUMP_ONLY = 1 << 7


#
Expand Down Expand Up @@ -139,15 +135,10 @@ class FileNotFoundError(GribInternalError):
"""File not found."""


ERROR_MAP = {
-18: ReadOnlyError,
-10: KeyValueNotFoundError,
-7: FileNotFoundError,
}
ERROR_MAP = {-18: ReadOnlyError, -10: KeyValueNotFoundError, -7: FileNotFoundError}


def check_last(func):

@functools.wraps(func)
def wrapper(*args):
code = ffi.new('int *')
Expand All @@ -164,7 +155,6 @@ def wrapper(*args):


def check_return(func):

@functools.wraps(func)
def wrapper(*args):
code = func(*args)
Expand Down Expand Up @@ -364,7 +354,7 @@ def codes_get_native_type(handle, key):
return KEYTYPES.get(grib_type[0], grib_type[0])


def codes_get_array(handle, key, key_type=None, size=None, length=None, log=LOG):
def codes_get_array(handle, key, key_type=None, size=None, length=None, log=LOG):
# type: (cffi.FFI.CData, str, int, int, int, logging.Logger) -> T.Any
if key_type is None:
key_type = codes_get_native_type(handle, key)
Expand Down Expand Up @@ -445,6 +435,7 @@ def portable_handle_new_from_samples(samplename, product_kind):
#
import os.path
import platform

handle = ffi.NULL
if platform.platform().startswith('Windows'):
samples_folder = ffi.string(lib.codes_samples_path(ffi.NULL))
Expand Down
22 changes: 18 additions & 4 deletions cfgrib/cfmessage.py
Expand Up @@ -31,8 +31,22 @@

# taken from eccodes stepUnits.table
GRIB_STEP_UNITS_TO_SECONDS = [
60, 3600, 86400, None, None, None, None, None, None, None,
10800, 21600, 43200, 1, 900, 1800,
60,
3600,
86400,
None,
None,
None,
None,
None,
None,
None,
10800,
21600,
43200,
1,
900,
1800,
]
DEFAULT_EPOCH = datetime.datetime(1970, 1, 1)

Expand Down Expand Up @@ -62,7 +76,7 @@ def from_grib_date_time(message, date_key='dataDate', time_key='dataTime', epoch


def to_grib_date_time(
message, time_ns, date_key='dataDate', time_key='dataTime', epoch=DEFAULT_EPOCH,
message, time_ns, date_key='dataDate', time_key='dataTime', epoch=DEFAULT_EPOCH
):
# type: (T.MutableMapping, np.datetime64, str, str, datetime.datetime) -> None
time_s = int(time_ns) * 1e-9
Expand All @@ -75,7 +89,7 @@ def to_grib_date_time(
def from_grib_step(message, step_key='endStep', step_unit_key='stepUnits'):
# type: (T.Mapping, str, str) -> float
to_seconds = GRIB_STEP_UNITS_TO_SECONDS[message[step_unit_key]]
return message[step_key] * to_seconds / 3600.
return message[step_key] * to_seconds / 3600.0


def to_grib_step(message, step_ns, step_unit=1, step_key='endStep', step_unit_key='stepUnits'):
Expand Down

0 comments on commit 19c0067

Please sign in to comment.