Skip to content

Commit

Permalink
Merge pull request #1768 from UV-CDAT/issue_1763_lambert
Browse files Browse the repository at this point in the history
Issue 1763 lambert
  • Loading branch information
aashish24 committed Jan 12, 2016
2 parents 6f64cc6 + 3d751cc commit 6e7db69
Show file tree
Hide file tree
Showing 9 changed files with 93 additions and 58 deletions.
3 changes: 3 additions & 0 deletions Packages/vcs/Lib/projection.py
Expand Up @@ -21,6 +21,9 @@
round_projections = ['polar (non gctp)', 'stereographic',
'orthographic', "ortho", ]

no_over_proj4_parameter_projections = round_projections+["aeqd", "lambert conformal c"]
elliptical_projections = ["robinson", "mollweide"]


def process_src(nm, code):
try:
Expand Down
3 changes: 3 additions & 0 deletions Packages/vcs/Lib/template.py
Expand Up @@ -37,6 +37,7 @@
import inspect
import cdutil
from projection import round_projections
from projection import elliptical_projections

# Following for class properties

Expand Down Expand Up @@ -1140,6 +1141,8 @@ def drawTicks(self, slab, gm, x, axis, number,
ys.append([obj.y1, obj.y2])
txs.append((l - wc[0]) / dx + vp[0])
tys.append(objlabl.y)
elif vcs.elements["projection"][gm.projection].type in elliptical_projections:
pass
else:
xs.append([l, l])
end = wc[
Expand Down
87 changes: 43 additions & 44 deletions Packages/vcs/Lib/vcs2vtk.py
Expand Up @@ -9,7 +9,7 @@
import cdms2
import warnings
import cdtime
from projection import round_projections
from projection import round_projections, no_over_proj4_parameter_projections
from vcsvtk import fillareautils

f = open(os.path.join(vcs.prefix, "share", "vcs", "wmo_symbols.json"))
Expand Down Expand Up @@ -555,6 +555,43 @@ def prepContinents(fnm):
return poly


def apply_proj_parameters(pd, projection, xm, xM, ym, yM):
pname = projDict.get(projection._type, projection.type)
projName = pname
pd.SetName(projName)
if projection.type == "polar (non gctp)":
if ym < yM:
pd.SetOptionalParameter("lat_0", "-90.")
pd.SetCentralMeridian(xm)
else:
pd.SetOptionalParameter("lat_0", "90.")
pd.SetCentralMeridian(xm + 180.)
else:
if projection.type not in no_over_proj4_parameter_projections:
pd.SetOptionalParameter("over", "true")
else:
pd.SetOptionalParameter("over", "false")
setProjectionParameters(pd, projection)
if (hasattr(projection, 'centralmeridian') and
numpy.allclose(projection.centralmeridian, 1e+20)):
pd.SetCentralMeridian(float(xm + xM) / 2.0)
if (hasattr(projection, 'centerlongitude') and
numpy.allclose(projection.centerlongitude, 1e+20)):
pd.SetOptionalParameter("lon_0", str(float(xm + xM) / 2.0))
if (hasattr(projection, 'originlatitude') and
numpy.allclose(projection.originlatitude, 1e+20)):
pd.SetOptionalParameter("lat_0", str(float(ym + yM) / 2.0))
if (hasattr(projection, 'centerlatitude') and
numpy.allclose(projection.centerlatitude, 1e+20)):
pd.SetOptionalParameter("lat_0", str(float(ym + yM) / 2.0))
if (hasattr(projection, 'standardparallel1') and
numpy.allclose(projection.standardparallel1, 1.e20)):
pd.SetOptionalParameter('lat_1', str(min(ym, yM)))
if (hasattr(projection, 'standardparallel2') and
numpy.allclose(projection.standardparallel2, 1.e20)):
pd.SetOptionalParameter('lat_2', str(max(ym, yM)))


def projectArray(w, projection, wc, geo=None):
xm, xM, ym, yM = wc
if isinstance(projection, (str, unicode)):
Expand All @@ -567,27 +604,8 @@ def projectArray(w, projection, wc, geo=None):
ps = vtk.vtkGeoProjection()
pd = vtk.vtkGeoProjection()

pname = projDict.get(projection._type, projection.type)
projName = pname
pd.SetName(projName)
if projection.type == 'aeqd':
# this is a temporary branch to keep the same
# baselines
setProjectionParameters(pd, projection)
else:
pd.SetOptionalParameter("over", "true")
if projection.type == "polar (non gctp)":
if ym < yM:
pd.SetOptionalParameter("lat_0", "-90.")
pd.SetCentralMeridian(xm)
else:
pd.SetOptionalParameter("lat_0", "90.")
pd.SetCentralMeridian(xm + 180.)
else:
setProjectionParameters(pd, projection)
if ((not hasattr(projection, 'centralmeridian') or
numpy.allclose(projection.centralmeridian, 1e+20))):
pd.SetCentralMeridian(float(xm + xM) / 2.0)
apply_proj_parameters(pd, projection, xm, xM, ym, yM)

geo.SetSourceProjection(ps)
geo.SetDestinationProjection(pd)

Expand All @@ -610,27 +628,8 @@ def project(pts, projection, wc, geo=None):
ps = vtk.vtkGeoProjection()
pd = vtk.vtkGeoProjection()

pname = projDict.get(projection._type, projection.type)
projName = pname
pd.SetName(projName)
if projection.type == 'aeqd':
# this is a temporary branch to keep the same
# baselines
setProjectionParameters(pd, projection)
else:
pd.SetOptionalParameter("over", "true")
if projection.type == "polar (non gctp)":
if ym < yM:
pd.SetOptionalParameter("lat_0", "-90.")
pd.SetCentralMeridian(xm)
else:
pd.SetOptionalParameter("lat_0", "90.")
pd.SetCentralMeridian(xm + 180.)
else:
setProjectionParameters(pd, projection)
if (not hasattr(projection, 'centralmeridian') or
numpy.allclose(projection.centralmeridian, 1e+20)):
pd.SetCentralMeridian(float(xm + xM) / 2.0)
apply_proj_parameters(pd, projection, xm, xM, ym, yM)

geo.SetSourceProjection(ps)
geo.SetDestinationProjection(pd)
geopts = vtk.vtkPoints()
Expand Down Expand Up @@ -964,7 +963,7 @@ def setClipPlanes(mapper, xmin, xmax, ymin, ymax):

# def doClip1(data,value,normal,axis=0):
# return data
# # We have the actor, do clipping
# We have the actor, do clipping
# clpf = vtk.vtkPlane()
# if axis == 0:
# clpf.SetOrigin(value,0,0)
Expand Down
16 changes: 12 additions & 4 deletions testing/vcs/CMakeLists.txt
Expand Up @@ -744,7 +744,7 @@ cdat_add_test(test_vcs_set_colors_name_rgba_isofill
ENDFOREACH(gm)

FOREACH(gm isofill meshfill boxfill)
FOREACH(proj polar robinson mercator mollweide lambert)
FOREACH(proj robinson)
cdat_add_test(vcs_test_animate_projected_${gm}_${proj}
"${PYTHON_EXECUTABLE}"
"${cdat_SOURCE_DIR}/testing/vcs/test_vcs_gms_animate_projected_plots.py"
Expand All @@ -764,10 +764,18 @@ cdat_add_test(test_vcs_set_colors_name_rgba_isofill
)
ENDFOREACH(flip)

if (NOT APPLE)
cdat_add_test(vcs_test_lambert
"${PYTHON_EXECUTABLE}"
${cdat_SOURCE_DIR}/testing/vcs/test_vcs_lambert.py
"${BASELINE_DIR}/test_vcs_lambert.png"
)
endif()

cdat_add_test(vcs_test_boxfill_lev1_lev2_ta_missing
"${PYTHON_EXECUTABLE}"
${cdat_SOURCE_DIR}/testing/vcs/test_boxfill_lev1_lev2_ta_missing.py
"${BASELINE_DIR}/test_boxfill_lev1_lev2_ta_missing.png"
"${PYTHON_EXECUTABLE}"
${cdat_SOURCE_DIR}/testing/vcs/test_boxfill_lev1_lev2_ta_missing.py
"${BASELINE_DIR}/test_boxfill_lev1_lev2_ta_missing.png"
)

cdat_add_test(vcs_test_close
Expand Down
7 changes: 1 addition & 6 deletions testing/vcs/editors/test_vcs_editor_marker_delete.py
@@ -1,12 +1,7 @@
import vcs
import sys

x = vcs.init()

# Needs to set the size of window so it is consistent accross
# test platforms
x.open()
x.geometry(800, 606)
x = vcs.init(geometry=(800,600))

m = x.createmarker()
m.x = .1,
Expand Down
2 changes: 1 addition & 1 deletion testing/vcs/test_vcs_basic_gms.py
Expand Up @@ -143,7 +143,7 @@
print "src:",src
if args.show:
raw_input("Press Enter")
ret = checkimage.check_result_image(fnm+'.png',src,checkimage.defaultThreshold, cleanup=not args.keep)
ret = checkimage.check_result_image(fnm+'.png',src,20., cleanup=not args.keep)
if args.show:
raw_input("Press Enter")
sys.exit(ret)
27 changes: 27 additions & 0 deletions testing/vcs/test_vcs_lambert.py
@@ -0,0 +1,27 @@
import vcs,cdms2
import os,sys
f = cdms2.open(os.path.join(vcs.sample_data, "clt.nc"))
s = f("clt")
x = vcs.init()
x.setantialiasing(0)
x.drawlogooff()
x.setbgoutputdimensions(1200,1090,units="pixels")
iso = x.createisofill()
p=x.createprojection()
p.type="lambert"

iso.projection = p
x.plot(s(latitude=(20, 60),longitude=(-140,-20)), iso, bg=True)

# Load the image testing module:
testingDir = os.path.join(os.path.dirname(__file__), "..")
sys.path.append(testingDir)
import checkimage

# Create the test image and compare:
baseline = sys.argv[1]
testFile = "test_vcs_lambert.png"
x.png(testFile)
ret = checkimage.check_result_image(testFile, baseline,
checkimage.defaultThreshold)
sys.exit(ret)
4 changes: 2 additions & 2 deletions testing/vcs/test_vcs_large_pattern_hatch.py
Expand Up @@ -10,7 +10,7 @@

canvas = vcs.init()
canvas.setantialiasing(0)
canvas.setbgoutputdimensions(792, 611, units="pixels")
canvas.setbgoutputdimensions(1200,1090, units="pixels")
canvas.drawlogooff()

fillarea = vcs.createfillarea()
Expand All @@ -20,7 +20,7 @@
fillarea.index = [1, 5, 5]
fillarea.color = [50, 50, 50]

canvas.plot(fillarea, bg=1)
canvas.plot(fillarea, bg=True)

testImage = os.path.abspath("test_vcs_large_pattern_hatch.png")
canvas.png(testImage)
Expand Down
2 changes: 1 addition & 1 deletion testing/vcs/test_vcs_patterns.py
Expand Up @@ -13,7 +13,7 @@
x = vcs.init()
x.setantialiasing(0)
x.drawlogooff()
x.setbgoutputdimensions(1200, 1091, units="pixels")
x.setbgoutputdimensions(1200, 1090, units="pixels")
iso = vcs.createisofill("isoleg")
iso.levels = [0, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
iso.fillareastyle = "pattern"
Expand Down

0 comments on commit 6e7db69

Please sign in to comment.