Skip to content

Commit

Permalink
Fix scanner (#18)
Browse files Browse the repository at this point in the history
* test: Get recent data

Verify InRange searching for recent data. So many unrelated things can
go wrong to fail this test, but should work just fine most of the time.

* fix: inrange() was renamed to matchup()

* fix: bloom_filter for multiple sensors

It was missing dL_tol on recursive calls.

* Bump version: 0.0.9 → 0.0.10

* fix: typo

* fix: Inconsistent title between HISTORY & README
  • Loading branch information
castelao authored Mar 15, 2022
1 parent c17f9e5 commit 8786f97
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 7 deletions.
2 changes: 1 addition & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ authors:
family-names: Castelao
affiliation: Scripps Institution of Oceanography - UC San Diego
orcid: https://orcid.org/0000-0002-6765-0708
version: 0.0.9
version: 0.0.10
doi: 10.5281/zenodo.4646628
date-released: 2021-03-21
repository-code: https://github.com/castelao/CoTeDe
Expand Down
3 changes: 3 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,19 @@ History

Before release 0.1 expect gaps in the history description

-----
0.0.9
-----

* Stable concurrent searches using loky

------------------
0.0.1 (2020-02-24)
------------------

* First release on PyPI.

------------------------
pre-release (since 2018)
------------------------

Expand Down
2 changes: 1 addition & 1 deletion OceanColor/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

__author__ = """Guilherme Castelão"""
__email__ = "[email protected]"
__version__ = "0.0.9"
__version__ = "0.0.10"

# Recent OSX requires this environment variable to run parallel processes
if sys.platform == "darwin":
Expand Down
2 changes: 1 addition & 1 deletion OceanColor/cmr.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ def bloom_filter(
"""
if isinstance(sensor, list):
for s in sensor:
filenames = bloom_filter(track, s, dtype, dt_tol)
filenames = bloom_filter(track, s, dtype, dt_tol, dL_tol)
yield from filenames
return

Expand Down
4 changes: 2 additions & 2 deletions OceanColor/inrange.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def scanner_threading(self, queue, parent, npes, track, sensor, dtype, dt_tol, d
return
results.append(
threading.Thread(
target=inrange, args=(track, ds, dL_tol, dt_tol, queue)
target=matchup, args=(track, ds, dL_tol, dt_tol, queue)
)
)
results[-1].start()
Expand Down Expand Up @@ -185,7 +185,7 @@ def scanner(self, queue, parent, npes, track, sensor, dtype, dt_tol, dL_tol):
if not parent.is_alive():
return
module_logger.debug("Submitting a new inrange process")
results.append(executor.submit(inrange, track, ds, dL_tol, dt_tol))
results.append(executor.submit(matchup, track, ds, dL_tol, dt_tol))

for tmp in (r.result(timeout) for r in results):
if not parent.is_alive():
Expand Down
3 changes: 2 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[bumpversion]
current_version = 0.0.9
current_version = 0.0.10
commit = True
tag = True

Expand Down Expand Up @@ -29,3 +29,4 @@ test = pytest

[tool:pytest]
collect_ignore = ['setup.py']

2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def requirements():
test_suite='tests',
tests_require=test_requirements,
url='https://github.com/castelao/OceanColor',
version="0.0.9",
version="0.0.10",
zip_safe=False,
extras_require = {
'parallel': ["loky>=2.8"],
Expand Down
12 changes: 12 additions & 0 deletions tests/test_cmr.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,18 @@ def test_bloom_filter_spaced_target():
assert len(results) < 5
assert len(results) == 3


def test_bloom_multiple_sensors():
track = [{"time": datetime64("2019-05-01"), "lat": 18, "lon": 38}]
filter = bloom_filter(
pd.DataFrame(track),
sensor=["aqua", "terra", "snpp"],
dtype="L2",
dt_tol=timedelta64(36, "h"),
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 Down
33 changes: 33 additions & 0 deletions tests/test_inrange.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
"""Test module inrange
"""

from datetime import datetime
import tempfile

from numpy import datetime64, timedelta64
import os

import pandas as pd
from pandas import DataFrame

from OceanColor.inrange import matchup_L2, matchup_L3m, matchup
Expand Down Expand Up @@ -80,6 +85,34 @@ def test_matchup():
assert data.size == 42


def test_InRange_recent():
"""Find recent in range
By using FileSystem in a temporary directory guarantees that the cache
is not been used. At some point a typo in the InRange's scanner was
missed by the tests since it was acessing the cache without actually
downloading it.
"""
track = DataFrame(
[
{
"time": datetime64(datetime.utcnow()) - timedelta64(15, "D"),
"lat": 35.6,
"lon": -126.81,
}
]
)

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
)
output = pd.concat([m for m in matchup])

assert len(output) > 0


def test_InRange_early_termination():
"""Terminate before consuming or even finished searching
"""
Expand Down

0 comments on commit 8786f97

Please sign in to comment.