Skip to content

Commit

Permalink
reformat another test
Browse files Browse the repository at this point in the history
  • Loading branch information
LuukBlom committed Jan 22, 2025
1 parent 0d42f29 commit 7ae90b5
Showing 1 changed file with 52 additions and 44 deletions.
96 changes: 52 additions & 44 deletions tests/test_reading_writing.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,55 @@
from cht_cyclones.cyclone_track_database import CycloneTrackDatabase
from cht_cyclones.tropical_cyclone import TropicalCyclone

# Create track file
database_file = Path(__file__).parent / "IBTrACS.ALL.v04r00.nc"
db = CycloneTrackDatabase("ibtracs", file_name=database_file)
ind = db.list_names().index("IDAI")
tc = db.get_track(index=ind)
tc.write_track(Path(__file__).parent / "best_track_idai.cyc", "ddb_cyc")

# Define a track
tc = TropicalCyclone(name="Idai")

# Read a track
current_directory = os.path.dirname(os.path.abspath(__file__))
file_path = os.path.join(current_directory, "best_track_idai.cyc")
tc.from_ddb_cyc(file_path)

# 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
)

# create (regular) ASCII spiderweb
file_path = os.path.join(current_directory, "best_track_idai.spw")
tc.to_spiderweb(file_path)

# create (netcdf) spiderweb
file_path = os.path.join(current_directory, "best_track_idai.nc")
tc.to_spiderweb(file_path, format_type="netcdf")

# Write out as shapefile
file_path = os.path.join(current_directory, "best_track_idai.shp")
tc.track.to_file(file_path)

# Write out as geojson
file_path = os.path.join(current_directory, "best_track_idai.json")
tc.track.to_file(file_path, driver="GeoJSON")

# Write as cyc again
tc.convert_units_metric_imperial()
file_path = os.path.join(current_directory, "best_track_idai_cht.cyc")
tc.write_track(file_path, "ddb_cyc")

def test_reading_writing():
# Create track file
database_file = Path(__file__).parent / "IBTrACS.ALL.v04r00.nc"
db = CycloneTrackDatabase("ibtracs", file_name=database_file)
ind = db.list_names().index("IDAI")
tc = db.get_track(index=ind)
tc.write_track(Path(__file__).parent / "best_track_idai.cyc", "ddb_cyc")

# Define a track
tc = TropicalCyclone(name="Idai")

# Read a track
current_directory = Path(__file__).parent
file_path = os.path.join(current_directory, "best_track_idai.cyc")
tc.from_ddb_cyc(file_path)

# 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
)

# create (regular) ASCII spiderweb
file_path = os.path.join(current_directory, "best_track_idai.spw")
tc.to_spiderweb(file_path)

# create (netcdf) spiderweb
file_path = os.path.join(current_directory, "best_track_idai.nc")
tc.to_spiderweb(file_path, format_type="netcdf")

# Write out as shapefile
file_path = os.path.join(current_directory, "best_track_idai.shp")
tc.track.to_file(file_path)

# Write out as geojson
file_path = os.path.join(current_directory, "best_track_idai.json")
tc.track.to_file(file_path, driver="GeoJSON")

# Write as cyc again
tc.convert_units_metric_imperial()
file_path = os.path.join(current_directory, "best_track_idai_cht.cyc")
tc.write_track(file_path, "ddb_cyc")

suffixes = ["cpg", "cyc", "dbf", "json", "nc", "shp", "shx", "prj", "spw"]
assert all(
(Path(current_directory) / f"best_track_idai.{suffix}").exists()
for suffix in suffixes
)

0 comments on commit 7ae90b5

Please sign in to comment.