import argparse
import datetime
import pickle
import math
import logging

import numpy as np
import pandas as pd
import dateutil
from scipy.special import erf

from epa.models import EpaStationTextarRawData, EpaStationTextarAbnormal
from epa.logging import get_logger

logger = get_logger(__name__)


def extract_mark(df):
    df = df.fillna("NoValue")
    s = df.stack(df.columns.names)
    regex = "(-?\d+\.?\d*|NR)?([\*#x]|NoValue)?"
    df_value_mark = s.astype(str).str.extract(regex, expand=False)

    df_value = df_value_mark.iloc[:, 0].unstack(["station", "item"])
    df_mark = df_value_mark.iloc[:, 1].unstack(["station", "item"])

    return df_value, df_mark


def extract_features(df, main_feature="PM10"):
Ejemplo n.º 2
0
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import time
import importlib
from inspect import isclass
from functools import wraps

from epa import logging

logger = logging.get_logger(__name__)


class ClassNotFoundError(Exception):
    """Class not found in module"""
    def __init__(self, module_name, class_name):
        self.module_name = module_name
        self.class_name = class_name


def get_class_with_name(module_name, class_name):
    module = importlib.import_module(module_name)
    attrs = [a for a in dir(module) if not a.startswith("__")]
    for attr in attrs:
        x = getattr(module, attr)
        if isclass(x) and x.__name__ == class_name:
            return x
    raise ClassNotFoundError(module_name, class_name)


def timer(f):