def run(dictArgs): """Function to call read, calc, and plot in sequence""" # set visual backend if dictArgs["interactive"] is False: plt.switch_backend("Agg") else: # plt.switch_backend("TkAgg") plt.switch_backend("qt5agg") # --- the main show --- ( x, y, yq, basin_code, atlantic_arctic_mask, indo_pacific_mask, advective, diffusive, ) = read(dictArgs) trans_global = compute(advective, diffusive) trans_atlantic = compute(advective, diffusive, vmask=atlantic_arctic_mask) trans_pacific = compute(advective, diffusive, vmask=indo_pacific_mask) fig = plot(dictArgs, yq, trans_global, trans_atlantic, trans_pacific) filename = f"{dictArgs['outdir']}/heat_transport" imgbufs = image_handler([fig], dictArgs, filename=filename) return imgbufs
def run(dictArgs): """Function to call read, calc, and plot in sequence Parameters ---------- dictArgs : dict Dictionary of parsed options Returns ------- io.BytesIO In-memory image buffer """ # set visual backend if dictArgs["interactive"] is False: plt.switch_backend("Agg") # read in data array, areacello, reference = read(dictArgs) # calculate otsfn results = calculate(array, areacello, reference=reference) # make the plots fig = plot(results, dictArgs["label"]) filename = [f"{dictArgs['outdir']}/enso_{x['label']}" for x in regions] imgbufs = image_handler(fig, dictArgs, filename=filename) return imgbufs
def run(dictArgs): """Function to call read, calc, and plot in sequence Parameters ---------- dictArgs : dict Dictionary of parsed options Returns ------- io.BytesIO In-memory image buffer """ # set visual backend if dictArgs["interactive"] is False: plt.switch_backend("Agg") # read in data dset, dset_static = read(dictArgs) # calculate arr = calculate(dset, dset_static) # make the plots fig = plot(arr, dictArgs["label"]) filename = f"{dictArgs['outdir']}/template" imgbufs = image_handler([fig], dictArgs, filename=filename) return imgbufs
def run(dictArgs): """Function to call read, calc, and plot in sequence""" # set visual backend if dictArgs["interactive"] is False: plt.switch_backend("Agg") else: plt.switch_backend("TkAgg") # --- the main show --- dset_transport = read(dictArgs["infile"]) transport = calculate(dset_transport) dictArgs["obsrange"] = (tuple([ float(x) for x in dictArgs["obsrange"].split(",") ]) if dictArgs["obsrange"] is not None else None) fig = plot( transport, label=dictArgs["label"], passage_label=dictArgs["passage_label"], obsrange=dictArgs["obsrange"], ) # --------------------- # construct output filename based on "passage_label" argument, if present filename = dictArgs["outfile"] filename = filename.replace(" ", "_") filename = f"{dictArgs['outdir']}/{filename}" imgbufs = image_handler([fig], dictArgs, filename=filename) return imgbufs
def run(dictArgs): """Function to call read, calc, and plot in sequence""" # set visual backend if dictArgs["interactive"] is False: plt.switch_backend("Agg") else: plt.switch_backend("TkAgg") # --- the main show --- assert len(dictArgs["ppdir"] ) == 1, "Only one path may be provided to this routine" ppdir = dictArgs["ppdir"][0] # read in the data passages = [ Passage(dictArgs["label"], ppdir, *x) for x in defined_passages ] # calculate the transports for each of the passages passages = [x.calculate() for x in passages] # create a unifying xarray.Dataset object ds_out = xr.Dataset() for x in passages: if x.transport is not None: outvarname = x.passage_label.replace(" ", "_").replace("-", "_") ds_out[outvarname] = x.transport # save timeseries to netcdf format if requested outfile = ds_out.to_netcdf() if dictArgs["netcdf"] is not None: with open(f"{dictArgs['outdir']}/{dictArgs['netcdf']}", "wb") as fhandle: fhandle.write(outfile) # loop over passages and call their plot method figs = [ passage.plot() for passage in passages if passage.transport is not None ] # get a list of output filenames filenames = [ passage.passage_label for passage in passages if passage.transport is not None ] # --------------------- filenames = [x.replace(" ", "_") for x in filenames] filenames = [f"{dictArgs['outdir']}/{x}" for x in filenames] imgbufs = image_handler(figs, dictArgs, filename=filenames) return (imgbufs, outfile)
def run(dictArgs): """main can be called from either command line and then use parser from run() or DORA can build the args and run it directly""" # read the data needed for plots x, y, area, model, obs, dates = read(dictArgs) # make the plots figs = plot(x, y, area, model, obs, dates, dictArgs) filename = f"{dictArgs['outdir']}/{dictArgs['var']}_{dictArgs['style']}" imgbufs = image_handler(figs, dictArgs, filename=filename) return imgbufs
def run(dictArgs): """main can be called from either command line and then use parser from run() or DORA can build the args and run it directly""" # read the data needed for plots y, z, depth, area, code, model, obs, dates = read(dictArgs) if len(code.shape) == 2: code = np.tile(code[None, :, :], (len(z), 1, 1)) figs = [] filename = [] # global figs.append(plot(y, z, depth, area, model, obs, dates, dictArgs)[0]) filename.append( f"{dictArgs['outdir']}/{dictArgs['var']}_yz_gbl_{dictArgs['style']}") # atlantic figs.append( plot(y, z, depth, area, model, obs, dates, dictArgs, code=code, basin="atlantic")[0]) filename.append( f"{dictArgs['outdir']}/{dictArgs['var']}_yz_atl_{dictArgs['style']}") # indopacific figs.append( plot(y, z, depth, area, model, obs, dates, dictArgs, code=code, basin="indopac")[0]) filename.append( f"{dictArgs['outdir']}/{dictArgs['var']}_yz_pac_{dictArgs['style']}") imgbufs = image_handler(figs, dictArgs, filename=filename) return imgbufs
def run(dictArgs): """Function to call read, calc, and plot in sequence""" ## parameters # interactive = args.interactive # outdir = args.outdir # pltfmt = args.format # infile = args.infile # static = args.static # month = args.month # obsfile = args.obsfile # region = args.region # label = args.label # set visual backend if dictArgs["interactive"] is False: plt.switch_backend("Agg") else: # plt.switch_backend("TkAgg") plt.switch_backend("qt5agg") # --- the main show --- ds, dobs, valid_mask = read(dictArgs) current_dir = os.getcwd() tmpdir = tempfile.mkdtemp() os.chdir(tmpdir) model, obs = calculate(ds, dobs, region=dictArgs["region"]) os.chdir(current_dir) shutil.rmtree(tmpdir) fig = plot( model, obs, valid_mask, label=dictArgs["label"], region=dictArgs["region"], month=dictArgs["month"], ) # --------------------- filename = f"{dictArgs['outdir']}/seaice.{dictArgs['region']}" imgbufs = image_handler([fig], dictArgs, filename=filename) return imgbufs
def run(dictArgs): # set visual backend if dictArgs["interactive"] is False: plt.switch_backend("Agg") darray = read(dictArgs) darray_ts = calculate(darray) figs = plot(darray_ts) figs = [figs] if not isinstance(figs, list) else figs assert isinstance(figs, list), "Figures must be inside a list object" filenames = [ f"{dictArgs['outdir']}/Volume_Transport_Drake", ] imgbufs = image_handler(figs, dictArgs, filename=filenames) return imgbufs
def run(dictArgs): """Function to call read, calc, and plot in sequence""" # set visual backend if dictArgs["interactive"] is False: plt.switch_backend("Agg") # --- the main show --- (ds, bins, group_tend) = read(dictArgs) G = calculate(ds, bins, group_tend) fig = plot(G) filename = f"{dictArgs['outdir']}/surface_wmt" imgbufs = image_handler([fig], dictArgs, filename=filename) return imgbufs
def run(dictArgs): # set visual backend if dictArgs["interactive"] is False: plt.switch_backend("Agg") ds_model, ds_ref_tau, ds_static = read(dictArgs) results = calculate(ds_model, ds_ref_tau, ds_static, dictArgs) figs = plot(dictArgs, results) figs = [figs] if not isinstance(figs, list) else figs assert isinstance(figs, list), "Figures must be inside a list object" filenames = [ f"{dictArgs['outdir']}/surface_stress_curl", ] imgbufs = image_handler(figs, dictArgs, filename=filenames) return imgbufs
def run(dictArgs): """Function to call read, calc, and plot in sequence""" # set visual backend if dictArgs["interactive"] is False: plt.switch_backend("Agg") else: # plt.switch_backend("TkAgg") plt.switch_backend("qt5agg") # --- the main show --- ds = xr.open_mfdataset(dictArgs["infile"], combine="by_coords") if "msftyyz" in list(ds.variables): varname = "msftyyz" elif "vmo" in list(ds.variables): varname = "vmo" ds.close() x, y, yh, z, depth, basin_code, atlantic_arctic_mask, indo_pacific_mask, arr = read( dictArgs, varname=varname ) if varname != "msftyyz": msftyyz = calculate(arr, basin_code) else: msftyyz = arr fig = plot( y, yh, z, depth, atlantic_arctic_mask, indo_pacific_mask, msftyyz, dictArgs["label"], ) # --------------------- filename = f"{dictArgs['outdir']}/moc" imgbufs = image_handler([fig], dictArgs, filename=filename) return imgbufs
def run(dictArgs): """Function to call read, calc, and plot in sequence""" # set visual backend if dictArgs["interactive"] is False: plt.switch_backend("Agg") else: plt.switch_backend("TkAgg") # --- the main show --- assert len(dictArgs["ppdir"] ) == 1, "Only one path may be provided to this routine" ppdir = dictArgs["ppdir"][0] # read in the data passages = [ Passage(dictArgs["label"], ppdir, *x) for x in defined_passages ] # calculate the transports for each of the passages passages = [x.calculate() for x in passages] # loop over passages and call their plot method figs = [ passage.plot() for passage in passages if passage.transport is not None ] # get a list of output filenames filenames = [ passage.passage_label for passage in passages if passage.transport is not None ] # --------------------- filenames = [x.replace(" ", "_") for x in filenames] filenames = [f"{dictArgs['outdir']}/{x}" for x in filenames] imgbufs = image_handler(figs, dictArgs, filename=filenames) return imgbufs
def run(dictArgs): """Function to call read, calc, and plot in sequence Parameters ---------- dictArgs : dict Dictionary of parsed options Returns ------- io.BytesIO In-memory image buffer """ # set visual backend if dictArgs["interactive"] is False: plt.switch_backend("Agg") # read in data dset = read(dictArgs) # calculate arr = calculate(dset, dictArgs["varname"]) # make the plots fig = plot( arr, label=dictArgs["label"], vardesc=dictArgs["description"], rangemax=dictArgs["range"], interval=dictArgs["interval"], ) filename = f"{dictArgs['outdir']}/drift_{dictArgs['varname']}" imgbufs = image_handler([fig], dictArgs, filename=filename) return imgbufs
def run(dictArgs): """Function to call read, calc, and plot in sequence Parameters ---------- dictArgs : dict Dictionary of parsed options Returns ------- io.BytesIO In-memory image buffer """ # set visual backend if dictArgs["interactive"] is False: plt.switch_backend("Agg") # read in data model, woa, argo_dset = read(dictArgs) # calculate max_comparison_results, dtdz_model, dtdz_argo = calculate(model, woa, argo_dset) # make the plots figs = plot(max_comparison_results, dtdz_model, dtdz_argo) filename = [ f"{dictArgs['outdir']}/thermocline_strength", f"{dictArgs['outdir']}/thermocline_depth", f"{dictArgs['outdir']}/argo_comparison_atlantic", f"{dictArgs['outdir']}/argo_comparison_pacific", ] imgbufs = image_handler(figs, dictArgs, filename=filename) return imgbufs