def uvlines(uvvals, uv='uv', uvbounds=dict(), sty={}, c=0., eps=1e-24, inf=100., npoints=1001): """ Produce lines of constant radius for r in rvals. Return list of curves. """ crvlist = [] for val in uvvals: ## create new curve ucrv = curve() vcrv = curve() ## adjust uvbounds uvb = dict(vmin=np.nan, vmax=np.nan, umin=np.nan, umax=np.nan) uvb.update(uvbounds) for key in ['vmin', 'umin']: if not np.isfinite(uvb[key]): uvb[key] = -1. * inf for key in ['vmax', 'umax']: if not np.isfinite(uvb[key]): uvb[key] = 1. * inf ## readable params umin, umax, vmin, vmax = uvb['umin'], uvb['umax'], uvb['vmin'], uvb[ 'vmax'] ## push inward just a bit to avoid mask umin, umax = umin + 1. * eps, umax - 1. * eps, vmin, vmax = vmin + 1. * eps, vmax - 1. * eps ## define linearly spaced array sa1 = np.linspace(umin, umax, npoints) sa2 = np.linspace(vmin, vmax, npoints) sb = val - 2. * c + eps * np.array([-1., 0., 1.]) sc = val + 2. * c + eps * np.array([-1., 0., 1.]) s = np.sort(np.concatenate([sa1, sa2, sb, sc])) ## ucrv is line of const, vcrv is line of const v ucrv.uv = np.array([val + 0. * s, 1. * s]) vcrv.uv = np.array([1. * s, val + 0. * s]) ## update curve style from default style = dict(zorder=200) style.update(sty) ucrv.sty.update(style) vcrv.sty.update(style) ## add crvs to output list if 'u' in uv: crvlist += [ucrv] if 'v' in uv: crvlist += [vcrv] ## return return crvlist
def rstarlines_special_2(vals, uvbounds, c=None, sty={}, inf=100., npoints=1000, eps=1e-12): """ Produce lines of constant rstar for rstar in vals. Return list of curves. (v-u)/2 = rstar - c """ ## initialize crvlist = [] uvb = uvbounds.copy() cc = 1. * float(c) ## go for val in vals: ## create new curve crv = curve() ## adjust uvbounds for key in ['vmin', 'umin']: if not np.isfinite(uvb[key]): uvb[key] = -1. * inf for key in ['vmax', 'umax']: if not np.isfinite(uvb[key]): uvb[key] = 1. * inf ## readable params umin, umax, vmin, vmax = uvb['umin'], uvb['umax'], uvb['vmin'], uvb[ 'vmax'] ## push inward just a bit to avoid mask umin, umax = umin + 1. * eps, umax - 1. * eps, vmin, vmax = vmin + 1. * eps, vmax - 1. * eps ## curve a ua = np.linspace(umin, umax, npoints) va = ua + 2. * (val - 1. * cc) ## curve b vb = np.linspace(vmin, vmax, npoints) ub = vb - 2. * (val - 1. * cc) ## combine uu = np.concatenate([ua, ub]) vv = np.concatenate([va, vb]) ## sort idx = np.argsort(uu) uu = uu[idx] vv = vv[idx] ## add coords to curve crv.uv = np.array([uu, vv]) ## update curve style from default style = dict(zorder=600) style.update(sty) crv.sty.update(style) ## add crv to output list crvlist += [crv] ## return return crvlist
def test3(): """ Demonstrate the functionality of mask_split_curve(crv, mask). """ ## create input curve crv = curve() ## input curve coordinates s = np.linspace(-5, 3, 1001) crv.r = s**2 crv.tr = np.array([s, s**2]) crv.uv = np.array([s, s]) crv.uvdl = np.array([s**3, s**2]) ## define mask mask = np.logical_or( np.sin(5. * crv.uv[0]**2) > .5, np.abs(crv.uv[1]) > 3.5) ## run out = mask_split_curve(crv, mask) # plot for s in ['tr', 'uv', 'uvdl', 'UV']: x = crv.__dict__[s] ## plot unmasked plt.plot(x[0], x[1], 'b-', lw=15, label='unmasked') ## plot naive numpy mask application if len(x[0]) > 0: plt.plot(x[0][mask], x[1][mask], 'y-', lw=10, label='naive numpy mask') ## plot valid subcurves label = 'split mask with mask_split_curve' for i in range(len(out)): x = out[i].__dict__[s] plt.plot(x[0], x[1], 'r-', lw=5, label=label) label = None plt.title(s) plt.legend(loc='lower left', fontsize=10) plt.show()
def rlines(rvals, sty={}, inf=50., t0=0., npoints=1000): """ Produce lines of constant radius for r in rvals. Return list of curves. """ ## default style style = dict(zorder=600) ## go crvlist = [] for rval in rvals: ## create new curve crv = curve() ## define t and r arrays t = t0 + np.linspace(-inf, inf, 2. * npoints + 1) r = rval + 0. * t ## add coords to curve crv.tr = np.array([t, r]) ## set style style.update(sty) crv.sty.update(style) ## add crv to output list crvlist += [crv] ## return return crvlist
def mask_split_curve(crv, mask): """ """ ## prep output list out = [] ## get unmasked array values r, tr, uv, uvdl, UV = crv.r, crv.tr, crv.uv, crv.uvdl, crv.UV ## create list of masked array values r = mask_split_array(r, mask) tr = mask_split_2darray(tr, mask) uv = mask_split_2darray(uv, mask) uvdl = mask_split_2darray(uvdl, mask) UV = mask_split_2darray(UV, mask) ## for each valid subcurve create new curve and fill values Nsubs = len(r) for i in range(Nsubs): newcrv = curve() newcrv.sty = crv.sty newcrv.r, newcrv.tr, newcrv.uv, newcrv.uvdl, newcrv.UV = r[i], tr[ i], uv[i], uvdl[i], UV[i] out += [newcrv] ## return return out
def rstarlines(vals, c=None, sty={}, inf=50., npoints=1000): """ Produce lines of constant rstar for rstar in vals. Return list of curves. """ crvlist = [] for val in vals: ## create new curve crv = curve() ## define t array t = np.linspace(-inf, inf, 2. * npoints + 1) ## define u and v arrays c = float(c) u = t - val + c v = t + val - c ## add coords to curve crv.uv = np.array([u, v]) ## update curve style from default style = dict(zorder=600) style.update(sty) crv.sty.update(style) ## add crv to output list crvlist += [crv] ## return return crvlist
def rstarlines_special_1(vals, c=None, s0=None, ki=None, A=1e4, sty={}, inf=100., npoints1=1001, npoints2=1001, npoints3=1001): """ Produce lines of constant rstar for rstar in vals. Return list of curves. These are specially supplemented to give many data points immediately after s0 for zoom views. """ crvlist = [] for val in vals: ## initialize params c = float(c) ## create new curve crv = curve() ## initialize u and v lists ulist = [] vlist = [] ## small values ss = np.linspace(-1.02 * s0, 1.02 * s0, npoints1) for x in [2. * ss]: ## u values ulist += [x] vlist += [x + 2. * (val - c)] ## v values vlist += [-x] ulist += [-x - 2. * (val - c)] ## large values ss = np.linspace(s0, inf, npoints3) for x in [2. * ss, -2. * ss]: ## u values ulist += [x] vlist += [x + 2. * (val - c)] ## v values vlist += [-x] ulist += [-x - 2. * (val - c)] ## prep intermediate values e = np.sign(ki) ds = ki**(-1) * np.log(1. + e * ki * A) np2 = [int(np.abs(e[i])) * npoints2 for i in range(len(ki))] ss = [ np.linspace(e[i] * s0, e[i] * s0 + ds[i], np2[i]) for i in range(len(ki)) ] ## intermediate values for x in [2. * ss[0], 2. * ss[1]]: ## u values ulist += [x] vlist += [x + 2. * (val - c)] ## v values vlist += [-x] ulist += [-x - 2. * (val - c)] ## concatenate to form output u = np.concatenate(ulist) v = np.concatenate(vlist) ## sort mask = np.argsort(u) u = u[mask] v = v[mask] ## add coords to curve crv.uv = np.array([u, v]) ## update curve style from default style = dict(zorder=600) style.update(sty) crv.sty.update(style) ## add crv to output list crvlist += [crv] ## return return crvlist