Exemple #1
0
    def test_init(self):
        dataset = self.get_dataset()
        uri = dataset['uri']
        variable = dataset['variable']
        with nc_scope(uri) as ds:
            nc_metadata = NcMetadata(ds)

        keywords = dict(
            uri=[None, self.get_dataset()['uri']],
            variable=[None, self.get_dataset()['variable']],
            request_dataset=[None, RequestDataset(uri=uri, variable=variable)],
            meta=[None, nc_metadata])

        for k in itr_products_keywords(keywords, as_namedtuple=True):
            try:
                ip = Inspect(**k._asdict())
            except ValueError:
                if k.uri is None and k.request_dataset is None and k.meta is None:
                    continue
                else:
                    raise
            ret = ip.__repr__()
            search = re.search('URI = (.*)\n', ret).groups()[0]
            if k.uri is None and k.meta is not None and k.request_dataset is None:
                self.assertEqual(search, 'None')
            else:
                self.assertTrue(os.path.exists(search))
Exemple #2
0
    def inspect_as_dct(self):
        '''
        Return a dictionary representation of the target's metadata. If the variable
        is `None`. An attempt will be made to find the target dataset's time bounds
        raising a warning if none is found or the time variable is lacking units
        and/or calendar attributes.

        >>> rd = ocgis.RequestDataset('rhs_day_CanCM4_decadal2010_r2i1p1_20110101-20201231.nc','rhs')
        >>> ret = rd.inspect_as_dct()
        >>> ret.keys()
        ['dataset', 'variables', 'dimensions', 'derived']
        >>> ret['derived']
        OrderedDict([('Start Date', '2011-01-01 12:00:00'), ('End Date', '2020-12-31 12:00:00'), ('Calendar', '365_day'), ('Units', 'days since 1850-1-1'), ('Resolution (Days)', '1'), ('Count', '8192'), ('Has Bounds', 'True'), ('Spatial Reference', 'WGS84'), ('Proj4 String', '+proj=longlat +datum=WGS84 +no_defs '), ('Extent', '(-1.40625, -90.0, 358.59375, 90.0)'), ('Interface Type', 'NcPolygonDimension'), ('Resolution', '2.80091351339')])

        :rtype: :class:`collections.OrderedDict`
        '''
        from ocgis import Inspect
        ip = Inspect(request_dataset=self)
        ret = ip._as_dct_()
        return ret
Exemple #3
0
    def test_init(self):
        dataset = self.get_dataset()
        uri = dataset["uri"]
        variable = dataset["variable"]

        keywords = dict(
            uri=[None, self.get_dataset()["uri"]],
            variable=[None, self.get_dataset()["variable"]],
            request_dataset=[None, RequestDataset(uri=uri, variable=variable)],
        )
        for k in itr_products_keywords(keywords, as_namedtuple=True):
            try:
                ip = Inspect(**k._asdict())
            except ValueError:
                if k.uri is None and k.request_dataset is None:
                    continue
                else:
                    raise
            ret = ip.__str__()
            search = re.search("URI = (.*)\n", ret).groups()[0]
            if k.uri is None and k.request_dataset is None:
                self.assertEqual(search, "None")
            else:
                self.assertTrue(os.path.exists(search))
Exemple #4
0
from ocgis import Inspect
import os.path

## Directory holding climate data.
DATA_DIR = '/usr/local/climate_data/CanCM4'
## Location and variable name for a daily decadal temperature simulation.
URI_TAS = os.path.join(
    DATA_DIR, 'tas_day_CanCM4_decadal2000_r2i1p1_20010101-20101231.nc')
VAR_TAS = 'tas'

## Inspect the dataset at the global level.
print(Inspect(URI_TAS))
## Inspect a variable contained in a dataset.
print(Inspect(URI_TAS, variable=VAR_TAS))
Exemple #5
0
 def test_get_report_possible(self):
     uri = [self.test_data.get_uri("cancm4_tas"), self.get_netcdf_path_no_dimensioned_variables()]
     for u in uri:
         ip = Inspect(uri=u)
         target = ip.get_report_possible()
         self.assertTrue(len(target) > 10)
Exemple #6
0
 def test_get_field_report(self):
     rd = self.test_data.get_rd("cancm4_tas")
     fai = Inspect(request_dataset=rd)
     target = fai.get_field_report()
     self.assertEqual(len(target), 25)
Exemple #7
0
 def test_append_dump_report(self):
     path = self.get_netcdf_path_no_dimensioned_variables()
     ip = Inspect(uri=path)
     target = []
     ip._append_dump_report_(target)
     self.assertTrue(len(target) > 5)