Commit ea937bb6 authored by CEVAER's avatar CEVAER
Browse files

Added radii to fix

parent 7916e20c
......@@ -3,24 +3,29 @@ import atcf
import pandas as pd
import owi
import logging
import numpy as np
logger = logging.getLogger(__name__)
def save_fix_analysis(path, sat_file, atcf_filename, lon_eye, lat_eye, rmw, vmax, cyclone_name, sid, sat_mission,
def save_fix_analysis(path, sat_file, atcf_filename, lon_eye, lat_eye, radii_quad, radii_nmi_quad, cyclone_name,
sid, sat_mission,
sub_basin, acq_time):
atcf_outfile = os.path.join(path, atcf_filename)
sar_outfile = os.path.join(path, f"{os.path.basename(sat_file).replace('.nc', '')}.dat")
fix = pd.DataFrame()
for emptyCol in ["BASIN", "CY", "date", "fix format", "fix type", "center/intensity", "flagged indicator", "lat", "lon",
"height of ob", "posit confidence", "wind speed", "confidence", "pressure", "pressure confidence",
"pressure derivation", "rad", "windcode", "rad1", "rad2", "rad3", "rad4",
"radmod1", "radmod2", "radmod3", "radmod4", "radii confidence", "MRD", "eye", "subregion",
"fix site", "initials", "analyst initials", "start time", "end time", "distance to nearest data", "SST",
"observation sources", "comments"]:
for emptyCol in ["BASIN", "CY", "date", "fix format", "fix type", "center/intensity", "flagged indicator", "lat",
"lon",
"height of ob", "posit confidence", "wind speed", "confidence", "pressure", "pressure confidence",
"pressure derivation", "rad", "windcode", "rad1", "rad2", "rad3", "rad4",
"radmod1", "radmod2", "radmod3", "radmod4", "radii confidence", "MRD", "eye", "subregion",
"fix site", "initials", "analyst initials", "start time", "end time", "distance to nearest data",
"SST",
"observation sources", "comments"]:
fix.loc[0, emptyCol] = None
stormid = sid[2:4]#al092020
stormid = sid[2:4] # al092020
basin = sid[0:2]
mis_to_type = {"SENTINEL-1 A": "SEN1", "SENTINEL-1 B": "SEN1", "RADARSAT-2": "RS2"}
......@@ -49,24 +54,53 @@ def save_fix_analysis(path, sat_file, atcf_filename, lon_eye, lat_eye, rmw, vmax
fix.loc[0, "observation sources"] = sat_mission
fix.loc[0, "comments"] = "Synthetic Aperture Radar 3KM Wind Speed Analysis"
fix_radii = pd.DataFrame(columns=fix.columns)
# quadrants = ["all", "NE", "SE", "SW", "NW"]
wind_vals = [64, 50, 34]
for i_wnd in range(len(wind_vals)):
new_row = fix.iloc[0].copy(deep=True)
new_row["windcode"] = "NEQ"
new_row["rad"] = str(int(wind_vals[i_wnd]))
new_row["rad1"] = ""
new_row["rad2"] = ""
new_row["rad3"] = ""
new_row["rad4"] = ""
if not np.isnan(radii_nmi_quad["NE"][i_wnd + 2]) and radii_nmi_quad["NE"][i_wnd + 2] != -1:
new_row["rad1"] = int(radii_nmi_quad["NE"][i_wnd + 2])
if not np.isnan(radii_nmi_quad["SE"][i_wnd + 2]) and radii_nmi_quad["SE"][i_wnd + 2] != -1:
new_row["rad2"] = int(radii_nmi_quad["SE"][i_wnd + 2])
if not np.isnan(radii_nmi_quad["SW"][i_wnd + 2]) and radii_nmi_quad["SW"][i_wnd + 2] != -1:
new_row["rad3"] = int(radii_nmi_quad["SW"][i_wnd + 2])
if not np.isnan(radii_nmi_quad["NW"][i_wnd + 2]) and radii_nmi_quad["NW"][i_wnd + 2] != -1:
new_row["rad4"] = int(radii_nmi_quad["NW"][i_wnd + 2])
fix_radii = fix_radii.append(new_row)
if os.path.isfile(atcf_outfile):
logger.info(f"ATCF output file exists ({atcf_outfile}). Reading and merging.")
existing_fix = atcf.read(atcf_outfile, model="fix")
existing_fix["date"] = existing_fix["date"].apply(lambda x: x.strftime("%Y%m%d%H%M"))
existing_fix["start time"] = existing_fix["start time"].apply(lambda x: x.strftime("%Y%m%d%H%M"))
existing_fix["end time"] = existing_fix["end time"].apply(lambda x: x.strftime("%Y%m%d%H%M"))
to_save = existing_fix.append(fix.iloc[0], ignore_index=True)
to_save = to_save.drop_duplicates(subset=["start time"], keep="last")
existing_fix["rad1"] = existing_fix["rad1"].apply(lambda x: str(int(x)) if not np.isnan(x) else "")
existing_fix["rad2"] = existing_fix["rad2"].apply(lambda x: str(int(x)) if not np.isnan(x) else "")
existing_fix["rad3"] = existing_fix["rad3"].apply(lambda x: str(int(x)) if not np.isnan(x) else "")
existing_fix["rad4"] = existing_fix["rad4"].apply(lambda x: str(int(x)) if not np.isnan(x) else "")
to_save = existing_fix.append(fix_radii, ignore_index=True)
to_save["start time"] = to_save["start time"].astype("string")
to_save["rad"] = to_save["rad"].astype("string")
to_save = to_save.drop_duplicates(subset=["start time", "rad"], keep="last")
to_save["CY"] = to_save["CY"].apply(lambda x: str(x).zfill(2))
else:
to_save = fix
to_save = fix_radii
df_result = to_save
atcf.write(df_result, open(atcf_outfile, "w"), model="fix")
logger.info("wrote %s" % atcf_outfile)
atcf.write(fix, open(sar_outfile, "w"), model="fix")
atcf.write(fix_radii, open(sar_outfile, "w"), model="fix")
logger.info("wrote %s" % sar_outfile)
......@@ -84,15 +118,15 @@ def save_fix(path, sat_file, atcf_filename, lon_eye, lat_eye, rmw, vmax, cyclone
'USERDEFINED4', 'userdata4', 'USERDEFINED5', 'userdata5']:
fix.loc[0, emptyCol] = None
stormid = sid[2:4]#al092020
stormid = sid[2:4] # al092020
basin = sid[0:2]
fix.loc[0, 'date'] = owi.getDateFromFname(os.path.basename(sat_file))
fix.loc[0, 'TAU'] = 0
fix.loc[0, 'TECH'] = 'SAR'
fix.loc[0, 'VMAX'] = None#vmax
fix.loc[0, 'RMW'] = None#props['rmw'][eye_position_full[0], eye_position_full[1]] / 1.852
fix.loc[0, 'EYE'] = None#props['eye'][eye_position_full[0], eye_position_full[1]] / 1.852 * 2
fix.loc[0, 'VMAX'] = None # vmax
fix.loc[0, 'RMW'] = None # props['rmw'][eye_position_full[0], eye_position_full[1]] / 1.852
fix.loc[0, 'EYE'] = None # props['eye'][eye_position_full[0], eye_position_full[1]] / 1.852 * 2
fix.loc[0, 'lat'] = lat_eye
fix.loc[0, 'lon'] = lon_eye
fix.loc[0, 'INITIALS'] = 'IFR'
......
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