Skip to content

Commit

Permalink
Merge pull request #15 from wpreimes/develop
Browse files Browse the repository at this point in the history
Add download test
  • Loading branch information
wpreimes authored Feb 5, 2019
2 parents 14eeed4 + f393e00 commit 0d3b4dd
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Version 0.x
Version 0.3
===========

- Add test for download
- Update documentation
- Add kwargs to time series reader
- Add option for download checking
Expand Down
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ packages =
# py.test options when running `python setup.py test`
addopts = tests

[pytest]
[tool:pytest]
# Options for py.test:
# Specify command line options as you would do when invoking py.test directly.
# e.g. --cov-report html (or xml) for html/xml output or --junitxml junit.xml
Expand Down
7 changes: 1 addition & 6 deletions smap_io/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -247,9 +247,4 @@ def __init__(self, ts_path, grid_path=None, **kwargs):
grid_path = os.path.join(ts_path, "grid.nc")

grid = ncdf.load_grid(grid_path)
super(SMAPTs, self).__init__(ts_path, grid, **kwargs)





super(SMAPTs, self).__init__(ts_path, grid, **kwargs)
18 changes: 12 additions & 6 deletions smap_io/reshuffle.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,17 @@ def mkdate(datestring):

def parse_args(args):
"""
Parse command line parameters for conversion from image to timeseries
:param args: command line parameters as list of strings
:return: command line parameters as :obj:`argparse.Namespace`
Parse command line parameters for conversion from image to time series.
Parameters
----------
args: list
command line parameters as list of strings
Returns
----------
args : argparse.Namespace
Parsed command line parameters
"""

parser = argparse.ArgumentParser(
description="Convert SMAP data into time series format.")
parser.add_argument("dataset_root",
Expand All @@ -117,7 +123,7 @@ def parse_args(args):
help=("Enddate. Either in format YYYY-MM-DD or YYYY-MM-DDTHH:MM."))
parser.add_argument("parameters", metavar="parameters",
nargs="+",
help=("Parameters to convert as strings "
help=("Parameters to convert as strings as in the downloaded file"
"e.g. soil_moisture soil_moisture_error"))
parser.add_argument("--overpass", type=str, default=None,
help=("Select 'AM' for the descending overpass or 'PM' "
Expand All @@ -126,7 +132,7 @@ def parse_args(args):
parser.add_argument("--crid", type=int, default=None,
help='Composite Release ID. Reshuffle only files with this ID.'
'See also https://nsidc.org/data/smap/data_versions#CRID '
'If not specified, all files in the passed directory are used.')
'If not specified, all files in the dataset_root directory are used.')
parser.add_argument("--imgbuffer", type=int, default=50,
help=("How many images to read at once. Bigger numbers make the "
"conversion faster but consume more memory."))
Expand Down
29 changes: 29 additions & 0 deletions tests/test_env_download.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# -*- coding: utf-8 -*-

'''
Tests that use passed login information from travis CI to download a few files
'''

import os
import tempfile

from smap_io.download import main
import unittest
import time

class DownloadTest(unittest.TestCase):

# these tsts only run of a username and pw are in the environment variables
# can be set manually with export USERNAME="my_username" etc.
@unittest.skipIf("SMAPUSERNAME" not in os.environ or "SMAPPWD" not in os.environ, 'Username and/or PW not found')
def test_full_download(self):

dl_path = tempfile.mkdtemp()
startdate = enddate = "2018-12-01"

args = [dl_path, '-s', startdate, '-e', enddate, '--product', 'SPL3SMP.005',
'--username', os.environ['SMAPUSERNAME'], '--password', os.environ['SMAPPWD']]

main(args)
assert(os.listdir(dl_path) == ['2018.12.01'])
assert(os.listdir(os.path.join(dl_path, '2018.12.01')) == ['SMAP_L3_SM_P_20181201_R16020_002.h5'])
2 changes: 1 addition & 1 deletion tests/test_reshuffle.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def test_reshuffle():
assert len(glob.glob(os.path.join(ts_path, "*.nc"))) == 2449
ds = SMAPTs(ts_path, parameters=['soil_moisture','soil_moisture_error'],
ioclass_kws={'read_bulk': True, 'read_dates': False})
ts = ds.read_ts(-2.8, 55.4)
ts = ds.read(-2.8, 55.4)
ds.grid.arrcell[35 * 964 + 474] == 1289
soil_moisture_values_should = np.array(
[0.267108, 0.275263], dtype=np.float32)
Expand Down

0 comments on commit 0d3b4dd

Please sign in to comment.