def __init__(self, nparray, **kwargs): """ Set attributes See class Figure(object) for information about: Modifies -------- Parameters ---------- Advanced parameters -------------------- """ # make a copy of nparray (otherwise a new reference to the same data is # created and the original input data is destroyed at process()) array = np.array(nparray) self.logger = add_logger('Nansat') # if 2D array is given, reshape to 3D if array.ndim == 2: self.array = array.reshape(1, array.shape[0], array.shape[1]) else: self.array = array # note swaping of axis by PIL self.width = self.array.shape[2] self.height = self.array.shape[1] # modify the default values using input values self._set_defaults(kwargs) # set fonts for Legend self.fontFileName = os.path.join(os.path.dirname( os.path.realpath(__file__)), 'fonts/DejaVuSans.ttf')
def __init__(self, nparray, **kwargs): """ Set attributes See class Figure(object) for information about: Modifies -------- Parameters ---------- Advanced parameters -------------------- """ # make a copy of nparray (otherwise a new reference to the same data is # created and the original input data is destroyed at process()) array = np.array(nparray) self.logger = add_logger('Nansat') # if 2D array is given, reshape to 3D if array.ndim == 2: self.array = array.reshape(1, array.shape[0], array.shape[1]) else: self.array = array # note swaping of axis by PIL self.width = self.array.shape[2] self.height = self.array.shape[1] # modify the default values using input values self._set_defaults(kwargs) # set fonts for Legend self.fontFileName = os.path.join( os.path.dirname(os.path.realpath(__file__)), 'fonts/DejaVuSans.ttf')
def __init__(self, srs=None, ext=None, ds=None, lon=None, lat=None, name='', logLevel=None): '''Create Domain from GDALDataset or string options or lat/lon grids d = Domain(srs, ext) Size, extent and spatial reference is given by strings d = Domain(ds=GDALDataset): Size, extent and spatial reference is copied from input GDAL dataset d = Domain(srs, ds=GDALDataset): Spatial reference is given by srs, but size and extent is determined from input GDAL dataset d = Domain(lon=lonGrid, lat=latGrid) Size, extent and spatial reference is given by two grids Parameters ---------- srs : PROJ4 or EPSG or WKT or NSR or osr.SpatialReference() Input parameter for nansat.NSR() ext : string some gdalwarp options + additional options [http://www.gdal.org/gdalwarp.html] Specifies extent, resolution / size Available options: (('-te' or '-lle') and ('-tr' or '-ts')) (e.g. '-lle -10 30 55 60 -ts 1000 1000' or '-te 100 2000 300 10000 -tr 300 200') -tr resolutionx resolutiony -ts sizex sizey -te xmin ymin xmax ymax -lle lonmin latmin lonmax latmax ds : GDAL dataset lat : Numpy array Grid with latitudes lon : Numpy array Grid with longitudes name : string, optional Name to be added to the Domain object logLevel : int, optional, default=30 level of logging Raises ------- ProjectionError : occurs when Projection() is empty despite it is required for creating extentDic. OptionError : occures when the arguments are not proper. Modifies --------- self.vrt.datasetset : dataset in memory dataset is created based on the input arguments See Also --------- Nansat.reproject() [http://www.gdal.org/gdalwarp.html] [http://trac.osgeo.org/proj/] [http://spatialreference.org/] [http://www.gdal.org/ogr/osr_tutorial.html] ''' # set default attributes self.logger = add_logger('Nansat', logLevel) self.name = name self.logger.debug('ds: %s' % str(ds)) self.logger.debug('srs: %s' % srs) self.logger.debug('ext: %s' % ext) # If too much information is given raise error if ds is not None and srs is not None and ext is not None: raise OptionError('Ambiguous specification of both ' 'dataset, srs- and ext-strings.') # choose between input opitons: # ds # ds and srs # srs and ext # lon and lat # if only a dataset is given: # copy geo-reference from the dataset if ds is not None and srs is None: self.vrt = VRT(gdalDataset=ds) # If dataset and srs are given (but not ext): # use AutoCreateWarpedVRT to determine bounds and resolution elif ds is not None and srs is not None: srs = NSR(srs) tmpVRT = gdal.AutoCreateWarpedVRT(ds, None, srs.wkt) if tmpVRT is None: raise ProjectionError('Could not warp the given dataset' 'to the given SRS.') else: self.vrt = VRT(gdalDataset=tmpVRT) # If SpatialRef and extent string are given (but not dataset) elif srs is not None and ext is not None: srs = NSR(srs) # create full dictionary of parameters extentDic = self._create_extentDic(ext) # convert -lle to -te if 'lle' in extentDic.keys(): extentDic = self._convert_extentDic(srs, extentDic) # get size/extent from the created extet dictionary [geoTransform, rasterXSize, rasterYSize] = self._get_geotransform(extentDic) # create VRT object with given geo-reference parameters self.vrt = VRT(srcGeoTransform=geoTransform, srcProjection=srs.wkt, srcRasterXSize=rasterXSize, srcRasterYSize=rasterYSize) self.extentDic = extentDic elif lat is not None and lon is not None: # create self.vrt from given lat/lon self.vrt = VRT(lat=lat, lon=lon) else: raise OptionError('"dataset" or "srsString and extentString" ' 'or "dataset and srsString" are required') self.logger.debug('vrt.dataset: %s' % str(self.vrt.dataset))
def __init__(self, srs=None, ext=None, ds=None, lon=None, lat=None, name='', logLevel=None): """Create Domain from GDALDataset or string options or lat/lon grids""" # set default attributes self.logger = add_logger('Nansat', logLevel) self.name = name self.logger.debug('ds: %s' % str(ds)) self.logger.debug('srs: %s' % srs) self.logger.debug('ext: %s' % ext) # If too much information is given raise error if ds is not None and srs is not None and ext is not None: raise ValueError( 'Ambiguous specification of both dataset, srs- and ext-strings.' ) # choose between input opitons: # ds # ds and srs # srs and ext # lon and lat # if only a dataset is given: # copy geo-reference from the dataset if ds is not None and srs is None: self.vrt = VRT.from_gdal_dataset(ds) # If dataset and srs are given (but not ext): # use AutoCreateWarpedVRT to determine bounds and resolution elif ds is not None and srs is not None: srs = NSR(srs) tmp_vrt = gdal.AutoCreateWarpedVRT(ds, None, srs.wkt) if tmp_vrt is None: raise NansatProjectionError( 'Could not warp the given dataset to the given SRS.') else: self.vrt = VRT.from_gdal_dataset(tmp_vrt) # If SpatialRef and extent string are given (but not dataset) elif srs is not None and ext is not None: srs = NSR(srs) # create full dictionary of parameters extent_dict = Domain._create_extent_dict(ext) # convert -lle to -te if 'lle' in extent_dict.keys(): extent_dict = self._convert_extentDic(srs, extent_dict) # get size/extent from the created extent dictionary geo_transform, raster_x_size, raster_y_size = self._get_geotransform( extent_dict) # create VRT object with given geo-reference parameters self.vrt = VRT.from_dataset_params(x_size=raster_x_size, y_size=raster_y_size, geo_transform=geo_transform, projection=srs.wkt, gcps=[], gcp_projection='') elif lat is not None and lon is not None: # create self.vrt from given lat/lon self.vrt = VRT.from_lonlat(lon, lat) else: raise ValueError('"dataset" or "srsString and extentString" ' 'or "dataset and srsString" are required') self.logger.debug('vrt.dataset: %s' % str(self.vrt.dataset))
def __init__(self, nparray, **kwargs): ''' Set attributes Parameters ----------- array : numpy array (2D or 3D) dataset from Nansat cmin : number (int ot float) or [number, number, number] 0, minimum value of varibale in the matrix to be shown cmax : number (int ot float) or [number, number, number] 1, minimum value of varibale in the matrix to be shown gamma : float, >0 2, coefficient for tone curve udjustment subsetArraySize : int 100000, size of the subset array which is used to get histogram numOfColor : int 250, number of colors for use of the palette. 254th is black and 255th is white. cmapName : string 'jet', name of Matplotlib colormaps see --> http://www.scipy.org/Cookbook/Matplotlib/Show_colormaps ratio : float, [0 1] 1.0, ratio of pixels which are used to write the figure numOfTicks : int 5, number of ticks on a colorbar titleString : string '', title of legend (1st line) caption : string '', caption of the legend (2nd line, e.g. long name and units) fontRatio : positive float 1, factor for changing the fontSize. fontSize : int 12, size of the font of title, caption and ticks. If not given, fontSize is calculated using fontRatio: fontSize = height / 45 * fontRatio. fontSize has priority over fontRatio logarithm : boolean, defult = False If True, tone curve is used to convert pixel values. If False, linear. legend : boolean, default = False if True, information as textString, colorbar, longName and units are added in the figure. mask_array : 2D numpy array, int, the shape should be equal array.shape. If given this array is used for masking land, clouds, etc on the output image. Value of the array are indeces. LUT from mask_lut is used for coloring upon this indeces. mask_lut : dictionary Look-Up-Table with colors for masking land, clouds etc. Used tgether with mask_array: {0, [0,0,0], 1, [100,100,100], 2: [150,150,150], 3: [0,0,255]} index 0 - will have black color 1 - dark gray 2 - light gray 3 - blue logoFileName : string name of the file with logo logoLocation : list of two int, default = [0,0] X and Y offset of the image If positive - offset is from left, upper edge If Negative - from right, lower edge Offset is calculated from the entire image legend inclusive logoSize : list of two int desired X,Y size of logo. If None - original size is used latGrid : numpy array full size array with latitudes. For adding lat/lon grid lines lonGrid : numpy array full size array with longitudes. For adding lat/lon grid lines nGridLines : int number of lat/lon grid lines to show latlonLabels : int number of lat/lon labels to show along each side. transparency : int transparency of the image background(mask), set for PIL alpha mask in Figure.save() default : None Advanced parameters -------------------- LEGEND_HEIGHT : float, [0 1] 0.1, legend height relative to image height CBAR_HEIGHTMIN : int 5, minimum colorbar height, pixels CBAR_HEIGHT : float, [0 1] 0.15, colorbar height relative to image height CBAR_WIDTH : float [0 1] 0.8, colorbar width relative to legend width CBAR_LOCATION_X : float [0 1] 0.1, colorbar offset X relative to legend width CBAR_LOCATION_Y : float [0 1] 0.5, colorbar offset Y relative to legend height CBTICK_LOC_ADJUST_X : int 5, colorbar tick label offset X, pixels CBTICK_LOC_ADJUST_Y : int 3, colorbar tick label offset Y, pixels CAPTION_LOCATION_X : float, [0 1] 0.1, caption offset X relative to legend width CAPTION_LOCATION_Y : float, [0 1] 0.1, caption offset Y relative to legend height TITLE_LOCATION_X : float, [0 1] 0.1, title offset X relative to legend width TITLE_LOCATION_Y : 0.3, title offset Y relative to legend height DEFAULT_EXTENSION : string '.png' -------------------------------------------------- Modifies --------- self.sizeX, self.sizeY : int width and height of the image self.pilImg : PIL image figure self.pilImgLegend : PIL image if pilImgLegend is None, legend is not added to the figure if it is replaced, pilImgLegend includes text string, color-bar, longName and units. ''' # make a copy of nparray (otherwise a new reference to the same data is # created and the original input data is destroyed at process()) array = np.array(nparray) self.logger = add_logger('Nansat') # if 2D array is given, reshape to 3D if array.ndim == 2: self.array = array.reshape(1, array.shape[0], array.shape[1]) else: self.array = array # note swaping of axis by PIL self.width = self.array.shape[2] self.height = self.array.shape[1] # modify the default values using input values self._set_defaults(kwargs) # set fonts for Legend self.fontFileName = os.path.join( os.path.dirname(os.path.realpath(__file__)), 'fonts/DejaVuSans.ttf')
def __init__(self, nparray, **kwargs): ''' Set attributes Parameters ----------- array : numpy array (2D or 3D) dataset from Nansat cmin : number (int ot float) or [number, number, number] 0, minimum value of varibale in the matrix to be shown cmax : number (int ot float) or [number, number, number] 1, minimum value of varibale in the matrix to be shown gamma : float, >0 2, coefficient for tone curve udjustment subsetArraySize : int 100000, size of the subset array which is used to get histogram numOfColor : int 250, number of colors for use of the palette. 254th is black and 255th is white. cmapName : string 'jet', name of Matplotlib colormaps see --> http://www.scipy.org/Cookbook/Matplotlib/Show_colormaps ratio : float, [0 1] 1.0, ratio of pixels which are used to write the figure numOfTicks : int 5, number of ticks on a colorbar titleString : string '', title of legend (1st line) caption : string '', caption of the legend (2nd line, e.g. long name and units) fontRatio : positive float 1, factor for changing the fontSize. fontSize : int 12, size of the font of title, caption and ticks. If not given, fontSize is calculated using fontRatio: fontSize = height / 45 * fontRatio. fontSize has priority over fontRatio logarithm : boolean, defult = False If True, tone curve is used to convert pixel values. If False, linear. legend : boolean, default = False if True, information as textString, colorbar, longName and units are added in the figure. mask_array : 2D numpy array, int, the shape should be equal array.shape. If given this array is used for masking land, clouds, etc on the output image. Value of the array are indeces. LUT from mask_lut is used for coloring upon this indeces. mask_lut : dictionary Look-Up-Table with colors for masking land, clouds etc. Used tgether with mask_array: {0, [0,0,0], 1, [100,100,100], 2: [150,150,150], 3: [0,0,255]} index 0 - will have black color 1 - dark gray 2 - light gray 3 - blue logoFileName : string name of the file with logo logoLocation : list of two int, default = [0,0] X and Y offset of the image If positive - offset is from left, upper edge If Negative - from right, lower edge Offset is calculated from the entire image legend inclusive logoSize : list of two int desired X,Y size of logo. If None - original size is used latGrid : numpy array full size array with latitudes. For adding lat/lon grid lines lonGrid : numpy array full size array with longitudes. For adding lat/lon grid lines nGridLines : int number of lat/lon grid lines to show latlonLabels : int number of lat/lon labels to show along each side. transparency : int transparency of the image background(mask), set for PIL alpha mask in Figure.save() default : None Advanced parameters -------------------- LEGEND_HEIGHT : float, [0 1] 0.1, legend height relative to image height CBAR_HEIGHTMIN : int 5, minimum colorbar height, pixels CBAR_HEIGHT : float, [0 1] 0.15, colorbar height relative to image height CBAR_WIDTH : float [0 1] 0.8, colorbar width relative to legend width CBAR_LOCATION_X : float [0 1] 0.1, colorbar offset X relative to legend width CBAR_LOCATION_Y : float [0 1] 0.5, colorbar offset Y relative to legend height CBTICK_LOC_ADJUST_X : int 5, colorbar tick label offset X, pixels CBTICK_LOC_ADJUST_Y : int 3, colorbar tick label offset Y, pixels CAPTION_LOCATION_X : float, [0 1] 0.1, caption offset X relative to legend width CAPTION_LOCATION_Y : float, [0 1] 0.1, caption offset Y relative to legend height TITLE_LOCATION_X : float, [0 1] 0.1, title offset X relative to legend width TITLE_LOCATION_Y : 0.3, title offset Y relative to legend height DEFAULT_EXTENSION : string '.png' -------------------------------------------------- Modifies --------- self.sizeX, self.sizeY : int width and height of the image self.pilImg : PIL image figure self.pilImgLegend : PIL image if pilImgLegend is None, legend is not added to the figure if it is replaced, pilImgLegend includes text string, color-bar, longName and units. ''' # make a copy of nparray (otherwise a new reference to the same data is # created and the original input data is destroyed at process()) array = np.array(nparray) self.logger = add_logger('Nansat') # if 2D array is given, reshape to 3D if array.ndim == 2: self.array = array.reshape(1, array.shape[0], array.shape[1]) else: self.array = array # note swaping of axis by PIL self.width = self.array.shape[2] self.height = self.array.shape[1] # modify the default values using input values self._set_defaults(kwargs) # set fonts for Legend self.fontFileName = os.path.join(os.path.dirname( os.path.realpath(__file__)), 'fonts/DejaVuSans.ttf')