Skip to content

Commit

Permalink
http -> https
Browse files Browse the repository at this point in the history
  • Loading branch information
loeiten committed May 5, 2020
1 parent 3672ead commit c2a3226
Show file tree
Hide file tree
Showing 12 changed files with 86 additions and 86 deletions.
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
GNU LESSER GENERAL PUBLIC LICENSE
Version 3, 29 June 2007

Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ See [this issue](https://github.com/boutproject/BOUT-dev/issues/1347),

`boututils` depends on
[`netcfd4`](https://github.com/Unidata/netcdf4-python) which requires
[`HDF5`](http://www.h5py.org) and
[`HDF5`](https://www.h5py.org) and
[`netcdf-4`](https://github.com/Unidata/netcdf-c/releases) are
installed, and that the `nc-config` utility is in your `PATH`. This
can be install with
Expand Down
2 changes: 1 addition & 1 deletion boututils/View3D.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
is computed from efit_analyzed.py. The script can be used as a template to show additional properties of the field
based on enthought's example by Gael Varoquaux <[email protected]>
http://docs.enthought.com/mayavi/mayavi/auto/example_magnetic_field.html#example-magnetic-field
https://docs.enthought.com/mayavi/mayavi/auto/example_magnetic_field.html#example-magnetic-field
"""
from __future__ import absolute_import
Expand Down
2 changes: 1 addition & 1 deletion boututils/ask.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def query_yes_no(question, default="yes"):
Answers are case-insensitive.
Probably originally from http://code.activestate.com/recipes/577058/
Probably originally from https://code.activestate.com/recipes/577058/
via https://stackoverflow.com/a/3041990/2043465
Parameters
Expand Down
24 changes: 12 additions & 12 deletions boututils/contour.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
Contour calculation routines
http://members.bellatlantic.net/~vze2vrva/thesis.html
https://members.bellatlantic.net/~vze2vrva/thesis.html
"""
from __future__ import print_function
Expand All @@ -18,21 +18,21 @@ def contour(f, level):
print("Contour only works on 2D data")
return None
nx,ny = f.shape

# Go through each cell edge and mark which ones contain
# a level crossing. Approximating function as
# f = axy + bx + cy + d
# f = axy + bx + cy + d
# Hence linear interpolation along edges.

edgecross = {} # Dictionary: (cell number, edge number) to crossing location

for i in np.arange(nx-1):
for j in np.arange(ny-1):
# Lower-left corner of cell is (i,j)
if (np.max(f[i:(i+2),j:(j+2)]) < level) or (np.min(f[i:(i+2),j:(j+2)]) > level):
# not in the correct range - skip
continue

# Check each edge
ncross = 0
def location(a, b):
Expand All @@ -43,19 +43,19 @@ def location(a, b):
return old_div((level - a), (b - a))
else:
return None

loc = [
location(f[i,j], f[i+1,j]),
location(f[i+1,j], f[i+1,j+1]),
location(f[i+1,j+1], f[i,j+1]),
location(f[i,j+1], f[i,j])]

if ncross != 0: # Only put into dictionary if has a crossing
cellnr = (ny-1)*i + j # The cell number
edgecross[cellnr] = [loc,ncross] # Tack ncross onto the end

# Process crossings into contour lines

while True:
# Start from an arbitrary location and follow until
# it goes out of the domain or closes
Expand All @@ -64,12 +64,12 @@ def location(a, b):
except KeyError:
# No keys left so finished
break

def follow():
return

# Follow
# Follow

return

def find_opoints(var2d):
Expand Down
70 changes: 35 additions & 35 deletions boututils/crosslines.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
from past.utils import old_div
import numpy as np
from numpy.lib.stride_tricks import as_strided
import itertools
import itertools

def unique(a, atol=1e-08):
"""Find unique rows in 2d array
Parameters
----------
a : 2d ndarray, float
array to find unique rows in
array to find unique rows in
atol : float, optional
tolerance to check uniqueness
Expand All @@ -22,90 +22,90 @@ def unique(a, atol=1e-08):
Notes
-----
Adapted to include tolerance from code at http://stackoverflow.com/questions/8560440/removing-duplicate-columns-and-rows-from-a-numpy-2d-array#answer-8564438
Adapted to include tolerance from code at https://stackoverflow.com/questions/8560440/removing-duplicate-columns-and-rows-from-a-numpy-2d-array#answer-8564438
"""

if np.issubdtype(a.dtype, float):
if np.issubdtype(a.dtype, float):
order = np.lexsort(a.T)
a = a[order]
diff = np.diff(a, axis=0)
np.abs(diff,out = diff)
ui = np.ones(len(a), 'bool')
ui[1:] = (diff > atol).any(axis=1)
ui[1:] = (diff > atol).any(axis=1)
return a[ui]
else:
order = np.lexsort(a.T)
a = a[order]
diff = np.diff(a, axis=0)
diff = np.diff(a, axis=0)
ui = np.ones(len(a), 'bool')
ui[1:] = (diff != 0).any(axis=1)
ui[1:] = (diff != 0).any(axis=1)
return a[ui]

def linelineintersect(a, b, atol=1e-08):
"""Find all intersection points of two lines defined by series of x,y pairs
Intersection points are unordered
Colinear lines that overlap intersect at any end points that fall within the overlap
Colinear lines that overlap intersect at any end points that fall within the overlap
Parameters
----------
a, b : ndarray
2 column ndarray of x,y values defining a two dimensional line. 1st
column is x values, 2nd column is x values.
2 column ndarray of x,y values defining a two dimensional line. 1st
column is x values, 2nd column is x values.
Notes
-----
An example of 3 segment line is: a = numpy.array([[0,0],[5.0,3.0],[4.0,1]])
Function faster when there are no overlapping line segments
add some lines for preventing zero-division
"""
add some lines for preventing zero-division
"""

def x_y_from_line(line):
"""1st and 2nd column of array"""
return (line[:, 0],line[:, 1])
def meshgrid_as_strided(x, y, mask=None):
"""numpy.meshgrid without copying data (using as_strided)"""
if mask is None:
"""numpy.meshgrid without copying data (using as_strided)"""
if mask is None:
return (as_strided(x, strides=(0, x.strides[0]), shape=(y.size, x.size)),
as_strided(y, strides=(y.strides[0],0), shape=(y.size, x.size)))
else:
as_strided(y, strides=(y.strides[0],0), shape=(y.size, x.size)))
else:
return (np.ma.array(as_strided(x, strides=(0, x.strides[0]), shape=(y.size, x.size)), mask=mask),
np.ma.array(as_strided(y, strides=(y.strides[0],0), shape=(y.size, x.size)), mask=mask))

#In the following the indices i, j represents the pairing of the ith segment of b and the jth segment of a
#e.g. if ignore[i,j]==True then the ith segment of b and the jth segment of a cannot intersect
ignore = np.zeros([b.shape[0]-1, a.shape[0]-1], dtype=bool)
ignore = np.zeros([b.shape[0]-1, a.shape[0]-1], dtype=bool)

x11, x21 = meshgrid_as_strided(a[:-1, 0], b[:-1, 0], mask=ignore)
x12, x22 = meshgrid_as_strided(a[1: , 0], b[1: , 0], mask=ignore)
y11, y21 = meshgrid_as_strided(a[:-1, 1], b[:-1, 1], mask=ignore)
y12, y22 = meshgrid_as_strided(a[1: , 1], b[1: , 1], mask=ignore)
y12, y22 = meshgrid_as_strided(a[1: , 1], b[1: , 1], mask=ignore)

#ignore segements with non-overlappiong bounding boxes
ignore[np.ma.maximum(x11, x12) < np.ma.minimum(x21, x22)] = True
ignore[np.ma.minimum(x11, x12) > np.ma.maximum(x21, x22)] = True
ignore[np.ma.maximum(y11, y12) < np.ma.minimum(y21, y22)] = True
ignore[np.ma.minimum(y11, y12) > np.ma.maximum(y21, y22)] = True

#find intersection of segments, ignoring impossible line segment pairs when new info becomes available
denom_ = np.empty(ignore.shape, dtype=float)
#find intersection of segments, ignoring impossible line segment pairs when new info becomes available
denom_ = np.empty(ignore.shape, dtype=float)
denom = np.ma.array(denom_, mask=ignore)
denom_[:, :] = ((y22 - y21) * (x12 - x11)) - ((x22 - x21) * (y12 - y11))
denom_[:, :] = ((y22 - y21) * (x12 - x11)) - ((x22 - x21) * (y12 - y11))
#denom_tmp = ((y22 - y21) * (x12 - x11)) - ((x22 - x21) * (y12 - y11)) # H.SETO
denom_[:, :] = np.where(denom_ == 0.0, 1.e-100,denom_)

ua_ = np.empty(ignore.shape, dtype=float)
ua_ = np.empty(ignore.shape, dtype=float)
ua = np.ma.array(ua_, mask=ignore)
ua_[:, :] = (((x22 - x21) * (y11 - y21)) - ((y22 - y21) * (x11 - x21)))
ua_[:, :] /= denom

ignore[ua < 0] = True
ignore[ua > 1] = True

ub_ = np.empty(ignore.shape, dtype=float)
ub_ = np.empty(ignore.shape, dtype=float)
ub = np.ma.array(ub_, mask=ignore)
ub_[:, :] = (((x12 - x11) * (y11 - y21)) - ((y12 - y11) * (x11 - x21)))
ub_[:, :] /= denom
Expand All @@ -115,33 +115,33 @@ def meshgrid_as_strided(x, y, mask=None):
ignore[ub > 1] = True

nans_ = np.zeros(ignore.shape, dtype = bool)
nans = np.ma.array(nans_, mask = ignore)
nans_[:,:] = np.isnan(ua)
nans = np.ma.array(nans_, mask = ignore)
nans_[:,:] = np.isnan(ua)

if not np.ma.any(nans):

#remove duplicate cases where intersection happens on an endpoint
# ignore[np.ma.where((ua[:, :-1] == 1) & (ua[:, 1:] == 0))] = True
# ignore[np.ma.where((ub[:-1, :] == 1) & (ub[1:, :] == 0))] = True
# ignore[np.ma.where((ub[:-1, :] == 1) & (ub[1:, :] == 0))] = True
ignore[np.ma.where((ua[:, :-1] < 1.0 + atol) & (ua[:, :-1] > 1.0 - atol) & (ua[:, 1:] < atol) & (ua[:, 1:] > -atol))] = True
ignore[np.ma.where((ub[:-1, :] < 1 + atol) & (ub[:-1, :] > 1 - atol) & (ub[1:, :] < atol) & (ub[1:, :] > -atol))] = True
ignore[np.ma.where((ub[:-1, :] < 1 + atol) & (ub[:-1, :] > 1 - atol) & (ub[1:, :] < atol) & (ub[1:, :] > -atol))] = True

xi = x11 + ua * (x12 - x11)
yi = y11 + ua * (y12 - y11)
return np.ma.compressed(xi), np.ma.compressed(yi)
else:
n_nans = np.ma.sum(nans)
n_nans = np.ma.sum(nans)
n_standard = np.ma.count(x11) - n_nans
#I initially tried using a set to get unique points but had problems with floating point equality

#create n by 2 array to hold all possible intersection points, check later for uniqueness
points = np.empty([n_standard + 2 * n_nans, 2], dtype = float) #each colinear segment pair has two intersections, hence the extra n_colinear points
points = np.empty([n_standard + 2 * n_nans, 2], dtype = float) #each colinear segment pair has two intersections, hence the extra n_colinear points

#add standard intersection points
xi = x11 + ua * (x12 - x11)
yi = y11 + ua * (y12 - y11)
yi = y11 + ua * (y12 - y11)
points[:n_standard,0] = np.ma.compressed(xi[~nans])
points[:n_standard,1] = np.ma.compressed(yi[~nans])
points[:n_standard,1] = np.ma.compressed(yi[~nans])
ignore[~nans]=True


Expand Down Expand Up @@ -180,18 +180,18 @@ def find_inter( contour1, contour2):
xi = np.array([])
yi = np.array([])

i=0
ncombos = (sum([len(x.get_paths()) for x in contour1.collections]) *
i=0
ncombos = (sum([len(x.get_paths()) for x in contour1.collections]) *
sum([len(x.get_paths()) for x in contour2.collections]))
for linecol1, linecol2 in itertools.product(contour1.collections, contour2.collections):
for path1, path2 in itertools.product(linecol1.get_paths(),linecol2.get_paths()):
i += 1
print('line combo %5d of %5d' % (i, ncombos))
print('line combo %5d of %5d' % (i, ncombos))
xinter, yinter = linelineintersect(path1.vertices, path2.vertices)

xi = np.append(xi, xinter)
yi = np.append(yi, yinter)

#plt.scatter(xi, yi, s=20)
#plt.scatter(xi, yi, s=20)
#plt.show()
return xi, yi
2 changes: 1 addition & 1 deletion boututils/datafile.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class DataFile(object):
def __init__(self, filename=None, write=False, create=False, format='NETCDF3_64BIT', **kwargs):
"""
NetCDF formats are described here: http://unidata.github.io/netcdf4-python/
NetCDF formats are described here: https://unidata.github.io/netcdf4-python/
- NETCDF3_CLASSIC Limited to 2.1Gb files
- NETCDF3_64BIT_OFFSET or NETCDF3_64BIT is an extension to allow larger file sizes
- NETCDF3_64BIT_DATA adds 64-bit integer data types and 64-bit dimension sizes
Expand Down
2 changes: 1 addition & 1 deletion boututils/geqdsk.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
See LICENSE file for conditions of use.
The official document describing g-eqdsk files:
http://fusion.gat.com/conferences/snowmass/working/mfe/physics/p3/equilibria/g_eqdsk_s.pdf
https://fusion.gat.com/conferences/snowmass/working/mfe/physics/p3/equilibria/g_eqdsk_s.pdf
"""

class Geqdsk(object):
Expand Down
Loading

0 comments on commit c2a3226

Please sign in to comment.