Exemple #1
0
def _view(filename):
    """
    Plot the data contained in the BIL file.
    @requires: I{Matplotlib} module
    """
    try:
        import matplotlib.pyplot as plt
        from pysenorge.grid import senorge_mask

        mask = senorge_mask()
        imask = mask == False

        bd = BILdata(filename)
        bd.read()
        data = float32(bd.data)
        data[mask] = nan

        # Set class values and colors
        colors = ("lightgrey", "g", "b", "m", "r")  # class colors
        convalues = [-1, 0, 1, 2, 3, 4]  # contour values
        labvalues = [-0.5, 0.5, 1.5, 2.5, 3.5]  # label values
        labels = [
            "not classified", "unchanged", "increase", "decrease",
            "drastic decrease"
        ]

        plt.figure(facecolor='lightgrey')
        plt.contourf(data, convalues, colors=colors)
        cb = plt.colorbar()
        cb.set_ticks(labvalues)
        cb.set_ticklabels(labels)
        plt.show()

    except ImportError:
        print '''Required plotting module "matplotlib" not found!\nVisit www.matplotlib.sf.net'''
def _view(filename):
    """
    Plot the data contained in the BIL file.
    @requires: I{Matplotlib} module
    """
    try:
        import matplotlib.pyplot as plt
        from pysenorge.grid import senorge_mask
        
        mask = senorge_mask()
        imask = mask==False

        bd = BILdata(filename)
        bd.read()
        data = float32(bd.data)
        data[mask] = nan
        
        # Set class values and colors
        colors = ("lightgrey", "g", "b", "m", "r") # class colors
        convalues = [-1,0,1,2,3,4] # contour values
        labvalues = [-0.5, 0.5, 1.5, 2.5, 3.5] # label values
        labels = ["not classified", "unchanged", "increase", "decrease", "drastic decrease"]
        
        plt.figure(facecolor='lightgrey')
        plt.contourf(data, convalues, colors=colors)
        cb = plt.colorbar()
        cb.set_ticks(labvalues)
        cb.set_ticklabels(labels)
        plt.show()
        
    except ImportError:
        print '''Required plotting module "matplotlib" not found!\nVisit www.matplotlib.sf.net'''
Exemple #3
0
def BIL2netCDF(BILfile, BILdtype='uint16', outdir=os.getcwd(), theme_name='undefined',
               theme_unit='undefined', long_name='undefined'):
    '''
    Convenience function converting the given BIL file to netCDF.
    
    @param BILfile: Input BIl file.
    @param outdir: Output directory.
    @param theme_name: Short name for the theme.   
    @param theme_unit: Metric unit of the theme data.
    @param long_name: Descriptive name for the theme. 
    
    @return: netCDF file in the output directory.
    '''
    ncfilename = os.path.splitext(os.path.basename(BILfile))[0] + '.nc'
    bd = BILdata(BILfile, BILdtype)
    bd.read()
    yy, mm, dd = "13", "09", "11"
    tstring = yy+'-'+mm+'-'+dd+' 06:00:00'
    secs = date2num(iso2datetime(tstring), timeunit)
    mask = flipud(senorge_mask())
    ncdata = flipud(int16(bd.data)) # array needs to be flipped ud-down and transposed to fit the coordinate system
    ncdata[mask] = get_FillValue(ncdata.dtype)
    ncfile = NCdata(os.path.join(outdir, ncfilename))
#    ncfile.zip = True
    ncfile.new(secs)
    print ncdata.dtype.str
    ncfile.add_variable(theme_name, ncdata.dtype.str, theme_unit,
                        long_name, ncdata, lsd=1)
    ncfile.close()
Exemple #4
0
def BIL2PNG(BILfile, BILdtype='uint16', CLTfile=None, outdir=os.getcwd()):

    bd = BILdata(BILfile, BILdtype)
    bd.read()

    wdata = float32(flipud(bd.data)) * 0.1
    print wdata.shape

    # Write to PNG file
    writePNG(wdata, "/home/ralf/Dokumente/summerjob/data/test", CLTfile)
Exemple #5
0
def BIL2PNG(BILfile, BILdtype='uint16', CLTfile=None, outdir=os.getcwd()):
   
    bd = BILdata(BILfile, BILdtype)
    bd.read()
 
    wdata = float32(flipud(bd.data))*0.1
    print wdata.shape
    
    # Write to PNG file
    writePNG(wdata,"/home/ralf/Dokumente/summerjob/data/test", CLTfile)
Exemple #6
0
    def testName(self):
        # Create an array
#        A = arange(1852250, dtype=uint16)
        A = ones((1550,1195), dtype=uint16)
        print A
        
        # Store it in .bil format
        bd = BILdata("tmp_test.bil")
#        bd.set_dimension(4,3)
        bd.write(A)
        print bd.datatype
        
        # Open .bil file
        bdo = BILdata("tmp_test.bil")
#        bdo.set_dimension(4,3)
        bdo.read()
        print bdo.data
        # Assert if data from bil file is equal to the inital array
        self.assertEqual(A.all, bdo.data.all, "Not equal")
Exemple #7
0
def BIL2PNG(BILfile, BILdtype='uint16', CLTfile=None, outdir=os.getcwd()):
    '''
    Convenience function converting the given BIL file to PNG.
    
    @param BILfile: Input BIl file.
    @param outdir: Output directory.
    @param theme_name: Short name for the theme.   
    @param theme_unit: Metric unit of the theme data.
    @param long_name: Descriptive name for the theme. 
    
    @return: PNG file in the output directory.
    '''
    bd = BILdata(BILfile, BILdtype)
    bd.read()
 
    wdata = float32(flipud(bd.data))*0.1
    print wdata.shape
    # Write to PNG file
    writePNG(wdata,"/home/ralf/Dokumente/summerjob/data/test", CLTfile)
Exemple #8
0
    def testName(self):
        # Create an array
        #        A = arange(1852250, dtype=uint16)
        A = ones((1550, 1195), dtype=uint16)
        print A

        # Store it in .bil format
        bd = BILdata("tmp_test.bil")
        #        bd.set_dimension(4,3)
        bd.write(A)
        print bd.datatype

        # Open .bil file
        bdo = BILdata("tmp_test.bil")
        #        bdo.set_dimension(4,3)
        bdo.read()
        print bdo.data
        # Assert if data from bil file is equal to the inital array
        self.assertEqual(A.all, bdo.data.all, "Not equal")
Exemple #9
0
def BIL2PNG(BILfile, BILdtype='uint16', CLTfile=None, outdir=os.getcwd()):
    '''
    Convenience function converting the given BIL file to PNG.
    
    @param BILfile: Input BIl file.
    @param outdir: Output directory.
    @param theme_name: Short name for the theme.   
    @param theme_unit: Metric unit of the theme data.
    @param long_name: Descriptive name for the theme. 
    
    @return: PNG file in the output directory.
    '''
    bd = BILdata(BILfile, BILdtype)
    bd.read()
    #    bd._view()
    #    bd._hist()

    outfile = os.path.splitext(BILfile)[0]

    wdata = flipud(bd.data)
    # Write to PNG file
    writePNG(wdata, os.path.join(outdir, outfile), CLTfile)
Exemple #10
0
def BIL2netCDF(BILfile,
               BILdtype='uint16',
               outdir=os.getcwd(),
               theme_name='undefined',
               theme_unit='undefined',
               long_name='undefined'):
    '''
    Convenience function converting the given BIL file to netCDF.
    
    @param BILfile: Input BIl file.
    @param outdir: Output directory.
    @param theme_name: Short name for the theme.   
    @param theme_unit: Metric unit of the theme data.
    @param long_name: Descriptive name for the theme. 
    
    @return: netCDF file in the output directory.
    '''
    ncfilename = os.path.splitext(os.path.basename(BILfile))[0] + '.nc'
    bd = BILdata(BILfile, BILdtype)
    bd.read()
    yy, mm, dd = "13", "09", "11"
    tstring = yy + '-' + mm + '-' + dd + ' 06:00:00'
    secs = date2num(iso2datetime(tstring), timeunit)
    mask = flipud(senorge_mask())
    ncdata = flipud(
        int16(bd.data)
    )  # array needs to be flipped ud-down and transposed to fit the coordinate system
    ncdata[mask] = get_FillValue(ncdata.dtype)
    ncfile = NCdata(os.path.join(outdir, ncfilename))
    #    ncfile.zip = True
    ncfile.new(secs)
    print ncdata.dtype.str
    ncfile.add_variable(theme_name,
                        ncdata.dtype.str,
                        theme_unit,
                        long_name,
                        ncdata,
                        lsd=1)
    ncfile.close()
Exemple #11
0
def BIL2PNG(BILfile, BILdtype='uint16', CLTfile=None, outdir=os.getcwd()):
    '''
    Convenience function converting the given BIL file to PNG.
    
    @param BILfile: Input BIl file.
    @param outdir: Output directory.
    @param theme_name: Short name for the theme.   
    @param theme_unit: Metric unit of the theme data.
    @param long_name: Descriptive name for the theme. 
    
    @return: PNG file in the output directory.
    '''
    bd = BILdata(BILfile, BILdtype)
    bd.read()
#    bd._view()
#    bd._hist()
    
    outfile = os.path.splitext(BILfile)[0]
    
    wdata = flipud(bd.data)
    # Write to PNG file
    writePNG(wdata, os.path.join(outdir, outfile), CLTfile)
def main():
    '''
    Loads and verifies input data, calls the model, and controls the output stream. 
    '''
    # Theme variables
    themedir = 'tmgr'
    themename = 'Temperature gradient last 24h'

    # Setup input parser
    usage = "usage: python //~HOME/pysenorge/themes/temperature_gradient_daily.py tm_TODAY.bil tm_YESTERDAY.bil [options]"

    parser = OptionParser(usage=usage)
    parser.add_option("-o",
                      "--outdir",
                      action="store",
                      dest="outdir",
                      type="string",
                      metavar="DIR",
                      default=os.path.join(BILout, themedir),
                      help="Output directory - default: $BILout/%s/$YEAR" %
                      themedir)
    parser.add_option("--no-bil",
                      action="store_false",
                      dest="bil",
                      default=True,
                      help="Set to suppress output in BIL format")
    parser.add_option("--nc",
                      action="store_true",
                      dest="nc",
                      default=False,
                      help="Set to store output in netCDF format")
    parser.add_option("--png",
                      action="store_true",
                      dest="png",
                      default=False,
                      help="Set to store output as PNG image")
    # Comment to suppress help
    parser.print_help()

    (options, args) = parser.parse_args()

    yy, mm, dd = get_date_filename(args[0])
    yy_range = arange(1950, 2050)

    # Verify input parameters
    if int(yy) not in yy_range:
        parser.error("Could not determine year from file name.")

    if len(args) != 2:
        parser.error("Please provide two input files!")
        parser.print_help()
    else:
        # Add full path to the filename
        todaysfile = os.path.join(METdir, "tm", yy, args[0])
        yesterdaysfile = os.path.join(METdir, "tm", yy, args[1])

    if not os.path.exists(
            todaysfile):  # and os.path.isfile(options.todaysfile):
        parser.error(
            "BIL file containing todays temperature data does not exist!")
    elif not os.path.exists(
            yesterdaysfile):  # and os.path.isfile(options.todaysfile):
        parser.error(
            "BIL file containing yesterdays temperature data does not exist!")
    else:
        # Load todays data
        today = BILdata(todaysfile, 'uint16')
        today.read()
        # Load yesterdays data
        yesterday = BILdata(yesterdaysfile, 'uint16')
        yesterday.read()

    # Setup outputs
    outfile = themedir + '_' + yy + '_' + mm + '_' + dd
    tstring = yy + '-' + mm + '-' + dd + ' 06:00:00'
    if options.nc:
        secs = date2epoch(tstring)  # used in NCdata.new()
    outdir = os.path.join(options.outdir, yy)
    if not os.path.exists(outdir):
        if not os.path.exists(options.outdir):
            os.chdir(BILout)
            os.system('mkdir %s' % themedir)
        os.chdir(options.outdir)
        os.system('mkdir %s' % yy)


#    # Calculate temperature gradient
    tmgr = int16(model(float32(today.data), float32(yesterday.data)))

    # Set no-data values to IntFillValue
    mask = senorge_mask()
    imask = mask == False
    tmgr[mask] = IntFillValue

    if options.bil:
        # Write to BIL file
        bilfile = BILdata(os.path.join(outdir, outfile + '.bil'),
                          datatype='int16')
        biltext = bilfile.write(tmgr)
        print biltext

    if options.nc:
        from pysenorge.io.nc import NCdata  #@UnresolvedImport
        # Prepare data
        nctmgr = int2float(tmgr)
        imask = mask == False
        # Convert to Celcius/Kelvin
        nctmgr[imask] = nctmgr[imask] / 10.0
        # Change array order
        nctmgr = flipud(nctmgr)
        # Write to NC file
        ncfile = NCdata(os.path.join(outdir, outfile + '.nc'))
        ncfile.zip = True
        ncfile.new(secs)
        ncfile.add_variable(themedir, nctmgr.dtype.str, "K s-1", themename,
                            nctmgr)
        ncfile.close()

    if options.png:
        from pysenorge.io.png import writePNG  #@UnresolvedImport
        # Write to PNG file
        writePNG(tmgr, os.path.join(outdir, outfile))
    # At last - cross fingers it all worked out!
    print "\n*** Finished successfully ***\n"
def main():
    '''
    Loads and verifies input data, calls the model, and controls the output stream. 
    '''
    # Theme variables
    themedir = 'tmgr'
    themename = 'Temperature gradient last 24h'
    
    # Setup input parser
    usage = "usage: python //~HOME/pysenorge/themes/temperature_gradient_daily.py tm_TODAY.bil tm_YESTERDAY.bil [options]"
    
    parser = OptionParser(usage=usage)
    parser.add_option("-o", "--outdir", 
                      action="store", dest="outdir", type="string",
                      metavar="DIR", default=os.path.join(BILout, themedir),
                      help="Output directory - default: $BILout/%s/$YEAR" % themedir)
    parser.add_option("--no-bil",
                  action="store_false", dest="bil", default=True,
                  help="Set to suppress output in BIL format")
    parser.add_option("--nc",
                  action="store_true", dest="nc", default=False,
                  help="Set to store output in netCDF format")
    parser.add_option("--png",
                  action="store_true", dest="png", default=False,
                  help="Set to store output as PNG image")
    # Comment to suppress help
    parser.print_help()

    (options, args) = parser.parse_args()
    
    yy, mm, dd = get_date_filename(args[0])
    yy_range = arange(1950, 2050)
    
    # Verify input parameters
    if int(yy) not in yy_range:
        parser.error("Could not determine year from file name.")
    
    if len(args) != 2:
        parser.error("Please provide two input files!")
        parser.print_help() 
    else:
        # Add full path to the filename
        todaysfile = os.path.join(METdir, "tm", yy, args[0])
        yesterdaysfile = os.path.join(METdir, "tm", yy, args[1])
        
    
    if not os.path.exists(todaysfile):# and os.path.isfile(options.todaysfile):
        parser.error("BIL file containing todays temperature data does not exist!")
    elif not os.path.exists(yesterdaysfile):# and os.path.isfile(options.todaysfile):
        parser.error("BIL file containing yesterdays temperature data does not exist!")
    else:
        # Load todays data
        today = BILdata(todaysfile, 'uint16')
        today.read()
        # Load yesterdays data 
        yesterday = BILdata(yesterdaysfile, 'uint16')
        yesterday.read()
    
    
    # Setup outputs
    outfile = themedir+'_'+yy+'_'+mm+'_'+dd
    tstring = yy+'-'+mm+'-'+dd+' 06:00:00'
    if options.nc:
        secs = date2epoch(tstring) # used in NCdata.new()
    outdir = os.path.join(options.outdir, yy)
    if not os.path.exists(outdir):
        if not os.path.exists(options.outdir):
            os.chdir(BILout)
            os.system('mkdir %s' % themedir)
        os.chdir(options.outdir)
        os.system('mkdir %s' % yy)
    
    
#    # Calculate temperature gradient    
    tmgr = int16(model(float32(today.data), float32(yesterday.data)))
    
    # Set no-data values to IntFillValue
    mask = senorge_mask()
    imask = mask==False
    tmgr[mask] = IntFillValue
    
    if options.bil:
        # Write to BIL file
        bilfile = BILdata(os.path.join(outdir, outfile+'.bil'), datatype='int16')
        biltext = bilfile.write(tmgr)
        print biltext
    
    if options.nc:
        from pysenorge.io.nc import NCdata #@UnresolvedImport
        # Prepare data
        nctmgr = int2float(tmgr)
        imask = mask == False
        # Convert to Celcius/Kelvin
        nctmgr[imask] = nctmgr[imask]/10.0
        # Change array order 
        nctmgr = flipud(nctmgr)
        # Write to NC file
        ncfile = NCdata(os.path.join(outdir, outfile+'.nc'))
        ncfile.zip = True
        ncfile.new(secs)
        ncfile.add_variable(themedir, nctmgr.dtype.str, "K s-1", themename, nctmgr)
        ncfile.close()
    
    if options.png:
        from pysenorge.io.png import writePNG #@UnresolvedImport
        # Write to PNG file
        writePNG(tmgr, os.path.join(outdir, outfile))
    # At last - cross fingers it all worked out!
    print "\n*** Finished successfully ***\n"
Exemple #14
0
def main():
    '''
    Loads and verifies input data, calls the model, and controls the output stream. 
    
    Command line usage::
    
        python //~HOME/pysenorge/themes/additional_snow_depth_wind.py YYYY-MM-DD [options]
    '''
    # Theme variables
    themedir = 'additional_snow_depth'
    themename = ''
    
    # Setup input parser
    usage = "usage: python //~HOME/pysenorge/themes/additional_snow_depth.py YYYY-MM-DD [options]"
    
    parser = OptionParser(usage=usage)
    parser.add_option("-o", "--outdir", 
                      action="store", dest="outdir", type="string",
                      metavar="DIR", default=os.path.join(BILout, themedir),
                      help="Output directory - default: $BILout/%s/$HYDROYEAR" % \
                      themedir)
    parser.add_option("--no-bil",
                  action="store_false", dest="bil", default=True,
                  help="Set to suppress output in BIL format")
    parser.add_option("--nc",
                  action="store_true", dest="nc", default=False,
                  help="Set to store output in netCDF format")
    parser.add_option("--png",
                  action="store_true", dest="png", default=False,
                  help="Set to store output as PNG image")
    # Comment to suppress help
#    parser.print_help()

    (options, args) = parser.parse_args()
    
    if len(args) != 1:
        parser.error("Please provide the date in ISO format YYYY-MM-DD!")
        parser.print_help() 
    
    # get current datetime
    cdt = iso2datetime(args[0]+" 06:00:00")
    windfilename = "wind_speed_avg_10m_%s.bil" % datetime2BILdate(cdt)
    
    # Add full path to the filename
    windfile = os.path.join(BILout, "wind_speed_avg_10m", str(get_hydroyear(cdt)),
                            windfilename)
    if not os.path.exists(windfile):
        parser.error("BIL file %s containing wind data does not exist!" %\
                     windfile)
    else:
        # Load todays data
        wind = BILdata(windfile, 'uint16')
        wind.read()
        # convert to Celsius
        wind.data = float32(wind.data)*0.1
    
    sdfilename = "sdfsw_%s.bil" % datetime2BILdate(cdt)
    sdfile = os.path.join(BILout, "sdfsw", str(get_hydroyear(cdt)), sdfilename)
        
    if not os.path.exists(sdfile):
        parser.error("BIL file %s containing snow-depth data does not exist!" %\
                     sdfile)
    else:
        sd = BILdata(sdfile, 'uint16')
        sd.read()
        
    agefilename = "age_%s.bil" % datetime2BILdate(cdt)
    agefile = os.path.join(BILout, "age", str(get_hydroyear(cdt)), agefilename)
        
    if not os.path.exists(agefile):
        parser.error("BIL file %s containing snow-age data does not exist!" %\
                     agefile)
    else:
        age = BILdata(agefile, 'uint8')
        age.read()
    
    lwcfilename = "lwc_%s.bil" % datetime2BILdate(cdt)
    lwcfile = os.path.join(BILout, "lwc", str(get_hydroyear(cdt)), lwcfilename)
        
    if not os.path.exists(lwcfile):
        parser.error("BIL file %s containing snow-LWC data does not exist!" %\
                     lwcfile)
    else:
        lwc = BILdata(lwcfile, 'uint8')
        lwc.read()
#    from pysenorge.tools.show_histogram import Histogram
#    Histogram(sd.data, R=(0, 2000))
    
    # Setup outputs
    outfile = themedir+'_'+datetime2BILdate(cdt)
    outdir = os.path.join(options.outdir, str(get_hydroyear(cdt)))
    if not os.path.exists(outdir):
        if not os.path.exists(options.outdir):
            os.chdir(BILout)
            os.system('mkdir %s' % themedir)
        os.chdir(options.outdir)
        os.system('mkdir %s' % str(get_hydroyear(cdt)))
        
    
    # Calculate additional snow depth due to wind
    #Hwind = __model(wind.data, sd.data)
    Hwind = model(wind.data, sd.data, lwc.data, age.data)
    # Set no-data values to UintFillValue
    mask = senorge_mask()
    Hwind[mask] = UintFillValue
    
    
    if options.bil:
        # Write to BIL file
        bilfile = BILdata(os.path.join(outdir, outfile+'.bil'),
                          datatype='uint16')
        Hwind = uint16(Hwind*1000)
        Hwind[mask] = UintFillValue
        
#        import pylab
#        pylab.imshow(Hwind, vmin=0, vmax=300, cmap=pylab.cm.gist_stern)
#        pylab.colorbar()
#        pylab.show()
        
#        from pysenorge.tools.show_histogram import Histogram
#        Histogram(Hwind, R=(0, 500))
        
        biltext = bilfile.write(Hwind)
        print biltext
    
    if options.nc:
        from pysenorge.io.nc import NCdata
        # Prepare data
        # Change array order 
        ncHwind = flipud(Hwind)
        # Write to NC file
        ncfile = NCdata(os.path.join(outdir, outfile+'.nc'))
        ncfile.zip = True
#        secs = date2num(cdt, timeunit) # used in NCdata.new()
#        ncfile.new(secs)
        ncfile.add_variable(themedir, ncHwind.dtype.str, "m",
                            themename, ncHwind)
        ncfile.close()
    
    if options.png:
        from pysenorge.io.png import writePNG
        # Write to PNG file
        writePNG(flipud(Hwind), os.path.join(outdir, outfile),
                 cltfile=os.path.join(BILout, themedir, "Hwind.clt")
                 )
        
    # At last - cross fingers it all worked out!
    print "\n*** Finished successfully ***\n"
def main():
    '''
    Loads and verifies input data, calls the model, and controls the output stream. 
    '''
    # Theme variables
    themedir  = 'ssttm'
    themename = 'Snow stability index (temperature)'
    
    # Setup input parser
    usage = "usage: python //~HOME/pysenorge/themes/temperature_stability_index.py tm_DATE.bil tmgr_DATE.bil [options]"
    
    parser = OptionParser(usage=usage)
    parser.add_option("-o", "--outdir", 
                      action="store", dest="outdir", type="string",
                      metavar="DIR", default=os.path.join(netCDFout, themedir),
                      help="Output directory - default: $netCDFout/%s/$YEAR" % themedir)
    parser.add_option("--no-bil",
                  action="store_false", dest="bil", default=True,
                  help="Set to suppress output in BIL format")
    
    # Comment to suppress help
#    parser.print_help()

    (options, args) = parser.parse_args()
        
    # Verify input parameters
    if len(args) != 2:
        parser.print_help()
        parser.error("Please provide two input files!")
    else:
        yy, mm, dd = get_date_filename(args[0])
        yy_range = arange(1950, 2050)
        if int(yy) not in yy_range:
            parser.error("Could not determine year from file name.")
        # Add full path to the filename
        tmfile = os.path.join(METdir, "tm", yy, args[0])
        tmgrfile = os.path.join(BILout, "tmgr", yy, args[1])
        
    if not os.path.exists(tmfile):
        parser.print_help()
        parser.error("BIL file containing temperatures does not exist!")
    elif not os.path.exists(tmgrfile):
        parser.print_help()
        parser.error("BIL file containing temperature gradients does not exist!")
    else:
        # Load tm data
        tm = BILdata(tmfile)
        tm.read()
        # Load tmgr data 
        tmgr = BILdata(tmgrfile, int16)
        tmgr.read()
    
    
    # Setup outputs
    outfile = themedir+'_'+yy+'_'+mm+'_'+dd
    tstring = yy+'-'+mm+'-'+dd+' 06:00:00'
    outdir = os.path.join(options.outdir, yy)
    if not os.path.exists(outdir):
        if not os.path.exists(options.outdir):
            os.chdir(netCDFout)
            os.system('mkdir %s' % themedir)
        os.chdir(options.outdir)
        os.system('mkdir %s' % yy)
    
    # Convert tm to Celsius
    ftm = (float32(tm.data)-2731) * 0.1
    mask = senorge_mask()
    imask = mask==False
    print ftm[imask].min(), ftm[imask].max()
    # Convert tmgr to Celsius
    print tmgr.data[imask].min(), tmgr.data[imask].max()
    ftmgr = float32(tmgr.data) * 0.1
    print ftmgr[imask].min(), ftmgr[imask].max()
    
    # Apply model
    ssttm = model(ftm, ftmgr, mask)
    ssttm[mask] = UintFillValue
    
    if options.bil:
        # Write to BIL file
        bilfile = BILdata(os.path.join(outdir, outfile+'.bil'), datatype=uint16)
        biltext = bilfile.write(ssttm)
        print biltext
    
    # At last - cross fingers it all worked out!
    print "\n*** Finished successfully ***\n"
Exemple #16
0
def main():
    '''
    Loads and verifies input data, calls the model, and controls the output stream. 
    '''
    # Theme variables
    themedir = 'ssttm'
    themename = 'Snow stability index (temperature)'

    # Setup input parser
    usage = "usage: python //~HOME/pysenorge/themes/temperature_stability_index.py tm_DATE.bil tmgr_DATE.bil [options]"

    parser = OptionParser(usage=usage)
    parser.add_option("-o",
                      "--outdir",
                      action="store",
                      dest="outdir",
                      type="string",
                      metavar="DIR",
                      default=os.path.join(netCDFout, themedir),
                      help="Output directory - default: $netCDFout/%s/$YEAR" %
                      themedir)
    parser.add_option("--no-bil",
                      action="store_false",
                      dest="bil",
                      default=True,
                      help="Set to suppress output in BIL format")

    # Comment to suppress help
    #    parser.print_help()

    (options, args) = parser.parse_args()

    # Verify input parameters
    if len(args) != 2:
        parser.print_help()
        parser.error("Please provide two input files!")
    else:
        yy, mm, dd = get_date_filename(args[0])
        yy_range = arange(1950, 2050)
        if int(yy) not in yy_range:
            parser.error("Could not determine year from file name.")
        # Add full path to the filename
        tmfile = os.path.join(METdir, "tm", yy, args[0])
        tmgrfile = os.path.join(BILout, "tmgr", yy, args[1])

    if not os.path.exists(tmfile):
        parser.print_help()
        parser.error("BIL file containing temperatures does not exist!")
    elif not os.path.exists(tmgrfile):
        parser.print_help()
        parser.error(
            "BIL file containing temperature gradients does not exist!")
    else:
        # Load tm data
        tm = BILdata(tmfile)
        tm.read()
        # Load tmgr data
        tmgr = BILdata(tmgrfile, int16)
        tmgr.read()

    # Setup outputs
    outfile = themedir + '_' + yy + '_' + mm + '_' + dd
    tstring = yy + '-' + mm + '-' + dd + ' 06:00:00'
    outdir = os.path.join(options.outdir, yy)
    if not os.path.exists(outdir):
        if not os.path.exists(options.outdir):
            os.chdir(netCDFout)
            os.system('mkdir %s' % themedir)
        os.chdir(options.outdir)
        os.system('mkdir %s' % yy)

    # Convert tm to Celsius
    ftm = (float32(tm.data) - 2731) * 0.1
    mask = senorge_mask()
    imask = mask == False
    print ftm[imask].min(), ftm[imask].max()
    # Convert tmgr to Celsius
    print tmgr.data[imask].min(), tmgr.data[imask].max()
    ftmgr = float32(tmgr.data) * 0.1
    print ftmgr[imask].min(), ftmgr[imask].max()

    # Apply model
    ssttm = model(ftm, ftmgr, mask)
    ssttm[mask] = UintFillValue

    if options.bil:
        # Write to BIL file
        bilfile = BILdata(os.path.join(outdir, outfile + '.bil'),
                          datatype=uint16)
        biltext = bilfile.write(ssttm)
        print biltext

    # At last - cross fingers it all worked out!
    print "\n*** Finished successfully ***\n"
Exemple #17
0
def main():
    '''
    Loads and verifies input data, calls the models, and controls the output stream. 
    
    Command line usage::
    
        python //~HOME/pysenorge/themes/additional_snow_depth_wind.py YYYY-MM-DD [options]
    '''
    # Theme variables
    themedir = 'additional_snow_depth'
    themename = ''

    # Setup input parser
    usage = "usage: python //~HOME/pysenorge/themes/additional_snow_depth.py YYYY-MM-DD [options]"

    parser = OptionParser(usage=usage)
    parser.add_option("-o", "--outdir",
                      action="store", dest="outdir", type="string",
                      metavar="DIR", default=os.path.join(BILout, themedir),
                      help="Output directory - default: $BILout/%s/$HYDROYEAR" % \
                      themedir)
    parser.add_option("--no-bil",
                      action="store_false",
                      dest="bil",
                      default=True,
                      help="Set to suppress output in BIL format")
    parser.add_option("--nc",
                      action="store_true",
                      dest="nc",
                      default=False,
                      help="Set to store output in netCDF format")
    parser.add_option("--png",
                      action="store_true",
                      dest="png",
                      default=False,
                      help="Set to store output as PNG image")

    # Comment to suppress help
    # parser.print_help()
    (options, args) = parser.parse_args()

    if len(args) != 1:
        parser.error("Please provide the date in ISO format YYYY-MM-DD!")
        parser.print_help()

    # Get current datetime
    cdt = iso2datetime(args[0] + " 06:00:00")
    #Ändern Fehler...
    windfilename = "wind_speed_avg_10m_%s.bil" % datetime2BILdate(cdt)

    #----------------------------------------------------------------------------
    # Import wind-speed 10m map
    # windfile = os.path.join(BILout, "wind_speed_avg_10m", str(get_hydroyear(cdt)),windfilename)
    windfile = os.path.join(BILout, windfilename)

    if not os.path.exists(windfile):
        parser.error("BIL file %s containing wind data does not exist!" %\
                     windfile)
    else:
        # Load todays data
        wind = BILdata(windfile, 'uint16')
        wind.read()
        # convert to Celsius
        wind.data = float32(
            wind.data
        ) * 0.1  #multiplyed by 0.1 because of in integer values in wind_model

    #----------------------------------------------------------------------------
    #import snow-depth map
    sdfilename = "sdfsw_%s.bil" % datetime2BILdate(cdt)
    #sdfile = os.path.join(BILout, "sdfsw", str(get_hydroyear(cdt)), sdfilename)
    sdfile = os.path.join(BILout, sdfilename)

    if not os.path.exists(sdfile):
        parser.error("BIL file %s containing snow-depth data does not exist!" %\
                     sdfile)
    else:
        sd = BILdata(sdfile, 'uint16')
        sd.read()

    #----------------------------------------------------------------------------
    #import snow-age map
    agefilename = "age_%s.bil" % datetime2BILdate(cdt)
    #agefile = os.path.join(BILout, "age", str(get_hydroyear(cdt)), agefilename)
    agefile = os.path.join(BILout, agefilename)

    if not os.path.exists(agefile):
        parser.error("BIL file %s containing snow-age data does not exist!" %\
                     agefile)
    else:
        age = BILdata(agefile, 'uint8')
        age.read()

    #----------------------------------------------------------------------------
    #import liquid-water-content map
    lwcfilename = "lwc_%s.bil" % datetime2BILdate(cdt)
    #lwcfile = os.path.join(BILout, "lwc", str(get_hydroyear(cdt)), lwcfilename)
    lwcfile = os.path.join(BILout, lwcfilename)

    if not os.path.exists(lwcfile):
        parser.error("BIL file %s containing snow-LWC data does not exist!" %\
                     lwcfile)
    else:
        lwc = BILdata(lwcfile, 'uint8')
        lwc.read()

    #----------------------------------------------------------------------------
    #Calculate and import frozen-snow map
    try:
        frz = frozen_snow.frozen()
        frz.load_data(os.path.join(BILout, "ssttm_2013_01_13.bil"))
        frz.check_value(frz.tsi)
    except (IOError, NameError):
        print "Couldn't find or load frozen-snow map"

    # Setup outputs
    outfile = themedir + '_' + datetime2BILdate(cdt)
    outdir = os.path.join(options.outdir, str(get_hydroyear(cdt)))
    if not os.path.exists(outdir):
        if not os.path.exists(options.outdir):
            os.chdir(BILout)
            os.system('mkdir %s' % themedir)
        os.chdir(options.outdir)
        os.system('mkdir %s' % str(get_hydroyear(cdt)))

    #Run additional-snow map model
    Hwind = model(wind.data, sd.data, lwc.data, age.data, frz.idex)

    # Set no-data values to UintFillValue
    mask = senorge_mask()
    Hwind[mask] = UintFillValue

    #Option create bil-file
    if options.bil:
        # Write to BIL file
        bilfile = BILdata(os.path.join(outdir, outfile + '.bil'),
                          datatype='uint16')
        Hwind = uint16(Hwind * 1000)
        Hwind[mask] = UintFillValue

        biltext = bilfile.write(Hwind)
        print biltext

    #Option create nc-file
    if options.nc:
        from pysenorge.io.nc import NCdata
        # Prepare data
        # Change array order
        ncHwind = flipud(Hwind)
        # Write to NC file
        ncfile = NCdata(os.path.join(outdir, outfile + '.nc'))
        ncfile.zip = True
        ncfile.add_variable(themedir, ncHwind.dtype.str, "m", themename,
                            ncHwind)
        ncfile.close()

    #Option create png imagefile
    if options.png:
        from pysenorge.io.png import writePNG
        # Write to PNG file
        writePNG(
            flipud(Hwind),
            os.path.join(outdir, outfile),
            cltfile=os.path.join(
                "/home/ralf/Dokumente/summerjob/data/additional_snow_depth_wind.clt"
            ))

    # At last - cross fingers it all worked out!
    print "\n*** Finished successfully ***\n"
Exemple #18
0
 def load_data(self, ssttm):
     tsi = BILdata(ssttm, datatype='uint16')
     tsi.read()
     self.tsi = tsi.data
def main():
    '''
    Loads and verifies input data, calls the model, and controls the output stream. 
    
    Command line usage::
    
        python //~HOME/pysenorge/themes/temperature_destabilization.py YYYY-MM-DD [options]
    '''
    # Theme variables
    themedir = 'depth_hoar_index_2'
    themename = 'Depth hoar index 2'
    
    # Setup input parser
    usage = "usage: python //~HOME/pysenorge/themes/temperature_destabilization.py YYYY-MM-DD [options]"
    
    parser = OptionParser(usage=usage)
    parser.add_option("-o", "--outdir", 
                      action="store", dest="outdir", type="string",
                      metavar="DIR", default=os.path.join(BILout, themedir),
                      help="Output directory - default: $BILout/%s/$HYDROYEAR" % themedir)
    parser.add_option("--no-bil",
                  action="store_false", dest="bil", default=True,
                  help="Set to suppress output in BIL format")
    parser.add_option("--nc",
                  action="store_true", dest="nc", default=False,
                  help="Set to store output in netCDF format")
    parser.add_option("--png",
                  action="store_true", dest="png", default=False,
                  help="Set to store output as PNG image")
    # Comment to suppress help
    parser.print_help()

    (options, args) = parser.parse_args()
    
    if len(args) != 1:
        parser.error("Please provide the date in ISO format YYYY-MM-DD!")
        parser.print_help() 
    
    # get current datetime
    cdt = iso2datetime(args[0]+" 06:00:00")
    oneday = timedelta(days=1)
    tmfilename = "tm_%s.bil" % datetime2BILdate(cdt)
    sdfilename = "sd_%s.bil" % datetime2BILdate(cdt)
    # yesterdays tds data file
    tdsfilename = "%s_%s.bil" % (themedir, datetime2BILdate(cdt-oneday))
    
    # Add full path to the filename
    tmfile = os.path.join(METdir, "tm", str(cdt.year), tmfilename)
    sdfile = os.path.join(BILin, "sd", str(get_hydroyear(cdt)), sdfilename)
    tdsfile = os.path.join(BILout, themedir, str(get_hydroyear(cdt-oneday)),
                            tdsfilename)
    
    if not os.path.exists(tmfile):
        tmfile = os.path.join(PROGdir, str(cdt.year), tmfilename)
        print "Warning: Observation not found - using prognosis instead!"
    
    if not os.path.exists(tmfile):
        parser.error("BIL file containing temperature data does not exist!" %\
                     tmfile)
    elif not os.path.exists(sdfile):
        parser.error("BIL file %s containing snow-depth data does not exist!" %\
                     sdfile)
    else:
        # Load todays data
        tm = BILdata(tmfile, 'uint16')
        tm.read()
        # convert to Celsius
        tm.data = (float32(tm.data) / 10.0) - 273.1
        # Load yesterdays data 
        sd = BILdata(sdfile, 'uint16')
        sd.read()
        # convert mm to m 
        sd.data = float32(sd.data) / 1000.0  
        
    if not os.path.exists(tdsfile):
        print "Yesterdays TDS2 data does not exist - using None!"
        tds = BILdata("tdsdummy", 'uint16')
    else:
        # Load todays data
        tds = BILdata(tdsfile, 'uint16')
        tds.read()
#        tds.data = float32(tds.data)
        
    # Setup outputs
    outfile = themedir+'_'+datetime2BILdate(cdt)
    if options.nc:
        secs = date2num(cdt, timeunit) # used in NCdata.new()
    outdir = os.path.join(options.outdir, str(get_hydroyear(cdt)))
    if not os.path.exists(outdir):
        if not os.path.exists(options.outdir):
            os.chdir(BILout)
            os.system('mkdir %s' % themedir)
        os.chdir(options.outdir)
        os.system('mkdir %s' % str(get_hydroyear(cdt)))
        
    # Calculate sum of snow temperature gradients    
#    tds = uint16(model(tm.data, sd.data, tds.data))
    tds = model(tm.data, sd.data, tds.data)
        
    # Set no-data values to UintFillValue
    mask = senorge_mask()
    tds[mask] = UintFillValue    
    
    if options.bil:
        # Write to BIL file
        bilfile = BILdata(os.path.join(outdir, outfile+'.bil'),
                          datatype='uint16')
        biltext = bilfile.write(tds)
        print biltext
    
    if options.nc:
        from pysenorge.io.nc import NCdata
        # Prepare data
#        nctds = int2float(tds)
#        imask = mask == False
#        # Convert to Celcius/Kelvin
#        nctds[imask] = nctds[imask]/10.0
        # Change array order 
        nctds = flipud(tds)
        # Write to NC file
        ncfile = NCdata(os.path.join(outdir, outfile+'.nc'))
        ncfile.zip = True
        ncfile.new(secs)
        ncfile.add_variable(themedir, nctds.dtype.str, "days",
                            themename, nctds)
        ncfile.close()
    
    if options.png:
        from pysenorge.io.png import writePNG
        # Write to PNG file
        writePNG(flipud(tds), os.path.join(outdir, outfile),
                 cltfile=r"Z:\snowsim\%s\tgss2_v2.clt" % themedir
                 )
        
    # At last - cross fingers it all worked out!
    print "\n*** Finished successfully ***\n"
Exemple #20
0
 def load_data(self,ssttm): 
     tsi = BILdata(ssttm, datatype='uint16')
     tsi.read()
     self.tsi = tsi.data
Exemple #21
0
def main():
    '''
    Loads and verifies input data, calls the model, and controls the output stream. 
    
    Command line usage::
    
        python //~HOME/pysenorge/themes/temperature_destabilization.py YYYY-MM-DD [options]
    '''
    # Theme variables
    themedir = 'depth_hoar_index_2'
    themename = 'Depth hoar index 2'

    # Setup input parser
    usage = "usage: python //~HOME/pysenorge/themes/temperature_destabilization.py YYYY-MM-DD [options]"

    parser = OptionParser(usage=usage)
    parser.add_option(
        "-o",
        "--outdir",
        action="store",
        dest="outdir",
        type="string",
        metavar="DIR",
        default=os.path.join(BILout, themedir),
        help="Output directory - default: $BILout/%s/$HYDROYEAR" % themedir)
    parser.add_option("--no-bil",
                      action="store_false",
                      dest="bil",
                      default=True,
                      help="Set to suppress output in BIL format")
    parser.add_option("--nc",
                      action="store_true",
                      dest="nc",
                      default=False,
                      help="Set to store output in netCDF format")
    parser.add_option("--png",
                      action="store_true",
                      dest="png",
                      default=False,
                      help="Set to store output as PNG image")
    # Comment to suppress help
    parser.print_help()

    (options, args) = parser.parse_args()

    if len(args) != 1:
        parser.error("Please provide the date in ISO format YYYY-MM-DD!")
        parser.print_help()

    # get current datetime
    cdt = iso2datetime(args[0] + " 06:00:00")
    oneday = timedelta(days=1)
    tmfilename = "tm_%s.bil" % datetime2BILdate(cdt)
    sdfilename = "sd_%s.bil" % datetime2BILdate(cdt)
    # yesterdays tds data file
    tdsfilename = "%s_%s.bil" % (themedir, datetime2BILdate(cdt - oneday))

    # Add full path to the filename
    tmfile = os.path.join(METdir, "tm", str(cdt.year), tmfilename)
    sdfile = os.path.join(BILin, "sd", str(get_hydroyear(cdt)), sdfilename)
    tdsfile = os.path.join(BILout, themedir, str(get_hydroyear(cdt - oneday)),
                           tdsfilename)

    if not os.path.exists(tmfile):
        tmfile = os.path.join(PROGdir, str(cdt.year), tmfilename)
        print "Warning: Observation not found - using prognosis instead!"

    if not os.path.exists(tmfile):
        parser.error("BIL file containing temperature data does not exist!" %\
                     tmfile)
    elif not os.path.exists(sdfile):
        parser.error("BIL file %s containing snow-depth data does not exist!" %\
                     sdfile)
    else:
        # Load todays data
        tm = BILdata(tmfile, 'uint16')
        tm.read()
        # convert to Celsius
        tm.data = (float32(tm.data) / 10.0) - 273.1
        # Load yesterdays data
        sd = BILdata(sdfile, 'uint16')
        sd.read()
        # convert mm to m
        sd.data = float32(sd.data) / 1000.0

    if not os.path.exists(tdsfile):
        print "Yesterdays TDS2 data does not exist - using None!"
        tds = BILdata("tdsdummy", 'uint16')
    else:
        # Load todays data
        tds = BILdata(tdsfile, 'uint16')
        tds.read()
#        tds.data = float32(tds.data)

# Setup outputs
    outfile = themedir + '_' + datetime2BILdate(cdt)
    if options.nc:
        secs = date2num(cdt, timeunit)  # used in NCdata.new()
    outdir = os.path.join(options.outdir, str(get_hydroyear(cdt)))
    if not os.path.exists(outdir):
        if not os.path.exists(options.outdir):
            os.chdir(BILout)
            os.system('mkdir %s' % themedir)
        os.chdir(options.outdir)
        os.system('mkdir %s' % str(get_hydroyear(cdt)))

    # Calculate sum of snow temperature gradients


#    tds = uint16(model(tm.data, sd.data, tds.data))
    tds = model(tm.data, sd.data, tds.data)

    # Set no-data values to UintFillValue
    mask = senorge_mask()
    tds[mask] = UintFillValue

    if options.bil:
        # Write to BIL file
        bilfile = BILdata(os.path.join(outdir, outfile + '.bil'),
                          datatype='uint16')
        biltext = bilfile.write(tds)
        print biltext

    if options.nc:
        from pysenorge.io.nc import NCdata
        # Prepare data
        #        nctds = int2float(tds)
        #        imask = mask == False
        #        # Convert to Celcius/Kelvin
        #        nctds[imask] = nctds[imask]/10.0
        # Change array order
        nctds = flipud(tds)
        # Write to NC file
        ncfile = NCdata(os.path.join(outdir, outfile + '.nc'))
        ncfile.zip = True
        ncfile.new(secs)
        ncfile.add_variable(themedir, nctds.dtype.str, "days", themename,
                            nctds)
        ncfile.close()

    if options.png:
        from pysenorge.io.png import writePNG
        # Write to PNG file
        writePNG(flipud(tds),
                 os.path.join(outdir, outfile),
                 cltfile=r"Z:\snowsim\%s\tgss2_v2.clt" % themedir)

    # At last - cross fingers it all worked out!
    print "\n*** Finished successfully ***\n"
def main():
    '''
    Loads and verifies input data, calls the models, and controls the output stream. 
    
    Command line usage::
    
        python //~HOME/pysenorge/themes/additional_snow_depth_wind.py YYYY-MM-DD [options]
    '''
    # Theme variables
    themedir = 'additional_snow_depth'
    themename = ''
    
    # Setup input parser
    usage = "usage: python //~HOME/pysenorge/themes/additional_snow_depth.py YYYY-MM-DD [options]"
    
    parser = OptionParser(usage=usage)
    parser.add_option("-o", "--outdir", 
                      action="store", dest="outdir", type="string",
                      metavar="DIR", default=os.path.join(BILout, themedir),
                      help="Output directory - default: $BILout/%s/$HYDROYEAR" % \
                      themedir)
    parser.add_option("--no-bil",
                  action="store_false", dest="bil", default=True,
                  help="Set to suppress output in BIL format")
    parser.add_option("--nc",
                  action="store_true", dest="nc", default=False,
                  help="Set to store output in netCDF format")
    parser.add_option("--png",
                  action="store_true", dest="png", default=False,
                  help="Set to store output as PNG image")
    
    # Comment to suppress help
    # parser.print_help()
    (options, args) = parser.parse_args()
    
    if len(args) != 1:
        parser.error("Please provide the date in ISO format YYYY-MM-DD!")
        parser.print_help() 
    
    # Get current datetime
    cdt = iso2datetime(args[0]+" 06:00:00")
    #Ändern Fehler...
    windfilename = "wind_speed_avg_10m_%s.bil" % datetime2BILdate(cdt)
    
    #----------------------------------------------------------------------------
    # Import wind-speed 10m map 
    # windfile = os.path.join(BILout, "wind_speed_avg_10m", str(get_hydroyear(cdt)),windfilename)
    windfile = os.path.join(BILout, windfilename)
    
    if not os.path.exists(windfile):
        parser.error("BIL file %s containing wind data does not exist!" %\
                     windfile)
    else:
        # Load todays data
        wind = BILdata(windfile, 'uint16')
        wind.read()
        # convert to Celsius
        wind.data = float32(wind.data)*0.1 #multiplyed by 0.1 because of in integer values in wind_model
    
    #----------------------------------------------------------------------------
    #import snow-depth map 
    sdfilename = "sdfsw_%s.bil" % datetime2BILdate(cdt)
    #sdfile = os.path.join(BILout, "sdfsw", str(get_hydroyear(cdt)), sdfilename)
    sdfile = os.path.join(BILout, sdfilename)
         
    if not os.path.exists(sdfile):
        parser.error("BIL file %s containing snow-depth data does not exist!" %\
                     sdfile)
    else:
        sd = BILdata(sdfile, 'uint16')
        sd.read()
    
    #----------------------------------------------------------------------------
    #import snow-age map 
    agefilename = "age_%s.bil" % datetime2BILdate(cdt)
    #agefile = os.path.join(BILout, "age", str(get_hydroyear(cdt)), agefilename)
    agefile = os.path.join(BILout, agefilename)
    
    if not os.path.exists(agefile):
        parser.error("BIL file %s containing snow-age data does not exist!" %\
                     agefile)
    else:
        age = BILdata(agefile, 'uint8')
        age.read()
    
    #----------------------------------------------------------------------------
    #import liquid-water-content map 
    lwcfilename = "lwc_%s.bil" % datetime2BILdate(cdt)
    #lwcfile = os.path.join(BILout, "lwc", str(get_hydroyear(cdt)), lwcfilename)
    lwcfile = os.path.join(BILout, lwcfilename)

    if not os.path.exists(lwcfile):
        parser.error("BIL file %s containing snow-LWC data does not exist!" %\
                     lwcfile)
    else:
        lwc = BILdata(lwcfile, 'uint8')
        lwc.read()

    #----------------------------------------------------------------------------
    #Calculate and import frozen-snow map 
    try:
        frz = frozen_snow.frozen()
        frz.load_data(os.path.join(BILout, "ssttm_2013_01_13.bil"))
        frz.check_value(frz.tsi)    
    except (IOError,NameError):
        print "Couldn't find or load frozen-snow map"

    # Setup outputs
    outfile = themedir+'_'+datetime2BILdate(cdt)
    outdir = os.path.join(options.outdir, str(get_hydroyear(cdt)))
    if not os.path.exists(outdir):
        if not os.path.exists(options.outdir):
            os.chdir(BILout)
            os.system('mkdir %s' % themedir)
        os.chdir(options.outdir)
        os.system('mkdir %s' % str(get_hydroyear(cdt)))

    #Run additional-snow map model
    Hwind = model(wind.data, sd.data, lwc.data, age.data, frz.idex)

    # Set no-data values to UintFillValue
    mask = senorge_mask()
    Hwind[mask] = UintFillValue

    #Option create bil-file
    if options.bil:
        # Write to BIL file
        bilfile = BILdata(os.path.join(outdir, outfile+'.bil'),
                          datatype='uint16')
        Hwind = uint16(Hwind*1000)
        Hwind[mask] = UintFillValue

        biltext = bilfile.write(Hwind)
        print biltext

    #Option create nc-file
    if options.nc:
        from pysenorge.io.nc import NCdata
        # Prepare data
        # Change array order 
        ncHwind = flipud(Hwind)
        # Write to NC file
        ncfile = NCdata(os.path.join(outdir, outfile+'.nc'))
        ncfile.zip = True
        ncfile.add_variable(themedir, ncHwind.dtype.str, "m",
                            themename, ncHwind)
        ncfile.close()

    #Option create png imagefile
    if options.png:
        from pysenorge.io.png import writePNG
        # Write to PNG file
        writePNG(flipud(Hwind), os.path.join(outdir, outfile),
                 cltfile=os.path.join("/home/ralf/Dokumente/summerjob/data/additional_snow_depth_wind.clt")
                 )

    # At last - cross fingers it all worked out!
    print "\n*** Finished successfully ***\n"