Commit 2429a72f authored by CEVAER's avatar CEVAER
Browse files

Added cyclone_category variable

parent a90ea28b
......@@ -2,7 +2,7 @@ import xarray as xr
import numpy as np
from tc_center.polar import to_polar, to_north_ref
from tc_center.plotting import contour_indices
from tc_center.functions import CenterStatus
from tc_center.functions import spd2cat
import owi
from shapely.geometry import LineString, Point
import os
......@@ -33,7 +33,8 @@ def radius_for_wind(polar_ds, wind_mean, wind_knots, idx_max):
percent_invalid = wind_nan_count / count_total * 100
logger.debug(f"Total count points at {polar_ds.isel(rad=idx)['rad'].item()}m : {count_total}. "
f"Number of invalid point at same distance : {wind_nan_count}")
f"Number of invalid point at same distance : {wind_nan_count}. "
f"Percent invalid : {percent_invalid}")
if percent_invalid > 75:
return np.nan, np.nan
......@@ -65,6 +66,8 @@ def save_netcdf(sat_file, path, center_status, percent_outside, percent_inside_i
ds_polar_north["track_vmax"] = xr.DataArray(data=float(atcf_vmax),
attrs={"long_name": "Track VMAX", "units": "m/s"})
ds_polar_north["cyclone_category"] = xr.DataArray(data=spd2cat(atcf_vmax, unit="m/s"),
attrs={"long_name": "Cyclone category based on track VMAX"})
ds_polar_north["eye_shape"] = xr.DataArray(data=eye_shape.wkt, attrs={"long_name": "Eye shape (WKT)"})
ds_polar_north["eye_center"] = xr.DataArray(data=Point(lon_center, lat_center).wkt,
attrs={"long_name": "TC eye center"})
......@@ -106,7 +109,6 @@ def save_netcdf(sat_file, path, center_status, percent_outside, percent_inside_i
# Compute and add radii to xarray dataset
quadrants = {"all": slice(0, 360), "NE": slice(0, 90), "SE": slice(90, 180), "SW": slice(180, 270), "NW": slice(270, 360)}
for quad, sl in quadrants.items():
print(quad)
polar_quad = ds_polar_north.sel(theta=sl)
invalid_x, invalid_y = np.where(ds_polar_north["mask_flag"].values > 0)
wind_masked = polar_quad["wind_speed"]
......
......@@ -5,6 +5,7 @@ Created on Wed Aug 5 16:25:11 2020
@author: lvinour
"""
import collections
import numpy as np
import netCDF4 as nc4
......@@ -1066,7 +1067,34 @@ def proportion_valid_data_around_center(sat_bb, atcf_pt, land):
return percent_bb_intersection, percent_intersect_land, percent_sum_non_usable
# Converts wind speed (int) (knots or m/s) to cyclone category
def spd2cat(spd, unit="knots"):
"""
Converts wind speed (int) in m/s into cyclone category
Parameters
----------
spd : int Wind speed in meters per second.
Returns
-------
str
The cyclone category (dep, storm, cat-X)
"""
# Dict to convert from string categories to their corresponding maximal wind_speed
# See also function spd2cat
maxspd = collections.OrderedDict([
("dep", 34),
("storm", 64),
("cat-1", 82),
("cat-2", 95),
("cat-3", 112),
("cat-4", 136),
("cat-5", 999)])
# Convert to knot
if unit == "m/s":
spd = spd * 1.94384
return list(maxspd.keys())[[i for i, m in enumerate(maxspd) if maxspd[m] - spd > 0][0]]
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment