-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #27 from USDA-ARS-NWRC/file_loading
HRRR module
- Loading branch information
Showing
40 changed files
with
1,682 additions
and
1,214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,4 +4,5 @@ coverage==5.0.3 | |
pylint==2.4.4 | ||
flake8 | ||
autopep8 | ||
isort==4.3.21 | ||
isort==4.3.21 | ||
mock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import os | ||
import shutil | ||
import unittest | ||
from pathlib import Path | ||
|
||
import pandas as pd | ||
|
||
|
||
class RMETestCase(unittest.TestCase): | ||
""" | ||
Base class for all unit tests using the RME data | ||
""" | ||
test_dir = Path(__file__).parent | ||
basin_dir = test_dir.joinpath('RME') | ||
gold_dir = basin_dir.joinpath('gold', 'hrrr') | ||
hrrr_dir = basin_dir.joinpath('gridded/hrrr_test') | ||
output_path = basin_dir.joinpath('output') | ||
|
||
START_DATE = pd.to_datetime('2018-07-22 01:00') | ||
END_DATE = pd.to_datetime('2018-07-22 06:00') | ||
UTM_ZONE_NUMBER = 11 | ||
BBOX = [-116.85837324, 42.96134124, -116.64913327, 43.16852535] | ||
|
||
def setUp(self): | ||
""" | ||
Create test directory structure | ||
Change directory to RME test | ||
""" | ||
self.output_path.mkdir(exist_ok=True) | ||
os.chdir(self.basin_dir.as_posix()) | ||
|
||
def tearDown(self): | ||
""" | ||
Cleanup the downloaded files | ||
Cleanup grib2 index files | ||
""" | ||
shutil.rmtree(self.output_path) | ||
for index_file in self.hrrr_dir.rglob('**/*.grib2.*.idx'): | ||
index_file.unlink() |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
""" | ||
The High Resolution Rapid Refresh (HRRR) model is a NOAA | ||
real-time 3 km resolution forecast. The model output is updated | ||
hourly and assimilates 3km radar. More information can be found | ||
at https://rapidrefresh.noaa.gov/hrrr/. | ||
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import unittest | ||
|
||
from weather_forecast_retrieval.data.hrrr.base_file import BaseFile | ||
|
||
|
||
class TestBaseFile(unittest.TestCase): | ||
LOGGER_NAME = 'BaseFileTest' | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
cls.subject = BaseFile(cls.LOGGER_NAME) | ||
|
||
def test_bbox_property(self): | ||
self.assertIsNone(self.subject.bbox) | ||
|
||
self.subject.bbox = [] | ||
|
||
self.assertEqual([], self.subject.bbox) | ||
|
||
def test_has_log_property(self): | ||
self.assertEqual(self.LOGGER_NAME, self.subject.log.name) | ||
|
||
def test_variable_map_property(self): | ||
self.assertEqual( | ||
BaseFile.VAR_MAP, | ||
self.subject.variable_map | ||
) | ||
|
||
def test_load_method(self): | ||
with self.assertRaises(NotImplementedError): | ||
self.subject.load(None) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import logging | ||
import unittest | ||
|
||
import mock | ||
import pandas as pd | ||
|
||
from weather_forecast_retrieval.data.hrrr.config_file import ConfigFile | ||
|
||
|
||
class TestConfigFile(unittest.TestCase): | ||
LOGGER_NAME = 'ConfigFileTest' | ||
CONFIG = { | ||
'output': { | ||
'output_dir': 'output_location', | ||
'start_date': '2020-12-31 00:00', | ||
'end_date': '2020-12-31 23:00', | ||
} | ||
} | ||
|
||
@classmethod | ||
def setUpClass(cls): | ||
with mock.patch( | ||
'weather_forecast_retrieval.utils.read_config', | ||
return_value=cls.CONFIG | ||
): | ||
cls.subject = ConfigFile(cls.LOGGER_NAME, cls.CONFIG) | ||
|
||
def test_output_dir(self): | ||
self.assertEqual( | ||
self.CONFIG['output']['output_dir'], | ||
self.subject.output_dir | ||
) | ||
|
||
def test_start_date(self): | ||
self.assertEqual( | ||
pd.to_datetime(self.CONFIG['output']['start_date']), | ||
self.subject.start_date, | ||
) | ||
|
||
def test_end_date(self): | ||
self.assertEqual( | ||
pd.to_datetime(self.CONFIG['output']['end_date']), | ||
self.subject.end_date | ||
) | ||
|
||
def test_no_config(self): | ||
subject = ConfigFile(self.LOGGER_NAME) | ||
self.assertIsNone(subject.config) | ||
|
||
def test_default_properties(self): | ||
subject = ConfigFile(self.LOGGER_NAME) | ||
self.assertIsNone(subject.start_date) | ||
self.assertIsNone(subject.end_date) | ||
self.assertIsNone(subject.output_dir) | ||
|
||
def test_logger_name(self): | ||
self.assertEqual(self.LOGGER_NAME, self.subject.log.name) | ||
|
||
def test_external_logger(self): | ||
external_logger = logging.Logger('External') | ||
subject = ConfigFile( | ||
self.LOGGER_NAME, external_logger=external_logger | ||
) | ||
self.assertEqual(external_logger.name, subject.log.name) | ||
|
||
def test_log_property(self): | ||
self.assertIsInstance(self.subject.log, logging.Logger) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import unittest | ||
|
||
import pandas as pd | ||
|
||
from weather_forecast_retrieval.data.hrrr import FileHandler | ||
|
||
|
||
class TestHRRRFileHandler(unittest.TestCase): | ||
def test_file_date(self): | ||
file_time = pd.to_datetime('2018-02-08 05:00') | ||
|
||
forecast_hour = 1 | ||
day, file_hour = FileHandler.file_date( | ||
file_time, forecast_hour | ||
) | ||
self.assertEqual('2018-02-08', str(day)) | ||
self.assertEqual(4, file_hour) | ||
|
||
forecast_hour = 3 | ||
day, file_hour = FileHandler.file_date( | ||
file_time, forecast_hour | ||
) | ||
self.assertEqual('2018-02-08', str(day)) | ||
self.assertEqual(2, file_hour) | ||
|
||
forecast_hour = 8 | ||
day, file_hour = FileHandler.file_date( | ||
file_time, forecast_hour | ||
) | ||
self.assertEqual('2018-02-07', str(day)) | ||
self.assertEqual(21, file_hour) | ||
|
||
def test_file_name(self): | ||
self.assertEqual( | ||
'hrrr.t04z.wrfsfcf01.grib2', | ||
FileHandler.file_name(4, 1) | ||
) | ||
self.assertEqual( | ||
'hrrr.t04z.wrfsfcf01.nc', | ||
FileHandler.file_name(4, 1, 'netcdf') | ||
) | ||
|
||
def test_folder_name(self): | ||
self.assertEqual( | ||
'hrrr.20180208', | ||
FileHandler.folder_name(pd.to_datetime('2018-02-08')) | ||
) | ||
|
||
def test_folder_and_file(self): | ||
folder_name, file_name = FileHandler.folder_and_file( | ||
pd.to_datetime('2018-02-08 05:00'), 1 | ||
) | ||
|
||
self.assertEqual('hrrr.20180208', folder_name) | ||
self.assertEqual('hrrr.t04z.wrfsfcf01.grib2', file_name) |
Oops, something went wrong.