Exemple #1
0
    def get_dimensions(self):
        """Get the file's dimensions.

        This is used by `xarray.open_dataset`.

        """
        return FrozenDict(x=self.prod_desc.nx, y=self.prod_desc.ny)
Exemple #2
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 FrozenDict(variables)
Exemple #3
0
    def get_attrs(self):
        """Get the global attributes.

        This is used by `xarray.open_dataset`.

        """
        return FrozenDict(satellite=self.prod_desc.creating_entity,
                          sector=self.prod_desc.sector_id)
    def get_attrs(self):
        """Returns a dictionary of metadata stored in the array.

        Note that xarray attributes are roughly equivalent to TileDB metadata. The
        metadata returned here metadata for the dataset, but excludes encoding data for
        TileDB and attribute metadata.
        """
        with tiledb.open(self._uri, key=self._key, mode="r") as array:
            attrs = {
                key: array.meta[key]
                for key in array.meta.keys()
                if not key.startswith((_ATTR_PREFIX, _DIM_PREFIX))
            }
        return FrozenDict(attrs)
    def get_variables(self):
        """Returns a dictionary of variables.

        Return a dictionary of variables (by name) stored in the TileDB array. Each
        variable is generated from a TileDB attributes, TileDB encoding metadata,
        metadata belonging to the attribute, and the name and size of the dimensions of
        the array.
        """
        variable_metadata = self.get_variable_metadata()
        schema = tiledb.ArraySchema.load(self._uri, key=self._key)
        index_converters = tuple(map(TileDBIndexConverter, schema.domain))
        variables = {}
        # Add TileDB dimensions as xarray variables (these are the coordinates for the
        # DataArray) for all dimensions that are not "simple" 0-based integer indexes.
        for converter in index_converters:
            if converter.dtype.kind == "M" or converter.min_value:
                variables[converter.name] = Variable(
                    {converter.name: converter.size},
                    LazilyIndexedArray(TileDBCoordinateWrapper(converter)),
                    variable_metadata.get(converter.name),
                )
        # Add TileDB attributes as variables.
        dims = {indexer.name: indexer.size for indexer in index_converters}
        for attr in schema:
            variable_name = attr.name
            if variable_name.endswith(_COORD_SUFFIX):
                variable_name = variable_name[:-len(_COORD_SUFFIX)]
            data = LazilyIndexedArray(
                TileDBDenseArrayWrapper(
                    attr,
                    self._uri,
                    self._key,
                    self._timestamp,
                    index_converters,
                ))
            metadata = variable_metadata.get(attr.name)
            if attr.fill is not None:
                if metadata is None:
                    metadata = {"_FillValue": attr.fill}
                elif metadata.get("_FillValue") is not None:
                    metadata["_FillValue"] = attr.fill
            variables[variable_name] = Variable(dims, data, metadata)
        return FrozenDict(variables)
Exemple #6
0
 def get_dimensions(self):
     """Get the dimensions from underlying data set."""
     return FrozenDict((k, len(v)) for k, v in self.ds.dimensions.items())
Exemple #7
0
 def get_attrs(self):
     """Get the global attributes from underlying data set."""
     return FrozenDict((a, getattr(self.ds, a)) for a in self.ds.ncattrs())
Exemple #8
0
 def get_variables(self):
     """Get the variables from underlying data set."""
     return FrozenDict((k, self.open_store_variable(k, v))
                       for k, v in self.ds.variables.items())
 def get_dimensions(self):
     """Returns a dictionary of dimension names to sizes."""
     schema = tiledb.ArraySchema.load(self._uri, key=self._key)
     return FrozenDict({dim.name: dim.size for dim in schema.domain})
Exemple #10
0
 def get_variables(self):
     return FrozenDict((k, self.open_store_variable(k, v))
                       for k, v in self._items['array'].items())