Skip to content
Snippets Groups Projects
Commit ce312cf0 authored by Clemens Berteld's avatar Clemens Berteld
Browse files

Merge remote-tracking branch 'origin/master'

parents d7363fe0 e843614e
No related branches found
No related tags found
No related merge requests found
import configparser
import numpy as np
from psycopg2 import sql
import numpy as np
cfg = configparser.ConfigParser()
cfg.read('../config.ini')
......@@ -127,3 +128,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)
......
import configparser
import numpy as np
import psycopg2
import pandas as pd
from osgeo import gdal, osr
cfg = configparser.ConfigParser()
cfg.read('../config.ini')
assert "POSTGRES" in cfg, "missing POSTGRES in config.ini"
param_postgres = cfg["POSTGRES"]
param_interpol = cfg["INTERPOLATION"]
db_name, user, pw, host, port = param_postgres['dbName'], param_postgres["user"], param_postgres["password"], param_postgres["host"], param_postgres["port"]
with psycopg2.connect(database=db_name, user=user, password=pw, host=param_postgres["host"], port=port) as connection:
with connection.cursor() as cursor:
cursor.execute('SELECT station_id, "2018" FROM stations WHERE file IS NULL ORDER BY station_id ASC;')
pixel_array = []
pixel_array_alpha = []
results = cursor.fetchall()
for j in range(0, 36):
row_array = []
row_array_alpha = []
for i, station_id in enumerate(results):
if i % 36 == 0:
<<<<<<< HEAD
row_array.append(results[i + j][1])
=======
value = results[i + j][1]
row_array.append(value)
row_array_alpha.append(value)
np_row_array = np.array(row_array)
np_row_array_alpha = np.array(row_array_alpha)
np_row_array_alpha = np.where(np_row_array_alpha < 8, 0, 255)
>>>>>>> 94001e7882d184c3101f8663bc43b41ad9cb4e98
# print(row_array)
pixel_array.append(np_row_array)
pixel_array_alpha.append(np_row_array_alpha)
np_pixel_array = np.array(pixel_array)
np_pixel_array_alpha = np.array(pixel_array_alpha)
xmin, ymin, xmax, ymax = [5.01, 47.15, 14.81, 55.33]
nrows, ncols = np.shape(np_pixel_array)
xres = (xmax - xmin) / float(ncols)
yres = (ymax - ymin) / float(nrows)
geotransform = (xmin, xres, 0, ymax, 0, -yres)
output_raster = gdal.GetDriverByName('GTiff').Create('D:/Uni/Master/01_SS2021/Automatisierte_Geodatenprozessierung/temperaturverteilung/dataacquisition/output/myraster.tif', ncols, nrows, 4, gdal.GDT_Float32) # Open the file
output_raster.SetGeoTransform(geotransform)
srs = osr.SpatialReference()
srs.ImportFromEPSG(4326)
output_raster.SetProjection(srs.ExportToWkt())
output_raster.GetRasterBand(1).WriteArray(np_pixel_array)
# output_raster.GetRasterBand(2).WriteArray(np_pixel_array)
# output_raster.GetRasterBand(3).WriteArray(np_pixel_array)
output_raster.GetRasterBand(4).WriteArray(np_pixel_array_alpha)
output_raster.FlushCache()
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