Exemplo n.º 1
0
 def _qc_taxon(req):
     points, aphiaid, mad_coef, iqr_coef, return_values = QcResource._parse_request(
         req)
     try:
         qcstats = None
         if aphiaid is not None:
             qcstats = taxoninfo.qc_stats(aphiaid)
         points, duplicate_indices = np.unique(points,
                                               return_inverse=True,
                                               axis=0)
         qc = outliers.environmental(points, duplicate_indices, mad_coef,
                                     iqr_coef, qcstats, return_values)
         qc['spatial'] = outliers.spatial(points, duplicate_indices,
                                          mad_coef, iqr_coef, qcstats,
                                          return_values)
         if qcstats is not None:
             qc['count'] = qcstats['count']
             qc['id'] = qcstats['id']
         else:
             qc['count'] = len(points)
             qc['id'] = None
         return qc
     except Exception as ex:
         raise falcon.HTTPError(
             falcon.HTTP_400, 'Error looking up data for provided points',
             str(ex))
Exemplo n.º 2
0
def test_spatial_qcstats():
    """outliers - spatial qc stats"""
    qcstats = taxoninfo.qc_stats(aphiaid=141433)
    points, duplicate_indices = t.rand_xy_list(200)
    qc = outliers.spatial(points, duplicate_indices, None, None, qcstats=qcstats)
    assert len(qc['ok_mad']) == len(points) and 0 < np.sum(qc['ok_mad']) < len(points)
    assert len(qc['ok_iqr']) == len(points) and 0 < np.sum(qc['ok_iqr']) < len(points)
    for i, k in enumerate(['median', 'mad', 'q1', 'q3']):
        assert isinstance(qc[k], float) and qc[k] == qcstats['spatial'][i+1]
Exemplo n.º 3
0
def test_fetch_taxon_qc():
    """taxoninfo - qc stats"""
    stats = taxoninfo.qc_stats(test_aphiaid)
    assert stats['id'] == 141433
    for env in ['bathymetry', 'sssalinity', 'sstemperature']:
        assert env in stats and len(stats[env]) == 4

    assert 'count' in stats and stats['count'] > 0
    assert 'spatial' in stats and len(stats['spatial']) == 5
Exemplo n.º 4
0
def test_environmental_qcstats():
    """outliers - environmental qc stats"""
    qcstats = taxoninfo.qc_stats(aphiaid=141433)
    points, duplicate_indices = t.rand_xy_list(200)
    qc = outliers.environmental(points, duplicate_indices, 12, 6, qcstats=qcstats)
    for grid in ['bathymetry', 'sssalinity', 'sstemperature']:
        g = qc[grid]
        print(grid)
        print(np.sum(g['ok_mad']))
        print(np.sum(g['ok_iqr']))
        assert len(g['ok_mad']) == len(points) and 0 < np.sum(g['ok_mad']) < len(points)
        assert len(g['ok_iqr']) == len(points) and 0 < np.sum(g['ok_iqr']) < len(points)
        for i, k in enumerate(['median', 'mad', 'q1', 'q3']):
            assert isinstance(g[k], float) and g[k] == qcstats[grid][i]
Exemplo n.º 5
0
def test_fetch_taxon_qc_missing_species():
    """taxoninfo - qc stats data poor taxon"""

    stats = taxoninfo.qc_stats(145552)  # Sargassum baccularia: 7 records
    assert stats['count'] > 0
    centroid, median, mad, q1, q3 = stats['spatial']
    assert len(centroid) == 2
    assert median > 0
    assert mad > 0
    assert q1 is None
    assert q3 is None
    for env in ['sssalinity', 'sstemperature']:
        median, mad, q1, q3 = stats[env]
        assert median is not None
        assert mad > 0
        assert q1 is None
        assert q3 is None
Exemplo n.º 6
0
def test_fetch_taxon_qc_missing_species():
    """taxoninfo - qc stats missing species"""
    stats = taxoninfo.qc_stats(-1)
    assert stats is None