Commit 120fa6a9 authored by CEVAER's avatar CEVAER
Browse files

Converted attributes to variables

parent 1e7afc3f
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
import owi
......@@ -34,22 +35,32 @@ def save_netcdf(sat_file, path, center_status, percent_outside, percent_inside_i
eye_coords.append((lons_eye_shape[c_i], lats_eye_shape[c_i]))
eye_shape = LineString(eye_coords)
ds_polar_north.attrs["Eye shape"] = eye_shape.wkt
ds_polar_north.attrs["Low wind area barycenter"] = Point(lon_eye_lwind, lat_eye_lwind).wkt
ds_polar_north.attrs["High wind area barycenter"] = Point(lon_eye_hwind, lat_eye_hwind).wkt
ds_polar_north.attrs["Interpolated ATCF track point"] = Point(lon_eye_fg, lat_eye_fg).wkt
ds_polar_north.attrs["Storm name"] = storm_name
ds_polar_north.attrs["Track VMAX"] = f"{float(atcf_vmax)} m/s"
ds_polar_north.attrs["Storm ID"] = sid
ds_polar_north.attrs["Track source file"] = atcf_filename
ds_polar_north.attrs["Source satellite file"] = os.path.basename(sat_file_sw)
ds_polar_north.attrs["Track point status"] = ",".join([str(ct_st.value) for ct_st in center_status])
ds_polar_north.attrs["Percent outside"] = percent_outside
ds_polar_north.attrs["Percent inside is land"] = percent_inside_island
#ds_polar_north.attrs["Percent outside + inside is land"] = percent_inside_island
ds_polar_north.attrs["Status"] = status
#ds_polar_north.attrs["% of area of 100km around track point outside acquisition bounding box"] = percent_outside
#ds_polar_north.attrs["% of area of 100km around track point inside acquisition bounding and on land"] = percent_inside_island
ds_polar_north["track_vmax"] = xr.DataArray(data=float(atcf_vmax),
attrs={"long_name": "Track VMAX", "units": "m/s"})
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"})
ds_polar_north["low_wind_area_barycenter"] = xr.DataArray(data=Point(lon_eye_lwind, lat_eye_lwind).wkt,
attrs={"long_name": "Low wind area barycenter"})
ds_polar_north["high_wind_area_barycenter"] = xr.DataArray(data=Point(lon_eye_hwind, lat_eye_hwind).wkt,
attrs={"long_name": "High wind area barycenter"})
ds_polar_north["interpolated_track_point"] = xr.DataArray(data=Point(lon_eye_fg, lat_eye_fg).wkt,
attrs={"long_name": "Closest interpolated track point"})
ds_polar_north["track_point_status"] = xr.DataArray(data=",".join([str(ct_st.value) for ct_st in center_status]))
ds_polar_north["percent_outside"] = xr.DataArray(data=percent_outside)
ds_polar_north["percent_inside_island"] = xr.DataArray(data=percent_inside_island)
ds_polar_north["percent_non_usable"] = xr.DataArray(data=percent_non_usable)
#ds_polar_north.attrs["TC center status"] = status
#ds_polar_north.attrs["Area within 100km around track point outside acquisition bounding box in percent"] = percent_outside
#ds_polar_north.attrs["Area of 100km around track point inside acquisition bounding and on land in percent"] = percent_inside_island
#ds_polar_north.attrs["% of area of 100km around track point inside " \
# "acquisition bounding and on land or outside of bounding box"] = percent_inside_island
......@@ -58,15 +69,16 @@ def save_netcdf(sat_file, path, center_status, percent_outside, percent_inside_i
for c_i in range(0, len(lon_lwind)):
lwind_contour_coords.append((lon_lwind[c_i], lat_lwind[c_i]))
lwind_contour = LineString(lwind_contour_coords)
ds_polar_north.attrs["Low wind research area"] = lwind_contour.wkt
ds_polar_north["low_wind_research"] = xr.DataArray(data=lwind_contour.wkt)
lon_hwind, lat_hwind = research_contour(msk_hwind, lon_algo, lat_algo)
hwind_contour_coords = []
for c_i in range(0, len(lon_lwind)):
hwind_contour_coords.append((lon_hwind[c_i], lat_hwind[c_i]))
hwind_contour = LineString(hwind_contour_coords)
ds_polar_north.attrs["High wind research area"] = hwind_contour.wkt
ds_polar_north["high_wind_research"] = xr.DataArray(data=hwind_contour.wkt)
outfile = os.path.join(path, f"{os.path.basename(sat_file_sw).replace('.nc', '').replace('cm', 'ca')}_{sid}.nc")
logger.info(f"Writing netCDF product to {outfile}")
ds_polar_north.to_netcdf(path=outfile)
logger.info(f"Wrote netCDF product to {outfile}")
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