Exemple #1
0
def window_daymet(output):
	"""
	Shrinks the Daymet DEM to include only relevant data to the Open
	Topography data set. 
	"""

	print 'Download and convert Daymet DEM.'
	# Parse dem file
	demParser = TiffParser()
	demParser.loadTiff(os.path.join(output,'pit_c.tif'))
    
    # get coordinates
	coords = demParser.getProjCoords()

	# Check for the Daymet DEM
	if not os.path.isfile('na_dem.tif'):
		# If it's not there, download it
		command = ['iget', '/iplant/home/tyson_swetnam/DAYMET/NA_DEM/na_dem.tif']
		process = Popen(command, stdout=PIPE, shell=False)

		print '\tDownloading Daymet DEM....'
		out, err = process.communicate()

		if process.returncode != 0:
			print 'Failed to download.\n'
			print err
			sys.exit(1)

		print '\tFinished downloading.\n'

	else:
		print '\tDaymet DEM detected. Processing.'

	# Round to the outside edges of overlapping Daymet tiles
	ul = [str(math.floor(decimal.Decimal(coords[1][0]) / 1000) * 1000), str(math.ceil(decimal.Decimal(coords[1][1]) / 1000) * 1000)]
	lr = [str(math.ceil(decimal.Decimal(coords[0][0]) / 1000) * 1000), str(math.floor(decimal.Decimal(coords[0][1]) / 1000) * 1000)]

	# Build command
	command = ['gdal_translate', '-projwin', ul[0], ul[1], lr[0], lr[1], 'na_dem.tif', os.path.join(output, 'na_dem.part.tif')]

	print '\tPartitioning Daymet....'

	process = Popen(command, stdout=PIPE, shell=False)

	out, err = process.communicate()

	if process.returncode != 0:
		print 'Failed to partition Daymet DEM. \n'
		print err
		sys.exit(1)

	print 'Finished partitioning Daymet DEM as na_dem.part.tif.\n'
def main():
    
    """
    This script examine a default dem file or 
    a user specified dem file
    download data for the area it covered from daymet
    """

    # Default parameters
    inputTiff = 'pit_c.tif'
    params = ['tmin']
    startYr = 2013
    endYr = 2013
    
    supportedParam = ['tmin', 'tmax', 'prcp'];
    
    # allocate user specified parameters
    if len(sys.argv) == 2:
        if not sys.argv[1].endswith('.tif') or not os.path.exists(sys.argv[1]):
            print "File not exist or wrong type"
            sys.exit(1)
        else:
            inputTiff = sys.argv[1]
    elif len(sys.argv) >= 4:
        try:
            if not sys.argv[1].endswith('.tif') or not os.path.exists(sys.argv[1]):
                print "File not exist or wrong type"
                sys.exit(1)
            else:
                inputTiff = sys.argv[1]

            startYr = int(sys.argv[2])
            endYr = int(sys.argv[3])
        except ValueError:
            print "Invalid year parameters"
            sys.exit(1)
        
        if endYr < startYr or endYr > 2013 or startYr < 1980:
            print "Invalid year parameters:[1980 - 2013]"
            sys.exit(1)
        if len(sys.argv) > 4:
            try:
                if not sys.argv[1].endswith('.tif') or not os.path.exists(sys.argv[1]):
                    print "File not exist or wrong type"
                    sys.exit(1)
                else:
                    inputTiff = sys.argv[1]
                    
                startYr = int(sys.argv[2])
                endYr = int(sys.argv[3])
            except ValueError:
                print "Invalid year parameters"
                sys.exit(1)
            
            if endYr < startYr or endYr > 2013 or startYr < 1980:
                print "Invalid year parameters:[1980 - 2013]"
                sys.exit(1)
                
            for opt in sys.argv[4:]:
                if opt == 'all':
                    params = supportedParam
                    break
                elif opt not in supportedParam:
                    print "Invalid measurement parameters"
                    sys.exit(1)
            if params != supportedParam: 
                params = sys.argv[4:]

    # Parse dem file
    demParser = TiffParser()
    demParser.loadTiff(inputTiff)
    
    # get coordinates
    coords = demParser.getDecimalCoords()
    
    # get projection coords
    projs = demParser.getProjCoords()
     
    # get converted name
    tiffName = demParser.getName()
    #print endYr, startYr
    # download daymet data   
    print coords
    for opt in params:
        getDaymetData(tiffName, coords[1][0], coords[1][1], coords[0][0], coords[0][1], \
                      startYr, endYr, opt)
    #print projs
    #print coords
    #projDem('na_dem.tif', projs[1][0], projs[1][1], projs[0][0], projs[0][1],\
    #              tiffName + '_dem.tif')
    """ 
Exemple #3
0
def window_daymet(output):
    """
	Shrinks the Daymet DEM to include only relevant data to the Open
	Topography data set. 
	"""

    print 'Download and convert Daymet DEM.'
    # Parse dem file
    demParser = TiffParser()
    demParser.loadTiff(os.path.join(output, 'pit_c.tif'))

    # get coordinates
    coords = demParser.getProjCoords()

    # Check for the Daymet DEM
    if not os.path.isfile('na_dem.tif'):
        # If it's not there, download it
        command = [
            'iget', '/iplant/home/tyson_swetnam/DAYMET/NA_DEM/na_dem.tif'
        ]
        process = Popen(command, stdout=PIPE, shell=False)

        print '\tDownloading Daymet DEM....'
        out, err = process.communicate()

        if process.returncode != 0:
            print 'Failed to download.\n'
            print err
            sys.exit(1)

        print '\tFinished downloading.\n'

    else:
        print '\tDaymet DEM detected. Processing.'

    # Round to the outside edges of overlapping Daymet tiles
    ul = [
        str(math.floor(decimal.Decimal(coords[1][0]) / 1000) * 1000),
        str(math.ceil(decimal.Decimal(coords[1][1]) / 1000) * 1000)
    ]
    lr = [
        str(math.ceil(decimal.Decimal(coords[0][0]) / 1000) * 1000),
        str(math.floor(decimal.Decimal(coords[0][1]) / 1000) * 1000)
    ]

    # Build command
    command = [
        'gdal_translate', '-projwin', ul[0], ul[1], lr[0], lr[1], 'na_dem.tif',
        os.path.join(output, 'na_dem.part.tif')
    ]
    print ' '.join(command)
    print demParser.getProjCoords()
    print '\tPartitioning Daymet....'

    process = Popen(command, stdout=PIPE, shell=False)

    out, err = process.communicate()

    if process.returncode != 0:
        print 'Failed to partition Daymet DEM. \n'
        print err
        sys.exit(1)

    print 'Finished partitioning Daymet DEM as na_dem.part.tif.\n'