Commit ee6d0940 authored by CEVAER's avatar CEVAER
Browse files

Added plots_from_netcdf.py

parent bafccca7
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
Created on Wed Aug 5 15:12:06 2020
@author: lvinour
"""
import matplotlib.pyplot as plt
import argparse
from tc_center import find_center_plot_save
import owi
......
#!/usr/bin/env python
import argparse
import glob
import os
import xarray as xr
from tc_center.plotting import control_plot_from_shp, save_plot
from tc_center import track_data
import pandas as pd
import pathurl
import owi
from shapely.wkt import loads
import holoviews as hv
import logging
logger = logging.getLogger(__name__)
if __name__ == "__main__":
description = """
Generate control plot from analysis NetCDF file.
"""
parser = argparse.ArgumentParser(description=description)
parser.add_argument("-p", "--path", action="store", required=True,
help="The base path where to find netcdfs")
parser.add_argument("-o", "--outpath", action="store", required=True,
help="The base path where to save plot files")
parser.add_argument("-b", "--backend", action="store", default="bokeh", help="Backend to use for plotting")
parser.add_argument("--debug", action="store_true", default=False,
help="Enable debug logging level.")
args = parser.parse_args()
files = glob.glob(os.path.join(args.path, "*.nc"))
hv.extension(args.backend)
for f in files:
ds = xr.open_dataset(f)
source_sat = ds.attrs["Source satellite file"].replace("_sw", "_ll_gd")
df = pd.read_csv(f"https://cyclobs.ifremer.fr/app/api/getData?include_cols=all&filename={source_sat}")
s_file = pathurl.toPath(df.iloc[0]["data_url"], schema="dmz")
sat_date = owi.getDateFromFname(os.path.basename(s_file))
track_gdf = track_data(ds.attrs["Storm ID"], sat_date)
p = control_plot_from_shp(s_file, eye_shape=loads(ds["eye_shape"].item()),
center_pt=loads(ds["eye_center"].item()),
fg_pt=loads(ds["interpolated_track_point"].item()),
hwind_pt=loads(ds["high_wind_area_barycenter"].item()),
lwind_pt=loads(ds["low_wind_area_barycenter"].item()),
hwind_research=loads(ds["high_wind_research"].item()),
lwind_research=loads(ds["low_wind_research"].item()),
atcf_vmax=ds["track_vmax"].item(),
track_gdf=track_gdf,
cyclone_name=ds.attrs["Storm name"],
backend=args.backend
)
if args.backend == "matplotlib":
p.opts(aspect=1, fig_inches=10, fig_bounds=(0, 0, 1, 1))
save_plot(source_sat, args.outpath, p, prepend="control", backend=args.backend)
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