def setup_rfdir(self, path, num_procs): """ Creates the directory path and copies required files from ``self.base_dir`` into path:type path: string :param path: folder_name :param num_procs: number of processors per :program:`ADCIRC` run """ mkdir(path) copy(self.save_dir+'/fort.13', path) # crete sybolic links from fort.* files to path inputs1 = glob.glob(self.grid_dir+'/fort.1*') inputs2 = glob.glob(self.grid_dir+'/fort.2*') inputs0 = glob.glob(self.grid_dir+'/fort.01*') inputs = inputs0 + inputs1 + inputs2 if self.grid_dir+'/fort.13' in inputs: inputs.remove(self.grid_dir+'/fort.13') if not self.grid_dir+'/fort.019' in inputs: if self.grid_dir+'/fort.015' in inputs: inputs.remove(self.grid_dir+'/fort.015') for fid in inputs: if os.path.exists(path+'/'+fid.rpartition('/')[-1]): os.remove(path+'/'+fid.rpartition('/')[-1]) os.symlink(fid, path+'/'+fid.rpartition('/')[-1]) #copy(fid, path+'/'+fid.rpartition('/')[-1]) if not os.path.exists(path+'/adcprep'): os.symlink(self.base_dir+'/adcprep', path+'/adcprep') prep.write_1(path, num_procs) prep.write_2(path, num_procs) prep.write_5(path, num_procs)
def make_plots(self, points, domain, save=True, show=False, bathymetry=False): """ Plots ``mesh``, ``station_locations``, ``basis_functions``, ``random_fields``, ``mean_field``, ``station_data``, and save in save_dir/figs .. todo:: this uses bv_array everywhere. I might want to change this later when I go to the nested mesh approach """ mkdir(self.save_dir + '/figs') domain.get_Triangulation(self.save_dir, save, show) domain.plot_bathymetry(self.save_dir, save, show) domain.plot_station_locations(self.save_dir, bathymetry, save, show) bv_array = tmm.get_basis_vec_array(self.basis_dir) self.plot_basis_functions(domain, bv_array, save, show) self.plot_random_fields(domain, points, bv_array, save, show) self.plot_mean_field(domain, points, bv_array, save, show) self.plot_station_data(save, show)
def setup_rfdir(self, path, num_procs): """ Creates the directory path and copies required files from ``self.base_dir`` into path:type path: string :param path: folder_name :param num_procs: number of processors per :program:`ADCIRC` run """ mkdir(path) copy(self.save_dir + '/fort.13', path) # crete sybolic links from fort.* files to path inputs1 = glob.glob(self.grid_dir + '/fort.1*') inputs2 = glob.glob(self.grid_dir + '/fort.2*') inputs0 = glob.glob(self.grid_dir + '/fort.01*') inputs = inputs0 + inputs1 + inputs2 if self.grid_dir + '/fort.13' in inputs: inputs.remove(self.grid_dir + '/fort.13') if not self.grid_dir + '/fort.019' in inputs: if self.grid_dir + '/fort.015' in inputs: inputs.remove(self.grid_dir + '/fort.015') for fid in inputs: if os.path.exists(path + '/' + fid.rpartition('/')[-1]): os.remove(path + '/' + fid.rpartition('/')[-1]) os.symlink(fid, path + '/' + fid.rpartition('/')[-1]) #copy(fid, path+'/'+fid.rpartition('/')[-1]) if not os.path.exists(path + '/adcprep'): os.symlink(self.base_dir + '/adcprep', path + '/adcprep') prep.write_1(path, num_procs) prep.write_2(path, num_procs) prep.write_5(path, num_procs)
def get_Triangulation(domain, path=None, save=True, show=False, ics=1, ext='.png'): """ :param domain: :class:`~polyadcirc.run_framework.domain` :type path: string or None :param path: directory to store plots :type save: boolean :param save: flag for whether or not to save plots :type show: boolean :param show: flag for whether or not to show plots :param int ics: coordinate system (1 cartisian, 2 polar) :param string ext: file extesion :returns: :class:`matplotlib.tri.Triangulation` """ x = np.array([n.x for n in domain.node.itervalues()]) y = np.array([n.y for n in domain.node.itervalues()]) triangles = np.array([e-1 for e in domain.element.itervalues()]) triangulation = tri.Triangulation(x, y, triangles) plt.figure() if path == None: path = os.getcwd() if not os.path.exists(path+'/figs'): fm.mkdir(path+'/figs') if save or show: plt.triplot(triangulation, 'g-') plt.title('grid') plt.gca().set_aspect('equal') add_2d_axes_labels(ics) save_show(path+'/figs/grid', save, show, ext) domain.triangulation = triangulation return triangulation
def setup_landuse_folder(self, class_num, manningsn_value=1, folder_name=None): """ Set up a single landuse with name landuse_class_num :param int class_num: land classification number for this folder :param int manningsn_value: Manning's *n* value for this land classification :param string folder_name: folder name relative to ``self.base_dir`` :rtype: string :returns: file name of bash script for this land class """ if folder_name is None: folder_name = 'landuse_'+'{:=02d}'.format(class_num) print 'Setting up folder -- '+folder_name+'...' # create a folder for this land-use classification fm.mkdir(os.path.join(self.basis_dir, folder_name)) # cp self.file_name folder_name fm.copy(os.path.join(self.basis_dir, self.file_name), os.path.join(self.basis_dir, folder_name)) # create *.in files self.create_griddata_input_files(folder_name) # create *.sh files script_name = self.create_bash_script(folder_name) # create the *.table file needed for grid_all_data self.setup_tables_single_value(class_num, manningsn_value, os.path.join(self.basis_dir, folder_name)) return script_name
def make_plots(self, points, domain, save=True, show=False, bathymetry=False, ext='.eps', ics=2): """ Plots ``mesh``, ``station_locations``, ``basis_functions``, ``random_fields``, ``mean_field``, ``station_data``, and save in save_dir/figs """ mkdir(os.path.join(self.save_dir, 'figs')) domain.get_Triangulation(self.save_dir, save, show, ext, ics) domain.plot_bathymetry(self.save_dir, save, show, ext, ics) domain.plot_station_locations(self.save_dir, bathymetry, save, show, ext, ics) bv_dict = tmm.get_basis_vectors(self.basis_dir) self.plot_basis_functions(domain, tmm.get_basis_vec_array(self.basis_dir), save, show, ext, ics) self.plot_random_fields(domain, points, bv_dict, save, show, ext, ics) self.plot_mean_field(domain, points, bv_dict, save, show, ext, ics) self.plot_station_data(save, show, ext)
def nts_line_data(nts_data, keys=None, path=None, save=True, show=False, ext='.png'): """ Plot the non timeseries data in ``data`` with ``points`` as the x axis. To plot only a subset of this data list which ADCIRC Output types to plot in keys. .. note:: This only applies to 1D nts data (``irtype`` = 1) :type nts_data: :class:`dict` :param nts_data: ``nts_data`` from :class:`~polyadcirc.run_framework.random_manningsn.runSet` :param list keys: list of types of ADCIRC output data to plot :type path: string or None :param path: directory to store plots :type save: bool :param save: flag for whether or not to save plots :type show: bool :param show: flag for whether or not to show plots :param string ext: file extension """ if path is None: path = os.getcwd() if keys is None: keys = nts_data.keys() s_keys = list() for k in keys: if not (f15.filetype[k][0]) and f15.filetype[k][1] == 1: s_keys.append(k) keys = s_keys fm.mkdir(os.path.join(path, 'figs', 'nts')) for k in keys: fig = plt.figure() x = np.arange(nts_data[k].shape[0]) ax = fig.add_subplot(111) ax.set_xlim((np.min(x), np.max(x))) ax.set_ylim((np.min(nts_data[k]), np.max(nts_data[k]))) segs = list() for j in xrange(nts_data[k].shape[1]): segs.append(zip(x, nts_data[k][..., j])) line_segs = LineCollection(segs, linestyles='solid') line_segs.set_array(np.arange(nts_data[k].shape[1])) ax.add_collection(line_segs) colorbar(line_segs) fig.title(k) fig.xlabel('node number') save_show(os.path.join(path, 'figs', 'nts', k), save, show, ext)
def nts_line_data(nts_data, keys=None, path=None, save=True, show=False, ext='.png'): """ Plot the non timeseries data in ``data`` with ``points`` as the x axis. To plot only a subset of this data list which ADCIRC Output types to plot in keys. .. note:: This only applies to 1D nts data (``irtype`` = 1) :type nts_data: :class:`dict` :param nts_data: ``nts_data`` from :class:`~polyadcirc.run_framework.random_manningsn.runSet` :param list() keys: list of types of ADCIRC output data to plot :type path: string or None :param path: directory to store plots :type save: boolean :param save: flag for whether or not to save plots :type show: boolean :param show: flag for whether or not to show plots :param string ext: file extension """ if path == None: path = os.getcwd() if keys == None: keys = nts_data.keys() s_keys = list() for k in keys: if not(f15.filetype[k][0]) and f15.filetype[k][1] == 1: s_keys.append(k) keys = s_keys fm.mkdir(path+'/figs/nts') for k in keys: fig = plt.figure() x = np.arange(nts_data[k].shape[0]) ax = fig.add_subplot(111) ax.set_xlim((np.min(x),np.max(x))) ax.set_ylim((np.min(nts_data[k]),np.max(nts_data[k]))) segs = list() for j in xrange(nts_data[k].shape[1]): segs.append(zip(x, nts_data[k][...,j])) line_segs = LineCollection(segs, linestyles = 'solid') line_segs.set_array(np.arange(nts_data[k].shape[1])) ax.add_collection(line_segs) colorbar(line_segs, fig) fig.title(k) fig.xlabel('node number') save_show(path+'/figs/nts/'+k, save, show, ext)
def link_random_field_directories(self): """ Assumes that the pre-preped ``RF_directory`` is ``RF_directory_1``. In each of the ``RF_directory_*`` create the ``PE****`` folders copy over the ``fort.13`` and then link the ``fort.019``, ``fort.18``, ``fort.15``, fort.14`` into the ``PE****`` folder. Also link ``metis_graph.txt`` and ``partmesh.txt`` into the ``RF_directory``. :param int num_procs: number of processes per padcirc run """ # get a list of all RF_dirs rf_dirs = glob.glob(os.path.join(self.save_dir, 'RF_directory_*')) link_rf_files = ['metis_graph.txt', 'partmesh.txt'] # remove the first RF_dir from the list and save the name as a vairbale prime_rf_dir = os.path.join(self.save_dir, 'RF_directory_1') rf_dirs.remove(prime_rf_dir) # create lists of PE directories and files to link PE_dirs = glob.glob(os.path.join(prime_rf_dir, 'PE*')) link_inputs = ['fort.019', 'fort.18', 'fort.15', 'fort.14'] if not os.path.exists(os.path.join(prime_rf_dir, 'fort.019')): link_inputs.remove('fort.019') for rf_dir in rf_dirs: # link rf files for rf_file in link_rf_files: if os.path.exists(os.path.join(rf_dir, rf_file)): os.remove(os.path.join(rf_dir, rf_file)) os.symlink(os.path.join(prime_rf_dir, rf_file), os.path.join(rf_dir, rf_file)) for PE_dir in PE_dirs: # create the PE* directories my_PE_dir = os.path.join(rf_dir, os.path.basename(PE_dir)) if not os.path.exists(my_PE_dir): mkdir(my_PE_dir) # link files into the PE* directories for l_input in link_inputs: if os.path.exists(os.path.join(my_PE_dir, l_input)): os.remove(os.path.join(my_PE_dir, l_input)) os.symlink(os.path.join(PE_dir, l_input), os.path.join(my_PE_dir, l_input)) # copy fort.13 into the PE* directories if os.path.exists(os.path.join(my_PE_dir, 'fort.13')): os.remove(os.path.join(my_PE_dir, 'fort.13')) shutil.copy(os.path.join(PE_dir, 'fort.13'), os.path.join(my_PE_dir, 'fort.13'))
def __init__(self, path, node_num=0, element_num=0, node=None, element=None): """ Initialization """ super(subdomain, self).__init__(path, node_num, element_num, node, element) # figure out where the script dir for the ncsu subdomain code is for sys_path in sys.path: potential_file_list = glob.glob(os.path.join(sys_path, 'py')) if potential_file_list: self.script_dir = potential_file_list[0] break fm.mkdir(path) #: flag for shape of subdomain (0 ellipse, 1 circle) self.flag = None
def setup_rfdir(self, path, num_procs): """ Creates the directory path and copies required files from ``self.base_dir`` into :param string path: folder_name :param int num_procs: number of processors per :program:`ADCIRC` run """ mkdir(path) copy(os.path.join(self.save_dir, 'fort.13'), path) # crete sybolic links from fort.* files to path inputs1 = glob.glob(os.path.join(self.grid_dir, 'fort.1*')) inputs2 = glob.glob(os.path.join(self.grid_dir, 'fort.2*')) inputs0 = glob.glob(os.path.join(self.grid_dir, 'fort.01*')) inputs = inputs0 + inputs1 + inputs2 if os.path.join(self.grid_dir, 'fort.13') in inputs: inputs.remove(os.path.join(self.grid_dir, 'fort.13')) if not os.path.join(self.grid_dir, 'fort.019') in inputs: if os.path.join(self.grid_dir, 'fort.015') in inputs: inputs.remove(os.path.join(self.grid_dir, 'fort.015')) else: sub_files = ['bv.nodes', 'py.140', 'py.141'] sub_files = [os.path.join(self.grid_dir, sf) for sf in sub_files] inputs.extend(sub_files) for fid in inputs: rf_fid = os.path.join(path, fid.rpartition('/')[-1]) if os.path.exists(rf_fid): if os.path.islink(rf_fid): os.unlink(rf_fid) else: os.remove(rf_fid) os.symlink(fid, rf_fid) if not os.path.exists(os.path.join(path, 'padcirc')): os.symlink(os.path.join(self.base_dir, 'padcirc'), os.path.join(path, 'padcirc')) if not os.path.exists(os.path.join(path, 'adcprep')): os.symlink(os.path.join(self.base_dir, 'adcprep'), os.path.join(path, 'adcprep')) prep.write_1(path, num_procs) prep.write_2(path, num_procs) prep.write_5(path, num_procs)
def get_Triangulation(domain, path=None, save=True, show=False, ics=1, ext='.png', title=False): """ :param domain: :class:`~polyadcirc.run_framework.domain` :type path: string or None :param path: directory to store plots :type save: bool :param save: flag for whether or not to save plots :type show: bool :param show: flag for whether or not to show plots :param int ics: coordinate system (1 cartisian, 2 polar) :param string ext: file extesion :rtype: :class:`matplotlib.tri.Triangulation` :returns: triangulation of ``domain`` """ x = np.array([n.x for n in domain.node.itervalues()]) y = np.array([n.y for n in domain.node.itervalues()]) triangles = np.array([e - 1 for e in domain.element.itervalues()]) triangulation = tri.Triangulation(x, y, triangles) plt.figure() if path is None: path = os.getcwd() fig_folder = os.path.join(path, 'figs') if not os.path.exists(fig_folder): fm.mkdir(fig_folder) if save or show: plt.triplot(triangulation, 'g-') if title: plt.title('grid') plt.gca().set_aspect('equal') add_2d_axes_labels(ics=ics) save_show(os.path.join(fig_folder, 'grid'), save, show, ext) domain.triangulation = triangulation return triangulation
def setup_folder(self, folder_name = 'temp'): """ Set up a single folder with name folder_name :param string folder_name: folder name relative to ``self.base_dir`` :rtype: string :returns: file name of bash script for this land class """ print 'Setting up folder -- '+folder_name+'...' # create a folder for this land-use classification fm.mkdir(self.basis_dir+'/'+folder_name) # cp self.file_name folder_name fm.copy(self.basis_dir+'/'+self.file_name, self.basis_dir+'/'+folder_name) # create *.in files self.create_griddata_input_files(folder_name) # create *.sh files script_name = self.create_bash_script(folder_name) # create the *.table file needed for grid_all_data self.setup_tables(self.basis_dir+'/'+folder_name) return script_name
def compare(basis_dir=None, default=0.012): """ Create a set of diagnostic plots in basis_dir/figs :param string basis_dir: directory containing the test folder and landuse folders :param float default: default Manning's *n* """ if basis_dir is None: basis_dir = os.getcwd() tables = tm.read_tables(os.path.join(basis_dir, 'test')) domain = dom.domain(basis_dir) domain.read_spatial_grid() fm.mkdir(os.path.join(basis_dir, 'figs')) old_files = glob.glob(os.path.join(basis_dir, 'figs', '*.png')) for fid in old_files: os.remove(fid) domain.get_Triangulation(path=basis_dir) original = f13.read_nodal_attr_dict(os.path.join(basis_dir, 'test')) original = tmm.dict_to_array(original, default, domain.node_num) weights = np.array(tables[0].land_classes.values()) lim = (np.min(weights), np.max(weights)) bv_dict = tmm.get_basis_vectors(basis_dir) combo = tmm.combine_basis_vectors(weights, bv_dict, default, domain.node_num) bv_array = tmm.get_basis_vec_array(basis_dir, domain.node_num) plt.basis_functions(domain, bv_array, path=basis_dir) plt.field(domain, original, 'original', clim=lim, path=basis_dir) plt.field(domain, combo, 'reconstruction', clim=lim, path=basis_dir) plt.field(domain, original-combo, 'difference', path=basis_dir) combo_array = tmm.combine_bv_array(weights, bv_array) plt.field(domain, combo_array, 'combo_array', clim=lim, path=basis_dir) plt.field(domain, original-combo_array, 'diff_ori_array', path=basis_dir) plt.field(domain, combo-combo_array, 'diff_com_array', path=basis_dir) combo_bv = tmm.combine_basis_vectors(np.ones(weights.shape), bv_dict, default, domain.node_num) plt.field(domain, combo_bv, 'combo_bv', path=basis_dir)
def make_plots(self, points, domain, save=True, show=False, bathymetry=False): """ Plots ``mesh``, ``station_locations``, ``basis_functions``, ``random_fields``, ``mean_field``, ``station_data``, and save in save_dir/figs .. todo:: this uses bv_array everywhere. I might want to change this later when I go to the nested mesh approach """ mkdir(self.save_dir+'/figs') domain.get_Triangulation(self.save_dir, save, show) domain.plot_bathymetry(self.save_dir, save, show) domain.plot_station_locations(self.save_dir, bathymetry, save, show) bv_array = tmm.get_basis_vec_array(self.basis_dir) self.plot_basis_functions(domain, bv_array, save, show) self.plot_random_fields(domain, points, bv_array, save, show) self.plot_mean_field(domain, points, bv_array, save, show) self.plot_station_data(save, show)
def station_data(ts_data, time_obs, keys=None, stations=None, path=None, save=True, show=False, ext='.png'): """ Plot the station data in ``ts_data`` with ``time_obs`` as the x axis. To plot only a subset of this data list which ADCIRC Output types to plot in keys. :type ts_data: :class:`dict` :param ts_data: ``ts_data`` from :class:`~polyadcirc.run_framework.random_manningsn.runSet` :type time_obs: :class:`dict` :param time_obs: ``time_obs`` from :class:`~polyadcirc.run_framework.random_manningsn.runSet` :param list keys: list of types of ADCIRC output data to plot :param dict stations: dictonary of lists of stations to plot :type path: string or None :param path: directory to store plots :type save: bool :param save: flag for whether or not to save plots :type show: bool :param show: flag for whether or not to show plots :param string ext: file extension """ if path is None: path = os.getcwd() if keys is None: keys = ts_data.keys() s_keys = list() for k in keys: if f15.filetype[k][0]: s_keys.append(k) keys = s_keys for k in keys: fm.mkdir(os.path.join(path, 'figs', k)) if stations[k] is None: stations = xrange(ts_data[k].shape[0]) for i in stations: fig = plt.figure() x = time_obs[k] num_plts = f15.filetype[k][1] if num_plts == 1: ax = fig.add_subplot(111) ax.set_xlim((np.min(x), np.max(x))) ax.set_ylim((np.min(ts_data[k]), np.max(ts_data[k]))) segs = list() for j in xrange(ts_data[k].shape[2]): segs.append(zip(x, ts_data[k][i, ..., j])) line_segs = LineCollection(segs, linestyles='solid') line_segs.set_array(np.arange(ts_data[k].shape[2])) ax.add_collection(line_segs) ax.set_xlabel('time') colorbar(line_segs) elif num_plts == 2: ax1 = fig.add_subplot(121) ax2 = fig.add_subplot(122) ax1.set_xlim((np.min(x), np.max(x))) ax1.set_ylim( (np.min(ts_data[k][:, :, 0, :]), np.max(ts_data[k][:, :, 0, :]))) ax2.set_xlim((np.min(x), np.max(x))) ax2.set_ylim( (np.min(ts_data[k][:, :, 1, :]), np.max(ts_data[k][:, :, 1, :]))) segs1 = list() segs2 = list() for j in xrange(ts_data[k].shape[-1]): segs1.append(zip(x, ts_data[k][i, :, 0, j])) segs2.append(zip(x, ts_data[k][i, :, 1, j])) line_segs1 = LineCollection(segs1, linestyles='solid') line_segs1.set_array(np.arange(ts_data[k].shape[-1])) ax1.add_collection(line_segs1) ax1.set_ylabel('u (m/s)') ax1.set_xlabel('time') line_segs2 = LineCollection(segs2, linestyles='solid') line_segs2.set_array(np.arange(ts_data[k].shape[-1])) ax2.add_collection(line_segs2) ax2.set_xlabel('time') ax2.set_ylabel('v (m/s)') colorbar(line_segs2) save_show(os.path.join(path, 'figs', k, 'station' + str(i)), save, show, ext)
def ts_pcolor(ts_data, time_obs, domain, keys=None, points=None, path=None, save=True, show=False, ics=1, ext='.png'): """ Plot the timeseries data in ``ts_data`` as a series of 2D color plots. To plot only a subset of this data list which ADCIRC Output types to plot in keys and which runs in points. .. note:: This only applies to 1D nts data (``irtype`` = 1) :type ts_data: :class:`dict` :param ts_data: ``ts_data`` from :class:`~polyadcirc.run_framework.random_manningsn.runSet` :type time_obs: :class:``dict`` :param time_obs: ``time_obs`` from :class:`~polyadcirc.run_framework.random_manningsn.runSet` :param domain: :class:`~polyadcirc.run_framework.domain` :param list keys: list of types of ADCIRC output data to plot :param list points: list of runs or points to plot :type path: string or None :param path: directory to store plots :type save: bool :param save: flag for whether or not to save plots :type show: bool :param show: flag for whether or not to show plots :param int ics: polar coordinate option (1 = cart coords, 2 = polar) :param string ext: file extension """ if path is None: path = os.getcwd() if keys is None: keys = ts_data.keys() s_keys = list() for k in keys: if not (f15.filetype[k][0]) and f15.filetype[k][1] == 1: s_keys.append(k) keys = s_keys if points is None: points = (0, ts_data[keys[0]].shape[-1] - 1) fm.mkdir(os.path.join(path, 'figs', 'ts')) for k in keys: fig_folder = os.path.join(path, 'figs', 'ts', k) fm.mkdir(fig_folder) clim = (np.min(ts_data[k]), np.max(ts_data[k])) for j in points: subfig_folder = os.path.join(fig_folder, 'run' + str(j)) fm.mkdir(subfig_folder) for i, t in enumerate(time_obs[k]): plt.figure() add_2d_axes_labels(ics=ics) plt.tripcolor(domain.triangulation, ts_data[k][:, i, j], shading='gouraud', cmap=plt.cm.jet) plt.gca().set_aspect('equal') plt.clim(clim[0], clim[1]) colorbar() plt.title('time = ' + str(t)) save_show(os.path.join(subfig_folder, str(i)), save, show, ext) if len(points) == 2: fm.mkdir(os.path.join(path, 'figs', 'ts', k, 'diff')) diff = ts_data[k][:, :, points[-1]] - ts_data[k][:, :, points[0]] cdiff = (np.min(diff), np.max(diff)) for i, t in enumerate(time_obs[k]): plt.figure(figsize=(6, 9)) plt.subplot(311) plt.tripcolor(domain.triangulation, ts_data[k][:, i, points[0]], shading='gouraud', cmap=plt.cm.jet) plt.gca().set_aspect('equal') plt.clim(clim[0], clim[1]) cb = colorbar() #add_2d_axes_labels(ics=ics) cb.set_label(k + '_' + str(points[0])) plt.subplot(312) plt.tripcolor(domain.triangulation, ts_data[k][:, i, points[-1]], shading='gouraud', cmap=plt.cm.jet) plt.gca().set_aspect('equal') plt.clim(clim[0], clim[1]) cb = colorbar() #add_2d_axes_labels(ics=ics) cb.set_label(k + '_' + str(points[-1])) plt.subplot(313) plt.tripcolor(domain.triangulation, diff[:, i], shading='gouraud', cmap=plt.cm.jet) plt.gca().set_aspect('equal') plt.clim(cdiff[0], cdiff[1]) cb = colorbar() add_2d_axes_labels(ics=ics) cb.set_label(k + '_' + 'diff') plt.tight_layout() plt.suptitle('time = ' + str(t)) save_show(os.path.join(path, 'figs', 'ts', k, 'diff', str(i)), save, show, ext)
def ts_quiver(ts_data, time_obs, domain, keys=None, points=None, path=None, save=True, show=False, ics=1, ext='.png'): """ Plot the timeseries data in ``ts_data`` as a series of 2D quiver plots. To plot only a subset of this data list which ADCIRC Output types to plot in keys and which runs in points. .. note:: This only applies to 2D nts data (``irtype`` = 2) :type ts_data: :class:`dict` :param ts_data: ``ts_data`` from :class:`~polyadcirc.run_framework.random_manningsn.runSet` :type time_obs: :class:`dict` :param time_obs: ``time_obs`` from :class:`~polyadcirc.run_framework.random_manningsn.runSet` :param domain: :class:`~polyadcirc.run_framework.domain` :param list keys: list of types of ADCIRC output data to plot :param list points: list of runs or points to plot :type path: string or None :param path: directory to store plots :type save: bool :param save: flag for whether or not to save plots :type show: bool :param show: flag for whether or not to show plots :param int ics: polar coordinate option (1 = cart coords, 2 = polar :param string ext: file extension .. todo:: maybe add plt.streamplot, but this requires a regularly spaced grid and is therefore more expenseive to do """ if path is None: path = os.getcwd() if keys is None: keys = ts_data.keys() s_keys = list() for k in keys: if not f15.filetype[k][0] and f15.filetype[k][1] == 2: s_keys.append(k) keys = s_keys if points is None: points = (0, ts_data[keys[0]].shape[-1] - 1) fig_folder = os.path.join(path, 'figs', 'ts_quiver') fm.mkdir(fig_folder) x = domain.array_x() y = domain.array_y() for k in keys: fm.mkdir(os.path.join(fig_folder, k)) mag = np.sqrt( pow(ts_data[k][:, :, 0, :], 2) + pow(ts_data[k][:, :, 1, :], 2)) clim = (np.min(mag), np.max(mag)) for j in points: fm.mkdir(os.path.join(fig_folder, k, 'run' + str(j))) for i, t in enumerate(time_obs[k]): plt.figure() add_2d_axes_labels(ics=ics) plt.quiver(x, y, ts_data[k][:, i, 0, j], ts_data[k][:, i, 1, j], mag[:, i, j]) plt.gca().set_aspect('equal') plt.clim(clim[0], clim[1]) colorbar() plt.title('time = ' + str(t)) save_show(os.path.join(fig_folder, k, 'run' + str(j), str(i)), save, show, ext) if len(points) == 2: fm.mkdir(os.path.join(fig_folder, 'diff')) diff = ts_data[k][:, :, :, points[-1]] - ts_data[k][:, :, :, points[0]] mag_diff = np.sqrt(pow(diff[:, :, 0], 2) + pow(diff[:, :, 1], 2)) cdiff = (np.min(mag_diff), np.max(mag_diff)) for i, t in enumerate(time_obs[k]): plt.figure(figsize=(6, 9)) ax1 = plt.subplot(311) plt.quiver(x, y, ts_data[k][:, i, 0, points[0]], ts_data[k][:, i, 1, points[0]], mag[:, i, points[0]]) plt.gca().set_aspect('equal') plt.clim(clim[0], clim[1]) cb = colorbar() #add_2d_axes_labels(ics=ics) cb.set_label(k + '_' + str(points[0])) ax2 = plt.subplot(312) plt.quiver(x, y, ts_data[k][:, i, 0, points[-1]], ts_data[k][:, i, 1, points[-1]], mag[:, i, points[-1]]) plt.gca().set_aspect('equal') plt.clim(clim[0], clim[1]) cb = colorbar() #add_2d_axes_labels(ics=ics) cb.set_label(k + '_' + str(points[-1])) ax3 = plt.subplot(313) plt.quiver(x, y, diff[:, i, 0], diff[:, i, 1], mag_diff[:, i]) plt.gca().set_aspect('equal') plt.clim(cdiff[0], cdiff[1]) cb = colorbar() add_2d_axes_labels(ics=ics) cb.set_label(k + '_' + 'diff') plt.tight_layout() plt.suptitle('time = ' + str(t)) save_show(os.path.join(fig_folder, 'diff', str(i)), save, show, ext)
def nts_contour(nts_data, domain, keys=None, points=None, path=None, save=True, show=False, ics=1, ext='.png'): """ Plot the non timeseries data in ``nts_data`` as a set of 2D contour plots. To plot only a subset of this data list which ADCIRC Output types to plot in keys, and which runs in ``points``. .. note:: This only applies to 1D nts data (``irtype`` = 1) :type nts_data: :class:`dict` :param nts_data: ``nts_data`` from :class:`~polyadcirc.run_framework.random_manningsn.runSet` :param domain: :class:`~polyadcirc.run_framework.domain` :param list keys: list of types of ADCIRC output data to plot :param list points: list of runs to plot :type path: string or None :param path: directory to store plots :type save: bool :param save: flag for whether or not to save plots :type show: bool :param show: flag for whether or not to show plots :param int ics: polar coordinate option (1 = cart coords, 2 = polar :param string ext: file extension """ if path is None: path = os.getcwd() if keys is None: keys = nts_data.keys() s_keys = list() for k in keys: if not f15.filetype[k][0] and f15.filetype[k][1] == 1: s_keys.append(k) keys = s_keys if points is None: points = (0, nts_data[keys[0]].shape[-1] - 1) fig_folder = os.path.join(path, 'figs', 'nts_contour') fm.mkdir(fig_folder) for k in keys: for j in points: plt.figure() plt.tricontour(domain.triangulation, nts_data[k][:, j], shading='gouraud', cmap=plt.cm.jet) plt.gca().set_aspect('equal') colorbar() add_2d_axes_labels(ics=ics) plt.title(k + '_' + str(j)) save_show(os.path.join(fig_folder, k + '_' + str(j) + '_contour'), save, show, ext) if len(points) == 2: plt.figure(figsize=(6, 9)) plt.subplot(311) plt.tricontour(domain.triangulation, nts_data[k][:, points[0]], shading='gouraud', cmap=plt.cm.jet) plt.gca().set_aspect('equal') cb = colorbar() #add_2d_axes_labels(ics=ics) cb.set_label(k + '_' + str(points[0])) plt.subplot(312) plt.tricontour(domain.triangulation, nts_data[k][:, points[-1]], shading='gouraud', cmap=plt.cm.jet) plt.gca().set_aspect('equal') cb = colorbar() #add_2d_axes_labels(ics=ics) cb.set_label(k + '_' + str(points[-1])) plt.subplot(313) diff = nts_data[k][:, points[-1]] - nts_data[k][:, points[0]] plt.tricontour(domain.triangulation, diff, shading='gouraud', cmap=plt.cm.jet) plt.gca().set_aspect('equal') cb = colorbar() add_2d_axes_labels(ics=ics) cb.set_label(k + '_' + 'diff') save_show(os.path.join(fig_folder, k + '_diff_contour'), save, show, ext)
def nts_contour(nts_data, domain, keys=None, points=None, path=None, save=True, show=False, ics=1, ext='.png'): """ Plot the non timeseries data in ``nts_data`` as a set of 2D contour plots. To plot only a subset of this data list which ADCIRC Output types to plot in keys, and which runs in ``points``. .. note:: This only applies to 1D nts data (``irtype`` = 1) :type nts_data: :class:`dict` :param nts_data: ``nts_data`` from :class:`~polyadcirc.run_framework.random_manningsn.runSet` :param domain: :class:`~polyadcirc.run_framework.domain` :param list() keys: list of types of ADCIRC output data to plot :param list() points: list of runs to plot :type path: string or None :param path: directory to store plots :type save: boolean :param save: flag for whether or not to save plots :type show: boolean :param show: flag for whether or not to show plots :param int ics: polar coordinate option (1 = cart coords, 2 = polar :param string ext: file extension """ if path == None: path = os.getcwd() if keys == None: keys = nts_data.keys() s_keys = list() for k in keys: if not f15.filetype[k][0] and f15.filetype[k][1] == 1: s_keys.append(k) keys = s_keys if points == None: points = (0, nts_data[keys[0]].shape[-1]-1) fm.mkdir(path+'/figs/nts_contour') for k in keys: for j in points: plt.figure() plt.tricontour(domain.triangulation, nts_data[k][:,j], shading='gouraud', cmap=plt.cm.jet) plt.gca().set_aspect('equal') colorbar() add_2d_axes_labels(ics) plt.title(k+'_'+str(j)) save_show(path+'/figs/nts_contour/'+k+'_'+str(j)+'_contour', save, show, ext) if len(points) == 2: plt.figure(figsize=(6,9)) plt.subplot(311) plt.tricontour(domain.triangulation, nts_data[k][:,points[0]], shading='gouraud', cmap=plt.cm.jet) plt.gca().set_aspect('equal') cb = colorbar() #add_2d_axes_labels(ics) cb.set_label(k+'_'+str(points[0])) plt.subplot(312) plt.tricontour(domain.triangulation, nts_data[k][:,points[-1]], shading='gouraud', cmap=plt.cm.jet) plt.gca().set_aspect('equal') cb = colorbar() #add_2d_axes_labels(ics) cb.set_label(k+'_'+str(points[-1])) plt.subplot(313) diff = nts_data[k][:,points[-1]] - nts_data[k][:,points[0]] plt.tricontour(domain.triangulation, diff, shading='gouraud', cmap=plt.cm.jet) plt.gca().set_aspect('equal') cb = colorbar() add_2d_axes_labels(ics) cb.set_label(k+'_'+'diff') save_show(path+'/figs/nts_contour/'+k+'_diff_contour', save, show, ext)
def ts_quiver(ts_data, time_obs, domain, keys=None, points=None, path=None, save=True, show=False, ics=1, ext='.png'): """ Plot the timeseries data in ``ts_data`` as a series of 2D quiver plots. To plot only a subset of this data list which ADCIRC Output types to plot in keys and which runs in points. .. note:: This only applies to 2D nts data (``irtype`` = 2) :type ts_data: :class:`dict` :param ts_data: ``ts_data`` from :class:`~polyadcirc.run_framework.random_manningsn.runSet` :type time_obs: :class:`dict` :param time_obs: ``time_obs`` from :class:`~polyadcirc.run_framework.random_manningsn.runSet` :param domain: :class:`~polyadcirc.run_framework.domain` :param list() keys: list of types of ADCIRC output data to plot :param list() points: list of runs or points to plot :type path: string or None :param path: directory to store plots :type save: boolean :param save: flag for whether or not to save plots :type show: boolean :param show: flag for whether or not to show plots :param int ics: polar coordinate option (1 = cart coords, 2 = polar .. todo:: maybe add plt.streamplot, but this requires a regularly spaced grid and is therefore more expenseive to do """ if path == None: path = os.getcwd() if keys == None: keys = ts_data.keys() s_keys = list() for k in keys: if not f15.filetype[k][0] and f15.filetype[k][1] == 2: s_keys.append(k) keys = s_keys if points == None: points = (0, ts_data[keys[0]].shape[-1]-1) fm.mkdir(path+'/figs/ts_quiver') x = domain.array_x() y = domain.array_y() for k in keys: fm.mkdir(path+'/figs/ts_quiver/'+k) mag = np.sqrt(pow(ts_data[k][:,:,0,:],2)+pow(ts_data[k][:,:,1,:],2)) clim = (np.min(mag),np.max(mag)) for j in points: fm.mkdir(path+'/figs/ts_quiver/'+k+'/run'+str(j)) for i, t in enumerate(time_obs[k]): plt.figure() add_2d_axes_labels(ics) plt.quiver(x, y, ts_data[k][:,i,0,j], ts_data[k][:,i,1,j], mag[:,i,j]) plt.gca().set_aspect('equal') plt.clim(clim[0], clim[1]) colorbar() plt.title('time = '+str(t)) save_show(path+'/figs/ts_quiver/'+k+'/run'+str(j)+'/'+str(i), save, show, ext) if len(points) == 2: fm.mkdir(path+'/figs/ts_quiver/'+k+'/diff') diff = ts_data[k][:,:,:,points[-1]] - ts_data[k][:,:,:,points[0]] mag_diff = np.sqrt(pow(diff[:,:,0],2)+pow(diff[:,:,1],2)) cdiff = (np.min(mag_diff), np.max(mag_diff)) for i, t in enumerate(time_obs[k]): plt.figure(figsize=(6,9)) ax1 = plt.subplot(311) plt.quiver(x, y, ts_data[k][:,i,0,points[0]], ts_data[k][:,i,1,points[0]], mag[:,i,points[0]]) plt.gca().set_aspect('equal') plt.clim(clim[0], clim[1]) cb = colorbar() #add_2d_axes_labels(ics) cb.set_label(k+'_'+str(points[0])) ax2 = plt.subplot(312) plt.quiver(x, y, ts_data[k][:,i,0,points[-1]], ts_data[k][:,i,1,points[-1]], mag[:,i,points[-1]]) plt.gca().set_aspect('equal') plt.clim(clim[0], clim[1]) cb = colorbar() #add_2d_axes_labels(ics) cb.set_label(k+'_'+str(points[-1])) ax3 = plt.subplot(313) plt.quiver(x, y, diff[:,i,0], diff[:,i,1], mag_diff[:,i]) plt.gca().set_aspect('equal') plt.clim(cdiff[0], cdiff[1]) cb = colorbar() add_2d_axes_labels(ics) cb.set_label(k+'_'+'diff') plt.tight_layout() plt.suptitle('time = '+str(t)) save_show(path+'/figs/ts_quiver/'+k+'/diff/'+str(i), save, show, ext)
def ts_pcolor(ts_data, time_obs, domain, keys=None, points=None, path=None, save=True, show=False, ics=1, ext='.png'): """ Plot the timeseries data in ``ts_data`` as a series of 2D color plots. To plot only a subset of this data list which ADCIRC Output types to plot in keys and which runs in points. .. note:: This only applies to 1D nts data (``irtype`` = 1) :type ts_data: :class:`dict` :param ts_data: ``ts_data`` from :class:`~polyadcirc.run_framework.random_manningsn.runSet` :type time_obs: :class:``dict`` :param time_obs: ``time_obs`` from :class:`~polyadcirc.run_framework.random_manningsn.runSet` :param domain: :class:`~polyadcirc.run_framework.domain` :param list() keys: list of types of ADCIRC output data to plot :param list() points: list of runs or points to plot :type path: string or None :param path: directory to store plots :type save: boolean :param save: flag for whether or not to save plots :type show: boolean :param show: flag for whether or not to show plots :param int ics: polar coordinate option (1 = cart coords, 2 = polar) :param string ext: file extension """ if path == None: path = os.getcwd() if keys == None: keys = ts_data.keys() s_keys = list() for k in keys: if not(f15.filetype[k][0]) and f15.filetype[k][1] == 1: s_keys.append(k) keys = s_keys if points == None: points = (0, ts_data[keys[0]].shape[-1]-1) fm.mkdir(path+'/figs/ts') for k in keys: fm.mkdir(path+'/figs/ts/'+k) clim = (np.min(ts_data[k]),np.max(ts_data[k])) for j in points: fm.mkdir(path+'/figs/ts/'+k+'/run'+str(j)) for i, t in enumerate(time_obs[k]): plt.figure() add_2d_axes_labels(ics) plt.tripcolor(domain.triangulation, ts_data[k][:,i,j], shading='gouraud', cmap=plt.cm.jet) plt.gca().set_aspect('equal') plt.clim(clim[0], clim[1]) colorbar() plt.title('time = '+str(t)) save_show(path+'/figs/ts/'+k+'/run'+str(j)+'/'+str(i), save, show, ext) if len(points) == 2: fm.mkdir(path+'/figs/ts/'+k+'/diff') diff = ts_data[k][:,:,points[-1]] - ts_data[k][:,:,points[0]] cdiff = (np.min(diff), np.max(diff)) for i, t in enumerate(time_obs[k]): plt.figure(figsize=(6,9)) ax1 = plt.subplot(311) plt.tripcolor(domain.triangulation, ts_data[k][:,i,points[0]], shading='gouraud', cmap=plt.cm.jet) plt.gca().set_aspect('equal') plt.clim(clim[0], clim[1]) cb = colorbar() #add_2d_axes_labels(ics) cb.set_label(k+'_'+str(points[0])) ax2 = plt.subplot(312) plt.tripcolor(domain.triangulation, ts_data[k][:,i,points[-1]], shading='gouraud', cmap=plt.cm.jet) plt.gca().set_aspect('equal') plt.clim(clim[0], clim[1]) cb = colorbar() #add_2d_axes_labels(ics) cb.set_label(k+'_'+str(points[-1])) ax3 = plt.subplot(313) plt.tripcolor(domain.triangulation, diff[:,i] , shading='gouraud', cmap=plt.cm.jet) plt.gca().set_aspect('equal') plt.clim(cdiff[0], cdiff[1]) cb = colorbar() add_2d_axes_labels(ics) cb.set_label(k+'_'+'diff') plt.tight_layout() plt.suptitle('time = '+str(t)) save_show(path+'/figs/ts/'+k+'/diff/'+str(i), save, show, ext)
# Specify run parameter folders adcirc_dir = '/h1/lgraham/workspace' grid_dir = adcirc_dir + '/ADCIRC_landuse/Katrina_small/inputs' save_dir = adcirc_dir + '/ADCIRC_landuse/Katrina_small/runs/output_test' basis_dir = adcirc_dir +'/ADCIRC_landuse/Katrina_small/landuse_basis/gap/shelf_test' # load in the small katrina mesh domain = dom.domain(grid_dir) domain.update() # load in basis vectors for domain bv_dict = tmm.get_basis_vectors(basis_dir) # create the shelf basis vector dictonary shelf_limits = [0, 50] #[0, 100] [50, 100] shelf_bv = tmm.create_shelf(domain, shelf_limits, bv_dict) # write this out to an appropriately numbered basis vector mesh in the correct # basis_dir # get list of landuse folder names folders = glob.glob(basis_dir+'/landuse_*') # create new folder folder_name = basis_dir+'/landuse_'+'{:=02d}'.format(len(folders)) fm.mkdir(folder_name) # copy a fort.13 file to that folder fm.copy(save_dir+'/fort.13', folder_name+'/fort.13') f13.update_mann(shelf_bv, folder_name)
def station_data(ts_data, time_obs, keys=None, stations = None, path=None, save=True, show=False, ext='.png'): """ Plot the station data in ``ts_data`` with ``time_obs`` as the x axis. To plot only a subset of this data list which ADCIRC Output types to plot in keys. :type ts_data: :class:`dict` :param ts_data: ``ts_data`` from :class:`~polyadcirc.run_framework.random_manningsn.runSet` :type time_obs: :class:`dict` :param time_obs: ``time_obs`` from :class:`~polyadcirc.run_framework.random_manningsn.runSet` :param list() keys: list of types of ADCIRC output data to plot :param dict stations: dictonary of lists of stations to plot :type path: string or None :param path: directory to store plots :type save: boolean :param save: flag for whether or not to save plots :type show: boolean :param show: flag for whether or not to show plots :param string ext: file extension """ if path == None: path = os.getcwd() if keys == None: keys = ts_data.keys() s_keys = list() for k in keys: if f15.filetype[k][0]: s_keys.append(k) keys = s_keys for k in keys: fm.mkdir(path+'/figs/'+k) if stations[k] == None: stations = xrange(ts_data[k].shape[0]) for i in stations: fig = plt.figure() x = time_obs[k] num_plts = f15.filetype[k][1] if num_plts == 1: ax = fig.add_subplot(111) ax.set_xlim((np.min(x),np.max(x))) ax.set_ylim((np.min(ts_data[k]),np.max(ts_data[k]))) segs = list() for j in xrange(ts_data[k].shape[2]): segs.append(zip(x, ts_data[k][i,...,j])) line_segs = LineCollection(segs, linestyles = 'solid') line_segs.set_array(np.arange(ts_data[k].shape[2])) ax.add_collection(line_segs) ax.set_xlabel('time') colorbar(line_segs, fig) elif num_plts == 2: ax1 = fig.add_subplot(121) ax2 = fig.add_subplot(122) ax1.set_xlim((np.min(x),np.max(x))) ax1.set_ylim((np.min(ts_data[k][:,:,0,:]), np.max(ts_data[k][:,:,0,:]))) ax2.set_xlim((np.min(x),np.max(x))) ax2.set_ylim((np.min(ts_data[k][:,:,1,:]), np.max(ts_data[k][:,:,1,:]))) segs1 = list() segs2 = list() for j in xrange(ts_data[k].shape[-1]): segs1.append(zip(x, ts_data[k][i,:,0,j])) segs2.append(zip(x, ts_data[k][i,:,1,j])) line_segs1 = LineCollection(segs1, linestyles = 'solid') line_segs1.set_array(np.arange(ts_data[k].shape[-1])) ax1.add_collection(line_segs1) ax1.set_ylabel('u (m/s)') ax1.set_xlabel('time') line_segs2 = LineCollection(segs2, linestyles = 'solid') line_segs2.set_array(np.arange(ts_data[k].shape[-1])) ax2.add_collection(line_segs2) ax2.set_xlabel('time') ax2.set_ylabel('v (m/s)') colorbar(line_segs2, fig) save_show(path+'/figs/'+k+'/station'+str(i), save, show, ext)
import polyadcirc.pyADCIRC.fort13_management as f13 import glob # Specify run parameter folders adcirc_dir = '/h1/lgraham/workspace' grid_dir = adcirc_dir + '/ADCIRC_landuse/Katrina_small/inputs' save_dir = adcirc_dir + '/ADCIRC_landuse/Katrina_small/runs/output_test' basis_dir = adcirc_dir + '/ADCIRC_landuse/Katrina_small/landuse_basis/gap/shelf_test' # load in the small katrina mesh domain = dom.domain(grid_dir) domain.update() # load in basis vectors for domain bv_dict = tmm.get_basis_vectors(basis_dir) # create the shelf basis vector dictonary shelf_limits = [0, 50] shelf_bv = tmm.create_shelf(domain, shelf_limits, bv_dict) # write this out to an appropriately numbered basis vector mesh in the correct # basis_dir # get list of landuse folder names folders = glob.glob(basis_dir + '/landuse_*') # create new folder folder_name = basis_dir + '/landuse_' + '{:=02d}'.format(len(folders)) fm.mkdir(folder_name) # copy a fort.13 file to that folder fm.copy(save_dir + '/fort.13', folder_name + '/fort.13') f13.update_mann(shelf_bv, folder_name)