From c86d0ffa034dbcc69d61150261efd517fa8f27bb Mon Sep 17 00:00:00 2001 From: Gui Castelao Date: Thu, 5 Oct 2023 22:21:52 -0600 Subject: [PATCH] style: Updating syntax --- .gitignore | 2 +- README.rst | 2 +- docs/conf.py | 2 +- setup.cfg | 2 +- tests/test_cmr.py | 39 +++++++++++++++++++++++++++------ tests/test_inrange.py | 50 +++++++++++++++++++++++++++---------------- tests/test_storage.py | 21 ++++++++++-------- 7 files changed, 80 insertions(+), 38 deletions(-) diff --git a/.gitignore b/.gitignore index c545b16..c9fc5ae 100644 --- a/.gitignore +++ b/.gitignore @@ -103,4 +103,4 @@ ENV/ .mypy_cache/ # IDE settings -.vscode/ \ No newline at end of file +.vscode/ diff --git a/README.rst b/README.rst index d910829..c7babe3 100644 --- a/README.rst +++ b/README.rst @@ -29,7 +29,7 @@ situ observations by searching pixels within a given time and distance tolerance For instance, it is used to calibrate chlorophyll fluorescence measurements from Spray underwater gliders. -The OceanColor package was developed at the `Instrument Development Group +The OceanColor package was developed at the `Instrument Development Group `_ of `Scripps Institution of Oceanography `_ in support for the `California Underwater Glider Network `_ operations, which is diff --git a/docs/conf.py b/docs/conf.py index 5390ba7..585bbdc 100755 --- a/docs/conf.py +++ b/docs/conf.py @@ -57,7 +57,7 @@ # General information about the project. project = 'Ocean Color' -copyright = "2018-{}, Guilherme Castelão".format(datetime.now().year) +copyright = f"2018-{datetime.now().year}, Guilherme Castelão" author = "Guilherme Castelão" # The version info for the project you're documenting, acts as replacement diff --git a/setup.cfg b/setup.cfg index da6da0f..d265b7d 100644 --- a/setup.cfg +++ b/setup.cfg @@ -3,6 +3,6 @@ universal = 1 [flake8] exclude = docs -ignore = +ignore = E203 E501 diff --git a/tests/test_cmr.py b/tests/test_cmr.py index bc9344b..4c279c0 100644 --- a/tests/test_cmr.py +++ b/tests/test_cmr.py @@ -6,7 +6,12 @@ import pandas as pd import pytest -from OceanColor.cmr import api_walk, bloom_filter, granules_search, search_criteria +from OceanColor.cmr import ( + api_walk, + bloom_filter, + granules_search, + search_criteria, +) def test_api_walk(): @@ -37,12 +42,20 @@ def test_bloom_filter(): track = [{"time": datetime64("2019-05-01"), "lat": 18, "lon": 38}] track = pd.DataFrame(track) for f in bloom_filter( - track, sensor="aqua", dtype="L2", dt_tol=timedelta64(36, "h"), dL_tol=10e3 + track, + sensor="aqua", + dtype="L2", + dt_tol=timedelta64(36, "h"), + dL_tol=10e3, ): f for f in bloom_filter( - track, sensor="aqua", dtype="L3m", dt_tol=timedelta64(36, "h"), dL_tol=10e3 + track, + sensor="aqua", + dtype="L3m", + dt_tol=timedelta64(36, "h"), + dL_tol=10e3, ): f @@ -61,7 +74,13 @@ def test_bloom_filter_unique(): {"time": datetime64("2019-05-02"), "lat": 18, "lon": 38}, ] track = pd.DataFrame(track) - search = bloom_filter(track, sensor="aqua", dtype="L3m", dt_tol=timedelta64(24, "h"), dL_tol=10e3) + search = bloom_filter( + track, + sensor="aqua", + dtype="L3m", + dt_tol=timedelta64(24, "h"), + dL_tol=10e3, + ) results = [r for r in search] assert len(results) == len(set(results)), "Duplicates from bloom_filter" @@ -73,7 +92,13 @@ def test_bloom_filter_spaced_target(): {"time": datetime64("2019-05-15 12:00:00"), "lat": 18, "lon": 38}, ] track = pd.DataFrame(track, index=[0, 10, 100]) - search = bloom_filter(track, sensor="aqua", dtype="L3m", dt_tol=timedelta64(6, "h"), dL_tol=5e3) + search = bloom_filter( + track, + sensor="aqua", + dtype="L3m", + dt_tol=timedelta64(6, "h"), + dL_tol=5e3, + ) results = [r for r in search] print(results) assert len(results) < 5 @@ -87,10 +112,11 @@ def test_bloom_multiple_sensors(): sensor=["aqua", "terra", "snpp"], dtype="L2", dt_tol=timedelta64(36, "h"), - dL_tol=10e3 + dL_tol=10e3, ) assert len([f for f in filter]) > 0 + def test_search_criteria(): search = search_criteria(sensor="aqua", dtype="L2") assert search["short_name"] == "MODISA_L2_OC" @@ -105,6 +131,7 @@ def test_search_criteria_nonexistent_key(): with pytest.raises(ValueError): search_criteria(sensor="seawifs", dtype="nonexistent") + """ {'cdate': '2019-08-05 21:23:16', 'checksum': 'sha1:97b97ec2bc5c59255fd8e5ec8551f7bebb6f8be5', 'getfile': 'https://oceandata.sci.gsfc.nasa.gov/ob/getfile', 'size': 9881732, 'filename': 'A2019152.L3m_DAY_CHL_chlor_a_4km.nc'} {'cdate': '2019-08-05 20:56:42', 'checksum': 'sha1:de47941eb5c5454ac7b629c54643ccdbb482988b', 'getfile': 'https://oceandata.sci.gsfc.nasa.gov/ob/getfile', 'size': 9116814, 'filename': 'A2019153.L3m_DAY_CHL_chlor_a_4km.nc'} diff --git a/tests/test_inrange.py b/tests/test_inrange.py index 5eb2886..49ecbff 100644 --- a/tests/test_inrange.py +++ b/tests/test_inrange.py @@ -28,25 +28,25 @@ def test_matchup_L2(): ds = db["AQUA_MODIS.20170112T213500.L2.OC.nc"] dL_tol = 12e3 - dt_tol = timedelta64(6, 'h') - track = DataFrame([ - {"time": datetime64("2017-01-12 20:00:00"), "lat": 34, "lon": -126}]) + dt_tol = timedelta64(6, "h") + track = DataFrame( + [{"time": datetime64("2017-01-12 20:00:00"), "lat": 34, "lon": -126}] + ) data = matchup_L2(track, ds, dL_tol, dt_tol) # Dummy check assert data.index.size == 448 - @pytest.mark.skip() def test_matchup_L2_day_line(): - """Test nearby the international day line from both sides - """ + """Test nearby the international day line from both sides""" ds = db["V2017013002400.L2_SNPP_OC.nc"] dL_tol = 6e3 - dt_tol = timedelta64(6, 'h') - track = DataFrame([ - {"time": datetime64("2017-01-12 20:00:00"), "lat": 60, "lon": 179.99}]) + dt_tol = timedelta64(6, "h") + track = DataFrame( + [{"time": datetime64("2017-01-12 20:00:00"), "lat": 60, "lon": 179.99}] + ) data = matchup_L2(track, ds, dL_tol, dt_tol) # Dummy check @@ -55,8 +55,15 @@ def test_matchup_L2_day_line(): assert data.lon.max() > 0 # From the other side - track = DataFrame([ - {"time": datetime64("2017-01-12 20:00:00"), "lat": 60, "lon": -179.99}]) + track = DataFrame( + [ + { + "time": datetime64("2017-01-12 20:00:00"), + "lat": 60, + "lon": -179.99, + } + ] + ) data = matchup_L2(track, ds, dL_tol, dt_tol) # Dummy check @@ -68,9 +75,10 @@ def test_matchup_L2_day_line(): def test_matchup_L3m(): ds = db["AQUA_MODIS.20170112.L3m.DAY.CHL.chlor_a.4km.nc"] dL_tol = 12e3 - dt_tol = timedelta64(6, 'h') - track = DataFrame([ - {"time": datetime64("2017-01-12 20:00:00"), "lat": 34, "lon": -126}]) + dt_tol = timedelta64(6, "h") + track = DataFrame( + [{"time": datetime64("2017-01-12 20:00:00"), "lat": 34, "lon": -126}] + ) data = matchup_L3m(track, ds, dL_tol, dt_tol) # Dummy check @@ -81,9 +89,10 @@ def test_matchup_L3m(): def test_matchup(): ds = db["AQUA_MODIS.20170112.L3m.DAY.CHL.chlor_a.4km.nc"] dL_tol = 12e3 - dt_tol = timedelta64(6, 'h') - track = DataFrame([ - {"time": datetime64("2017-01-12 20:00:00"), "lat": 34, "lon": -126}]) + dt_tol = timedelta64(6, "h") + track = DataFrame( + [{"time": datetime64("2017-01-12 20:00:00"), "lat": 34, "lon": -126}] + ) data = matchup(track, ds, dL_tol, dt_tol) # Dummy check @@ -113,7 +122,11 @@ def test_InRange_recent(): with tempfile.TemporaryDirectory() as tmpdirname: matchup = InRange(username, password, tmpdirname, npes=3) matchup.search( - track, sensor="snpp", dtype="L2", dt_tol=timedelta64(12, "h"), dL_tol=10e3 + track, + sensor="snpp", + dtype="L2", + dt_tol=timedelta64(12, "h"), + dL_tol=10e3, ) output = pd.concat([m for m in matchup]) @@ -150,7 +163,6 @@ def test_InRange_monotonic_index(): """ sensor = "aqua" dtype = "L2" - # dtype = 'L2' dL_tol = 12e3 dt_tol = timedelta64(12, "h") track = DataFrame( diff --git a/tests/test_storage.py b/tests/test_storage.py index 7deacd9..b41ffbd 100644 --- a/tests/test_storage.py +++ b/tests/test_storage.py @@ -7,8 +7,10 @@ import pytest import xarray as xr + try: import s3fs + S3FS_AVAILABLE = True except: S3FS_AVAILABLE = False @@ -20,7 +22,7 @@ @pytest.mark.skip() def test_parse_filename_AL2(): - filename = "A2011010000000.L2_LAC_OC.nc" + filename = "AQUA_MODIS.2011010T000000.L2_LAC_OC.nc" descriptors = parse_filename(filename) ans = { @@ -119,7 +121,10 @@ def test_no_download(): @pytest.mark.skip() def test_S3Storage_path(): backend = S3Storage("s3://mybucket/datadir") - assert backend.path("A2019109.L3m_DAY_CHL_chlor_a_4km.nc") == 's3://mybucket/datadir/MODIS-Aqua/L3m/2019/109/A2019109.L3m_DAY_CHL_chlor_a_4km.zarr' + assert ( + backend.path("AQUA_MODIS.20190420.L3m.DAY.CHL.chlor_a.4km.nc") + == "s3://mybucket/datadir/MODIS-Aqua/L3m/2019/109/AQUA_MODIS.2019109.L3m.DAY.CHL.chlor_a.4km.zarr" + ) def test_inmemory(): @@ -129,16 +134,15 @@ def test_inmemory(): - Create test data with @pytest.fixture """ db = InMemory() - ds = xr.Dataset({"x": [1,2,3]}) + ds = xr.Dataset({"x": [1, 2, 3]}) db["test-1"] = ds assert "test-1" in db def test_inmemory_quota(): - """Independent of the quota, at least one item - """ - ds = xr.Dataset({"x": [1,2,3]}) + """Independent of the quota, at least one item""" + ds = xr.Dataset({"x": [1, 2, 3]}) db = InMemory(quota=ds.nbytes + 1) db["test-1"] = ds db["test-2"] = ds @@ -148,10 +152,9 @@ def test_inmemory_quota(): def test_inmemory_at_least_one(): - """Independent of the quota, at least one item - """ + """Independent of the quota, at least one item""" db = InMemory(quota=0) - ds = xr.Dataset({"x": [1,2,3]}) + ds = xr.Dataset({"x": [1, 2, 3]}) db["test-1"] = ds assert "test-1" in db