def writeGEFDCGridextFile(self, outputdir, filename='gridext.inp', shift=2): """ Writes to the nodes and I/J cell index as to a file for GEFDC. Parameters ---------- outputdir : str, optional The path to where the should be saved. filename : str, optional The name of the output file. shift : int, optional The shift that should be applied to the I/J index. The default value to 2 means that the first cell is at (2, 2) instead of (0, 0). Returns ------- df : pandas.DataFrame The dataframe of coordinates and I/J index. """ outfile = iotools._outputfile(outputdir, filename) df = self.to_dataframe().stack(level='i', dropna=True).reset_index() df['i'] += shift df['j'] += shift iotools._write_gridext_file(df, outfile) return df
def test__write_gridext_file(): known_filename = 'pygridtools/tests/baseline_files/testgridext.inp' result_filename = 'pygridtools/tests/result_files/testgridext.inp' df = pandas.DataFrame(np.array([ [1.25, 3, 4, 3.75], [1.75, 4, 4, 3.25], [1.25, 4, 5, 3.75], [1.75, 5, 5, 3.25], ]), columns=['x', 'ii', 'jj', 'y']) iotools._write_gridext_file(df, result_filename, icol='ii', jcol='jj', xcol='x', ycol='y') testing.compareTextFiles(result_filename, known_filename)