Skip to content

Commit

Permalink
HAR/TU WRF-Mercator (#242)
Browse files Browse the repository at this point in the history
* feat(TU): add wrf mercator products for TU

* 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.
  • Loading branch information
benatouba authored Jul 9, 2024
1 parent 9f2008c commit 2e8eaf9
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions salem/sio.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 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
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:
Expand Down Expand Up @@ -1214,4 +1217,4 @@ def ds_closer():
except AttributeError:
combined = combined.drop(vns)

return combined
return combined

0 comments on commit 2e8eaf9

Please sign in to comment.