Skip to content

Commit

Permalink
Merge branch 'develop' into feature/to_image
Browse files Browse the repository at this point in the history
  • Loading branch information
mlshapiro committed Nov 13, 2019
2 parents b2e219c + c77f62b commit c5fb3fb
Show file tree
Hide file tree
Showing 4 changed files with 76 additions and 87 deletions.
2 changes: 1 addition & 1 deletion podpac/core/coordinates/coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -1213,7 +1213,7 @@ def transform(self, crs=None, alt_units=None):
# include alt units in proj4 string
c = Coordinates([[0, 1, 2], [0, 1, 2], [1, 2, 3]], dims=['lat', 'lon', 'alt'])
c.transform('+init=epsg:2193 +vunits=ft')
c.transform('+proj=tmerc +vunits=ft')
>> Coordinates
lat: ArrayCoordinates1d(lat): Bounds[594971.8894642257, 819117.0608407748], N[3], ctype['midpoint']
Expand Down
156 changes: 72 additions & 84 deletions podpac/core/coordinates/test/test_coordinates.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
import sys
import json
import warnings
from copy import deepcopy

import pytest
import numpy as np
import xarray as xr
import pandas as pd
from numpy.testing import assert_equal
import xarray as xr
import pyproj

import podpac
Expand Down Expand Up @@ -381,85 +379,80 @@ def test_from_xarray(self):
Coordinates.from_xarray([0, 10])

def test_crs(self):
with warnings.catch_warnings():
warnings.filterwarnings(
"ignore", r".*init=<authority>:<code>' syntax is deprecated", DeprecationWarning, "pyproj"
)
lat = ArrayCoordinates1d([0, 1, 2], "lat")
lon = ArrayCoordinates1d([0, 1, 2], "lon")

# default
c = Coordinates([lat, lon])
assert c.crs == podpac.settings["DEFAULT_CRS"]
assert c.alt_units is None
assert set(c.properties.keys()) == {"crs"}

# crs
c = Coordinates([lat, lon], crs="EPSG:2193")
assert c.crs == "EPSG:2193"
assert c.alt_units is None
assert set(c.properties.keys()) == {"crs"}

# proj4
c = Coordinates([lat, lon], crs="EPSG:2193")
assert c.crs == "EPSG:2193"
assert c.alt_units is None
assert set(c.properties.keys()) == {"crs"}

lat = ArrayCoordinates1d([0, 1, 2], "lat")
lon = ArrayCoordinates1d([0, 1, 2], "lon")

# default
c = Coordinates([lat, lon])
assert c.crs == podpac.settings["DEFAULT_CRS"]
assert c.alt_units is None
assert set(c.properties.keys()) == {"crs"}

# crs
c = Coordinates([lat, lon], crs="EPSG:2193")
assert c.crs == "EPSG:2193"
assert c.alt_units is None
assert set(c.properties.keys()) == {"crs"}

# proj4
c = Coordinates([lat, lon], crs="+init=epsg:2193")
assert c.crs == "+init=epsg:2193"
assert c.alt_units is None
assert set(c.properties.keys()) == {"crs"}

c = Coordinates([lat, lon], crs="+proj=merc +lat_ts=56.5 +ellps=GRS80")
assert c.crs == "+proj=merc +lat_ts=56.5 +ellps=GRS80"
assert c.alt_units is None
assert set(c.properties.keys()) == {"crs"}

# with vunits
c = Coordinates([lat, lon], crs="+init=epsg:2193 +vunits=ft")
assert c.crs == "+init=epsg:2193 +vunits=ft"
assert c.alt_units == "ft"
assert set(c.properties.keys()) == {"crs"} # no alt_units, it is in the crs

# invalid
with pytest.raises(pyproj.crs.CRSError):
Coordinates([lat, lon], crs="abcd")
c = Coordinates([lat, lon], crs="+proj=merc +lat_ts=56.5 +ellps=GRS80")
assert c.crs == "+proj=merc +lat_ts=56.5 +ellps=GRS80"
assert c.alt_units is None
assert set(c.properties.keys()) == {"crs"}

# with vunits
c = Coordinates([lat, lon], crs="+proj=merc +lat_ts=56.5 +ellps=GRS80 +vunits=ft")
assert c.crs == "+proj=merc +lat_ts=56.5 +ellps=GRS80 +vunits=ft"
assert c.alt_units == "ft"
assert set(c.properties.keys()) == {"crs"} # no alt_units, it is in the crs

# invalid
with pytest.raises(pyproj.crs.CRSError):
Coordinates([lat, lon], crs="abcd")

# DeprecationWarning for +init (#316)
with pytest.warns(DeprecationWarning):
Coordinates([lat], crs="+init=epsg:4326")

def test_alt_units(self):
with warnings.catch_warnings():
warnings.filterwarnings(
"ignore", r".*init=<authority>:<code>' syntax is deprecated", DeprecationWarning, "pyproj"
)

alt = ArrayCoordinates1d([0, 1, 2], name="alt")
alt = ArrayCoordinates1d([0, 1, 2], name="alt")

# None
c = Coordinates([alt])
assert c.alt_units is None
assert set(c.properties.keys()) == {"crs"}
# None
c = Coordinates([alt])
assert c.alt_units is None
assert set(c.properties.keys()) == {"crs"}

c.set_trait("alt_units", None)
c.set_trait("alt_units", None)

# proj4
c = Coordinates([alt], crs="EPSG:2193", alt_units="ft")
assert c.alt_units == "ft"
assert set(c.properties.keys()) == {"crs", "alt_units"}
# proj4
c = Coordinates([alt], crs="EPSG:2193", alt_units="ft")
assert c.alt_units == "ft"
assert set(c.properties.keys()) == {"crs", "alt_units"}

# with crs
c = Coordinates([alt], crs="EPSG:2193", alt_units="ft")
assert c.crs == "EPSG:2193"
assert c.alt_units == "ft"
assert set(c.properties.keys()) == {"crs", "alt_units"}
# with crs
c = Coordinates([alt], crs="EPSG:2193", alt_units="ft")
assert c.crs == "EPSG:2193"
assert c.alt_units == "ft"
assert set(c.properties.keys()) == {"crs", "alt_units"}

# invalid
with pytest.raises(ValueError, match="Invalid alt_units"):
Coordinates([alt], alt_units="feet")
# invalid
with pytest.raises(ValueError, match="Invalid alt_units"):
Coordinates([alt], alt_units="feet")

# crs mismatch
with pytest.raises(ValueError, match="crs and alt_units mismatch"):
Coordinates([alt], crs="+init=epsg:2193 +vunits=ft", alt_units="m")
# crs mismatch
with pytest.raises(ValueError, match="crs and alt_units mismatch"):
Coordinates([alt], crs="+proj=merc +vunits=ft", alt_units="m")

# ignore
with pytest.warns(UserWarning, match="alt_units ignored"):
c = Coordinates([alt], crs="EPSG:4326", alt_units="ft")
assert c.alt_units is None
# ignore
with pytest.warns(UserWarning, match="alt_units ignored"):
c = Coordinates([alt], crs="EPSG:4326", alt_units="ft")
assert c.alt_units is None

def test_ctype(self):
# assign
Expand Down Expand Up @@ -1547,21 +1540,16 @@ def test_eq_ne_hash_alt_units(self):
assert c3.hash == deepcopy(c3).hash

def test_eq_ne_hash_crs_alt_units(self):
with warnings.catch_warnings():
warnings.filterwarnings(
"ignore", r".*init=<authority>:<code>' syntax is deprecated", DeprecationWarning, "pyproj"
)

lat = [0, 1, 2]
lon = [10, 20, 30]
lat = [0, 1, 2]
lon = [10, 20, 30]

# special case, these should be the same
c1 = Coordinates([lat, lon], dims=["lat", "lon"], crs="EPSG:2193", alt_units="ft")
c2 = Coordinates([lat, lon], dims=["lat", "lon"], crs="+init=EPSG:2193 +vunits=ft")
# special case, these should be the same
c1 = Coordinates([lat, lon], dims=["lat", "lon"], crs="EPSG:2193", alt_units="ft")
c2 = Coordinates([lat, lon], dims=["lat", "lon"], crs="+proj=tmerc +vunits=ft")

assert c1 == c2
assert not c1 != c2
assert c1.hash == c2.hash
assert c1 == c2
assert not c1 != c2
assert c1.hash == c2.hash


class TestCoordinatesFunctions(object):
Expand Down
2 changes: 1 addition & 1 deletion podpac/core/managers/aws.py
Original file line number Diff line number Diff line change
Expand Up @@ -1604,7 +1604,7 @@ def create_function(
elif function_source_dist_zip is not None:
with open(function_source_dist_zip, "rb") as f:
lambda_config["Code"] = {} # reset the code dict to make sure S3Bucket and S3Key are overridden
lambda_config["Code"]["ZipFile"]: f.read()
lambda_config["Code"]["ZipFile"] = f.read()

else:
raise ValueError("Function source is not defined")
Expand Down
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"traitlets>=4.3",
"xarray>=0.10",
"requests>=2.18",
"pyproj>=2.2",
"pyproj>=2.4",
"lazy-import>=0.2.2",
"psutil",
]
Expand Down Expand Up @@ -65,6 +65,7 @@
"pylint>=1.8.2",
"pytest-cov>=2.5.1",
"pytest-html>=1.7.0",
"pytest-remotedata>=0.3.1",
"recommonmark>=0.4",
"sphinx>=1.8",
"sphinx-rtd-theme>=0.4",
Expand Down

0 comments on commit c5fb3fb

Please sign in to comment.