def pronostico_normal(data,dirFestivos,dataMet,estacion,contaminant,dirData,dirTrain):
    data = data.reset_index(drop=True)
    data = separateDate(data)
    data = totalUnionData(data, dirFestivos)
    data = df.concat([data, dataMet], axis=1, join='inner')
    #data =  data.merge(dataMet, how='left', on='fecha')
    data = filterData(data, dirData + estacion + "_" + contaminant + ".csv")
    data = data.fillna(value=-1)
    index = data.index.values
    arrayPred = []
    for x in index:
        pred = data.ix[x].values
        valPred = pred[2:]
        valNorm = pre.normalize(valPred, estacion, contaminant, dirData)
        arrayPred.append(convert(valNorm))
    result = pre.prediction(estacion, contaminant, arrayPred, dirTrain, dirData)
    columnContaminant = findTable2(contaminant)
    real = pre.desNorm(result, estacion, contaminant, dirData, columnContaminant+ '_')
    for xs in range(len(real)):
        fechaPronostico = data['fecha'].iloc[xs].values
        fechaPronostico = datetime.strptime(fechaPronostico[1], '%Y-%m-%d %H:%M:%S')
        fechaPronostico = fechaPronostico - timedelta(days=1)
        pronostico = real[xs]
        guardarPrediccion(estacion, fechaPronostico, [pronostico],contaminant,2)
    return 1
def forecast_month(month, year, dirData, dirTotalCsv, dirTrain,estacion, contaminant):
    lastDay = calendar.monthrange(year,month)[1]
    fechaInicio =  str(year) + '-' + numString(month) + '-01 00:00:00'
    fechaFinal = str(year) + '-' + numString(month) + '-'+ numString(lastDay) +' 23:00:00'
    #print(fechaInicio)
    #print(fechaFinal)
    data = fd.readData(fechaInicio, fechaFinal, [estacion], contaminant)
    data = separateDate(data)
    data = unionMeteorologia(data,dirTotalCsv)
    data = data.fillna(value=-1)
    #print(data)
    #sys.out
    frame_dates = data['fecha'].values
    data =  filterData(data, dirData + estacion + "_" + contaminant + ".csv")
    data = data.fillna(value=-1)
    index = data.index.values
    arrayPred = []
    for x in index:
        pred = data.ix[x].values
        valPred= pred[1:]
        valNorm = pre.normalize(valPred,estacion, contaminant, dirData)
        arrayPred.append(convert(valNorm))
    result = pre.prediction(estacion, contaminant, arrayPred, dirTrain, dirData)
    nameCont = findTable2(contaminant)
    real = pre.desNorm(result, estacion,contaminant, dirData, nameCont + '_')
    for xs in range(len(frame_dates)):
        fecha = frame_dates[xs]
        ts = df.to_datetime(str(fecha))
        fecha_string = ts.strftime('%Y-%m-%d %H:%M:%S')
        pronostico = real[xs]
        guardarPrediccion(estacion, fecha_string,[pronostico],contaminant,4)
Esempio n. 3
0
def prediccion(estacion, data, dirData, dirTrain, contaminant):
    """
    function that sends the data to the neural network for the prediction of the pollutant

    :param estacion: name the station
    :type estacion: String
    :param data: information for the prediction
    :type data : list float32
    :param dirData: address of the files with training information
    :type dirData: String
    :param dirTrain: address of the training files of the neural network
    :type dirTrain: String
    :return: prdiction values
    :type return : float32
    """
    temp = data.ix[0].values
    temp = temp[1:]
    dataPred = pre.normalize(temp, estacion, contaminant, dirData)
    dataPred = convert(dataPred)
    prediccion = pre.prediction(estacion, contaminant, [dataPred], dirTrain,
                                dirData)
    print(prediccion)
    columnContaminant = findTable2(contaminant)
    prediccion1 = pre.desNorm(prediccion, estacion, contaminant, dirData,
                              columnContaminant + '_')
    return prediccion1
Esempio n. 4
0
def dataCorrelacion(contaminant, estacion, fechaInicio, fechaFin, dataMet,
                    dirData, dirTrain, dirFestivos):
    print('COrrelacion')
    data_Corr = df.read_csv(
        '/media/storageBK/AirQualityForecast/Scripts/ContaminationForecast/Data/Correlacion_table.csv',
        index_col=0)
    corr_est = data_Corr[estacion].sort_values(ascending=False)
    estacion_corr = corr_est.index[1]
    data = fd.readData_corr(fechaInicio, fechaFin, [estacion_corr],
                            contaminant)
    if data.empty:
        useClimatology(contaminant, estacion, fechaUltima, fechaFin, dataMet,
                       dirData, dirTrain, dirFestivos)
    else:
        data = data.drop_duplicates(keep='first')
        data = data.reset_index(drop=True)
        index_values = data.columns.values[1:]
        for xs in index_values:
            data.rename(columns={
                xs: xs.replace(estacion_corr.lower(), estacion.lower())
            },
                        inplace=True)
        data = separateDate(data)
        data = totalUnionData(data, dirFestivos)
        data = df.concat([data, dataMet], axis=1, join='inner')
        print(data)
        #data =  data.merge(dataMet, how='left', on='fecha')
        data = filterData(data,
                          dirData + estacion + "_" + contaminant + ".csv")
        data = data.fillna(value=-1)
        index = data.index.values
        arrayPred = []
        for x in index:
            pred = data.ix[x].values
            valPred = pred[2:]
            print(valPred)
            valNorm = pre.normalize(valPred, estacion, contaminant, dirData)
            arrayPred.append(convert(valNorm))
        result = pre.prediction(estacion, contaminant, arrayPred, dirTrain,
                                dirData)
        columnContaminant = findTable2(contaminant)
        real = pre.desNorm(result, estacion, contaminant, dirData,
                           columnContaminant + '_')
        for xs in range(len(real)):
            fechaPronostico = data['fecha'].iloc[xs].values
            fechaPronostico = datetime.strptime(fechaPronostico[1],
                                                '%Y-%m-%d %H:%M:%S')
            pronostico = real[xs]
            guardarPrediccionRep(estacion, fechaPronostico, [pronostico],
                                 contaminant, 5)
Esempio n. 5
0
def useClimatology(contaminant, estacion, fechaInicio, fechaFinal, dataMet,
                   dirData, dirTrain, dirFestivos):
    """
    function to make the forecast using climatologies

    :param contaminant: name of the pollutant
    :type contaminant: String
    :param estacion: name of the weather station
    :type estacion: String
    :param fechaInicio: range of data wit wich the vaues of tue query are extracted
    :type fechaInicio: datetime
    :param fechaFinal: range of data wit wich the vaues of tue query are extracted
    :type fechaFinal: datetime
    :param dataMet: dataframe with the climatological information
    :type dataMet: DataFrame
    """
    data = fd.get_climatology(fechaInicio, fechaFinal, estacion)
    print(data)
    data = makeDates(fechaInicio, fechaFinal, data)
    #sys.out
    print(data)
    data = data.reset_index(drop=True)
    print(data)
    data = separateDate(data)
    data = totalUnionData(data, dirFestivos)
    data = df.concat([data, dataMet], axis=1, join='inner')
    #data = data.merge(dataMet, how='left', on='fecha')
    data = data.fillna(value=-1)
    data = filterData(data, dirData + estacion + "_" + contaminant + ".csv")
    data = data.fillna(value=-1)
    index = data.index.values
    arrayPred = []
    for x in index:
        pred = data.ix[x].values
        valPred = pred[2:]
        valNorm = pre.normalize(valPred, estacion, contaminant, dirData)
        arrayPred.append(convert(valNorm))
    result = pre.prediction(estacion, contaminant, arrayPred, dirTrain,
                            dirData)
    columnContaminant = findTable2(contaminant)
    real = pre.desNorm(result, estacion, contaminant, dirData,
                       columnContaminant + '_')
    fechaPronostico = fechaInicio
    for xs in real:
        print(fechaPronostico)
        fechaUpdate = fechaPronostico
        fechaUpdate = fechaUpdate - timedelta(days=1)
        guardarPrediccion(estacion, fechaUpdate, [xs], contaminant, 1)
        fechaPronostico = fechaPronostico + timedelta(hours=1)
    print('Climatologia:' + estacion)