def build(self, _UPLOAD_RESOURCES, _LOCAL_ONLY): _DEV = self._DEV if not _LOCAL_ONLY: input(f'make sure to change version ( {self.changelist.abspath} )') input(f'make sure to test all supported oss and browsers') self.pre_build() self.setup_databases_and_apis() html = self.html_body_children() if not isitr(html): html = [html] htmlDoc = HTMLPage( 'index', self.EXP_API.apiElements(), JScript(JS(compile_coffeescript(self.EXP_API.cs()), onload=False)), JScript(JS(self.EXP_FOLDER[f'{self.EXP_FOLDER.name}.coffee'])), *html, arg_tags(VERSION=self.THIS_VERSION[0], RESOURCES_ROOT=self.RESOURCES_ROOT.wcurl, RESOURCES_ROOT_REL=self.RESOURCES_ROOT.rel_to(self.ROOT), IS_DEV=_DEV), style=self.css()) write_index_webpage(htmlDoc=htmlDoc, root=self.ROOT, resource_root_file=self.RESOURCES_ROOT, upload_resources=_UPLOAD_RESOURCES, WOLFRAM=not _LOCAL_ONLY, DEV=_DEV)
def fix_index(i): if isinstance(i, slice): pass elif isitr(i): i = tuple([int(a) for a in i]) else: i = int(i) return i
def ContainsAny(e1, e2): if not isitr(e2): return e2 in e1 r = False for e in e2: if e in e1: r = True return r
def concat(*args, axis=0): if len(args) == 0: return arr(ndims=axis + 1) args = list(args) for idx, aa in enumerate(args): if not isitr(aa): args[idx] = arr([aa]) return arr(np.concatenate(tuple(args), axis=axis))
def flatten(v): r = [] for vv in v: if isitr(vv): for vvv in vv: r.append(vvv) else: r.append(vv) return arr(r)
def vert(a, row): if len(a) == 0 or numel(a) == 0: if isitr(row): row = make2d(row) else: row = arr(row) row.shape = (1, 1) return row else: return np.vstack((a, row))
def lay(a, new_layer): if len(a) == 0 or numel(a) == 0: if isitr(new_layer): new_layer = make3d(new_layer) else: new_layer = arr(new_layer) new_layer.shape = (1, 1, 1) return new_layer else: return np.concatenate((a, new_layer), axis=2)
def makefig( subplots, file=None, show=False, width=6, height=8 ): assert subplots is not None if not isitr(subplots): subplots = [[subplots]] subplots = arr(subplots, ndims=2) from matplotlib import rcParams rcParams['figure.figsize'] = width, height rcParams["savefig.dpi"] = 200 with plt.style.context('dark_background'): # if len(subplots.shape) != 2: if len(subplots.shape) == 1: ncol = 1 else: ncol = subplots.shape[1] nrow = subplots.shape[0] subplots = make2d(subplots) fig, axs = plt.subplots(ncols=ncol, nrows=nrow, squeeze=False) if len(axs.shape) == 1: # noinspection PyUnresolvedReferences axs.shape = (axs.shape[0], 1) for r, row in enumerate(subplots): for c, fd in enumerate(row): if isinstance(fd, MultiPlot): [d.show(axs[r, c]) for d in fd] else: fd.show(axs[r, c]) fig.tight_layout(pad=3.0) if file is None: plt.show() else: File(file).mkparents() plt.savefig(file) plt.clf() if show: showInPreview(imageFile=File(file).abspath) return File(file)
def jsonReprCP(o): import numpy as np # log('jsonReprCP of a ' + str(type(o))) if isinstsafe(o, np.ndarray): o = o.tolist() if not isitr(o) and isnan(o): return None if o == np.inf or o == -np.inf: return str(o) if isinstance(o, str) or isinstance(o, float) or isinstance( o, int) or o is None: return o if isinstance(o, np.int64): return int(o) if isinstance(o, np.float32): return float(o) if isitr(o) and not isinstance(o, str): cp = [] for vv in o: cp.append(jsonReprCP(vv)) return cp import copy cp = copy.deepcopy(o) # debug_on = False if hasattr(o, 'item_type') and o.item_type == 'violin': debug_on = True # import mdb; mdb.remote_breakpoint() for v in cp.__dict__: debug(f'V:{v}') # if debug_on: # breakpoint() val = getattr(cp, v) if isitr(val) and not isinstance(val, str): if isinstance(val, np.ndarray): setattr(cp, v, jsonReprCP(val.tolist())) else: newval = [] for vv in val: newval.append(jsonReprCP(vv)) setattr(cp, v, newval) if not isitr(val) and (val == np.inf or val == -np.inf): setattr(cp, v, str(val)) if isinstance(val, np.int64): setattr(cp, v, int(val)) import pandas if not isitr(val) and pandas.isnull(val): setattr(cp, v, None) if isinstance(val, JsonSerializable): setattr(cp, v, jsonReprCP(val).__dict__) if isitr(val) and not isempty(val) and isinstance( val[0], JsonSerializable): newval = [] for i in itr(val): newval.append(jsonReprCP(val[i]).__dict__) setattr(cp, v, newval) # if debug_on: # breakpoint() # if hasattr(o, 'item_type') and o.item_type == 'violin': # breakpoint() # import mdb; mdb.remote_breakpoint() return cp
def get_first_e(the_li): while isitr(the_li) and not isinstance(the_li, str): the_li = the_li[0] return the_li