Skip to content
Snippets Groups Projects
Commit 22c0ff59 authored by leufen1's avatar leufen1
Browse files

added automatic flip after check, missing values, check plot

parent e8461adf
No related branches found
No related tags found
2 merge requests!5New App; stable_night_lights,!2Resolve "TOPOGRAPHY: Correct missing value handling, add check plots, automatic data flip"
from django.test import TestCase
# Create your tests here.
from topography_file_extraction import read_proxydata
FILENAME = "greater_harz.tif"
read_proxydata(FILENAME)
......@@ -10,10 +10,7 @@ import numpy as np
import os
from toar_location_services.settings import DATA_DIR, DEBUG, USE_DUMMY_TOPOGRAPHY_TANDEM_DATA
from django.contrib.gis.gdal import GDALRaster
# import matplotlib.pyplot as plt
import matplotlib.pyplot as plt
def read_proxydata(filename, dummy=DEBUG and USE_DUMMY_TOPOGRAPHY_TANDEM_DATA):
......@@ -41,17 +38,27 @@ def read_proxydata(filename, dummy=DEBUG and USE_DUMMY_TOPOGRAPHY_TANDEM_DATA):
# rst.width*xscale + xmin == xmax
# construct data array and lonvec, latvec
data = rst.bands[0].data()
data = rst.bands[0].data().astype(np.float)
nodata_value = rst.bands[0].nodata_value
data[data == nodata_value] = np.nan
lonvec = np.linspace(xmin, xmax, cols)
latvec = np.linspace(ymin, ymax, rows)
# data are flipped, therefore reverse latitudes
# trick from http://stackoverflow.com/questions/6771428/most-efficient-way-to-reverse-a-numpy-array
latvec = np.fliplr(np.atleast_2d(latvec))[0]
# check if data is flipped
lat1 = lat0 + dlat * rows
if lat1 < lat0:
lat0, lat1 = lat1, lat0
latvec = np.flipud(latvec)
# set metadata
boundingbox = [lon0, latvec.min(), lonvec.max(), lat0]
if DEBUG:
plt.contourf(lonvec, latvec, data)
plt.savefig('../plots/topography.png')
plt.close()
#
datainfo = {'size': (rows, cols), 'resolution': (np.abs(dlon), np.abs(dlat)),
'boundingbox': boundingbox}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment