|
|
@ -8,6 +8,7 @@ from .util import extract_vars, get_id, get_iterable, is_mapping, to_np |
|
|
|
from .py3compat import viewkeys |
|
|
|
from .py3compat import viewkeys |
|
|
|
from .latlonutils import _lat_varname, _lon_varname, _ll_to_xy, _xy_to_ll |
|
|
|
from .latlonutils import _lat_varname, _lon_varname, _ll_to_xy, _xy_to_ll |
|
|
|
from .metadecorators import set_latlon_metadata |
|
|
|
from .metadecorators import set_latlon_metadata |
|
|
|
|
|
|
|
from .constants import Constants, ProjectionTypes |
|
|
|
from .config import xarray_enabled |
|
|
|
from .config import xarray_enabled |
|
|
|
|
|
|
|
|
|
|
|
if xarray_enabled(): |
|
|
|
if xarray_enabled(): |
|
|
@ -388,6 +389,127 @@ def ll_to_xy(wrfin, latitude, longitude, timeidx=0, |
|
|
|
squeeze, None, _key, as_int, **{}) |
|
|
|
squeeze, None, _key, as_int, **{}) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _set_defaults(projparams): |
|
|
|
|
|
|
|
"""Check projection parameters and set defaults. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Throws an exception if projection parameters required by WPS are not |
|
|
|
|
|
|
|
provided, along with any other parameters required by the map projection |
|
|
|
|
|
|
|
transformation routines. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
For parameters not used by the projection type, defaults are used so that |
|
|
|
|
|
|
|
the None values don't pass through to fortran downstream. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Args: |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
projparams (:obj:`dict`): Projection parameters dictionary. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Returns: |
|
|
|
|
|
|
|
:obj:`dict`: The projection parameters with default values inserted |
|
|
|
|
|
|
|
where applicable. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
""" |
|
|
|
|
|
|
|
_params = dict(projparams) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
map_proj = _params.get("map_proj") |
|
|
|
|
|
|
|
# All projections require these arguments |
|
|
|
|
|
|
|
if map_proj is None: |
|
|
|
|
|
|
|
raise ValueError("'map_proj' cannot be None") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if _params.get("ref_lat") is None: |
|
|
|
|
|
|
|
raise ValueError("'ref_lat' cannot be None") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if _params.get("ref_lon") is None: |
|
|
|
|
|
|
|
raise ValueError("'ref_lon' cannot be None") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if _params.get("known_x") is None: |
|
|
|
|
|
|
|
raise ValueError("'known_x' cannot be None") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if _params.get("known_y") is None: |
|
|
|
|
|
|
|
raise ValueError("'known_y' cannot be None") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if _params.get("dx") is None: |
|
|
|
|
|
|
|
raise ValueError("'dx' cannot be None") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Requires truelat1,stand_lon, truelat2, dx, dy |
|
|
|
|
|
|
|
if map_proj == ProjectionTypes.LAMBERT_CONFORMAL: |
|
|
|
|
|
|
|
if _params.get("truelat1") is None: |
|
|
|
|
|
|
|
raise ValueError("'truelat1' cannot be None") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if _params.get("stand_lon") is None: |
|
|
|
|
|
|
|
raise ValueError("'stand_lon' cannot be None") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if _params.get("truelat2") is None: |
|
|
|
|
|
|
|
_params["truelat2"] = _params["truelat1"] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Requires truelat1, stand_lon |
|
|
|
|
|
|
|
elif map_proj == ProjectionTypes.POLAR_STEREOGRAPHIC: |
|
|
|
|
|
|
|
if _params.get("truelat1") is None: |
|
|
|
|
|
|
|
raise ValueError("'truelat1' cannot be None") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if _params.get("stand_lon") is None: |
|
|
|
|
|
|
|
raise ValueError("'stand_lon' cannot be None") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Requires truelat1 |
|
|
|
|
|
|
|
elif map_proj == ProjectionTypes.MERCATOR: |
|
|
|
|
|
|
|
if _params.get("truelat1") is None: |
|
|
|
|
|
|
|
raise ValueError("'truelat1' cannot be None") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if _params.get("stand_lon") is None: |
|
|
|
|
|
|
|
_params["stand_lon"] = 0.0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Requires pole_lat, pole_lon, stand_lon |
|
|
|
|
|
|
|
elif map_proj == ProjectionTypes.LAT_LON: |
|
|
|
|
|
|
|
if _params.get("stand_lon") is None: |
|
|
|
|
|
|
|
raise ValueError("'stand_lon' cannot be None") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if _params.get("dy") is None: |
|
|
|
|
|
|
|
raise ValueError("'dy' cannot be None") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if _params.get("pole_lat") is None: |
|
|
|
|
|
|
|
raise ValueError("'pole_lat' cannot be None") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if _params.get("pole_lon") is None: |
|
|
|
|
|
|
|
raise ValueError("'pole_lon' cannot be None") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if _params.get("latinc") is None: |
|
|
|
|
|
|
|
_params["latinc"] = ((_params["dy"]*360.0)/2.0 / |
|
|
|
|
|
|
|
Constants.PI/Constants.WRF_EARTH_RADIUS) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if _params.get("loninc") is None: |
|
|
|
|
|
|
|
_params["loninc"] = ((_params["dx"]*360.0)/2.0 / |
|
|
|
|
|
|
|
Constants.PI/Constants.WRF_EARTH_RADIUS) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
else: |
|
|
|
|
|
|
|
raise ValueError("invalid 'map_proj' value of {}".format(map_proj)) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Set these to defaults if not used so that the Fortran routines |
|
|
|
|
|
|
|
# don't crash |
|
|
|
|
|
|
|
if _params.get("truelat1") is None: |
|
|
|
|
|
|
|
_params["truelat1"] = 0. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if _params.get("truelat2") is None: |
|
|
|
|
|
|
|
_params["truelat2"] = 0. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if _params.get("pole_lat") is None: |
|
|
|
|
|
|
|
_params["pole_lat"] = 90.0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if _params.get("pole_lon") is None: |
|
|
|
|
|
|
|
_params["pole_lon"] = 0.0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if _params.get("dx") is None: |
|
|
|
|
|
|
|
_params["dx"] = 0.0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if _params.get("dy") is None: |
|
|
|
|
|
|
|
_params["dy"] = 0.0 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if _params.get("latinc") is None: |
|
|
|
|
|
|
|
_params["latinc"] = 0. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if _params.get("loninc") is None: |
|
|
|
|
|
|
|
_params["loninc"] = 0. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return _params |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@set_latlon_metadata(xy=True) |
|
|
|
@set_latlon_metadata(xy=True) |
|
|
|
def ll_to_xy_proj(latitude, longitude, meta=True, squeeze=True, as_int=True, |
|
|
|
def ll_to_xy_proj(latitude, longitude, meta=True, squeeze=True, as_int=True, |
|
|
@ -435,7 +557,8 @@ def ll_to_xy_proj(latitude, longitude, meta=True, squeeze=True, as_int=True, |
|
|
|
truelat2 (:obj:`float`): True latitude 2. Optional for |
|
|
|
truelat2 (:obj:`float`): True latitude 2. Optional for |
|
|
|
map_proj = 1 (defaults to 0 otherwise). |
|
|
|
map_proj = 1 (defaults to 0 otherwise). |
|
|
|
|
|
|
|
|
|
|
|
stand_lon (:obj:`float`): Standard longitude. Required. |
|
|
|
stand_lon (:obj:`float`): Standard longitude. Required for map_proj = |
|
|
|
|
|
|
|
1, 2, 6 (defaults to 0 otherwise). |
|
|
|
|
|
|
|
|
|
|
|
ref_lat (:obj:`float`): A reference latitude. Required. |
|
|
|
ref_lat (:obj:`float`): A reference latitude. Required. |
|
|
|
|
|
|
|
|
|
|
@ -454,10 +577,10 @@ def ll_to_xy_proj(latitude, longitude, meta=True, squeeze=True, as_int=True, |
|
|
|
*map_proj* = 6 (defaults to 0 otherwise). |
|
|
|
*map_proj* = 6 (defaults to 0 otherwise). |
|
|
|
|
|
|
|
|
|
|
|
dx (:obj:`float`): The x spacing in meters at the true latitude. |
|
|
|
dx (:obj:`float`): The x spacing in meters at the true latitude. |
|
|
|
Required for *map_proj* = 1, 2, 3 (defaults to 0 otherwise). |
|
|
|
Required for all map projections. |
|
|
|
|
|
|
|
|
|
|
|
dy (:obj:`float`) - The y spacing in meters at the true latitude. |
|
|
|
dy (:obj:`float`) - The y spacing in meters at the true latitude. |
|
|
|
Required for *map_proj* = 1, 2, 3 (defaults to 0 otherwise). |
|
|
|
Required for *map_proj* = 6 (defaults to 0 otherwise). |
|
|
|
|
|
|
|
|
|
|
|
latinc (:obj:`float`): Required for *map_proj* = 6. Defined as: |
|
|
|
latinc (:obj:`float`): Required for *map_proj* = 6. Defined as: |
|
|
|
|
|
|
|
|
|
|
@ -480,12 +603,14 @@ def ll_to_xy_proj(latitude, longitude, meta=True, squeeze=True, as_int=True, |
|
|
|
|
|
|
|
|
|
|
|
""" |
|
|
|
""" |
|
|
|
loc = locals() |
|
|
|
loc = locals() |
|
|
|
projparams = {name : loc[name] for name in ("map_proj", "truelat1", |
|
|
|
_projparams = {name : loc[name] for name in ("map_proj", "truelat1", |
|
|
|
"truelat2", "stand_lon", "ref_lat", |
|
|
|
"truelat2", "stand_lon", "ref_lat", |
|
|
|
"ref_lon", "pole_lat", "pole_lon", |
|
|
|
"ref_lon", "pole_lat", "pole_lon", |
|
|
|
"known_x", "known_y", "dx", "dy", |
|
|
|
"known_x", "known_y", "dx", "dy", |
|
|
|
"latinc", "loninc")} |
|
|
|
"latinc", "loninc")} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
projparams = _set_defaults(_projparams) |
|
|
|
|
|
|
|
|
|
|
|
return _ll_to_xy(latitude, longitude, None, 0, True, "cat", squeeze, None, |
|
|
|
return _ll_to_xy(latitude, longitude, None, 0, True, "cat", squeeze, None, |
|
|
|
None, as_int, **projparams) |
|
|
|
None, as_int, **projparams) |
|
|
|
|
|
|
|
|
|
|
@ -600,7 +725,8 @@ def xy_to_ll_proj(x, y, meta=True, squeeze=True, map_proj=None, truelat1=None, |
|
|
|
truelat2 (:obj:`float`): True latitude 2. Optional for |
|
|
|
truelat2 (:obj:`float`): True latitude 2. Optional for |
|
|
|
map_proj = 1 (defaults to 0 otherwise). |
|
|
|
map_proj = 1 (defaults to 0 otherwise). |
|
|
|
|
|
|
|
|
|
|
|
stand_lon (:obj:`float`): Standard longitude. Required. |
|
|
|
stand_lon (:obj:`float`): Standard longitude. Required for map_proj = |
|
|
|
|
|
|
|
1, 2, 6 (defaults to 0 otherwise). |
|
|
|
|
|
|
|
|
|
|
|
ref_lat (:obj:`float`): A reference latitude. Required. |
|
|
|
ref_lat (:obj:`float`): A reference latitude. Required. |
|
|
|
|
|
|
|
|
|
|
@ -622,7 +748,7 @@ def xy_to_ll_proj(x, y, meta=True, squeeze=True, map_proj=None, truelat1=None, |
|
|
|
Required for *map_proj* = 1, 2, 3 (defaults to 0 otherwise). |
|
|
|
Required for *map_proj* = 1, 2, 3 (defaults to 0 otherwise). |
|
|
|
|
|
|
|
|
|
|
|
dy (:obj:`float`) - The y spacing in meters at the true latitude. |
|
|
|
dy (:obj:`float`) - The y spacing in meters at the true latitude. |
|
|
|
Required for *map_proj* = 1, 2, 3 (defaults to 0 otherwise). |
|
|
|
Required for *map_proj* = 6 (defaults to 0 otherwise). |
|
|
|
|
|
|
|
|
|
|
|
latinc (:obj:`float`): Required for *map_proj* = 6. Defined as: |
|
|
|
latinc (:obj:`float`): Required for *map_proj* = 6. Defined as: |
|
|
|
|
|
|
|
|
|
|
@ -645,11 +771,13 @@ def xy_to_ll_proj(x, y, meta=True, squeeze=True, map_proj=None, truelat1=None, |
|
|
|
be a :class:`numpy.ndarray` object with no metadata. |
|
|
|
be a :class:`numpy.ndarray` object with no metadata. |
|
|
|
""" |
|
|
|
""" |
|
|
|
loc = locals() |
|
|
|
loc = locals() |
|
|
|
projparams = {name : loc[name] for name in ("map_proj", "truelat1", |
|
|
|
_projparams = {name : loc[name] for name in ("map_proj", "truelat1", |
|
|
|
"truelat2", "stand_lon", "ref_lat", |
|
|
|
"truelat2", "stand_lon", "ref_lat", |
|
|
|
"ref_lon", "pole_lat", "pole_lon", |
|
|
|
"ref_lon", "pole_lat", "pole_lon", |
|
|
|
"known_x", "known_y", "dx", "dy", |
|
|
|
"known_x", "known_y", "dx", "dy", |
|
|
|
"latinc", "loninc")} |
|
|
|
"latinc", "loninc")} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
projparams = _set_defaults(_projparams) |
|
|
|
return _xy_to_ll(x, y, None, 0, None, "cat", squeeze, None, None, |
|
|
|
return _xy_to_ll(x, y, None, 0, None, "cat", squeeze, None, None, |
|
|
|
**projparams) |
|
|
|
**projparams) |
|
|
|
|
|
|
|
|
|
|
|