@@ -0,0 +1,2822 @@
+import json%0Aimport os%0A%0Aimport rasterio%0Afrom pyproj import Proj%0A%0Afrom vistas.core.gis.extent import Extent%0Afrom vistas.core.plugins.data import RasterDataPlugin, VariableStats%0A%0A%0Aclass GeoTIFF(RasterDataPlugin):%0A%0A    id = 'geotiff'%0A    name = 'GeoTIFF Data Plugin'%0A    description = 'Reads GeoTIFF (.tif) files'%0A    author = 'Conservation Biology Institute'%0A    version = '1.0'%0A    extensions = %5B('tif', 'GeoTIFF')%5D%0A%0A    def __init__(self, *args, **kwargs):%0A        super().__init__(*args, **kwargs)%0A%0A        self._name = None%0A        self._shape = None%0A        self._extent = None%0A        self._resolution = None%0A        self._nodata = None%0A        self._count = None%0A%0A    def load_data(self):%0A        self._name = self.path.split(os.sep)%5B-1%5D.split('.tif')%5B0%5D%0A        with rasterio.open(self.path) as src:%0A            projection = Proj(src.crs)%0A            self._shape = src.shape%0A            self._resolution = src.res%5B0%5D%0A            xmin, ymin = src.xy(src.height, 0, 'ul')%0A            xmax, ymax = src.xy(0, src.width, 'ul')%0A            self._extent = Extent(xmin, ymin, xmax, ymax, projection)%0A            self._nodata = src.nodata%0A            self._count = src.count%0A%0A    @property%0A    def data_name(self):%0A        return self._name%0A%0A    @staticmethod%0A    def is_valid_file(path):%0A        return True%0A%0A    def get_data(self, variable, date=None):%0A        band = int(variable.split(' ')%5B-1%5D)%0A        with rasterio.open(self.path, 'r') as src:%0A            return src.read(band).T%0A%0A    @property%0A    def shape(self):%0A        return self._shape%0A%0A    @property%0A    def resolution(self):%0A        return self._resolution%0A%0A    @property%0A    def extent(self):%0A        return self._extent%0A%0A    @property%0A    def variables(self):%0A        return %5B'Band %7B%7D'.format(i) for i in range(1, self._count + 1)%5D%0A%0A    def variable_stats(self, variable):%0A        band = variable.split(' ')%5B-1%5D%0A        stats_path = self.path.replace('.tif', '.json')%0A        if os.path.exists(stats_path):%0A            with open(stats_path, 'r') as f:%0A                all_stats = json.load(f)%0A                return VariableStats.from_dict(all_stats%5Bband%5D)%0A        else:%0A            return VariableStats()%0A%0A    @property%0A    def has_stats(self):%0A        return os.path.exists(self.path.replace('.tif', '.json'))%0A%0A    def calculate_stats(self):%0A        if self.has_stats:%0A            return%0A%0A        all_stats = %7B%7D%0A        with rasterio.open(self.path) as src:%0A            for band in range(1, self._count + 1):%0A                data = src.read(band)%0A                masked_data = data%5Bdata != self._nodata%5D%0A                stats = VariableStats(float(masked_data.min()), float(masked_data.max()), self._nodata)%0A                all_stats%5Bband%5D = stats.to_dict%0A        with open(self.path.replace('.tif', '.json'), 'w') as f:%0A            json.dump(all_stats, f)%0A

Add GeoTIFF data plugin.