Skip to content
Snippets Groups Projects
Commit 933855d9 authored by Florian Obersteiner's avatar Florian Obersteiner
Browse files

created .py for utility functions

parent 405c44f7
No related branches found
No related tags found
1 merge request!22towards release
...@@ -8,6 +8,8 @@ from enum import IntEnum ...@@ -8,6 +8,8 @@ from enum import IntEnum
import numpy as np import numpy as np
from . import ictutils as utl
DEFAULT_NUM_FORMAT = "%g" DEFAULT_NUM_FORMAT = "%g"
"""Default number format for output. Provides the `fmt` parameter of :func:`numpy.savetxt` internally.""" """Default number format for output. Provides the `fmt` parameter of :func:`numpy.savetxt` internally."""
...@@ -340,15 +342,13 @@ class Variable: ...@@ -340,15 +342,13 @@ class Variable:
descstr += [str(self.longname)] descstr += [str(self.longname)]
return delimiter.join(descstr) return delimiter.join(descstr)
def isValidVariablename(self, name): # TODO: this could be a 'utils' function def isValidVariablename(self, name):
# ICARTT Standard v2 2.1.1 2) # ICARTT Standard v2 2.1.1 2)
# Variable short names and variable standard names: # Variable short names and variable standard names:
# Uppercase and lowercase ASCII alphanumeric characters # Uppercase and lowercase ASCII alphanumeric characters
# and underscores. # and underscores.
def isAsciiAlphaOrUnderscore(x): # TODO: this could be a 'utils' function
return re.match("[a-zA-Z0-9_]", x)
allAreAlphaOrUnderscore = all(isAsciiAlphaOrUnderscore(x) for x in name) allAreAlphaOrUnderscore = all(utl.isAsciiAlphaOrUnderscore(x) for x in name)
# The first character must be a letter, # The first character must be a letter,
firstIsAlpha = bool(re.match("[a-zA-Z]", name[0])) firstIsAlpha = bool(re.match("[a-zA-Z]", name[0]))
# and the name can be at most 31 characters in length. # and the name can be at most 31 characters in length.
...@@ -401,10 +401,6 @@ class Variable: ...@@ -401,10 +401,6 @@ class Variable:
self.scale = scale self.scale = scale
self.miss = miss self.miss = miss
def __repr__(self):
# TODO: this sould be something else than __str__ ?
return self.desc()
def __str__(self): def __str__(self):
return self.desc() return self.desc()
......
# -*- coding: utf-8 -*-
import re
def isAsciiAlphaOrUnderscore(x: str, _only="[a-zA-Z0-9_]") -> bool:
"""check if string x contains only characters from [a-zA-Z0-9_] regex"""
return re.match(_only, x)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment