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))
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]
def test_spatial(): """outliers - spatial""" points, duplicate_indices = t.rand_xy_list(150) qc = outliers.spatial(points, duplicate_indices, None, None) assert len(qc['ok_mad']) == len(points) assert len(qc['ok_iqr']) == len(points) assert len(qc['centroid']) > 0 and "SRID=4326;POINT(" in qc['centroid'] assert 16000e3 > qc['median'] > 4000e3 assert 6000e3 > qc['mad'] > 1500e3 assert 12000e3 > qc['q1'] > 2000e3 assert 24000e3 > qc['q3'] > 6000e3 xy = [(random.uniform(-0.001, 0.001), random.uniform(-0.001, 0.001)) for _ in range(100)] duplicate_indices = list(range(100)) qc = outliers.spatial(xy, duplicate_indices, None, None) assert len(qc['ok_mad']) == len(xy) assert len(qc['ok_iqr']) == len(xy) assert qc['centroid'].startswith('SRID=4326;POINT(') assert round(qc['median']/1000) == 0 assert round(qc['mad']/1000) == 0 assert round(qc['q1']/1000) == 0 assert round(qc['q3']/1000) == 0
def test_spatial_few_points(): """ outliers - spatial few points """ points, duplicate_indices = [[1,2]], [0] qc = outliers.spatial(points, duplicate_indices, None, None) assert len(qc['ok_mad']) == len(points) and np.all(qc['ok_mad']) assert len(qc['ok_iqr']) == len(points) and np.all(qc['ok_iqr']) print(qc) assert qc['centroid'].startswith('SRID=4326;POINT(') x, y = [float(x) for x in qc['centroid'].replace('SRID=4326;POINT(', '').replace(')', '').split(' ')] assert abs(round(x) - 1) < 0.00001 and abs(round(y) - 2) < 0.00001 assert abs(round(qc['median'])) < 0.00001 for k in ['mad', 'q1', 'q3']: assert qc[k] is None
def _qc_dataset(req): points, _, mad_coef, iqr_coef, return_values = QcResource._parse_request( req) try: points, duplicate_indices = np.unique(points, return_inverse=True, axis=0) return { 'spatial': outliers.spatial(points, duplicate_indices, mad_coef, iqr_coef, return_values=return_values), 'count': len(points) } except Exception as ex: raise falcon.HTTPError( falcon.HTTP_400, 'Error looking up data for provided points', str(ex))
def test_spatial(): """outliers - spatial return values""" points, duplicate_indices = t.rand_xy_list(150) qc = outliers.spatial(points, duplicate_indices, None, None, return_values=True) assert len(qc['values']) == len(points)