Commit 04b550df authored by CEVAER's avatar CEVAER
Browse files

Fixed wrong polygon when data was crossing anti-meridian

parent 264f7225
......@@ -45,7 +45,7 @@ if __name__ == "__main__":
logger.setLevel(logging.INFO)
logging.basicConfig(level=logging.INFO)
from smap_cyclones import process_file
from extract_cyclones import process_file
engine = create_engine(args.dbd, pool_size=50, max_overflow=0)
Session = sessionmaker(bind=engine)
......
......@@ -50,9 +50,10 @@ if __name__ == "__main__":
engine = create_engine(args.dbd, pool_size=50, max_overflow=0)
Session = sessionmaker(bind=engine)
attrs_to_del = ["aprrox_local_equatorial_crossing_time", "swath_sector"]
attrs_to_del = ["aprrox_local_equatorial_crossing_time", "swath_sector", "geospatial_bounds",
"geospatial_lat_min", "geospatial_lat_max", "geospatial_lon_min", "geospatial_lon_max"]
from smap_cyclones import process_file
from extract_cyclones import process_file
for f in args.input:
# TODO generate filename_format depending on input filename
......
......@@ -12,6 +12,7 @@ import numpy as np
import math
from geo_shapely import shape360
from shapely.wkt import dumps
from shapely.geometry import Polygon
logger = logging.getLogger(__name__)
......@@ -27,6 +28,12 @@ def deg180(deg360):
return res
def deg360(deg180):
"""shapely shape to 0 360 (for shapely.ops.transform)"""
lon = np.array(deg180) % 360
return lon
def get_track_points_from_database(session, date):
req_tracks = session.query(SimpleTrack, func.ST_X(cast(SimpleTrack.geom, Geometry)).label("lon"),
func.ST_Y(cast(SimpleTrack.geom, Geometry)).label("lat")) \
......@@ -139,8 +146,18 @@ def set_nan_outside_time_offset(dataset, track_data, time_col_name, wind_col_nam
return dataset
def transform_polyg_180(p):
coords = p.exterior.coords
new_coords = [(c[0] - 360, c[1]) if c[0] > 180 else (c[0], c[1]) for c in coords]
return Polygon(new_coords)
# Extract footprint (not taking NaN data into account)
def compute_footprint(dataset, wind_field):
# Using 0:360 range because the -180:180 range does create the right polygon with gdf.unary_union.convex_hull
dataset["lon"] = deg360(dataset["lon"])
df = dataset.to_dataframe()
df = df[pd.isna(df[wind_field]) == False]
df = df.reset_index()
......@@ -149,6 +166,8 @@ def compute_footprint(dataset, wind_field):
df, geometry=gpd.points_from_xy(df.lon, df.lat))
p = gdf.unary_union.convex_hull
# Transforming the polygon so its coords are in range -180:180
p = transform_polyg_180(p)
return p
......
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