Skip to content

Commit

Permalink
update tests to data version 006 and resolve flake8 errors on edited …
Browse files Browse the repository at this point in the history
…files (#478)
  • Loading branch information
JessicaS11 authored Dec 14, 2023
1 parent d3d0e7f commit cc12838
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 56 deletions.
2 changes: 1 addition & 1 deletion icepyx/core/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ class Query(GenQuery, EarthdataAuthMixin):
Available data products can be found at: https://nsidc.org/data/icesat-2/data-sets
version : string, default most recent version
Product version, given as a 3 digit string. If no version is given, the current
version is used. Example: "004"
version is used. Example: "006"
cycles : string or a list of strings, default all available orbital cycles
Product cycle, given as a 2 digit string. If no cycle is given, all available
cycles are used. Example: "04"
Expand Down
27 changes: 19 additions & 8 deletions icepyx/tests/test_APIformatting.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
import pytest
import warnings
import datetime as dt
from shapely.geometry import Polygon

import icepyx.core.APIformatting as apifmt


# DevNote: is this a situation where you'd ideally build a test class, since you're just repeating the
# test function with different inputs? Especially for the _fmt_spaital, where there's >2 tests?
# DevNote: is this a situation where you'd ideally build a test class,
# since you're just repeating the test function with different inputs?
# Especially for the _fmt_spaital, where there's >2 tests?

# CMR temporal and spatial formats --> what's the best way to compare formatted text? character by character comparison of strings?
# CMR temporal and spatial formats --> what's the best way to compare formatted text?
# character by character comparison of strings?


########## _fmt_temporal ##########
Expand Down Expand Up @@ -46,7 +46,18 @@ def test_var_subset_list_fmt():
"start_delta_time": ["ancillary_data/start_delta_time"],
}
)
exp = "/ancillary_data/atlas_sdp_gps_epoch,/ancillary_data/data_end_utc,/ancillary_data/data_start_utc,/ancillary_data/end_delta_time,/ancillary_data/granule_end_utc,/ancillary_data/granule_start_utc,/profile_2/high_rate/latitude,/profile_2/low_rate/latitude,/orbit_info/sc_orient,/ancillary_data/start_delta_time"
exp = (
"/ancillary_data/atlas_sdp_gps_epoch,"
"/ancillary_data/data_end_utc,"
"/ancillary_data/data_start_utc,"
"/ancillary_data/end_delta_time,"
"/ancillary_data/granule_end_utc,"
"/ancillary_data/granule_start_utc,"
"/profile_2/high_rate/latitude,"
"/profile_2/low_rate/latitude,"
"/orbit_info/sc_orient,"
"/ancillary_data/start_delta_time"
)
assert obs == exp


Expand Down Expand Up @@ -139,7 +150,7 @@ def test_CMRparams_no_other_inputs():

CMRparams.build_params(
product="ATL06",
version="005",
version="006",
start=dt.datetime(2019, 2, 20, 0, 0),
end=dt.datetime(2019, 2, 24, 23, 59, 59),
extent_type="bounding_box",
Expand All @@ -148,7 +159,7 @@ def test_CMRparams_no_other_inputs():
obs_fmted_params = CMRparams.fmted_keys
exp_fmted_params = {
"short_name": "ATL06",
"version": "005",
"version": "006",
"temporal": "2019-02-20T00:00:00Z,2019-02-24T23:59:59Z",
"bounding_box": "-55.0,68.0,-48.0,71.0",
}
Expand Down
17 changes: 9 additions & 8 deletions icepyx/tests/test_behind_NSIDC_API_login.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
import icepyx as ipx
import os
import json
import pytest
import warnings

import icepyx as ipx
import icepyx.core.is2ref as is2ref


# Misc notes and needed tests
# test avail data and subsetting success for each input type (kml, shp, list of coords, bbox)
# check that downloaded data is subset? or is this an NSIDC level test so long as we verify the right info is submitted?
# test avail data and subsetting success for each input type
# (kml, shp, list of coords, bbox)
# check that downloaded data is subset?
# or is this an NSIDC level test so long as we verify the right info is submitted?


@pytest.fixture(scope="module")
def reg():
live_reg = ipx.Query(
"ATL06", [-55, 68, -48, 71], ["2019-02-22", "2019-02-28"], version="005"
"ATL06", [-55, 68, -48, 71], ["2019-02-22", "2019-02-28"], version="006"
)
yield live_reg
del live_reg
Expand All @@ -26,8 +29,6 @@ def session(reg):


########## is2ref module ##########
import icepyx.core.is2ref as is2ref
import json


def test_get_custom_options_output(session):
Expand Down
18 changes: 9 additions & 9 deletions icepyx/tests/test_granules.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import pytest
import re
import requests
import responses
import warnings

import icepyx as ipx
from icepyx.core import granules as granules
Expand All @@ -22,7 +20,8 @@
# check that agent key is added in event of no subsetting


# add test for granules info for ATL11 and ATL13 (and all datasets? or at least ones that don't have the same filename structure)
# add test for granules info for ATL11 and ATL13
# (and all datasets? or at least ones that don't have the same filename structure)
# this example failed in version 0.6.4, leading to a fix in 0.6.5
# short_name = 'ATL11'
# spatial_extent = [-38.65,72.5,-38.40,72.7]
Expand All @@ -31,7 +30,8 @@
# region_a.avail_granules(ids=True)


# DevNote: clearly there's a better way that doesn't make the function so long... what is it?
# DevNote: clearly there's a better way that doesn't make the function so long...
# what is it?
def test_granules_info():
# reg_a = ipx.Query('ATL06', [-55, 68, -48, 71], ['2019-02-20','2019-02-24'], version='3')
# granules = reg_a.granules.avail
Expand Down Expand Up @@ -609,15 +609,15 @@ def test_correct_granule_list_returned():
"ATL06",
[-55, 68, -48, 71],
["2019-02-20", "2019-02-28"],
version="5",
version="6",
)

(obs_grans,) = reg_a.avail_granules(ids=True)
exp_grans = [
"ATL06_20190221121851_08410203_005_01.h5",
"ATL06_20190222010344_08490205_005_01.h5",
"ATL06_20190225121032_09020203_005_01.h5",
"ATL06_20190226005526_09100205_005_01.h5",
"ATL06_20190221121851_08410203_006_02.h5",
"ATL06_20190222010344_08490205_006_02.h5",
"ATL06_20190225121032_09020203_006_02.h5",
"ATL06_20190226005526_09100205_006_02.h5",
]
assert set(obs_grans) == set(exp_grans)

Expand Down
6 changes: 2 additions & 4 deletions icepyx/tests/test_query.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
import icepyx as ipx
import pytest
import warnings

# ------------------------------------
# Generic Query tests
Expand All @@ -20,7 +18,7 @@ def test_icepyx_boundingbox_query():
["2019-02-22", "2019-02-28"],
start_time="03:30:00",
end_time="21:30:00",
version="5",
version="6",
)
obs_tuple = (
reg_a.product,
Expand All @@ -35,7 +33,7 @@ def test_icepyx_boundingbox_query():
["2019-02-22", "2019-02-28"],
"03:30:00",
"21:30:00",
"005",
"006",
("bounding_box", [-64.0, 66.0, -55.0, 72.0]),
)

Expand Down
6 changes: 4 additions & 2 deletions icepyx/tests/test_read.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ def test_check_datasource_type():
[
("./", "is2_local"),
(
"s3://nsidc-cumulus-prod-protected/ATLAS/ATL03/004/2019/11/30/ATL03_20191130221008_09930503_004_01.h5",
"""s3://nsidc-cumulus-prod-protected/ATLAS/
ATL03/006/2019/11/30/ATL03_20191130221008_09930503_006_01.h5""",
"is2_s3",
),
],
Expand Down Expand Up @@ -115,7 +116,8 @@ def test_get_track_type_str(
)


# Best way to test this may be by including a small sample file with the repo (which can be used for testing some of the catalog/read-in functions as well)
# Best way to test this may be by including a small sample file with the repo
# (which can be used for testing some of the catalog/read-in functions as well)
# def test_invalid_filename_pattern_in_file():
# ermesg = "Your input filename does not match the specified pattern."
# default_pattern = Read("/path/to/valid/source/file")._filename_pattern
Expand Down
48 changes: 24 additions & 24 deletions icepyx/tests/test_visualization.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,38 @@
(
1,
[
"ATL06_20200702014158_01020810_004_01.h5",
"ATL06_20200703011618_01170810_004_01.h5",
"ATL06_20200702014158_01020810_006_01.h5",
"ATL06_20200703011618_01170810_006_01.h5",
],
),
(
2,
[
"ATL06_20200612151119_11920712_004_01.h5",
"ATL06_20200616021517_12450710_004_01.h5",
"ATL06_20200702014158_01020810_004_01.h5",
"ATL06_20200703011618_01170810_004_01.h5",
"ATL06_20200612151119_11920712_006_01.h5",
"ATL06_20200616021517_12450710_006_01.h5",
"ATL06_20200702014158_01020810_006_01.h5",
"ATL06_20200703011618_01170810_006_01.h5",
],
),
(
3,
[
"ATL06_20200612151119_11920712_004_01.h5",
"ATL06_20200616021517_12450710_004_01.h5",
"ATL06_20200702014158_01020810_004_01.h5",
"ATL06_20200703011618_01170810_004_01.h5",
"ATL06_20200612151119_11920712_006_01.h5",
"ATL06_20200616021517_12450710_006_01.h5",
"ATL06_20200702014158_01020810_006_01.h5",
"ATL06_20200703011618_01170810_006_01.h5",
],
),
],
)
def test_files_in_latest_cycles(n, exp):
files = [
"ATL06_20190710071617_01860412_004_01.h5",
"ATL06_20190713182016_02390410_004_01.h5",
"ATL06_20200612151119_11920712_004_01.h5",
"ATL06_20200616021517_12450710_004_01.h5",
"ATL06_20200702014158_01020810_004_01.h5",
"ATL06_20200703011618_01170810_004_01.h5",
"ATL06_20190710071617_01860412_006_01.h5",
"ATL06_20190713182016_02390410_006_01.h5",
"ATL06_20200612151119_11920712_006_01.h5",
"ATL06_20200616021517_12450710_006_01.h5",
"ATL06_20200702014158_01020810_006_01.h5",
"ATL06_20200703011618_01170810_006_01.h5",
]
cycles = [8, 7, 4]
obs = vis.files_in_latest_n_cycles(files, cycles=cycles, n=n)
Expand All @@ -51,14 +51,14 @@ def test_files_in_latest_cycles(n, exp):
@pytest.mark.parametrize(
"filename, expect",
[
("ATL06_20190525202604_08790310_004_01.h5", [879, 3, "2019-05-25"]),
("ATL06_20190614194425_11840310_004_01.h5", [1184, 3, "2019-06-14"]),
("ATL07-02_20190624063616_13290301_004_01.h5", [1329, 3, "2019-06-24"]),
("ATL07-02_20190602190916_10010301_004_01.h5", [1001, 3, "2019-06-02"]),
("ATL10-02_20190611072656_11310301_004_01.h5", [1131, 3, "2019-06-11"]),
("ATL10-02_20190731045538_05060401_004_01.h5", [506, 4, "2019-07-31"]),
("ATL12_20190615023544_11890301_004_01.h5", [1189, 3, "2019-06-15"]),
("ATL12_20190721170332_03610401_004_01.h5", [361, 4, "2019-07-21"]),
("ATL06_20190525202604_08790310_006_01.h5", [879, 3, "2019-05-25"]),
("ATL06_20190614194425_11840310_006_01.h5", [1184, 3, "2019-06-14"]),
("ATL07-02_20190624063616_13290301_006_01.h5", [1329, 3, "2019-06-24"]),
("ATL07-02_20190602190916_10010301_006_01.h5", [1001, 3, "2019-06-02"]),
("ATL10-02_20190611072656_11310301_006_01.h5", [1131, 3, "2019-06-11"]),
("ATL10-02_20190731045538_05060401_006_01.h5", [506, 4, "2019-07-31"]),
("ATL12_20190615023544_11890301_006_01.h5", [1189, 3, "2019-06-15"]),
("ATL12_20190721170332_03610401_006_01.h5", [361, 4, "2019-07-21"]),
],
)
def test_gran_paras(filename, expect):
Expand Down

0 comments on commit cc12838

Please sign in to comment.