Commit 05d3bf1f authored by CEVAER's avatar CEVAER
Browse files

Fixed missing attributes for lon variable

parent 8005b5c0
......@@ -50,10 +50,15 @@ 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", "first_orbit", "last_orbit"]
var_attr_edit = {"lon": {"valid_min": -180, "valid_max": 180}}
for f in args.input:
# TODO generate filename_format depending on input filename
process_file(Session(), file=f, output_path=args.output, extract_date_func=extract_date_from_filename,
attrs_to_del=attrs_to_del, var_to_del=["minute"], wind_col="wind", time_col="minute", lat_col="lat",
lon_col="lon", pass_col="node", pass_width=1000, filename_format="RSS_smap_wind_<time>_<sid>_v01.0.nc")
attrs_to_del=attrs_to_del, var_attr_edit=var_attr_edit, var_to_del=["minute"],
wind_col="wind", time_col="minute",
lat_col="lat",
lon_col="lon", pass_col="node", pass_width=1000,
filename_format="RSS_smap_wind_<time>_<sid>_v01.0.nc")
......@@ -157,7 +157,9 @@ def transform_polyg_180(p):
# 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
lon_atts = dataset["lon"].attrs
dataset["lon"] = deg360(dataset["lon"])
dataset["lon"].attrs = lon_atts
df = dataset.to_dataframe()
df = df[pd.isna(df[wind_field]) == False]
......@@ -186,7 +188,8 @@ def extract_write_cyclone_data(dataset, kept_track_points, filename, output_path
lat_col_name, wind_col_name, time_col_name, pass_col_name,
filename_format,
is_full_time,
extract_size_km=2000):
extract_size_km=2000,
var_attr_edit={}):
for sid, track_point in kept_track_points.items():
# Km per deg in latitude
km_per_deg_lat = 111
......@@ -280,10 +283,16 @@ def extract_write_cyclone_data(dataset, kept_track_points, filename, output_path
footprint_polyg = compute_footprint(sel, new_wind_col)
# Converting lon from 0;360 range to -180;180
lon_attrs = sel[lon_col_name].attrs
sel[lon_col_name] = deg180(sel[lon_col_name])
sel[lon_col_name].attrs = lon_attrs
sel.attrs["footprint"] = dumps(footprint_polyg)
for var in var_attr_edit:
for attr in var_attr_edit[var]:
sel[var].attrs[attr] = var_attr_edit[var][attr]
output_filename = filename_format.replace("<time>", track_point['date'].strftime('%Y_%m_%d_%H_%M_%S'))
output_filename = output_filename.replace("<sid>", track_point['sid'])
......@@ -301,7 +310,7 @@ def extract_write_cyclone_data(dataset, kept_track_points, filename, output_path
def process_file(session, file, output_path, extract_date_func, attrs_to_del, var_to_del, wind_col,
time_col, lat_col, lon_col, filename_format, pass_width, pass_col=None):
time_col, lat_col, lon_col, filename_format, pass_width, pass_col=None, var_attr_edit={}):
logger.info(f"Processing {file}...")
filename = os.path.basename(file)
......@@ -329,7 +338,7 @@ def process_file(session, file, output_path, extract_date_func, attrs_to_del, va
time_col_name=time_col, lat_col_name=lat_col, lon_col_name=lon_col,
pass_col_name=pass_col, attrs_to_del=attrs_to_del, var_to_del=var_to_del,
filename_format=filename_format,
is_full_time=full_time, extract_size_km=pass_width * 2)
is_full_time=full_time, extract_size_km=pass_width * 2, var_attr_edit=var_attr_edit)
else:
logger.warning(f"Filename {filename} contains only NaN values for {wind_col} column. It will not be processed.")
sys.exit(2)
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