-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
reformat tests so pytest can discover them
- Loading branch information
Showing
4 changed files
with
94 additions
and
144 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,52 +1,61 @@ | ||
# Load modules | ||
import os | ||
from pathlib import Path | ||
|
||
from cht_cyclones.tropical_cyclone import ( | ||
TropicalCyclone, | ||
TropicalCycloneEnsemble, | ||
) | ||
|
||
# Define a track | ||
tc = TropicalCyclone(name="Maria_forecast") | ||
|
||
# Read a track | ||
current_directory = os.path.dirname(os.path.abspath(__file__)) | ||
file_path = os.path.join(current_directory, "TRK_COAMPS_CTCX_3_2017092006_15L") | ||
tc.read_track(file_path, "trk") | ||
|
||
# Define settings | ||
# Uses typical Wind Enhance Scheme (WES) formulations | ||
tc.include_rainfall = ( | ||
True # using empirical formulation to compute rainfall (IPET default) | ||
) | ||
tc.rainfall_factor = ( | ||
2.0 # factor to calibrate rainfall 2.0 means 2x as much as relationship | ||
) | ||
|
||
# Write as cyc | ||
tc.convert_units_metric_imperial() | ||
file_path = os.path.join(current_directory, "forecasted_track_Maria.cyc") | ||
tc.write_track(file_path, "ddb_cyc") | ||
|
||
# create (regular) ASCII spiderweb | ||
file_path = os.path.join(current_directory, "forecasted_track_Maria.spw") | ||
tc.to_spiderweb(file_path) | ||
|
||
# create (netcdf) spiderweb | ||
file_path = os.path.join(current_directory, "forecasted_track_Maria.nc") | ||
tc.to_spiderweb(file_path, format_type="netcdf") | ||
|
||
# Write out as shapefile | ||
file_path = os.path.join(current_directory, "forecasted_track_Maria.shp") | ||
tc.track.to_file(file_path) | ||
|
||
# Write out as geojson | ||
file_path = os.path.join(current_directory, "forecasted_track_Maria.json") | ||
tc.track.to_file(file_path, driver="GeoJSON") | ||
|
||
# TC-FF ensemble members | ||
tc2 = TropicalCycloneEnsemble(name="Maria_forecast_ensembles", TropicalCyclone=tc) | ||
tc2.dt = 3 # 3 hourly | ||
tc2.include_best_track = 0 # not included best-track | ||
tc2.compute_ensemble(100) | ||
tc2.to_shapefile(current_directory) | ||
def test_read_TRK_forecasted(): | ||
# Define a track | ||
tc = TropicalCyclone(name="Maria_forecast") | ||
|
||
# Read a track | ||
current_directory = os.path.dirname(os.path.abspath(__file__)) | ||
file_path = os.path.join(current_directory, "TRK_COAMPS_CTCX_3_2017092006_15L") | ||
tc.read_track(file_path, "trk") | ||
|
||
# Define settings | ||
# Uses typical Wind Enhance Scheme (WES) formulations | ||
tc.include_rainfall = ( | ||
True # using empirical formulation to compute rainfall (IPET default) | ||
) | ||
tc.rainfall_factor = ( | ||
2.0 # factor to calibrate rainfall 2.0 means 2x as much as relationship | ||
) | ||
|
||
# Write as cyc | ||
tc.convert_units_metric_imperial() | ||
file_path = os.path.join(current_directory, "forecasted_track_Maria.cyc") | ||
tc.write_track(file_path, "ddb_cyc") | ||
|
||
# create (regular) ASCII spiderweb | ||
file_path = os.path.join(current_directory, "forecasted_track_Maria.spw") | ||
tc.to_spiderweb(file_path) | ||
|
||
# create (netcdf) spiderweb | ||
file_path = os.path.join(current_directory, "forecasted_track_Maria.nc") | ||
tc.to_spiderweb(file_path, format_type="netcdf") | ||
|
||
# Write out as shapefile | ||
file_path = os.path.join(current_directory, "forecasted_track_Maria.shp") | ||
tc.track.to_file(file_path) | ||
|
||
# Write out as geojson | ||
file_path = os.path.join(current_directory, "forecasted_track_Maria.json") | ||
tc.track.to_file(file_path, driver="GeoJSON") | ||
|
||
# TC-FF ensemble members | ||
tc2 = TropicalCycloneEnsemble(name="Maria_forecast_ensembles", TropicalCyclone=tc) | ||
tc2.dt = 3 # 3 hourly | ||
tc2.include_best_track = 0 # not included best-track | ||
tc2.compute_ensemble(100) | ||
tc2.to_shapefile(current_directory) | ||
|
||
suffixes = ["cpg", "cyc", "dbf", "json", "shp", "shx", "prj", "spw"] | ||
assert all( | ||
(Path(current_directory) / f"forecasted_track_Maria.{suffix}").exists() | ||
for suffix in suffixes | ||
) |
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 |
---|---|---|
@@ -1,13 +1,10 @@ | ||
import os | ||
from pathlib import Path | ||
|
||
from cht_cyclones.cyclone_track_database import CycloneTrackDatabase | ||
|
||
|
||
def test_load_track_database(): | ||
database_file = Path(os.getcwd()).joinpath( | ||
"cyclone_track_database", "IBTrACS.NA.v04r00.nc" | ||
) | ||
database_file = Path(__file__).parent / "IBTrACS.ALL.v04r00.nc" | ||
tc = CycloneTrackDatabase("ibtracs", file_name=database_file) | ||
|
||
assert tc.nstorms == 2323 | ||
assert tc.nstorms == 13330 |