From 5e2dcf2100947f1414333375d623802b9417e128 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marek=20Ne=C4=8Dada?= Date: Thu, 15 Aug 2019 15:19:54 +0300 Subject: [PATCH] VSWFNorm IntFlag / IntEnum fallback Former-commit-id: f1cc46f208bdceac972409836a238a56966277a4 --- qpms/cybspec.pyx | 36 +++++++++++++++++++++++++----------- qpms/qpms_cdefs.pxd | 1 + qpms/qpms_types.h | 4 +++- 3 files changed, 29 insertions(+), 12 deletions(-) diff --git a/qpms/cybspec.pyx b/qpms/cybspec.pyx index 7e6ad16..d3ff8bf 100644 --- a/qpms/cybspec.pyx +++ b/qpms/cybspec.pyx @@ -1,17 +1,31 @@ import numpy as np import enum from .cycommon import get_mn_y, tlm2uvswfi +__VSWF_norm_dict = { + 'INVERSE' : QPMS_NORMALISATION_INVERSE, + 'REVERSE_AZIMUTHAL_PHASE' : QPMS_NORMALISATION_REVERSE_AZIMUTHAL_PHASE, + 'SPHARM_REAL' : QPMS_NORMALISATION_SPHARM_REAL, + 'M_I' : QPMS_NORMALISATION_M_I, + 'M_MINUS' : QPMS_NORMALISATION_M_MINUS, + 'N_I' : QPMS_NORMALISATION_N_I, + 'N_MINUS' : QPMS_NORMALISATION_N_MINUS, + 'L_I' : QPMS_NORMALISATION_L_I, + 'L_MINUS' : QPMS_NORMALISATION_L_MINUS, + 'CSPHASE' : QPMS_NORMALISATION_CSPHASE, + 'UNNORM' : QPMS_NORMALISATION_NORM_NONE, + 'UNNORM_CS' : QPMS_NORMALISATION_NORM_NONE | QPMS_NORMALISATION_CSPHASE, + 'POWERNORM' : QPMS_NORMALISATION_NORM_POWER, + 'POWERNORM_CS' : QPMS_NORMALISATION_NORM_POWER | QPMS_NORMALISATION_CSPHASE, + 'SPHARMNORM' : QPMS_NORMALISATION_NORM_SPHARM, + 'SPHARMNORM_CS' : QPMS_NORMALISATION_NORM_SPHARM | QPMS_NORMALISATION_CSPHASE, + 'UNDEF' : QPMS_NORMALISATION_UNDEF, + 'DEFAULT' : QPMS_NORMALISATION_DEFAULT, +} -class VSWFNorm(enum.IntEnum): - # TODO try to make this an enum.IntFlag if supported - # TODO add the other flags from qpms_normalisation_t as well - UNNORM = QPMS_NORMALISATION_NORM_NONE - UNNORM_CS = QPMS_NORMALISATION_NORM_NONE | QPMS_NORMALISATION_CSPHASE - POWERNORM = QPMS_NORMALISATION_NORM_POWER - POWERNORM_CS = QPMS_NORMALISATION_NORM_POWER | QPMS_NORMALISATION_CSPHASE - SPHARMNORM = QPMS_NORMALISATION_NORM_SPHARM - SPHARMNORM_CS = QPMS_NORMALISATION_NORM_SPHARM | QPMS_NORMALISATION_CSPHASE - UNDEF = QPMS_NORMALISATION_UNDEF +try: + VSWFNorm = enum.IntFlag('VSWFNorm', names=__VSWF_norm_dict, module=__name__) +except AttributeError: # For older Python versions, use IntEnum instead + VSWFNorm = enum.IntEnum('VSWFNorm', names=__VSWF_norm_dict, module=__name__) cdef class BaseSpec: '''Cython wrapper over qpms_vswf_set_spec_t. @@ -50,7 +64,7 @@ cdef class BaseSpec: if 'norm' in kwargs.keys(): self.s.norm = kwargs['norm'] else: - self.s.norm = (QPMS_NORMALISATION_NORM_POWER | QPMS_NORMALISATION_CSPHASE) + self.s.norm = (QPMS_NORMALISATION_DEFAULT) # set the other metadata cdef qpms_l_t l self.s.lMax_L = -1 diff --git a/qpms/qpms_cdefs.pxd b/qpms/qpms_cdefs.pxd index 9d7378a..2474e20 100644 --- a/qpms/qpms_cdefs.pxd +++ b/qpms/qpms_cdefs.pxd @@ -56,6 +56,7 @@ cdef extern from "qpms_types.h": QPMS_NORMALISATION_CONVENTION_KRISTENSSON_REAL QPMS_NORMALISATION_CONVENTION_KRISTENSSON QPMS_NORMALISATION_CONVENTION_SCUFF + QPMS_NORMALISATION_DEFAULT ctypedef enum qpms_bessel_t: QPMS_BESSEL_REGULAR QPMS_BESSEL_SINGULAR diff --git a/qpms/qpms_types.h b/qpms/qpms_types.h index 4d7955f..fd73ce0 100644 --- a/qpms/qpms_types.h +++ b/qpms/qpms_types.h @@ -158,7 +158,9 @@ typedef enum { /// VSWF convention used in SCUFF-EM \cite reid_electromagnetism_2016 QPMS_NORMALISATION_CONVENTION_SCUFF = QPMS_NORMALISATION_NORM_POWER | QPMS_NORMALISATION_CSPHASE | QPMS_NORMALISATION_M_I - | QPMS_NORMALISATION_N_MINUS + | QPMS_NORMALISATION_N_MINUS, + /// Default VSWF convention. We might encourage the compiler to expect this one. + QPMS_NORMALISATION_DEFAULT = QPMS_NORMALISATION_CONVENTION_KRISTENSSON } qpms_normalisation_t; /// Determine whether the convention includes Condon-Shortley phase (-1) or not (+1).