当前位置: 首页>>代码示例>>Python>>正文


Python Nansat.get_time方法代码示例

本文整理汇总了Python中nansat.Nansat.get_time方法的典型用法代码示例。如果您正苦于以下问题:Python Nansat.get_time方法的具体用法?Python Nansat.get_time怎么用?Python Nansat.get_time使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在nansat.Nansat的用法示例。


在下文中一共展示了Nansat.get_time方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: SARWind

# 需要导入模块: from nansat import Nansat [as 别名]
# 或者: from nansat.Nansat import get_time [as 别名]
class SARWind(Nansat, object):
    '''
    A class for calculating wind speed from SAR images using CMOD
    '''

    def __init__(self, sar_image, winddir=None, pixelsize=500):
        '''
            Parameters
            -----------
            sar_image : string or Nansat object
                SAR image filename (original, raw file)
            winddir : int, string, Nansat, None
                Auxiliary wind field information needed to calculate
                SAR wind (must be or have wind direction)
        '''
        if isinstance(sar_image, str) or isinstance(sar_image, unicode):
            super(SARWind, self).__init__(sar_image)
        elif isinstance(sar_image, Nansat):
            super(SARWind, self).__init__(domain=sar_image)
            self.vrt = sar_image.vrt

        # Check that this is a SAR image with VV pol NRCS
        try:
            self.sigma0_bandNo = self._get_band_number(
                            {'standard_name': 
            'surface_backwards_scattering_coefficient_of_radar_wave', 
                            'polarization': 'VV'})
        except:
            raise TypeError(self.fileName + 
                ' does not have SAR NRCS in VV polarization')

        self.SAR_image_time = self.get_time(
                self.sigma0_bandNo).replace(tzinfo=None)

        if pixelsize != 'fullres':
            print 'Resizing SAR image to ' + str(pixelsize) + ' m pixel size'
            self.resize(pixelsize=pixelsize)

        self.winddir = winddir
        if winddir is not None:
            self.calculate_wind()


    def calculate_wind(self, winddir=None, storeModelSpeed=True):
        # Calculate wind speed from SAR sigma0 in VV polarization

        if winddir:
            self.winddir = winddir
        if self.winddir is None or self.winddir == 'online':
            self.winddir = 'ncep_wind_online' # default source

        if isinstance(self.winddir, int):
            # Constant wind direction is input
            print 'Using constant wind (from) direction: ' + str(self.winddir) + \
                    ' degrees clockwise from North'
            winddirArray = np.ones(self.shape())*self.winddir
            winddir_time = None
            storeModelSpeed = False # Not relevant if direction given as number
        else:
            # Nansat readable file
            if isinstance(self.winddir, str):
                try:
                    self.winddir = Nansat(self.winddir)
                except:
                    try:
                        self.winddir = Nansat(self.winddir + 
                                            datetime.strftime(
                                            self.SAR_image_time, ':%Y%m%d%H%M'))
                    except:
                        pass

            if not isinstance(self.winddir, Nansat):
                raise ValueError('Wind direction not available')

            winddir_time = self.winddir.get_time()[0]

            # Bi-linear interpolation onto SAR image
            self.winddir.reproject(self, eResampleAlg=1)

            # Check time difference between SAR image and wind direction object
            timediff = self.SAR_image_time - winddir_time
            hoursDiff = np.abs(timediff.total_seconds()/3600.)
            print 'Time difference between SAR image and wind direction: ' \
                    + '%.2f' % hoursDiff + ' hours'
            print 'SAR image time: ' + str(self.SAR_image_time)
            print 'Wind dir time: ' + str(winddir_time)
            if hoursDiff > 3:
                print '#########################################'
                print 'WARNING: time difference exceeds 3 hours!'
                print '#########################################'

            wind_u_bandNo = self.winddir._get_band_number({
                                'standard_name': 'eastward_wind',
                            })
            wind_v_bandNo = self.winddir._get_band_number({
                                'standard_name': 'northward_wind',
                            })
            # Get wind direction
            u_array = self.winddir[wind_u_bandNo]
            v_array = self.winddir[wind_v_bandNo]
#.........这里部分代码省略.........
开发者ID:knutfrode,项目名称:openwind,代码行数:103,代码来源:sar_wind.py

示例2: test_get_time

# 需要导入模块: from nansat import Nansat [as 别名]
# 或者: from nansat.Nansat import get_time [as 别名]
    def test_get_time(self):
        n1 = Nansat(self.test_file_gcps, logLevel=40)
        t = n1.get_time()

        self.assertEqual(len(t), len(n1.bands()))
        self.assertEqual(type(t[0]), datetime.datetime)
开发者ID:WYC19910220,项目名称:nansat,代码行数:8,代码来源:test_nansat.py

示例3: Nansat

# 需要导入模块: from nansat import Nansat [as 别名]
# 或者: from nansat.Nansat import get_time [as 别名]
# Open an input file
# Create a Nansat object <n> for futher high-level operations
n = Nansat(iFileName)

# Open an input file, specify which Mapper to use, set logging level
n = Nansat(iFileName, mapperName='generic', logLevel=10)

# list bands and georeference of the object
print 'Raw Nansat:', n, '\n'

# get dictionary with metadata from all bands
print 'Bands:', n.bands(), '\n'

# get time of the image aquisition
print 'Time:', n.get_time()[0], '\n'

# set GlobalMetadata
n.set_metadata(key='GlobalKey', value='GlobalVal')
# get Global Metadata
print 'Global Metadata:', n.get_metadata(), '\n'

# set BandMetadata to the 1st band
n.set_metadata(key='BandKey', value='BandVal', bandID=1)
# get 1st Band Metadata
print '1st Band Metadata:', n.get_metadata(bandID=1), '\n'

# add a band from file (copy the 2nd band to the end (4th band)
n.add_band(fileName=n.fileName, bandID=2)
# add a band from numpy array (copy the 1st band to the end (5th band))
n.add_band(array=n[1], parameters={'name': 'Name1',
开发者ID:yuxiaobu,项目名称:nansat,代码行数:32,代码来源:test_nansat.py


注:本文中的nansat.Nansat.get_time方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。