diff --git a/src/wrf/projection.py b/src/wrf/projection.py index 0aa930b..5a75064 100644 --- a/src/wrf/projection.py +++ b/src/wrf/projection.py @@ -85,22 +85,36 @@ if cartopy_enabled(): self._threshold = np.diff(self.x_limits)[0] / 720 -def _ismissing(val): - """Return True if a value is None, greater than 90.0, or less than -90. +def _ismissing(val, islat=True): + """Return True if a value is None or out of bounds. - This function is used to check for invalid latitude values. + This function is used to check for invalid latitude/longitude values. Args: val (numeric): A numeric value. + islat (:obj:`bool`): Set to False if checking for longitude values. + Returns: - :obj:`bool`: True if the value is None, greater than 90.0, or less - than -90.0. Otherwise, False is returned. + :obj:`bool`: True if the value is None, or an out of bounds value. """ - return val is None or val > 90. or val < -90. + if islat: + if val is None: + return True + + if math.fabs(val) > 90.: + return True + else: + if val is None: + return True + + if math.fabs(val) > 360.: + return True + + return False class WrfProj(object): @@ -639,6 +653,9 @@ class Mercator(WrfProj): if self.truelat1 == 0. or _ismissing(self.truelat1) else self.truelat1) + self._stand_lon = (0. if _ismissing(self.stand_lon, islat=False) + else self.stand_lon) + def _cf_params(self): @@ -658,7 +675,7 @@ class Mercator(WrfProj): _pyngl.mpProjection = "Mercator" _pyngl.mpDataBaseVersion = "MediumRes" _pyngl.mpCenterLatF = 0.0 - _pyngl.mpCenterLonF = self.stand_lon + _pyngl.mpCenterLonF = self._stand_lon _pyngl.mpLimitMode = "Corners" _pyngl.mpLeftCornerLonF = geobounds.bottom_left.lon @@ -677,7 +694,7 @@ class Mercator(WrfProj): return None local_kwargs = dict(projection = "merc", - lon_0 = self.stand_lon, + lon_0 = self._stand_lon, lat_0 = self.moad_cen_lat, lat_ts = self._lat_ts, llcrnrlat = geobounds.bottom_left.lat, @@ -699,12 +716,12 @@ class Mercator(WrfProj): if self._lat_ts == 0.0: _cartopy = crs.Mercator( - central_longitude = self.stand_lon, + central_longitude = self._stand_lon, globe = self._globe()) else: _cartopy = MercatorWithLatTS( - central_longitude = self.stand_lon, + central_longitude = self._stand_lon, latitude_true_scale = self._lat_ts, globe = self._globe()) @@ -717,7 +734,7 @@ class Mercator(WrfProj): "+lon_0={} +lat_ts={}".format( Constants.WRF_EARTH_RADIUS, Constants.WRF_EARTH_RADIUS, - self.stand_lon, + self._stand_lon, self._lat_ts)) return _proj4 diff --git a/src/wrf/util.py b/src/wrf/util.py index 67d30eb..6a297d0 100644 --- a/src/wrf/util.py +++ b/src/wrf/util.py @@ -3392,7 +3392,7 @@ def latlon_coords(var, as_np=False): var (:class:`xarray.DataArray`): A variable. - to_np (:obj:`bool`): Set to True to return the coordinates as + as_np (:obj:`bool`): Set to True to return the coordinates as :class:`numpy.ndarray` objects instead of :class:`xarray.DataArray` objects.