From 2f340b9e3992026e0e5402e5509f3ebc4dac29cf Mon Sep 17 00:00:00 2001 From: JessicaS11 Date: Thu, 21 May 2020 21:29:14 +0000 Subject: [PATCH 1/2] begin writing tests for Parameters class in APIformatting --- icepyx/core/APIformatting.py | 17 +- icepyx/core/granules.py | 1 - icepyx/core/is2ref.py | 2 + icepyx/tests/behind_NSIDC_API_login.py | 4 +- icepyx/tests/is2class_query.py | 11 - icepyx/tests/test_APIformatting.py | 30 ++ icepyx/tests/test_granules.py | 409 +++++++++++++++++++++++++ 7 files changed, 456 insertions(+), 18 deletions(-) diff --git a/icepyx/core/APIformatting.py b/icepyx/core/APIformatting.py index ac4edfad3..66c858538 100644 --- a/icepyx/core/APIformatting.py +++ b/icepyx/core/APIformatting.py @@ -230,20 +230,23 @@ def _check_valid_keys(self): assert key in self.poss_keys.values(), "An invalid key was passed" + #DevGoal: this function needs fixing - it's not actually checking for the presence of values! def check_req_values(self): """ Check that all of the required keys have values, if the key was passed in with the values parameter. """ + # if self._reqtype == None: return False + # else: reqkeys = self.poss_keys[self._reqtype] - + if all(keys in self.fmted_keys.keys() for keys in reqkeys): assert all(values in self.fmted_keys.values() for keys in reqkeys), "One of your formated parameters is missing a value" return True else: return False - + #DevGoal: this function needs fixing - it's not actually checking for the presence of values! def check_values(self): """ Check that the non-required keys have values, if the key was @@ -272,8 +275,14 @@ def build_params(self, **kwargs): Parameters ---------- **kwargs - optional keyword arguments to be passed to the subsetter. Valid keywords are - time, bbox OR Boundingshape, format, projection, projection_parameters, and Coverage. + Keyword inputs containing the needed information to build the parameter list, depending on + parameter type, if the already formatted key:value is not submitted as a kwarg. + May include optional keyword arguments to be passed to the subsetter. Valid keywords + are time, bbox OR Boundingshape, format, projection, projection_parameters, and Coverage. + + Keyword argument inputs for 'CMR' may include: dataset, version, start, end, extent_type, spatial_extent + Keyword argument inputs for 'required' may include: page_size, page_num, request_mode, include_meta + Keyword argument inputs for 'subset' may include: geom_filepath, start, end, extent_type, spatial_extent """ diff --git a/icepyx/core/granules.py b/icepyx/core/granules.py index 8adc24507..0d3bfb75b 100644 --- a/icepyx/core/granules.py +++ b/icepyx/core/granules.py @@ -9,7 +9,6 @@ import icepyx.core.APIformatting as apifmt -#DevNote: currently this fn is not tested def info(grans): """ Return some basic summary information about a set of granules for an diff --git a/icepyx/core/is2ref.py b/icepyx/core/is2ref.py index 8178c6808..50b7597ed 100644 --- a/icepyx/core/is2ref.py +++ b/icepyx/core/is2ref.py @@ -2,6 +2,8 @@ from xml.etree import ElementTree as ET import json +import icepyx + #ICESat-2 specific reference functions #options to get customization options for ICESat-2 data (though could be used generally) diff --git a/icepyx/tests/behind_NSIDC_API_login.py b/icepyx/tests/behind_NSIDC_API_login.py index fccafbbf4..7e34fda77 100644 --- a/icepyx/tests/behind_NSIDC_API_login.py +++ b/icepyx/tests/behind_NSIDC_API_login.py @@ -12,13 +12,13 @@ #check that downloaded data is subset @pytest.fixture -def reg_a(): +def reg_a(scope='module'): return ipd.Icesat2Data('ATL06',[-55, 68, -48, 71],['2019-02-22','2019-02-28']) #@patch('my_module.__get_input', return_value='y') @pytest.fixture -def session(reg_a): +def session(reg_a, scope='module'): return reg_a._start_earthdata_session('icepyx_devteam', 'icepyx.dev@gmail.com', os.getenv('NSIDC_LOGIN')) #QUESTION: should we be testing to make sure the session starts? If so, how? The below doesn't work because the 'requests.sessions.Session' isn't recognized... is this a case where I'd need to have a mock session to compare it to? diff --git a/icepyx/tests/is2class_query.py b/icepyx/tests/is2class_query.py index 705803583..d778f1205 100644 --- a/icepyx/tests/is2class_query.py +++ b/icepyx/tests/is2class_query.py @@ -40,18 +40,7 @@ def test_properties(): #BestPractices: should do additional properties tests for each potential property type (e.g. spatial extent can have type bounding_box or polygon) -def test_no_granules_in_search_results(): - ermsg = "Your search returned no results; try different search parameters" - with pytest.raises(AssertionError, match=ermsg): - ipd.Icesat2Data('ATL06',[-55, 68, -48, 71],['2019-02-20','2019-02-20'], version='2').avail_granules() -def test_correct_granule_list_returned(): - reg_a = ipd.Icesat2Data('ATL06',[-55, 68, -48, 71],['2019-02-20','2019-02-28'], version='2') - reg_a.avail_granules() - obs_grans = [gran['producer_granule_id'] for gran in reg_a.granules] - exp_grans = ['ATL06_20190221121851_08410203_002_01.h5', 'ATL06_20190222010344_08490205_002_01.h5', 'ATL06_20190225121032_09020203_002_01.h5', 'ATL06_20190226005526_09100205_002_01.h5'] - - assert set(obs_grans) == set(exp_grans) diff --git a/icepyx/tests/test_APIformatting.py b/icepyx/tests/test_APIformatting.py index e0a92e8cd..802cfc872 100644 --- a/icepyx/tests/test_APIformatting.py +++ b/icepyx/tests/test_APIformatting.py @@ -67,3 +67,33 @@ def test_combine_params(): ########## Parameters (class) ########## + +# @pytest.fixture +# def CMRparams(scope='module'): +# return apifmt.Parameters('CMR') + +def test_CMRparams_no_other_inputs(): + CMRparams = apifmt.Parameters('CMR') + #TestQuestion: the next statement essentially tests _get_possible_keys as well, so how would I test them independently? + assert CMRparams.poss_keys == {'default': ['short_name','version','temporal'], 'spatial': ['bounding_box','polygon'], 'optional': []} + assert CMRparams.fmted_keys == {} + assert CMRparams._check_valid_keys + #Note: this test must be done before the next one + if CMRparams.partype == 'required': + assert CMRparams.check_req_values() == False + else: + assert CMRparams.check_values() == False + + CMRparams.build_params(dataset='ATL06', version='003', + start=dt.datetime(2019, 2, 20, 0, 0), + end=dt.datetime(2019, 2, 24, 23, 59, 59), + extent_type='bounding_box', + spatial_extent=[-55, 68, -48, 71]) + obs_fmted_params = CMRparams.fmted_keys + exp_fmted_params = {'short_name': 'ATL06', 'version': '003', + 'temporal': '2019-02-20T00:00:00Z,2019-02-24T23:59:59Z', + 'bounding_box': '-55,68,-48,71'} + assert obs_fmted_params == exp_fmted_params + + + \ No newline at end of file diff --git a/icepyx/tests/test_granules.py b/icepyx/tests/test_granules.py index b35afd86f..d173d69cd 100644 --- a/icepyx/tests/test_granules.py +++ b/icepyx/tests/test_granules.py @@ -1,5 +1,414 @@ import pytest import warnings +from icepyx.core import icesat2data as ipd +from icepyx.core import granules as granules from icepyx.core.granules import Granules as Granules + + +# @pytest.fixture +# def reg_a(): +# return ipd.Icesat2Data('ATL06',[-55, 68, -48, 71],['2019-02-22','2019-02-28']) + +# #@patch('my_module.__get_input', return_value='y') + +# @pytest.fixture +# def session(reg_a): +# return reg_a._start_earthdata_session('icepyx_devteam', 'icepyx.dev@gmail.com', os.getenv('NSIDC_LOGIN')) + + +#DevNote: clearly there's a better way that doesn't make the function so long... what is it? +def test_granules_info(): + # reg_a = ipd.Icesat2Data('ATL06', [-55, 68, -48, 71], ['2019-02-20','2019-02-24'], version='3') + # granules = reg_a.granules.avail + granules = [{'producer_granule_id': 'ATL06_20190221121851_08410203_003_01.h5', + 'time_start': '2019-02-21T12:19:05.000Z', + 'orbit': {'ascending_crossing': '-40.35812957405553', + 'start_lat': '59.5', + 'start_direction': 'A', + 'end_lat': '80', + 'end_direction': 'A'}, + 'updated': '2020-05-04T15:43:02.942Z', + 'orbit_calculated_spatial_domains': [{'equator_crossing_date_time': '2019-02-21T12:03:18.922Z', + 'equator_crossing_longitude': '-40.35812957405553', + 'orbit_number': '2429'}], + 'dataset_id': 'ATLAS/ICESat-2 L3A Land Ice Height V003', + 'data_center': 'NSIDC_ECS', + 'title': 'SC:ATL06.003:177534295', + 'coordinate_system': 'ORBIT', + 'time_end': '2019-02-21T12:24:16.000Z', + 'id': 'G1723268629-NSIDC_ECS', + 'original_format': 'ISO-SMAP', + 'granule_size': '50.3300800323', + 'browse_flag': True, + 'polygons': [['60.188087866839815 -48.12471565111877 79.13565976324539 -56.91308349854652 79.82054625244331 -57.75066986682175 79.88471463831527 -55.94835931630358 79.19580392788636 -55.21962622534677 60.21083561664105 -47.47451382423887 60.188087866839815 -48.12471565111877']], + 'collection_concept_id': 'C1706333750-NSIDC_ECS', + 'online_access_flag': True, + 'links': [{'rel': 'http://esipfed.org/ns/fedsearch/1.1/data#', + 'type': 'application/x-hdfeos', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP7/ATLAS/ATL06.003/2019.02.21/ATL06_20190221121851_08410203_003_01.h5'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.16/ATL06_20190221121851_08410203_003_01_BRW.default.default1.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.16/ATL06_20190221121851_08410203_003_01_BRW.default.default2.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.16/ATL06_20190221121851_08410203_003_01_BRW.gt1l.atl06_quality_summary.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.16/ATL06_20190221121851_08410203_003_01_BRW.gt1l.h_li.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.16/ATL06_20190221121851_08410203_003_01_BRW.gt1l.h_li_sigma.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.16/ATL06_20190221121851_08410203_003_01_BRW.gt1l.n_fit_photons.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.16/ATL06_20190221121851_08410203_003_01_BRW.gt1l.signal_selection_source.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.16/ATL06_20190221121851_08410203_003_01_BRW.gt1r.atl06_quality_summary.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.16/ATL06_20190221121851_08410203_003_01_BRW.gt1r.h_li.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.16/ATL06_20190221121851_08410203_003_01_BRW.gt1r.h_li_sigma.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.16/ATL06_20190221121851_08410203_003_01_BRW.gt1r.n_fit_photons.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.16/ATL06_20190221121851_08410203_003_01_BRW.gt1r.signal_selection_source.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.16/ATL06_20190221121851_08410203_003_01_BRW.gt2l.atl06_quality_summary.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.16/ATL06_20190221121851_08410203_003_01_BRW.gt2l.h_li.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.16/ATL06_20190221121851_08410203_003_01_BRW.gt2l.h_li_sigma.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.16/ATL06_20190221121851_08410203_003_01_BRW.gt2l.n_fit_photons.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.16/ATL06_20190221121851_08410203_003_01_BRW.gt2l.signal_selection_source.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.16/ATL06_20190221121851_08410203_003_01_BRW.gt2r.atl06_quality_summary.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.16/ATL06_20190221121851_08410203_003_01_BRW.gt2r.h_li.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.16/ATL06_20190221121851_08410203_003_01_BRW.gt2r.h_li_sigma.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.16/ATL06_20190221121851_08410203_003_01_BRW.gt2r.n_fit_photons.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.16/ATL06_20190221121851_08410203_003_01_BRW.gt2r.signal_selection_source.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.16/ATL06_20190221121851_08410203_003_01_BRW.gt3l.atl06_quality_summary.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.16/ATL06_20190221121851_08410203_003_01_BRW.gt3l.h_li.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.16/ATL06_20190221121851_08410203_003_01_BRW.gt3l.h_li_sigma.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.16/ATL06_20190221121851_08410203_003_01_BRW.gt3l.n_fit_photons.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.16/ATL06_20190221121851_08410203_003_01_BRW.gt3l.signal_selection_source.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.16/ATL06_20190221121851_08410203_003_01_BRW.gt3r.atl06_quality_summary.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.16/ATL06_20190221121851_08410203_003_01_BRW.gt3r.h_li.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.16/ATL06_20190221121851_08410203_003_01_BRW.gt3r.h_li_sigma.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.16/ATL06_20190221121851_08410203_003_01_BRW.gt3r.n_fit_photons.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.16/ATL06_20190221121851_08410203_003_01_BRW.gt3r.signal_selection_source.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/metadata#', + 'type': 'text/xml', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP7/ATLAS/ATL06.003/2019.02.21/ATL06_20190221121851_08410203_003_01.iso.xml'}, + {'inherited': True, + 'length': '0.0KB', + 'rel': 'http://esipfed.org/ns/fedsearch/1.1/data#', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/ATLAS/ATL06.003/'}, + {'inherited': True, + 'length': '0.0KB', + 'rel': 'http://esipfed.org/ns/fedsearch/1.1/data#', + 'hreflang': 'en-US', + 'href': 'https://search.earthdata.nasa.gov/search/granules?p=C1706333750-NSIDC_ECS&q=atl06%20v003&m=-29.109278436791882!-59.86889648437499!1!1!0!0%2C2&tl=1572814258!4!!'}, + {'inherited': True, + 'length': '0.0KB', + 'rel': 'http://esipfed.org/ns/fedsearch/1.1/data#', + 'hreflang': 'en-US', + 'href': 'https://openaltimetry.org/'}, + {'inherited': True, + 'rel': 'http://esipfed.org/ns/fedsearch/1.1/metadata#', + 'hreflang': 'en-US', + 'href': 'https://doi.org/10.5067/ATLAS/ATL06.003'}, + {'inherited': True, + 'rel': 'http://esipfed.org/ns/fedsearch/1.1/documentation#', + 'hreflang': 'en-US', + 'href': 'https://doi.org/10.5067/ATLAS/ATL06.003'}]}, + {'producer_granule_id': 'ATL06_20190222010344_08490205_003_01.h5', + 'time_start': '2019-02-22T01:03:44.000Z', + 'orbit': {'ascending_crossing': '130.68730694092687', + 'start_lat': '80', + 'start_direction': 'D', + 'end_lat': '59.5', + 'end_direction': 'D'}, + 'updated': '2020-05-04T15:35:15.570Z', + 'orbit_calculated_spatial_domains': [{'equator_crossing_date_time': '2019-02-22T00:37:38.252Z', + 'equator_crossing_longitude': '130.68730694092687', + 'orbit_number': '2437'}], + 'dataset_id': 'ATLAS/ICESat-2 L3A Land Ice Height V003', + 'data_center': 'NSIDC_ECS', + 'title': 'SC:ATL06.003:177974050', + 'coordinate_system': 'ORBIT', + 'time_end': '2019-02-22T01:07:47.000Z', + 'id': 'G1725880106-NSIDC_ECS', + 'original_format': 'ISO-SMAP', + 'granule_size': '42.656709671', + 'browse_flag': True, + 'polygons': [['80.11254119920325 -43.315444387475495 64.79892188605879 -52.21277462684438 64.82548575330607 -52.971370058601465 80.17859740110205 -45.168520453661074 80.11254119920325 -43.315444387475495']], + 'collection_concept_id': 'C1706333750-NSIDC_ECS', + 'online_access_flag': True, + 'links': [{'rel': 'http://esipfed.org/ns/fedsearch/1.1/data#', + 'type': 'application/x-hdfeos', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP7/ATLAS/ATL06.003/2019.02.22/ATL06_20190222010344_08490205_003_01.h5'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.22/ATL06_20190222010344_08490205_003_01_BRW.default.default1.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.22/ATL06_20190222010344_08490205_003_01_BRW.default.default2.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.22/ATL06_20190222010344_08490205_003_01_BRW.gt1l.atl06_quality_summary.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.22/ATL06_20190222010344_08490205_003_01_BRW.gt1l.h_li.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.22/ATL06_20190222010344_08490205_003_01_BRW.gt1l.h_li_sigma.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.22/ATL06_20190222010344_08490205_003_01_BRW.gt1l.n_fit_photons.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.22/ATL06_20190222010344_08490205_003_01_BRW.gt1l.signal_selection_source.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.22/ATL06_20190222010344_08490205_003_01_BRW.gt1r.atl06_quality_summary.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.22/ATL06_20190222010344_08490205_003_01_BRW.gt1r.h_li.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.22/ATL06_20190222010344_08490205_003_01_BRW.gt1r.h_li_sigma.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.22/ATL06_20190222010344_08490205_003_01_BRW.gt1r.n_fit_photons.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.22/ATL06_20190222010344_08490205_003_01_BRW.gt1r.signal_selection_source.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.22/ATL06_20190222010344_08490205_003_01_BRW.gt2l.atl06_quality_summary.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.22/ATL06_20190222010344_08490205_003_01_BRW.gt2l.h_li.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.22/ATL06_20190222010344_08490205_003_01_BRW.gt2l.h_li_sigma.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.22/ATL06_20190222010344_08490205_003_01_BRW.gt2l.n_fit_photons.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.22/ATL06_20190222010344_08490205_003_01_BRW.gt2l.signal_selection_source.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.22/ATL06_20190222010344_08490205_003_01_BRW.gt2r.atl06_quality_summary.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.22/ATL06_20190222010344_08490205_003_01_BRW.gt2r.h_li.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.22/ATL06_20190222010344_08490205_003_01_BRW.gt2r.h_li_sigma.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.22/ATL06_20190222010344_08490205_003_01_BRW.gt2r.n_fit_photons.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.22/ATL06_20190222010344_08490205_003_01_BRW.gt2r.signal_selection_source.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.22/ATL06_20190222010344_08490205_003_01_BRW.gt3l.atl06_quality_summary.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.22/ATL06_20190222010344_08490205_003_01_BRW.gt3l.h_li.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.22/ATL06_20190222010344_08490205_003_01_BRW.gt3l.h_li_sigma.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.22/ATL06_20190222010344_08490205_003_01_BRW.gt3l.n_fit_photons.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.22/ATL06_20190222010344_08490205_003_01_BRW.gt3l.signal_selection_source.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.22/ATL06_20190222010344_08490205_003_01_BRW.gt3r.atl06_quality_summary.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.22/ATL06_20190222010344_08490205_003_01_BRW.gt3r.h_li.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.22/ATL06_20190222010344_08490205_003_01_BRW.gt3r.h_li_sigma.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.22/ATL06_20190222010344_08490205_003_01_BRW.gt3r.n_fit_photons.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/browse#', + 'type': 'image/jpeg', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP0/BRWS/Browse.001/2020.04.22/ATL06_20190222010344_08490205_003_01_BRW.gt3r.signal_selection_source.jpg'}, + {'rel': 'http://esipfed.org/ns/fedsearch/1.1/metadata#', + 'type': 'text/xml', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/DP7/ATLAS/ATL06.003/2019.02.22/ATL06_20190222010344_08490205_003_01.iso.xml'}, + {'inherited': True, + 'length': '0.0KB', + 'rel': 'http://esipfed.org/ns/fedsearch/1.1/data#', + 'hreflang': 'en-US', + 'href': 'https://n5eil01u.ecs.nsidc.org/ATLAS/ATL06.003/'}, + {'inherited': True, + 'length': '0.0KB', + 'rel': 'http://esipfed.org/ns/fedsearch/1.1/data#', + 'hreflang': 'en-US', + 'href': 'https://search.earthdata.nasa.gov/search/granules?p=C1706333750-NSIDC_ECS&q=atl06%20v003&m=-29.109278436791882!-59.86889648437499!1!1!0!0%2C2&tl=1572814258!4!!'}, + {'inherited': True, + 'length': '0.0KB', + 'rel': 'http://esipfed.org/ns/fedsearch/1.1/data#', + 'hreflang': 'en-US', + 'href': 'https://openaltimetry.org/'}, + {'inherited': True, + 'rel': 'http://esipfed.org/ns/fedsearch/1.1/metadata#', + 'hreflang': 'en-US', + 'href': 'https://doi.org/10.5067/ATLAS/ATL06.003'}, + {'inherited': True, + 'rel': 'http://esipfed.org/ns/fedsearch/1.1/documentation#', + 'hreflang': 'en-US', + 'href': 'https://doi.org/10.5067/ATLAS/ATL06.003'}]}] + obs = granules.info(granules) + + exp = {'Number of available granules': 2, / + 'Average size of granules (MB)': 46.49339485165, / + 'Total size of all granules (MB)': 92.9867897033} + + assert obs==exp + + + + + + + +def test_no_granules_in_search_results(): + ermsg = "Your search returned no results; try different search parameters" + with pytest.raises(AssertionError, match=ermsg): + ipd.Icesat2Data('ATL06',[-55, 68, -48, 71],['2019-02-20','2019-02-20'], version='2').avail_granules() + +def test_correct_granule_list_returned(): + reg_a = ipd.Icesat2Data('ATL06',[-55, 68, -48, 71],['2019-02-20','2019-02-28'], version='2') + reg_a.avail_granules() + obs_grans = [gran['producer_granule_id'] for gran in reg_a.granules] + exp_grans = ['ATL06_20190221121851_08410203_002_01.h5', 'ATL06_20190222010344_08490205_002_01.h5', 'ATL06_20190225121032_09020203_002_01.h5', 'ATL06_20190226005526_09100205_002_01.h5'] + + assert set(obs_grans) == set(exp_grans) \ No newline at end of file From a4f5985096a86de3798392853816cf6d94040718 Mon Sep 17 00:00:00 2001 From: JessicaS11 Date: Fri, 22 May 2020 21:18:51 +0000 Subject: [PATCH 2/2] fix APIformatting checks for presence of values in passed keywords --- icepyx/core/APIformatting.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/icepyx/core/APIformatting.py b/icepyx/core/APIformatting.py index 66c858538..fc80f715a 100644 --- a/icepyx/core/APIformatting.py +++ b/icepyx/core/APIformatting.py @@ -230,38 +230,38 @@ def _check_valid_keys(self): assert key in self.poss_keys.values(), "An invalid key was passed" - #DevGoal: this function needs fixing - it's not actually checking for the presence of values! def check_req_values(self): """ Check that all of the required keys have values, if the key was passed in with the values parameter. """ - # if self._reqtype == None: return False - # else: + + assert self.partype == 'required', "You cannot call this function for your parameter type" reqkeys = self.poss_keys[self._reqtype] if all(keys in self.fmted_keys.keys() for keys in reqkeys): - assert all(values in self.fmted_keys.values() for keys in reqkeys), "One of your formated parameters is missing a value" + assert all(self.fmted_keys.get(key, -9999) != -9999 for key in reqkeys),"One of your formated parameters is missing a value" return True else: return False - #DevGoal: this function needs fixing - it's not actually checking for the presence of values! + def check_values(self): """ Check that the non-required keys have values, if the key was passed in with the values parameter. """ + assert self.partype != 'required', "You cannot call this function for your parameter type" + default_keys = self.poss_keys['default'] - spatial_keys = self.poss_keys['spatial'] if all(keys in self._fmted_keys.keys() for keys in default_keys): - assert all(values in self._fmted_keys.values() for keys in default_keys), "One of your formated parameters is missing a value" - + assert all(self.fmted_keys.get(key, -9999) != -9999 for key in default_keys),"One of your formated parameters is missing a value" + #not the most robust check, but better than nothing... if any(keys in self._fmted_keys.keys() for keys in spatial_keys): - assert any(values in self._fmted_keys.values() for keys in default_keys), "One of your formated parameters is missing a value" + assert any(self.fmted_keys.get(key, -9999) != -9999 for key in default_keys),"One of your formated parameters is missing a value" return True else: return False else: