Skip to content
Snippets Groups Projects
Commit ca5203c0 authored by Peter Morstein's avatar Peter Morstein
Browse files

build average range

parent 436af1bb
No related branches found
No related tags found
No related merge requests found
......@@ -2,6 +2,7 @@ import configparser
import psycopg2
from psycopg2 import sql
import numpy as np
cfg = configparser.ConfigParser()
cfg.read('../config.ini')
......@@ -92,3 +93,15 @@ def get_interpolation_data_for_point(lat, lon, columns, cursor):
# get_average_data_for_point(52.5, 13.4)
def calcAverageYear(stationList, fromYear, toYear):
dateRange = np.arange(fromYear, toYear+1)
dateRangeRegex = "|".join(np.char.mod('%d', dateRange))
stationListDate = stationList.filter(regex=dateRangeRegex)
stationList["anomalie"] = stationListDate.mean(axis=1)
stationList = stationList.dropna(axis=0, subset=['anomalie'])
return stationList
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Mon Sep 27 20:06:22 2021
@author: geopeter
"""
import SQLPandasTools as s2pTool
import GetAverageData as cut
import unittest
import pickle
class Testapi(unittest.TestCase):
def testcalcAverageYear(self):
with open("./pickle/fetchall.pickle", "rb") as pickleFile:
sqlResult = pickle.load(pickleFile)
stationList = s2pTool.sqlToGeoPandas(sqlResult)
stationList = cut.calcAverageYear(stationList, 1961, 1990)
for id, item in stationList.iterrows():
self.assertTrue(type(item["anomalie"]) == float)
if __name__ == '__main__':
unittest.main()
\ No newline at end of file
......@@ -5,7 +5,7 @@ import unittest
import pickle
class Testapi(unittest.TestCase):
def _testSqlToGeoPandas(self):
def testSqlToGeoPandas(self):
with open("./pickle/fetchall.pickle", "rb") as pickleFile:
sqlResult = pickle.load(pickleFile)
......@@ -28,7 +28,7 @@ class Testapi(unittest.TestCase):
self.assertTrue(annualMean[len(annualMean)-5]['date']>=2000)
self.assertTrue(annualMean[len(annualMean)-5]['value']>=2)
def _testDetermineAnnualMeanWithList(self):
def testDetermineAnnualMeanWithList(self):
with open("./pickle/fetchall.pickle", "rb") as pickleFile:
stationList = pickle.load(pickleFile)
......
......@@ -21,7 +21,7 @@ with psycopg2.connect(database=db_name, user=user, password=pw, host=param_postg
row_array = []
for i, station_id in enumerate(results):
if i % 36 == 0:
row_array.append(results[i + j][1])
row_array.append(results[i + j][1])
# print(row_array)
pixel_array.append(row_array)
np_pixel_array = np.array(pixel_array)
......
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