Skip to content

Commit

Permalink
fix: some small fixes to read tif files
Browse files Browse the repository at this point in the history
changes: made CWaTM to run as library inside calibration tool
  • Loading branch information
PeterBurek committed Oct 8, 2021
1 parent 90ea7ea commit 6ab622b
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
2 changes: 1 addition & 1 deletion cwatm/hydrological_modules/readmeteo.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Author: PB
#
# Created: 13/07/2016
# Copyright: (c) PB 2016
# Copyright: (c) PB 201664
# -------------------------------------------------------------------------

from cwatm.management_modules.data_handling import *
Expand Down
20 changes: 12 additions & 8 deletions cwatm/management_modules/data_handling.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,12 @@ def setmaskmapAttr(x,y,col,row,cell):
if (x-int(x)) != 0.:
if abs(x - int(x)) > 1e9:
x = 1/round(1/(x-int(x)),4) + int(x)
else: x = round(x,4)
else: x = round(x,6)
if (y - int(y)) != 0.:
if abs(y - int(y)) > 1e9:
y = 1 / round(1 / (y - int(y)), 4) + int(y)
else: y = round(y,4)
else: y = round(y,6)
# This is still not ok! Some rounding issues still appear sometimes

maskmapAttr['x'] = x
maskmapAttr['y'] = y
Expand Down Expand Up @@ -694,8 +695,11 @@ def mapattrNetCDF(name, check=True):

xx = maskmapAttr['x']
yy = maskmapAttr['y']
cut0 = int(0.0001 + np.abs(xx - lon) * invcell) # argmin() ??
cut2 = int(0.0001 + np.abs(yy - lat) * invcell)
#cut0 = int(0.0001 + np.abs(xx - lon) * invcell) # argmin() ??
#cut2 = int(0.0001 + np.abs(yy - lat) * invcell) #
cut0 = int(np.abs(xx + maskmapAttr['cell']/2 - lon) * invcell) # argmin() ??
cut2 = int(np.abs(yy - maskmapAttr['cell']/2 - lat) * invcell) #


cut1 = cut0 + maskmapAttr['col']
cut3 = cut2 + maskmapAttr['row']
Expand Down Expand Up @@ -779,7 +783,7 @@ def mapattrTiff(nf2):
cellSize = geotransform[1]

#invcell = round(1/cellSize,0)
if cellSize > 0:
if cellSize > 1:
invcell = 1 / cellSize
else:
invcell = round(1/cellSize,0)
Expand Down Expand Up @@ -846,14 +850,14 @@ def multinetdf(meteomaps, startcheck = 'dateBegin'):
except:
datediv = 1

datestart = num2date(nctime[0] ,units=nctime.units,calendar=nctime.calendar)
datestart = num2date(nctime[:][0] ,units=nctime.units,calendar=nctime.calendar)

# sometime daily records have a strange hour to start with -> it is changed to 0:00 to haqve the same record
datestart = datestart.replace(hour=0, minute=0)
dateend = num2date(nctime[-1], units=nctime.units, calendar=nctime.calendar)
dateend = num2date(nctime[:][-1], units=nctime.units, calendar=nctime.calendar)

datestartint = int(nctime[0]) // datediv
dateendint = int(nctime[-1]) // datediv
dateendint = int(nctime[:][-1]) // datediv

dateend = dateend.replace(hour=0, minute=0)
#if dateVar['leapYear'] > 0:
Expand Down

0 comments on commit 6ab622b

Please sign in to comment.