예제 #1
0
    def get_variables(self):
        def load(band):
            band = ds.GetRasterBand(band)
            a = band.ReadAsArray()
            no_data = band.GetNoDataValue()
            if no_data is not None:
                try:
                    a[a == no_data] = a.dtype.type(nan)
                except ValueError:
                    pass
            return a

        ds = self.ds
        dims = ['lat', 'lon']
        chunks = ((ds.RasterYSize, ), (ds.RasterXSize, ))
        shape = (ds.RasterYSize, ds.RasterXSize)
        variables = OrderedDict()
        for iband in range(1, ds.RasterCount + 1):
            band = ds.GetRasterBand(iband)
            dt = dtype(gdal_array.codes[band.DataType])
            if with_dask:
                dsk = {('x', 0, 0): (load, iband)}
                arr = Array(dsk, 'x', chunks, shape=shape, dtype=dt)
            else:
                arr = load(iband)
            attrs = band.GetMetadata_Dict()
            try:
                dt.type(nan)
                attrs['_FillValue'] = nan
            except ValueError:
                no_data = band.GetNoDataValue()
                attrs.update({'_FillValue': no_data} if no_data else {})
            variables['Band%i' % iband] = Variable(dims, arr, attrs)
        variables['lat'], variables['lon'] = self._load_GeoTransform()
        return FrozenOrderedDict(variables)
예제 #2
0
    def get_dimensions(self):
        """Get the file's dimensions.

        This is used by `xarray.open_dataset`.

        """
        return FrozenOrderedDict(x=self.prod_desc.nx, y=self.prod_desc.ny)
예제 #3
0
    def get_variables(self):
        """Get all variables in the file.

        This is used by `xarray.open_dataset`.

        """
        variables = [self._make_time_var()]
        proj_var_name, proj_var = self._make_proj_var()
        variables.append((proj_var_name, proj_var))
        variables.extend(self._make_coord_vars())

        # Now the data
        name = self.prod_desc.channel
        if '(' in name:
            name = name.split('(')[0].rstrip()

        missing_val = self.missing
        attrs = {
            'long_name': self.prod_desc.channel,
            'missing_value': missing_val,
            'coordinates': 'y x time',
            'grid_mapping': proj_var_name
        }
        data_var = Variable(('y', 'x'),
                            data=np.ma.array(self.data,
                                             mask=self.data == missing_val),
                            attrs=attrs)
        variables.append((name, data_var))

        return FrozenOrderedDict(variables)
예제 #4
0
    def get_attrs(self):
        """Get the global attributes.

        This is used by `xarray.open_dataset`.

        """
        return FrozenOrderedDict(satellite=self.prod_desc.creating_entity,
                                 sector=self.prod_desc.sector_id)
예제 #5
0
 def get_attrs(self):
     from osr import SpatialReference
     attrs = self.ds.GetMetadata()
     try:
         sp = SpatialReference(wkt=self.ds.GetProjection())
         proj4 = sp.ExportToProj4()
     except:
         warn('Could not identify projection')
     else:
         attrs['proj4'] = proj4
     return FrozenOrderedDict(attrs)
예제 #6
0
 def get_attrs(self):
     return FrozenOrderedDict(self.ds.attributes)
예제 #7
0
 def get_variables(self):
     return FrozenOrderedDict(
         (self.variable_map.get(k, k), self.open_store_variable(k, v))
         for k, v in self.ds.variables.items())
예제 #8
0
 def get_dimensions(self):
     """Get the dimensions from underlying data set."""
     return FrozenOrderedDict(
         (k, len(v)) for k, v in self.ds.dimensions.items())
예제 #9
0
 def get_attrs(self):
     """Get the global attributes from underlying data set."""
     return FrozenOrderedDict(
         (a, getattr(self.ds, a)) for a in self.ds.ncattrs())
예제 #10
0
 def get_variables(self):
     """Get the variables from underlying data set."""
     return FrozenOrderedDict((k, self.open_store_variable(k, v))
                              for k, v in self.ds.variables.items())