示例#1
0
    def test_from_dict(self):

        d = dict(standard_name='lwe_thickness_of_precipitation_amount')
        urn = IoosUrn.from_dict('axiom', 'foo', d)
        assert urn.urn == 'urn:ioos:sensor:axiom:foo:lwe_thickness_of_precipitation_amount'

        d = dict(standard_name='lwe_thickness_of_precipitation_amount',
                 vertical_datum='NAVD88')
        urn = IoosUrn.from_dict('axiom', 'foo', d)
        assert urn.urn == 'urn:ioos:sensor:axiom:foo:lwe_thickness_of_precipitation_amount#vertical_datum=navd88'

        d = dict(standard_name='lwe_thickness_of_precipitation_amount',
                 vertical_datum='NAVD88',
                 discriminant='2')
        urn = IoosUrn.from_dict('axiom', 'foo', d)
        assert urn.urn == 'urn:ioos:sensor:axiom:foo:lwe_thickness_of_precipitation_amount:2#vertical_datum=navd88'

        d = dict(standard_name='lwe_thickness_of_precipitation_amount',
                 cell_methods='time: sum (interval: PT24H) time: mean')
        urn = IoosUrn.from_dict('axiom', 'foo', d)
        assert urn.urn == 'urn:ioos:sensor:axiom:foo:lwe_thickness_of_precipitation_amount#cell_methods=time:mean,time:sum;interval=pt24h'

        # Interval as a dict key (not inline with cell_methods)
        d = dict(standard_name='lwe_thickness_of_precipitation_amount',
                 cell_methods='time: sum time: mean',
                 interval='pt24h')
        urn = IoosUrn.from_dict('axiom', 'foo', d)
        assert urn.urn == 'urn:ioos:sensor:axiom:foo:lwe_thickness_of_precipitation_amount#cell_methods=time:mean,time:sum;interval=pt24h'

        d = dict(standard_name='lwe_thickness_of_precipitation_amount',
                 cell_methods='time: minimum within years time: mean over years')
        urn = IoosUrn.from_dict('axiom', 'foo', d)
        assert urn.urn == 'urn:ioos:sensor:axiom:foo:lwe_thickness_of_precipitation_amount#cell_methods=time:mean_over_years,time:minimum_within_years'

        d = dict(standard_name='lwe_thickness_of_precipitation_amount',
                 cell_methods='time: variance (interval: PT1H comment: sampled instantaneously)')
        urn = IoosUrn.from_dict('axiom', 'foo', d)
        assert urn.urn == 'urn:ioos:sensor:axiom:foo:lwe_thickness_of_precipitation_amount#cell_methods=time:variance;interval=pt1h'

        d = dict(standard_name='lwe_thickness_of_precipitation_amount',
                 cell_methods='time: variance time: mean (interval: PT1H comment: sampled instantaneously)')
        urn = IoosUrn.from_dict('axiom', 'foo', d)
        assert urn.urn == 'urn:ioos:sensor:axiom:foo:lwe_thickness_of_precipitation_amount#cell_methods=time:mean,time:variance;interval=pt1h'

        # Interval specified twice
        d = dict(standard_name='lwe_thickness_of_precipitation_amount',
                 cell_methods='time: variance time: mean (interval: PT1H comment: sampled instantaneously)',
                 interval='PT1H')
        urn = IoosUrn.from_dict('axiom', 'foo', d)
        assert urn.urn == 'urn:ioos:sensor:axiom:foo:lwe_thickness_of_precipitation_amount#cell_methods=time:mean,time:variance;interval=pt1h'

        # Interval specified twice
        d = dict(standard_name='lwe_thickness_of_precipitation_amount',
                 cell_methods='time: variance time: mean (interval: PT1H comment: sampled instantaneously)',
                 interval='PT1H',
                 discriminant='2')
        urn = IoosUrn.from_dict('axiom', 'foo', d)
        assert urn.urn == 'urn:ioos:sensor:axiom:foo:lwe_thickness_of_precipitation_amount:2#cell_methods=time:mean,time:variance;interval=pt1h'
示例#2
0
    def test_from_variable(self):

        with netCDF4.Dataset(
            os.path.join(
                os.path.dirname(__file__),
                'resources',
                'test_urn_from_variable.nc'
            )
        ) as nc:

            urn = IoosUrn.from_dict('axiom', 'foo', nc.variables['temperature'].__dict__)
            assert urn.urn == 'urn:ioos:sensor:axiom:foo:lwe_thickness_of_precipitation_amount#vertical_datum=navd88'

            urn = IoosUrn.from_dict('axiom', 'foo', nc.variables['temperature2'].__dict__)
            assert urn.urn == 'urn:ioos:sensor:axiom:foo:lwe_thickness_of_precipitation_amount#cell_methods=time:variance;interval=pt1h'

            urn = IoosUrn.from_dict('axiom', 'foo', nc.variables['temperature3'].__dict__)
            assert urn.urn == 'urn:ioos:sensor:axiom:foo:lwe_thickness_of_precipitation_amount#cell_methods=time:mean,time:variance;interval=pt1h'

            urn = IoosUrn.from_dict('axiom', 'foo', nc.variables['temperature4'].__dict__)
            assert urn.urn == 'urn:ioos:sensor:axiom:foo:lwe_thickness_of_precipitation_amount:2#cell_methods=time:mean,time:variance;interval=pt1h'