[GRASS-SVN] r38845 - in grass-addons/raster: . r.sun.tools
svn_grass at osgeo.org
svn_grass at osgeo.org
Mon Aug 24 08:02:49 EDT 2009
Author: hamish
Date: 2009-08-24 08:02:48 -0400 (Mon, 24 Aug 2009)
New Revision: 38845
Added:
grass-addons/raster/r.sun.tools/
grass-addons/raster/r.sun.tools/g.linke_by_day.py
Log:
little tool to interpolate Linke turbidity factor value for a given day of the year. Monthly values are stored as an internal array, you have to adjust that yourself for your local area
Added: grass-addons/raster/r.sun.tools/g.linke_by_day.py
===================================================================
--- grass-addons/raster/r.sun.tools/g.linke_by_day.py (rev 0)
+++ grass-addons/raster/r.sun.tools/g.linke_by_day.py 2009-08-24 12:02:48 UTC (rev 38845)
@@ -0,0 +1,73 @@
+#!/usr/bin/python
+############################################################################
+#
+# MODULE: g.linke_by_day.py
+#
+# AUTHOR(S): Hamish Bowman, Dunedin, New Zealand
+#
+# PURPOSE: Interpolate day of year into Linke turbidity value
+#
+# COPYRIGHT: (c) 2009 Hamish Bowman, and The GRASS Development Team
+#
+# This program is free software under the GNU General Public
+# License (>=v2). Read the file COPYING that comes with GRASS
+# for details.
+#
+############################################################################
+#
+# Requires Numeric module (NumPy) and SciPy from http://numpy.scipy.org/
+# (older versions only implement linear interpolation & will throw an error)
+# Assumes monthly value corresponds to the actual mid-month value
+#
+# USAGE: g.linke_by_day [day number (1-365)]
+#
+
+import sys
+
+if len(sys.argv) != 2:
+ print "USAGE: g.linke_by_day [day number (1-365)]"
+ sys.exit(1)
+else:
+ day = float(sys.argv[1])
+
+if day < 1 or day > 365:
+ print "USAGE: g.linke_by_day [day number (1-365)]"
+ sys.exit(1)
+
+
+def main():
+ import numpy
+ from scipy.interpolate import interpolate
+
+ ##### put monthly data here
+ linke_data = numpy.array ([1.5,1.6,1.8,1.9,2.0,2.3,2.3,2.3,2.1,1.8,1.6,1.5])
+ ####
+
+ linke_data_wrap = numpy.concatenate((linke_data[9:12],
+ linke_data,
+ linke_data[0:3]))
+
+ monthDays = numpy.array ([0,31,28,31,30,31,30,31,31,30,31,30,31])
+ #init empty
+ midmonth_day = numpy.array ([0,0,0,0,0,0,0,0,0,0,0,0])
+ for i in range(1, 12+1):
+ midmonth_day[i-1] = 15 + sum(monthDays[0:i])
+
+ midmonth_day_wrap = numpy.concatenate((midmonth_day[9:12]-365, \
+ midmonth_day,
+ midmonth_day[0:3]+365))
+
+ interp_type = 'cubic' # 'linear'
+
+ linke = interpolate.interp1d(midmonth_day_wrap,
+ linke_data_wrap,
+ kind=interp_type)
+ # print data for full year:
+ #for i in range(1,365+1):
+ # print("%d %.4f" % (i, linke(i)) )
+
+ print("%.4f" % linke(day) )
+
+
+if __name__ == "__main__":
+ main()
Property changes on: grass-addons/raster/r.sun.tools/g.linke_by_day.py
___________________________________________________________________
Added: svn:executable
+ *
Added: svn:mime-type
+ text/x-python
Added: svn:eol-style
+ native
More information about the grass-commit
mailing list