コード例 #1
0
def test_cube_with_multiple(fname=os.path.join(data_path, 'OCOS.nc')):
    cube = iris.load_cube(fname, 'potential temperature')
    with pytest.raises(iris.exceptions.CoordinateNotFoundError):
        cube.coord(axis='X')
        cube.coord(axis='Y')
    grid = gridgeo.GridGeo(cube)
    assert isinstance(grid, gridgeo.GridGeo)
コード例 #2
0
    def get_models(self):
        self.dap_urls = []
        self.grids = {}
        self.model_urls = []

        for i, df_row in self.df.iterrows():
            row = df_row.to_dict()
            # Handle the presenece of "opendap" in the NOAA NOS-COOPS obs domain
            url = row['url']
            if row['scheme'] == 'OPeNDAP:OPeNDAP' or 'dodsC' in url:
                if not '.html' in url:
                    self.dap_urls.append(url)
    
        for url in self.dap_urls:
            try:
                nc = Dataset(url)
            except:
                continue
            try:
                temp = nc.get_variables_by_attributes(standard_name=lambda x: x in self.target)[0]
                standard_name = temp.standard_name
            except:
                continue
            try:
                grid = gridgeo.GridGeo(nc, standard_name=standard_name)
                title = getattr(nc, 'title', url)
                self.model_urls.append(url)
            except Exception:
                continue
            self.grids.update({title: grid})
        print(self.grids)
コード例 #3
0
    def get_models(self):
        '''
        Function for pulling models from the url queries.
        '''
        self.dap_urls = []
        self.grids = {}
        self.model_urls = []

        # Query each url in the database
        for i, df_row in self.df.iterrows():
            row = df_row.to_dict()
            # Handle the presenece of "opendap" in the NOAA NOS-COOPS obs domain
            url = row['url']
            if row['scheme'] == 'OPeNDAP:OPeNDAP' or 'dodsC' in url:
                if not '.html' in url:
                    self.dap_urls.append(url)

        # for the valid URLs, try to pull the data
        for url in self.dap_urls:
            # Some files may not be in the proper format. Ignore them.
            try:
                nc = Dataset(url)
            except:
                continue
            # Some files may not contain relevant information, even after filtering. Ignore them.
            try:
                temp = nc.get_variables_by_attributes(
                    standard_name=lambda x: x in self.target)[0]
                standard_name = temp.standard_name
            except:
                continue
            # Some files may not properly convert to a geo-object. Ignore them.
            try:
                grid = gridgeo.GridGeo(nc, standard_name=standard_name)
                title = getattr(nc, 'title', url)
                self.model_urls.append(url)
            except Exception:
                continue
            self.grids.update({title: grid})
        print(self.grids)
コード例 #4
0
ファイル: test_unknown_2d.py プロジェクト: pyoceans/gridgeo
from pathlib import Path

import numpy as np
from shapely.geometry import MultiPolygon, Polygon

import gridgeo

p = Path(__file__).parent.absolute()

fname = p.joinpath("data", "unknown_2d.nc")

grid = gridgeo.GridGeo(fname, standard_name="sea_water_temperature")
npoly = 12706

_iterables = (tuple, list, np.ndarray)


def test_mesh():
    assert grid.mesh == "unknown_2d"


def test__str__():
    assert grid.__str__() == grid.mesh


def test_outline():
    assert isinstance(grid.outline, (MultiPolygon, Polygon))


def test_polygons():
    assert isinstance(grid.polygons, _iterables)
コード例 #5
0
ファイル: test_sgrid.py プロジェクト: lizferguson5/gridgeo
import gridgeo

import numpy as np

from shapely.geometry import MultiPolygon, Polygon


url = 'http://geoport.whoi.edu/thredds/dodsC/clay/usgs/users/jcwarner/Sandy/triple_nest/00_dir_NYB07.ncml'  # noqa


grid = gridgeo.GridGeo(
    url,
    standard_name='sea_water_potential_temperature'
     )
npoly = 43688

_iterables = (tuple, list, np.ndarray)


def test_mesh():
    assert grid.mesh == 'sgrid'


def test__str__():
    assert grid.__str__() == grid.mesh


def test_outline():
    assert isinstance(grid.outline, (MultiPolygon, Polygon))

コード例 #6
0
def test_no_grid():
    with pytest.raises(ValueError):
        gridgeo.GridGeo(point_time_series_string)
コード例 #7
0
def test_more_than_one_grid():
    with pytest.raises(ValueError):
        gridgeo.GridGeo(espresso_string)
コード例 #8
0
def test_nc_from_object():
    nc = Dataset(coawst_string)
    grid = gridgeo.GridGeo(nc)
    assert isinstance(grid.nc, Dataset)
コード例 #9
0
import os
import types

import pysgrid
import numpy as np

from netCDF4 import Dataset
from shapely.geometry import MultiPolygon, Polygon

import gridgeo

data_path = os.path.join(os.path.dirname(__file__), 'data')

coawst_string = os.path.join(data_path, '00_dir_NYB05.nc')

grid = gridgeo.GridGeo(coawst_string)


def test_nc_from_string():
    assert isinstance(grid.nc, str)


def test_grid():
    assert isinstance(grid.grid, pysgrid.SGrid)


def test_mesh():
    assert grid.mesh == 'sgrid'


def test__str__():
コード例 #10
0
def test_rgrid_from_cube(fname=os.path.join(data_path, 'CA_DAS.nc')):
    cube = iris.load_cube(fname, 'sea_water_temperature')
    grid = gridgeo.GridGeo(cube)
    assert isinstance(grid, gridgeo.GridGeo)
コード例 #11
0
def test_ugrid_from_cube(fname=os.path.join(data_path,
                                            'FVCOM-Nowcast-Agg.nc')):
    cube = iris.load_cube(fname, 'sea_water_potential_temperature')
    with pytest.raises(NotImplementedError):
        gridgeo.GridGeo(cube)
コード例 #12
0
def test_sgrid_from_cube(fname=os.path.join(data_path, '00_dir_NYB05.nc')):
    cube = iris.load_cube(fname, 'sea_water_potential_temperature')
    grid = gridgeo.GridGeo(cube)
    assert isinstance(grid, gridgeo.GridGeo)
コード例 #13
0
import pytest
import numpy as np

import iris
from shapely.geometry import MultiPolygon, Polygon

import gridgeo

data_path = os.path.join(os.path.dirname(__file__), 'data')

espresso_string = os.path.join(data_path,
                               'ESPRESSO_Real-Time_v2_Averages_Best.nc')

cube = iris.load_cube(espresso_string, 'sea_water_potential_temperature')

grid = gridgeo.GridGeo(cube)


def test_from_cube():
    assert isinstance(grid.nc, iris.cube.Cube)


def test_grid():
    assert not grid.grid


def test_mesh():
    assert grid.mesh == 'non-compliant'


def test__str__():
コード例 #14
0
import os
import types

import numpy as np

from netCDF4 import Dataset
from shapely.geometry import MultiPolygon, Polygon

import gridgeo

data_path = os.path.join(os.path.dirname(__file__), 'data')

ca_das_string = os.path.join(data_path, 'CA_DAS.nc')

grid = gridgeo.GridGeo(ca_das_string)


def test_nc_from_string():
    assert isinstance(grid.nc, str)


def test_grid():
    assert not grid.grid


def test_mesh():
    assert grid.mesh == 'non-compliant'


def test__str__():
コード例 #15
0
import os
import types

import pyugrid
import numpy as np

from netCDF4 import Dataset
from shapely.geometry import MultiPolygon, Polygon

import gridgeo

data_path = os.path.join(os.path.dirname(__file__), 'data')

fvcom_string = os.path.join(data_path, 'FVCOM-Nowcast-Agg.nc')

grid = gridgeo.GridGeo(fvcom_string)


def test_nc_from_string():
    assert isinstance(grid.nc, str)


def test_grid():
    assert isinstance(grid.grid, pyugrid.UGrid)


def test_mesh():
    assert grid.mesh == 'ugrid'


def test__str__():