Skip to content

Commit

Permalink
test_datelist update
Browse files Browse the repository at this point in the history
  • Loading branch information
jlmaurer committed Jul 13, 2023
1 parent 9576989 commit be19195
Show file tree
Hide file tree
Showing 21 changed files with 90 additions and 217 deletions.
9 changes: 0 additions & 9 deletions test/scenario_5/hgt.hdr

This file was deleted.

Binary file removed test/scenario_5/hgt.rdr
Binary file not shown.
23 changes: 0 additions & 23 deletions test/scenario_5/hgt.rdr.aux.xml

This file was deleted.

9 changes: 0 additions & 9 deletions test/scenario_5/lat.hdr

This file was deleted.

Binary file removed test/scenario_5/lat.rdr
Binary file not shown.
23 changes: 0 additions & 23 deletions test/scenario_5/lat.rdr.aux.xml

This file was deleted.

18 changes: 0 additions & 18 deletions test/scenario_5/lat.rdr.vrt

This file was deleted.

9 changes: 0 additions & 9 deletions test/scenario_5/lon.hdr

This file was deleted.

Binary file removed test/scenario_5/lon.rdr
Binary file not shown.
23 changes: 0 additions & 23 deletions test/scenario_5/lon.rdr.aux.xml

This file was deleted.

18 changes: 0 additions & 18 deletions test/scenario_5/lon.rdr.vrt

This file was deleted.

9 changes: 0 additions & 9 deletions test/scenario_5/los.hdr

This file was deleted.

Binary file removed test/scenario_5/los.rdr
Binary file not shown.
16 changes: 0 additions & 16 deletions test/scenario_5/los.rdr.vrt

This file was deleted.

1 change: 0 additions & 1 deletion test/scenario_5/warpedDEM.dem

This file was deleted.

9 changes: 0 additions & 9 deletions test/scenario_5/warpedDEM.dem.vrt

This file was deleted.

9 changes: 0 additions & 9 deletions test/scenario_5/warpedDEM.hdr

This file was deleted.

2 changes: 0 additions & 2 deletions test/scenario_5/wmtype

This file was deleted.

Binary file removed test/scenario_5/wrfout_d01_2010-06-25
Binary file not shown.
Binary file removed test/scenario_5/wrfplev_d01_2010-06-25
Binary file not shown.
129 changes: 90 additions & 39 deletions test/test_datelist.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
import datetime
import os
import glob
import pytest
import subprocess
import shutil
# import glob
# import subprocess
# import shutil
import yaml
import numpy as np
# import numpy as np
from test import TEST_DIR, WM

from RAiDER.cli.raider import read_template_file

def test_datelist():
SCENARIO_DIR = os.path.join(TEST_DIR, 'datelist')

if os.path.exists(SCENARIO_DIR):
shutil.rmtree(SCENARIO_DIR)
os.makedirs(SCENARIO_DIR, exist_ok=False)

SCENARIO_DIR = os.path.join(TEST_DIR, 'scenario_5')
dates = ['20200124', '20200130']
true_dates = [datetime.datetime(2020,1,24), datetime.datetime(2020,1,30)]

dct_group = {
'aoi_group': {'bounding_box': [28, 39, -123, -112]},
'aoi_group': {'bounding_box': [28, 28.3, -116.3, -116]},
'date_group': {'date_list': dates},
'time_group': {'time': '00:00:00'},
'weather_model': WM,
Expand All @@ -34,28 +30,16 @@ def test_datelist():
with open(dst, 'w') as fh:
yaml.dump(params, fh, default_flow_style=False)


## run raider on new file (two dates)
cmd = f'raider.py {dst}'
proc = subprocess.run(cmd.split(), stdout=subprocess.PIPE, universal_newlines=True)
assert np.isclose(proc.returncode, 0)

## check that four files (2x date) were created
n_files = len(glob.glob(os.path.join(SCENARIO_DIR, 'weather_files/*.nc')))
n_dates = len(dates)
assert np.isclose(n_files, n_dates*2), 'Incorrect number of files produced'

## clean up
shutil.rmtree(SCENARIO_DIR)

return dst
param_dict = read_template_file(dst)

assert param_dict['date_list'] == true_dates


def test_datestep():
SCENARIO_DIR = os.path.join(TEST_DIR, 'datelist')
os.makedirs(SCENARIO_DIR, exist_ok=False)
SCENARIO_DIR = os.path.join(TEST_DIR, 'scenario_5')
st, en, step = '20200124', '20200130', 3
n_dates = 3
true_dates = [datetime.datetime(2020,1,24), datetime.datetime(2020,1,27), datetime.datetime(2020,1,30)]

dct_group = {
'aoi_group': {'bounding_box': [28, 39, -123, -112]},
Expand All @@ -74,15 +58,82 @@ def test_datestep():
with open(dst, 'w') as fh:
yaml.dump(params, fh, default_flow_style=False)

param_dict = read_template_file(dst)
assert param_dict['date_list'] == true_dates



# def test_datelist():
# SCENARIO_DIR = os.path.join(TEST_DIR, 'scenario_5')

# dates = ['20200124', '20200130']

# dct_group = {
# 'aoi_group': {'bounding_box': [28, 28.3, -116.3, -116]},
# 'date_group': {'date_list': dates},
# 'time_group': {'time': '00:00:00'},
# 'weather_model': WM,
# 'runtime_group': {
# 'output_directory': SCENARIO_DIR,
# 'weather_model_directory': os.path.join(SCENARIO_DIR, 'weather_files')
# }
# }

# params = dct_group
# dst = os.path.join(SCENARIO_DIR, 'temp.yaml')

# with open(dst, 'w') as fh:
# yaml.dump(params, fh, default_flow_style=False)


# ## run raider on new file (two dates)
# cmd = f'raider.py {dst}'
# proc = subprocess.run(cmd.split(), stdout=subprocess.PIPE, universal_newlines=True)
# assert np.isclose(proc.returncode, 0)

# ## check that four files (2x date) were created
# n_files = len(glob.glob(os.path.join(SCENARIO_DIR, 'weather_files/*.nc')))
# n_dates = len(dates)
# assert np.isclose(n_files, n_dates*2), 'Incorrect number of files produced'

# ## clean up
# shutil.rmtree(SCENARIO_DIR)

# return dst


# def test_datestep():
# SCENARIO_DIR = os.path.join(TEST_DIR, 'datelist')
# os.makedirs(SCENARIO_DIR, exist_ok=False)
# st, en, step = '20200124', '20200130', 3
# n_dates = 3

# dct_group = {
# 'aoi_group': {'bounding_box': [28, 39, -123, -112]},
# 'date_group': {'date_start': st, 'date_end': en, 'date_step': step},
# 'time_group': {'time': '00:00:00'},
# 'weather_model': WM,
# 'runtime_group': {
# 'output_directory': SCENARIO_DIR,
# 'weather_model_directory': os.path.join(SCENARIO_DIR, 'weather_files')
# }
# }

# params = dct_group
# dst = os.path.join(SCENARIO_DIR, 'temp.yaml')

# with open(dst, 'w') as fh:
# yaml.dump(params, fh, default_flow_style=False)


## run raider on new file (two dates)
cmd = f'raider.py {dst}'
proc = subprocess.run(cmd.split(), stdout=subprocess.PIPE, universal_newlines=True)
assert np.isclose(proc.returncode, 0)
# ## run raider on new file (two dates)
# cmd = f'raider.py {dst}'
# proc = subprocess.run(cmd.split(), stdout=subprocess.PIPE, universal_newlines=True)
# assert np.isclose(proc.returncode, 0)

## check that four files (2x date) were created
n_files = len(glob.glob(os.path.join(SCENARIO_DIR, 'weather_files/*.nc')))
assert np.isclose(n_files, n_dates*2), 'Incorrect number of files produced'
# ## check that four files (2x date) were created
# n_files = len(glob.glob(os.path.join(SCENARIO_DIR, 'weather_files/*.nc')))
# assert np.isclose(n_files, n_dates*2), 'Incorrect number of files produced'

## clean up
shutil.rmtree(SCENARIO_DIR)
# ## clean up
# shutil.rmtree(SCENARIO_DIR)

0 comments on commit be19195

Please sign in to comment.