本文整理汇总了Python中affine.Affine.translation方法的典型用法代码示例。如果您正苦于以下问题:Python Affine.translation方法的具体用法?Python Affine.translation怎么用?Python Affine.translation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类affine.Affine
的用法示例。
在下文中一共展示了Affine.translation方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: dose
# 需要导入模块: from affine import Affine [as 别名]
# 或者: from affine.Affine import translation [as 别名]
def dose(self, x, y, dunits='km', doseunits='Sv'):
"""Estimate of total "Equivalent Residual Dose" (ERD) at location x, y from time of fallout arrival to 30 days, including a 90% recovery factor.
"""
rx, _ = self.translation * (convert_units(x, dunits, 'mi'), convert_units(y, dunits, 'mi')) * ~Affine.rotation(-self.wd + 270)
t_a = self.fallouttoa(rx)
# To obtain a measure of dose to humans, "Biological Dose" was defined as the
# product of the DH+1 and a conversion factor, called Bio. Bio is an
# empirical function depending on fallout arrival time and length of
# exposure. Ten percent of the dose received is assumed irreparable and
# ninety percent is assumed reparable with a thirty day time constant. This
# was solved numerically and plotted as Dose vs. Time. Bio was then estimated
# as Bio = (t / 19)**0.33, so that the dose at some time after activity
# arrival is defined as Dose = DH+1 * Bio. Further refinements in the model
# resulted in a second order approximation for Bio used here:
bio = np.exp(-(0.287 + 0.52 * np.log(t_a / 31.6) + 0.04475 * np.log((t_a / 31.6)**2)))
return self.D_Hplus1(x, y, dunits=dunits, doseunits=doseunits) * bio
示例2: test_init_edge_cases
# 需要导入模块: from affine import Affine [as 别名]
# 或者: from affine.Affine import translation [as 别名]
def test_init_edge_cases(fps):
# rotation
aff = Affine.translation(42, 21) * Affine.rotation(12) * Affine.scale(0.1, -0.1)
with buzz.Env(allow_complex_footprint=True):
buzz.Footprint(gt=aff.to_gdal(), rsize=[1, 1])
# missing parameters
with pytest.raises(ValueError):
buzz.Footprint(tl=fps.A.tl, size=fps.A.size)
with pytest.raises(ValueError):
buzz.Footprint(rsize=fps.A.rsize, size=fps.A.size)
with pytest.raises(ValueError):
buzz.Footprint(rsize=fps.A.rsize, tl=fps.A.tl)
with pytest.raises(ValueError):
buzz.Footprint(rsize=fps.A.rsize)
# shapes
with pytest.raises(ValueError, match='shape'):
buzz.Footprint(rsize=[], tl=fps.A.tl, size=fps.A.size)
with pytest.raises(ValueError, match='shape'):
buzz.Footprint(rsize=fps.A.rsize, tl=[], size=fps.A.size)
with pytest.raises(ValueError, match='shape'):
buzz.Footprint(rsize=fps.A.rsize, tl=fps.A.tl, size=[])
with pytest.raises(ValueError, match='shape'):
buzz.Footprint(rsize=fps.A.rsize, gt=[])
# finitude
with pytest.raises(ValueError):
buzz.Footprint(rsize=[-1] * 2, tl=fps.A.tl, size=fps.A.size)
with pytest.raises(ValueError):
buzz.Footprint(rsize=fps.A.rsize, tl=[np.inf] * 2, size=fps.A.size)
with pytest.raises(ValueError):
buzz.Footprint(rsize=fps.A.rsize, tl=fps.A.tl, size=[np.inf] * 2)
with pytest.raises(ValueError):
buzz.Footprint(rsize=fps.A.rsize, gt=[np.inf] * 6)
示例3: test_move
# 需要导入模块: from affine import Affine [as 别名]
# 或者: from affine.Affine import translation [as 别名]
def test_move(fps1px):
fps = fps1px
with buzz.Env(warnings=False, allow_complex_footprint=True): # Test the `warnings` deprecation
assert fpeq(
fps.B,
fps.A.move(fps.B.tl),
fps.B.move(fps.B.tl),
fps.C.move(fps.B.tl),
fps.A.move(fps.B.tl, fps.B.tr),
fps.B.move(fps.B.tl, fps.B.tr),
fps.C.move(fps.B.tl, fps.B.tr),
fps.A.move(fps.B.tl, fps.B.tr, fps.B.br),
fps.B.move(fps.B.tl, fps.B.tr, fps.B.br),
fps.C.move(fps.B.tl, fps.B.tr, fps.B.br),
)
aff = (
Affine.translation(*fps.A.bl) * Affine.rotation(45) * Affine.scale(2**0.5, 2**0.5 * -2)
)
assert fpeq(
buzz.Footprint(gt=aff.to_gdal(), rsize=(1, 1)),
fps.A.move(fps.A.bl, fps.A.tr, fps.I.tr),
fps.B.move(fps.A.bl, fps.A.tr, fps.I.tr),
fps.C.move(fps.A.bl, fps.A.tr, fps.I.tr),
)
with pytest.raises(ValueError, match='angle'):
fps.C.move(fps.A.bl, fps.A.tr, fps.I.c)
示例4: from_origin
# 需要导入模块: from affine import Affine [as 别名]
# 或者: from affine.Affine import translation [as 别名]
def from_origin(west, north, xsize, ysize):
"""Return an Affine transformation given upper left and pixel sizes.
Return an Affine transformation for a georeferenced raster given
the coordinates of its upper left corner `west`, `north` and pixel
sizes `xsize`, `ysize`.
"""
return Affine.translation(west, north) * Affine.scale(xsize, -ysize)
示例5: from_bounds
# 需要导入模块: from affine import Affine [as 别名]
# 或者: from affine.Affine import translation [as 别名]
def from_bounds(west, south, east, north, width, height):
"""Return an Affine transformation given bounds, width and height.
Return an Affine transformation for a georeferenced raster given
its bounds `west`, `south`, `east`, `north` and its `width` and
`height` in number of pixels.
"""
return Affine.translation(west, north) * Affine.scale(
(east - west) / width, (south - north) / height)
示例6: __init__
# 需要导入模块: from affine import Affine [as 别名]
# 或者: from affine.Affine import translation [as 别名]
def __init__(self, gzx, gzy, yld, ff, wind, wd, shear, tob=0, dunits='km', wunits='km/h', shearunits='m/s-km', yunits='kT'):
self.translation = ~Affine.translation(convert_units(gzx, dunits, 'mi'), convert_units(gzy, dunits, 'mi')) # translate coordinates relative to GZ (st. mi)
self.wd = wd # wind direction in degrees (0=N, 90=E, etc.)
self.yld = convert_units(yld, yunits, 'MT') # yield (MT)
self.ff = ff # fission fraction, 0 < ff <= 1.0
self.wind = convert_units(wind, wunits, 'mph') # wind speed (mi/hr)
self.shear = convert_units(shear, shearunits, 'mph/kilofoot') # wind shear in mi/hr-kilofoot
self.tob = tob # time of burst (hrs)
# FORTRAN is ugly in any language
# Store these values in the WSEG10 object to avoid recalculating them
d = np.log(self.yld) + 2.42 # physically meaningless, but occurs twice
# According to Hanifen, "The cloud is initially formed because the nuclear
# fireball vaporizes both the surface of the earth at ground zero and the
# weapon itself. The activity contained in the cloud is both neutron induced
# and fission. After formation, the fireball rises and begins to cool at its
# outer edges faster than the center thereby creating the typical torroidal
# currents associated with the nuclear cloud. WSEG arbitrarily assumes that
# the cloud will rise to a maximum center height within fifteen minutes and
# then stabilize."
self.H_c = 44 + 6.1 * np.log(yld) - 0.205 * abs(d) * d # cloud center height
lnyield = np.log(self.yld)
self.s_0 = np.exp(0.7 + lnyield / 3 - 3.25 / (4.0 + (lnyield + 5.4)**2)) #sigma_0
self.s_02 = self.s_0**2
self.s_h = 0.18 * self.H_c # sigma_h
self.T_c = 1.0573203 * (12 * (self.H_c / 60) - 2.5 * (self.H_c / 60)**2) * (1 - 0.5 * np.exp(-1 * (self.H_c / 25)**2)) # time constant
self.L_0 = wind * self.T_c # L_0, used by g(x)
self.L_02 = self.L_0**2
self.s_x2 = self.s_02 * (self.L_02 + 8 * self.s_02) / (self.L_02 + 2 * self.s_02)
self.s_x = np.sqrt(self.s_x2) # sigma_x
self.L_2 = self.L_02 + 2 * self.s_x2
self.L = np.sqrt(self.L_2) # L
self.n = (ff * self.L_02 + self.s_x2) / (self.L_02 + 0.5 * self.s_x2) # n
self.a_1 = 1 / (1 + ((0.001 * self.H_c * wind) / self.s_0)) # alpha_1
示例7: D_Hplus1
# 需要导入模块: from affine import Affine [as 别名]
# 或者: from affine.Affine import translation [as 别名]
def D_Hplus1(self, x, y, dunits='km', doseunits='Sv'):
"""Returns dose rate at x, y at 1 hour after burst. This value includes dose rate from all activity that WILL be deposited at that location, not just that that has arrived by H+1 hr."""
rx, ry = self.translation * (convert_units(x, dunits, 'mi'), convert_units(y, dunits, 'mi')) * ~Affine.rotation(-self.wd + 270)
f_x = self.yld * 2e6 * self.phi(rx) * self.g(rx) * self.ff
s_y = np.sqrt(self.s_02 + ((8 * abs(rx + 2 * self.s_x) * self.s_02) / self.L) + (2 * (self.s_x * self.T_c * self.s_h * self.shear)**2 / self.L_2) + (((rx + 2 * self.s_x) * self.L_0 * self.T_c * self.s_h * self.shear)**2 / self.L**4))
a_2 = 1 / (1 + ((0.001 * self.H_c * self.wind) / self.s_0) * (1 - norm.cdf(2 * x / self.wind)))
f_y = np.exp(-0.5 * (ry / (a_2 * s_y))**2) / (2.5066282746310002 * s_y)
return convert_units(f_x * f_y, 'Roentgen', doseunits)
示例8: __geo_transform__
# 需要导入模块: from affine import Affine [as 别名]
# 或者: from affine.Affine import translation [as 别名]
def __geo_transform__(self):
west, south, east, north = self.bounds
tfm = Affine.translation(west, north) * Affine.scale((east - west) / self.shape[2], (south - north) / self.shape[1])
return AffineTransform(tfm, "EPSG:3857")
示例9: __add__
# 需要导入模块: from affine import Affine [as 别名]
# 或者: from affine.Affine import translation [as 别名]
def __add__(self, other):
if isinstance(other, Sequence) and len(other) == 2:
shift = np.asarray(other)
return AffineTransform(self._affine * Affine.translation(shift[0], shift[1]), proj=self.proj)
else:
raise NotImplemented
示例10: _transform_from_latlon
# 需要导入模块: from affine import Affine [as 别名]
# 或者: from affine.Affine import translation [as 别名]
def _transform_from_latlon(lon, lat):
"""perform an affine tranformation to the latitude/longitude coordinates"""
from affine import Affine
lat = np.asarray(lat)
lon = np.asarray(lon)
d_lon = lon[1] - lon[0]
d_lat = lat[1] - lat[0]
trans = Affine.translation(lon[0] - d_lon / 2, lat[0] - d_lat / 2)
scale = Affine.scale(d_lon, d_lat)
return trans * scale
示例11: xy
# 需要导入模块: from affine import Affine [as 别名]
# 或者: from affine.Affine import translation [as 别名]
def xy(transform, rows, cols, offset='center'):
"""Returns the x and y coordinates of pixels at `rows` and `cols`.
The pixel's center is returned by default, but a corner can be returned
by setting `offset` to one of `ul, ur, ll, lr`.
Parameters
----------
transform : affine.Affine
Transformation from pixel coordinates to coordinate reference system.
rows : list or int
Pixel rows.
cols : list or int
Pixel columns.
offset : str, optional
Determines if the returned coordinates are for the center of the
pixel or for a corner.
Returns
-------
xs : list
x coordinates in coordinate reference system
ys : list
y coordinates in coordinate reference system
"""
single_col = False
single_row = False
if not isinstance(cols, collections.Iterable):
cols = [cols]
single_col = True
if not isinstance(rows, collections.Iterable):
rows = [rows]
single_row = True
if offset == 'center':
coff, roff = (0.5, 0.5)
elif offset == 'ul':
coff, roff = (0, 0)
elif offset == 'ur':
coff, roff = (1, 0)
elif offset == 'll':
coff, roff = (0, 1)
elif offset == 'lr':
coff, roff = (1, 1)
else:
raise ValueError("Invalid offset")
xs = []
ys = []
for col, row in zip(cols, rows):
x, y = transform * transform.translation(coff, roff) * (col, row)
xs.append(x)
ys.append(y)
if single_row:
ys = ys[0]
if single_col:
xs = xs[0]
return xs, ys