Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Nov 20, 2021
1 parent eea7224 commit 8b3bcbd
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 30 deletions.
11 changes: 4 additions & 7 deletions xwrf/diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def calc_base_diagnostics(dataset, drop=True):
dataset['air_potential_temperature'] = dataset['T'] + 300
dataset['air_potential_temperature'].attrs = {
'units': 'K',
'standard_name': 'air_potential_temperature'
'standard_name': 'air_potential_temperature',
}
if drop:
del dataset['T']
Expand All @@ -47,22 +47,19 @@ def calc_base_diagnostics(dataset, drop=True):
dataset['air_pressure'] = dataset['P'] + dataset['PB']
dataset['air_pressure'].attrs = {
'units': dataset['P'].attrs.get('units', 'Pa'),
'standard_name': 'air_pressure'
'standard_name': 'air_pressure',
}
if drop:
del dataset['P'], dataset['PB']

# Geopotential and geopotential height
if _check_if_dask(dataset['PH']) and _check_if_dask(dataset['PHB']):
dataset['geopotential'] = dataset['PH'] + dataset['PHB']
dataset['geopotential'].attrs = {
'units': 'm**2 s**-2',
'standard_name': 'geopotential'
}
dataset['geopotential'].attrs = {'units': 'm**2 s**-2', 'standard_name': 'geopotential'}
dataset['geopotential_height'] = dataset['geopotential'] / 9.81
dataset['geopotential_height'].attrs = {
'units': 'm',
'standard_name': 'geopotential_height'
'standard_name': 'geopotential_height',
}
if drop:
del dataset['PH'], dataset['PHB']
Expand Down
33 changes: 12 additions & 21 deletions xwrf/grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import numpy as np
import pyproj


# Default CRS (lon/lat on WGS84, which is EPSG:4326)
wgs84 = pyproj.CRS(4326)

Expand All @@ -19,12 +18,7 @@
def _wrf_grid_from_dataset(ds):
"""Get the WRF projection and dimension coordinates out of the file."""

pargs = {
'x_0': 0,
'y_0': 0,
'a': 6370000,
'b': 6370000
}
pargs = {'x_0': 0, 'y_0': 0, 'a': 6370000, 'b': 6370000}
if hasattr(ds, 'PROJ_ENVI_STRING'):
# HAR and other TU Berlin files
dx = ds.GRID_DX
Expand All @@ -34,8 +28,7 @@ def _wrf_grid_from_dataset(ds):
pargs['lat_0'] = ds.PROJ_CENTRAL_LAT
pargs['lon_0'] = ds.PROJ_CENTRAL_LON
pargs['center_lon'] = ds.PROJ_CENTRAL_LON
if ds.PROJ_NAME in ['Lambert Conformal Conic',
'WRF Lambert Conformal']:
if ds.PROJ_NAME in ['Lambert Conformal Conic', 'WRF Lambert Conformal']:
proj_id = 1
else:
proj_id = 99 # pragma: no cover
Expand All @@ -60,7 +53,7 @@ def _wrf_grid_from_dataset(ds):
# Polar stereo
pargs['proj'] = 'stere'
pargs['lat_ts'] = pargs['lat_1']
pargs['lat_0'] = 90.
pargs['lat_0'] = 90.0
del pargs['lat_1'], pargs['lat_2'], pargs['center_lon']
elif proj_id == 3:
# Mercator
Expand All @@ -85,8 +78,8 @@ def _wrf_grid_from_dataset(ds):
# Normal WRF file
trf = pyproj.Transformer.from_crs(wgs84, crs)
e, n = trf.transform(cen_lon, cen_lat)
x0 = -(nx - 1) / 2. * dx + e # DL corner
y0 = -(ny - 1) / 2. * dy + n # DL corner
x0 = -(nx - 1) / 2.0 * dx + e # DL corner
y0 = -(ny - 1) / 2.0 * dy + n # DL corner

return {
'crs': crs,
Expand All @@ -99,20 +92,18 @@ def _wrf_grid_from_dataset(ds):

def add_horizontal_projection_coordinates(dataset):
"""Add missing horizontal projection coordinates and grid mapping to dataset."""
crs, south_north, west_east, south_north_stag, west_east_stag = (
_wrf_grid_from_dataset(dataset)
)
crs, south_north, west_east, south_north_stag, west_east_stag = _wrf_grid_from_dataset(dataset)

# Add grid center coordinates
dataset['south_north'] = (
'south_north',
south_north,
{'units': 'm', 'standard_name': 'projection_y_coordinate', 'axis': 'Y'}
{'units': 'm', 'standard_name': 'projection_y_coordinate', 'axis': 'Y'},
)
dataset['west_east'] = (
'west_east',
south_north,
{'units': 'm', 'standard_name': 'projection_x_coordinate', 'axis': 'X'}
{'units': 'm', 'standard_name': 'projection_x_coordinate', 'axis': 'X'},
)

# Optionally add staggered grid (cell boundary) coordinates
Expand All @@ -124,8 +115,8 @@ def add_horizontal_projection_coordinates(dataset):
'units': 'm',
'standard_name': 'projection_y_coordinate',
'axis': 'Y',
'c_grid_axis_shift': 0.5
}
'c_grid_axis_shift': 0.5,
},
)
if 'west_east_stag' in dataset.dims:
dataset['west_east_stag'] = (
Expand All @@ -135,8 +126,8 @@ def add_horizontal_projection_coordinates(dataset):
'units': 'm',
'standard_name': 'projection_x_coordinate',
'axis': 'X',
'c_grid_axis_shift': 0.5
}
'c_grid_axis_shift': 0.5,
},
)

# Add CF grid mapping
Expand Down
4 changes: 2 additions & 2 deletions xwrf/io_plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def open_dataset(
lock=None,
autoclose=False,
destagger=False,
drop_diagnostic_origin_components=True
drop_diagnostic_origin_components=True,
):

filename_or_obj = _normalize_path(filename_or_obj)
Expand Down Expand Up @@ -142,6 +142,6 @@ def open_dataset(

if destagger:
# TODO: dataset = destagger(dataset)
return NotImplementedError("Automatic destaggering not yet implemented")
return NotImplementedError('Automatic destaggering not yet implemented')

return fixup_coords(dataset)

0 comments on commit 8b3bcbd

Please sign in to comment.