Skip to content

Commit

Permalink
style: Updating syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
castelao committed Oct 6, 2023
1 parent 2a50bff commit c86d0ff
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,4 @@ ENV/
.mypy_cache/

# IDE settings
.vscode/
.vscode/
2 changes: 1 addition & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
<https://idg.ucsd.edu>`_ of `Scripps Institution of Oceanography
<https://scripps.ucsd.edu>`_ in support for the `California Underwater Glider
Network <https://spraydata.ucsd.edu/projects/CUGN/>`_ operations, which is
Expand Down
2 changes: 1 addition & 1 deletion docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ universal = 1

[flake8]
exclude = docs
ignore =
ignore =
E203
E501
39 changes: 33 additions & 6 deletions tests/test_cmr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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

Expand All @@ -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"

Expand All @@ -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
Expand All @@ -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"
Expand All @@ -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'}
Expand Down
50 changes: 31 additions & 19 deletions tests/test_inrange.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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])

Expand Down Expand Up @@ -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(
Expand Down
21 changes: 12 additions & 9 deletions tests/test_storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@

import pytest
import xarray as xr

try:
import s3fs

S3FS_AVAILABLE = True
except:
S3FS_AVAILABLE = False
Expand All @@ -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 = {
Expand Down Expand Up @@ -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():
Expand All @@ -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
Expand All @@ -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

0 comments on commit c86d0ff

Please sign in to comment.