def test_subset_issue769_1d_lons_lats(
     self, patch_get_dataset_config, patch_format_date
 ):
     """Confirm that the 1d lons and lats arrays condition that causes subset()
     to raise a ValueError has been fixed.
     """
     patch_get_dataset_config.return_value = self.patch_dataset_config_ret_val
     # Avoid the need for a Flask app context because format_date is from flask_babel
     patch_format_date.return_value = 19700101
     kwargs = {"dataset_key": "mercator_test"}
     with NetCDFData("tests/testdata/mercator_test.nc", **kwargs) as nc_data:
         query = dict(
             [
                 ("output_format", "NETCDF3_NC"),
                 ("dataset_name", "mercator_test"),
                 ("variables", "votemper"),
                 ("min_range", "-79.0,2.0"),
                 ("max_range", "-78.0,3.0"),
                 ("time", "2119651200,2119651200"),
                 ("should_zip", "0"),
             ]
         )
         nc_data.subset(query)
 def test_x_dimensions(self):
     with NetCDFData("tests/testdata/nemo_test.nc") as nc_data:
         self.assertEqual({"x", "xc", "longitude", "gridX"}, nc_data.x_dimensions)
Exemple #3
0
 def test_enter_no_nc_files_list(self):
     with NetCDFData("tests/testdata/nemo_test.nc") as nc_data:
         self.assertIsInstance(nc_data.dataset, xarray.Dataset)
         self.assertTrue(nc_data._dataset_open)
Exemple #4
0
 def test_enter_meta_only(self):
     kwargs = {"meta_only": True}
     with NetCDFData("tests/testdata/nemo_test.nc", **kwargs) as nc_data:
         self.assertFalse(nc_data._dataset_open)
         self.assertIsNone(nc_data.dataset)
Exemple #5
0
 def test_get_dataset_variable_raises_on_unknown_variable(self):
     with NetCDFData("tests/testdata/nemo_test.nc") as nc_data:
         with self.assertRaises(KeyError):
             nc_data.get_dataset_variable('fake_variable')
Exemple #6
0
 def test_yx_dimensions(self):
     with NetCDFData("tests/testdata/nemo_test.nc") as nc_data:
         y_coord, x_coord = nc_data.yx_dimensions
         self.assertEqual("y", y_coord)
         self.assertEqual("x", x_coord)
Exemple #7
0
 def test_y_dimensions(self):
     with NetCDFData("tests/testdata/nemo_test.nc") as nc_data:
         self.assertEqual({'y', 'yc', 'latitude', 'gridY'}, nc_data.y_dimensions)
Exemple #8
0
 def test_latlon_variables_not_found_raises(self):
     # Use salishseacast_ssh_test.nc here because it has neither nav_lat nor latitude variables
     with NetCDFData("tests/testdata/salishseacast_ssh_test.nc") as nc_data:
         with self.assertRaises(KeyError):
             lat, lon = nc_data.latlon_variables
Exemple #9
0
 def test_xarray_dimensions(self):
     with NetCDFData("tests/testdata/mercator_test.nc") as nc_data:
         self.assertEqual(['depth', 'latitude', 'longitude', 'time'],
                          nc_data.dimensions)
Exemple #10
0
 def test_convert_to_timestamp_list(self):
     with NetCDFData("tests/testdata/nemo_test.nc") as nc_data:
         date_formatted = nc_data.convert_to_timestamp(
             "2014-05-17T00:00:00Z, 2014-06-16T12:00:00Z")
         expected = {" 2014-06-16T12:00:00Z": 1, "2014-05-17T00:00:00Z": 0}
         self.assertEqual(date_formatted, expected)
 def test_enter_not_meta_only(self):
     nc_data = NetCDFData('tests/testdata/mercator_test.nc')
     with Mercator(nc_data) as ds:
         self.assertIsNotNone(ds.latvar)
         self.assertIsNotNone(ds.lonvar)
    def test_get_dataset_variable_returns_dataarray(self):
        with NetCDFData("tests/testdata/nemo_test.nc") as nc_data:
            res = nc_data.get_dataset_variable('votemper')

            self.assertEqual(xarray.DataArray, type(res))
Exemple #13
0
 def test_enter(self):
     nc_data = NetCDFData("tests/testdata/mercator_test.nc")
     with Mercator(nc_data) as ds:
         self.assertIsNotNone(ds.latvar)
         self.assertIsNotNone(ds.lonvar)
 def test_init(self):
     nc_data = NetCDFData("tests/testdata/nemo_test.nc")
     ds = Nemo(nc_data)
     self.assertIs(ds.nc_data, nc_data)
     self.assertEqual(ds.variables, nc_data.variables)
 def test_get_profile_raises_when_surface_variable_requested(self):
     nc_data = NetCDFData("tests/testdata/salishseacast_ssh_test.nc")
     with Nemo(nc_data) as ds:
         with self.assertRaises(APIError):
             ds.get_profile(None, None, "ssh", None, None)
Exemple #16
0
 def test_convert_to_timestamp_str(self):
     with NetCDFData("tests/testdata/nemo_test.nc") as nc_data:
         date_formatted = nc_data.convert_to_timestamp("2014-06-16T12:00:00Z")
         self.assertEqual(date_formatted, 1)
Exemple #17
0
    def test_nemo_latlon_variables(self):
        with NetCDFData("tests/testdata/nemo_test.nc") as nc_data:
            lat, lon = nc_data.latlon_variables

            self.assertEqual(lat.attrs["long_name"], "Latitude")
            self.assertEqual(lon.attrs["long_name"], "Longitude")
Exemple #18
0
 def test_zarr_xarray_dimensions(self):
     with NetCDFData("tests/testdata/giops_test.zarr") as nc_data:
         self.assertEqual(['depth', 'latitude', 'longitude', 'time'],
                          nc_data.dimensions)
Exemple #19
0
 def test_variable_list_cached(self):
     with NetCDFData("tests/testdata/nemo_test.nc") as nc_data:
         self.assertIsNone(nc_data._variable_list)
         variables = nc_data.variables
         self.assertEqual(nc_data._variable_list, variables)
Exemple #20
0
 def test_fvcom_dimensions(self):
     with NetCDFData("tests/testdata/fvcom_test.nc") as nc_data:
         self.assertEqual(["time", "maxStrlen64", "node", "siglay"],
                          nc_data.dimensions)
Exemple #21
0
 def test_x_dimensions(self):
     with NetCDFData("tests/testdata/nemo_test.nc") as nc_data:
         self.assertEqual({'x', 'xc', 'longitude', 'gridX'}, nc_data.x_dimensions)
Exemple #22
0
 def test_enter_zarr_file(self):
     nc_data = NetCDFData("tests/testdata/giops_test.zarr")
     nc_data.url = "tests/testdata/giops_test.zarr"
     nc_data.__enter__()
     self.assertIsInstance(nc_data.dataset, xarray.Dataset)
     self.assertTrue(nc_data._dataset_open)
Exemple #23
0
    def test_get_nc_file_no_variable_kwarg_raises(self, patch_get_dataset_config):
        patch_get_dataset_config.return_value = self.patch_dataset_config_ret_val

        with NetCDFData("tests/testdata/nemo_test.nc", **{"dataset_key": "nemo_sqlite3"}) as nc_data:
            with self.assertRaises(RuntimeError):
                nc_data.get_nc_file_list(nc_data._dataset_config)
Exemple #24
0
 def test_exit(self):
     with NetCDFData("tests/testdata/nemo_test.nc") as nc_data:
         self.assertTrue(nc_data._dataset_open)
     self.assertFalse(nc_data._dataset_open)
Exemple #25
0
 def test_interpolate_raises_on_unknown_interp_method(self):
     with NetCDFData("tests/testdata/nemo_test.nc") as nc_data:
         nc_data.interp = "fake_method"
         with self.assertRaises(ValueError):
             nc_data.interpolate(None, None, None)
Exemple #26
0
 def test_timestamp_to_time_index_int_timestamp(self):
     with NetCDFData("tests/testdata/nemo_test.nc") as nc_data:
         result = nc_data.timestamp_to_time_index(2031436800)
         self.assertEqual(result, 0)
Exemple #27
0
 def test_enter_nc_files_list_fvcom(self):
     nc_data = NetCDFData("tests/testdata/fvcom_test.nc")
     nc_data._nc_files = ["tests/testdata/fvcom_test.nc"]
     nc_data.__enter__()
     self.assertIsInstance(nc_data.dataset, xarray.Dataset)
     self.assertTrue(nc_data._dataset_open)
Exemple #28
0
 def test_timestamp_to_time_index_timestamp_list(self):
     with NetCDFData("tests/testdata/nemo_test.nc") as nc_data:
         result = nc_data.timestamp_to_time_index([2031436800, 2034072000])
         numpy.testing.assert_array_equal(result, numpy.array([0, 1]))
Exemple #29
0
 def test_enter_no_nc_files_list_fvcom(self):
     with NetCDFData("tests/testdata/fvcom_test.nc") as nc_data:
         self.assertIsInstance(nc_data.dataset, netCDF4.Dataset)
         self.assertTrue(nc_data._dataset_open)
Exemple #30
0
 def test_timestamp_to_iso_8601_int_timestamp(self):
     with NetCDFData("tests/testdata/nemo_test.nc") as nc_data:
         result = nc_data.timestamp_to_iso_8601(2031436800)
         self.assertEqual(result, cftime.real_datetime(2014, 5, 17, tzinfo=pytz.UTC))