From 5172f7cd628db4ef3ea5e8eed62f7d5fcc20ee5c Mon Sep 17 00:00:00 2001 From: Benjamin Schmidt Date: Sat, 29 Jun 2024 14:32:06 +0200 Subject: [PATCH 1/2] feat(TU): add wrf mercator products for TU --- salem/sio.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/salem/sio.py b/salem/sio.py index a8fda32..3ac9b79 100644 --- a/salem/sio.py +++ b/salem/sio.py @@ -126,22 +126,25 @@ def read_shapefile_to_grid(fpath, grid): def _wrf_grid_from_dataset(ds): """Get the WRF projection out of the file.""" - - pargs = dict() + pargs = {} if hasattr(ds, 'PROJ_ENVI_STRING'): # HAR and other TU Berlin files - dx = ds.GRID_DX - dy = ds.GRID_DY - pargs['lat_1'] = ds.PROJ_STANDARD_PAR1 - pargs['lat_2'] = ds.PROJ_STANDARD_PAR2 - pargs['lat_0'] = ds.PROJ_CENTRAL_LAT - pargs['lon_0'] = ds.PROJ_CENTRAL_LON - pargs['center_lon'] = ds.PROJ_CENTRAL_LON + dx = ds.GRID_DX or ds.DX + dy = ds.GRID_DY or ds.DY if ds.PROJ_NAME in ['Lambert Conformal Conic', 'WRF Lambert Conformal']: proj_id = 1 + pargs['lat_1'] = ds.PROJ_STANDARD_PAR1 + pargs['lat_2'] = ds.PROJ_STANDARD_PAR2 + pargs['lat_0'] = ds.PROJ_CENTRAL_LAT + pargs['lon_0'] = ds.PROJ_CENTRAL_LON + pargs['center_lon'] = ds.PROJ_CENTRAL_LON elif ds.PROJ_NAME in ['lat-lon']: proj_id = 6 + elif "mercator" in ds.PROJ_NAME.lower(): + proj_id = 3 + pargs['lat_ts'] = ds.TRUELAT1 + pargs['center_lon'] = ds.CEN_LON else: proj_id = 99 # pragma: no cover else: @@ -1214,4 +1217,4 @@ def ds_closer(): except AttributeError: combined = combined.drop(vns) - return combined + return combined \ No newline at end of file From 74882dff603f25c9300e7be2ed21fcb0cfb08a9e Mon Sep 17 00:00:00 2001 From: Benjamin Schmidt Date: Tue, 9 Jul 2024 11:46:51 +0200 Subject: [PATCH 2/2] fix(dxdy): avoid error if GRID_DX/GRID_DY are not present Check if GRID_DX/GRID_DY are present in the attributes of files that have proj_envi_string. GRID_DX/GRID_DY should be preferred over DX/DY in this case as they are specifically defined in product generation at least for files generated at TUB. Fixes an issue where the test errors if GRID_DX/GRID_DY are not present. --- salem/sio.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/salem/sio.py b/salem/sio.py index 3ac9b79..c6a739f 100644 --- a/salem/sio.py +++ b/salem/sio.py @@ -129,8 +129,8 @@ def _wrf_grid_from_dataset(ds): pargs = {} if hasattr(ds, 'PROJ_ENVI_STRING'): # HAR and other TU Berlin files - dx = ds.GRID_DX or ds.DX - dy = ds.GRID_DY or ds.DY + dx = ds.GRID_DX if hasattr(ds, 'GRID_DX') else ds.DX + dy = ds.GRID_DY if hasattr(ds, 'GRID_DY') else ds.DY if ds.PROJ_NAME in ['Lambert Conformal Conic', 'WRF Lambert Conformal']: proj_id = 1