pyspc.core.keyseries

Objets natifs et convention de pyspc - Clés des collections de Série de données

Functions

str2tuple([s, sep, forceobs, forcesim])

Convertir une chaine de caractères en tuple utilisé par pyspc.core.Series

tuple2str([t, dtfmt, sep])

Convertir un tuple utilisé par pyspc.core.Series en chaine de caractères

pyspc.core.keyseries.str2tuple(s=None, sep=None, forceobs=False, forcesim=False)[source]

Convertir une chaine de caractères en tuple utilisé par pyspc.core.Series

Paramètres:
  • s (str) – Chaine de caractère à convertir

  • sep (str) – Séparateur des champs. Défaut: “_”

  • forceobs (bool) – Forcer la conversion en tant que série d’observation. Défaut: False

  • forcesim (bool) – Forcer la conversion en tant que série de simulation. Défaut: False L’option forceobs a la préséance sur forcesim

Renvoie:

Tuple servant de clé pour Series:
  • observation : (identifiant, grandeur, None)

  • simulation : (identifiant, grandeur, modele)

  • prévision : (identifiant, grandeur, (runtime, model, scen, tend))

Type renvoyé:

tuple

Exemples

>>> from datetime import datetime as dt
>>> from pyspc.core.keyseries import str2tuple

Cas classiques

>>> str2tuple('ID_GRD')
('ID', 'GRD', None)
>>> str2tuple('ID_MDL_GRD')
('ID', 'GRD', 'MDL')
>>> str2tuple('ID_20210301_GRD')
('ID', 'GRD', (dt(2021, 3, 1, 0, 0), None, None, None))
>>> str2tuple('ID_20210301_MDL_GRD')
('ID', 'GRD', (dt(2021, 3, 1, 0, 0), 'MDL', None, None))
>>> str2tuple('ID_20210301_MDL_SCN_GRD')
('ID', 'GRD', (dt(2021, 3, 1, 0, 0), 'MDL', 'SCN', None))
>>> str2tuple('ID_20210301_MDL_SCN_INC_GRD')
('ID', 'GRD', (dt(2021, 3, 1, 0, 0), 'MDL', 'SCN', 'INC'))
>>> str2tuple('ID_2021030112_GRD')
('ID', 'GRD', (dt(2021, 3, 1, 12, 0), None, None, None))
>>> str2tuple('ID_2021030112_MDL_GRD')
('ID', 'GRD', (dt(2021, 3, 1, 12, 0), 'MDL', None, None))
>>> str2tuple('ID_2021030112_MDL_SCN_GRD')
('ID', 'GRD', (dt(2021, 3, 1, 12, 0), 'MDL', 'SCN', None))
>>> str2tuple('ID_2021030112_MDL_SCN_INC_GRD')
('ID', 'GRD', (dt(2021, 3, 1, 12, 0), 'MDL', 'SCN', 'INC'))
>>> str2tuple('ID_202103011230_GRD')
('ID', 'GRD', (dt(2021, 3, 1, 12, 30), None, None, None))
>>> str2tuple('ID_202103011230_MDL_GRD')
('ID', 'GRD', (dt(2021, 3, 1, 12, 30), 'MDL', None, None))
>>> str2tuple('ID_202103011230_MDL_SCN_GRD')
('ID', 'GRD', (dt(2021, 3, 1, 12, 30), 'MDL', 'SCN', None))
>>> str2tuple('ID_202103011230_MDL_SCN_INC_GRD')
('ID', 'GRD', (dt(2021, 3, 1, 12, 30), 'MDL', 'SCN', 'INC'))

Cas avec “forceobs=True”

>>> str2tuple('ID_GRD', forceobs=True)
('ID', 'GRD', None)
>>> str2tuple('ID_MDL_GRD', forceobs=True)
('ID_MDL', 'GRD', None)
>>> str2tuple('ID_20210301_GRD', forceobs=True)
('ID_20210301', 'GRD', None)
>>> str2tuple('ID_20210301_MDL_GRD', forceobs=True)
('ID_20210301_MDL', 'GRD', None)
>>> str2tuple('ID_20210301_MDL_SCN_GRD', forceobs=True)
('ID_20210301_MDL_SCN', 'GRD', None)
>>> str2tuple('ID_20210301_MDL_SCN_INC_GRD', forceobs=True)
('ID_20210301_MDL_SCN_INC', 'GRD', None)

Cas avec “forcesim=True”

>>> str2tuple('ID_GRD', forcesim=True)
('ID', 'GRD', None)
>>> str2tuple('ID_MDL_GRD', forcesim=True)
('ID', 'GRD', 'MDL')
>>> str2tuple('ID_20210301_GRD', forcesim=True)
('ID', 'GRD', '20210301')
>>> str2tuple('ID_20210301_MDL_GRD', forcesim=True)
('ID', 'GRD', '20210301_MDL')
>>> str2tuple('ID_20210301_MDL_SCN_GRD', forcesim=True)
('ID', 'GRD', '20210301_MDL_SCN')
>>> str2tuple('ID_20210301_MDL_SCN_INC_GRD', forcesim=True)
('ID', 'GRD', '20210301_MDL_SCN_INC')
pyspc.core.keyseries.tuple2str(t=None, dtfmt=None, sep=None)[source]

Convertir un tuple utilisé par pyspc.core.Series en chaine de caractères

Paramètres:
  • t (tuple) –

    Tuple servant de clé pour Series:
    • observation : (identifiant, grandeur, None)

    • simulation : (identifiant, grandeur, modele)

    • prévision : (identifiant, grandeur, (runtime, model, scen, tend))

  • sep (str) – Séparateur des champs. Défaut: “_”

  • dtfmt (str) – Format d’écriture des dates. Défaut: “%Y%m%d%H”

Renvoie:

s – Chaine de caractère à convertir

Type renvoyé:

str

Exemples

>>> from datetime import datetime as dt
>>> from pyspc.core.keyseries import tuple2str

Cas par défaut

>>> tuple2str(('ID', 'GRD', None))
ID_GRD
>>> tuple2str(('ID', 'GRD', 'MDL'))
ID_MDL_GRD
>>> tuple2str(('ID', 'GRD', (dt(2021, 3, 1, 0, 0), None, None, None)))
ID_2021030100_GRD
>>> tuple2str(('ID', 'GRD', (dt(2021, 3, 1, 0, 0), 'MDL', None, None)))
ID_2021030100_MDL_GRD
>>> tuple2str(('ID', 'GRD', (dt(2021, 3, 1, 0, 0), 'MDL', 'SCN', None)))
ID_2021030100_MDL_SCN_GRD
>>> tuple2str(('ID', 'GRD', (dt(2021, 3, 1, 0, 0), 'MDL', 'SCN', 'INC')))
ID_2021030100_MDL_SCN_INC_GRD
>>> tuple2str(('ID', 'GRD', (dt(2021, 3, 1, 12, 0), None, None, None)))
ID_2021030112_GRD
>>> tuple2str(('ID', 'GRD', (dt(2021, 3, 1, 12, 0), 'MDL', None, None)))
ID_2021030112_MDL_GRD
>>> tuple2str(('ID', 'GRD', (dt(2021, 3, 1, 12, 0), 'MDL', 'SCN', None)))
ID_2021030112_MDL_SCN_GRD
>>> tuple2str(('ID', 'GRD', (dt(2021, 3, 1, 12, 0), 'MDL', 'SCN', 'INC')))
ID_2021030112_MDL_SCN_INC_GRD
>>> tuple2str(('ID', 'GRD', (dt(2021, 3, 1, 13, 30), None, None, None)))
ID_2021030113_GRD
>>> tuple2str(('ID', 'GRD', (dt(2021, 3, 1, 13, 30), 'MDL', None, None)))
ID_2021030113_MDL_GRD
>>> tuple2str(('ID', 'GRD', (dt(2021, 3, 1, 13, 30), 'MDL', 'SCN', None)))
ID_2021030113_MDL_SCN_GRD
>>> tuple2str(('ID', 'GRD', (dt(2021, 3, 1, 13, 30), 'MDL', 'SCN', 'INC')))
ID_2021030113_MDL_SCN_INC_GRD

Cas avec “dtfmt” définie par l’utilisateur

>>> tuple2str(('ID', 'GRD', (dt(2021, 3, 1, 0, 0), None, None, None)),
               dtfmt='%Y%m%d%H%M')
ID_202103010000_GRD
>>> tuple2str(('ID', 'GRD', (dt(2021, 3, 1, 0, 0), 'MDL', None, None)),
               dtfmt='%Y%m%d%H%M')
ID_202103010000_MDL_GRD
>>> tuple2str(('ID', 'GRD', (dt(2021, 3, 1, 0, 0), 'MDL', 'SCN', None)),
               dtfmt='%Y%m%d%H%M')
ID_202103010000_MDL_SCN_GRD
>>> tuple2str(('ID', 'GRD', (dt(2021, 3, 1, 0, 0), 'MDL', 'SCN', 'INC')),
               dtfmt='%Y%m%d%H%M')
ID_202103010000_MDL_SCN_INC_GRD
>>> tuple2str(('ID', 'GRD', (dt(2021, 3, 1, 12, 0), None, None, None)),
               dtfmt='%Y%m%d%H%M')
ID_202103011200_GRD
>>> tuple2str(('ID', 'GRD', (dt(2021, 3, 1, 12, 0), 'MDL', None, None)),
               dtfmt='%Y%m%d%H%M')
ID_202103011200_MDL_GRD
>>> tuple2str(('ID', 'GRD', (dt(2021, 3, 1, 12, 0), 'MDL', 'SCN', None)),
               dtfmt='%Y%m%d%H%M')
ID_202103011200_MDL_SCN_GRD
>>> tuple2str(('ID', 'GRD', (dt(2021, 3, 1, 12, 0), 'MDL', 'SCN', 'INC')),
               dtfmt='%Y%m%d%H%M')
ID_202103011200_MDL_SCN_INC_GRD
>>> tuple2str(('ID', 'GRD', (dt(2021, 3, 1, 12, 30), None, None, None)),
               dtfmt='%Y%m%d%H%M')
ID_202103011230_GRD
>>> tuple2str(('ID', 'GRD', (dt(2021, 3, 1, 12, 30), 'MDL', None, None)),
               dtfmt='%Y%m%d%H%M')
ID_202103011230_MDL_GRD
>>> tuple2str(('ID', 'GRD', (dt(2021, 3, 1, 12, 30), 'MDL', 'SCN', None)),
               dtfmt='%Y%m%d%H%M')
ID_202103011230_MDL_SCN_GRD
>>> tuple2str(('ID', 'GRD', (dt(2021, 3, 1, 12, 30), 'MDL', 'SCN', 'INC')),
               dtfmt='%Y%m%d%H%M')
ID_202103011230_MDL_SCN_INC_GRD