diff --git a/.github/workflows/development-pipeline.yml b/.github/workflows/development-pipeline.yml index 01756dc..599537c 100644 --- a/.github/workflows/development-pipeline.yml +++ b/.github/workflows/development-pipeline.yml @@ -21,7 +21,8 @@ jobs: strategy: matrix: include: - - os: ubuntu-latest + # GitHub publishes Python 3.9 builds for Ubuntu 24.04. + - os: ubuntu-24.04 python-version: 3.9 python: xvfb-run python3 pip_arg: "" @@ -50,7 +51,7 @@ jobs: with: submodules: recursive - name: Set up Python ${{ matrix.python-version }} - uses: actions/setup-python@v2 + uses: actions/setup-python@v6 with: python-version: ${{ matrix.python-version }} - name: Install dependencies diff --git a/openfast_toolbox/airfoils/polar_file.py b/openfast_toolbox/airfoils/polar_file.py index cd72f61..6334fa8 100644 --- a/openfast_toolbox/airfoils/polar_file.py +++ b/openfast_toolbox/airfoils/polar_file.py @@ -236,6 +236,8 @@ def tryReading(f, reader): # --- Rename columns - Standardize column names if standardizeCols: COLS_TODO= {**DEFAULT_COLUMNS,**DEFAULT_COLUMNS_EXT} + # Index values are read-only with pandas 3, rename through a list + new_cols = list(df.columns) for ic, col in enumerate(df.columns): c = col.strip().lower().replace('_','') c = c.replace('aoa','alpha') @@ -249,11 +251,12 @@ def tryReading(f, reader): if c.startswith(kk): cnew = COLS_TODO.pop(kk) #print('changing {} to {}'.format(c, cnew)) - df.columns.values[ic] = cnew # rename column + new_cols[ic] = cnew # rename column found=True break if not found: print('[WARN] PolarFile: The following column was not understood: {}'.format(col)) + df.columns = new_cols # --- Standardize data for k,v in DEFAULT_COLUMNS.items(): diff --git a/openfast_toolbox/converters/hawc2ToBeamDyn.py b/openfast_toolbox/converters/hawc2ToBeamDyn.py index 13fc0da..d051dbf 100644 --- a/openfast_toolbox/converters/hawc2ToBeamDyn.py +++ b/openfast_toolbox/converters/hawc2ToBeamDyn.py @@ -142,7 +142,7 @@ def hawc2ToBeamDyn(H2MeanLine, H2Structure, BDBldFileOut, BDMainFileOut=None, BD else: c2def = CSVFile(H2MeanLine).toDataFrame() # For the equations below to be generic we force the column names - c2def.columns.values[0:4]=['x_[m]','y_[m]','z_[m]','twist_[deg]'] + c2def.columns = ['x_[m]','y_[m]','z_[m]','twist_[deg]'] + list(c2def.columns[4:]) # --- If necessary, interpolate mean line to user defined positions c2def_old = c2def.copy() diff --git a/openfast_toolbox/io/cactus_file.py b/openfast_toolbox/io/cactus_file.py index 265d0d8..8f5b003 100644 --- a/openfast_toolbox/io/cactus_file.py +++ b/openfast_toolbox/io/cactus_file.py @@ -234,7 +234,7 @@ def timeDataToOpenFAST(self, df): df.insert(c , 'RtAeroFzh_[N]' ,-(np.cos(theta)*df['Fz Coeff. (-)'] + np.sin(theta)*df['Fx Coeff. (-)'])*F0 ); c+=1 df.insert(c , 'RtAeroMxh_[N-m]' , df['Torque Coeff. (-)']*Q0) ; c+=1 df.insert(c , 'RtAeroPwr_[W]' , df['Power Coeff. (-)']*P0) ; c+=1 - df['RtAeroPwr_[W]'].values[0]=df['RtAeroPwr_[W]'].values[1] + df.iloc[0, df.columns.get_loc('RtAeroPwr_[W]')] = df['RtAeroPwr_[W]'].iloc[1] df.insert(c , 'RotSpeed_[rpm]' , self.RPM*ones) ; c+=1 @@ -260,7 +260,7 @@ def timeDataToOpenFAST(self, df): df.insert(c , 'Z'+sb+'AeroFzg_[N]' , df['Blade'+sb+' Fy Coeff. (-)']*F0) ; c+=1 df.insert(c , 'Z'+sb+'AeroMzg_[N-m]' , df['Blade'+sb+' Torque Coeff. (-)']*Q0) ; c+=1 - df['Y'+sb+'AeroPwr_[W]'].values[0] = df['Y'+sb+'AeroPwr_[W]'].values[1] + df.iloc[0, df.columns.get_loc('Y'+sb+'AeroPwr_[W]')] = df['Y'+sb+'AeroPwr_[W]'].iloc[1] df.insert(c , 'Wind1VelX_[m/s]' , U*ones) ; c+=1 diff --git a/openfast_toolbox/postpro/postpro.py b/openfast_toolbox/postpro/postpro.py index 23cccef..86f8cda 100644 --- a/openfast_toolbox/postpro/postpro.py +++ b/openfast_toolbox/postpro/postpro.py @@ -1392,14 +1392,16 @@ def remap_df(df, ColMap, bColKeepNewOnly=False, inPlace=False, dataDict=None, ve # Applying renaming only now so that expressions may be applied in any order + # Index values are read-only with pandas 3, rename through a list + new_cols = list(df.columns) for k,v in RenameMap.items(): if verbose: print('Renaming column {:15s} > {}'.format(v,k)) k=k.strip() - iCol = list(df.columns).index(v) - df.columns.values[iCol]=k + iCol = new_cols.index(v) + new_cols[iCol]=k ColNew.append(k) - df.columns = df.columns.values # Hack to ensure columns are updated + df.columns = new_cols if len(ColMapMiss)>0: print('[FAIL] The following columns were not found in the dataframe:',ColMapMiss) diff --git a/openfast_toolbox/postpro/tests/test_remap.py b/openfast_toolbox/postpro/tests/test_remap.py new file mode 100644 index 0000000..937d9ca --- /dev/null +++ b/openfast_toolbox/postpro/tests/test_remap.py @@ -0,0 +1,33 @@ +import unittest + +import numpy as np +import pandas as pd + +from openfast_toolbox.postpro import postpro +from openfast_toolbox.tools import pandalib + + +class TestRemap(unittest.TestCase): + + def _check_remap(self, remap_df): + df = pd.DataFrame({'Wind1VelX_[m/s]': [8.0, 9.0], 'RotSpeed_[rpm]': [10.0, 12.0]}) + ColMap = { + 'WS_[m/s]' : 'Wind1VelX_[m/s]', # rename + 'RotSpeed_[rad/s]' : '{RotSpeed_[rpm]} * 2*np.pi/60', # new column + } + df2 = remap_df(df, ColMap) + self.assertEqual(list(df2.columns), ['WS_[m/s]', 'RotSpeed_[rpm]', 'RotSpeed_[rad/s]']) + np.testing.assert_allclose(df2['WS_[m/s]'], [8.0, 9.0]) + np.testing.assert_allclose(df2['RotSpeed_[rad/s]'], np.array([10.0, 12.0])*2*np.pi/60) + # The input dataframe is not modified + self.assertEqual(list(df.columns), ['Wind1VelX_[m/s]', 'RotSpeed_[rpm]']) + + def test_remap_postpro(self): + self._check_remap(postpro.remap_df) + + def test_remap_pandalib(self): + self._check_remap(pandalib.remap_df) + + +if __name__ == '__main__': + unittest.main() diff --git a/openfast_toolbox/tools/pandalib.py b/openfast_toolbox/tools/pandalib.py index de3dfdd..0e86e5c 100644 --- a/openfast_toolbox/tools/pandalib.py +++ b/openfast_toolbox/tools/pandalib.py @@ -107,14 +107,16 @@ def remap_df(df, ColMap, bColKeepNewOnly=False, inPlace=False, dataDict=None, ve Found=True # Applying renaming only now so that expressions may be applied in any order + # Index values are read-only with pandas 3, rename through a list + new_cols = list(df.columns) for k,v in RenameMap.items(): if verbose: print('Renaming column {:15s} > {}'.format(v,k)) k=k.strip() - iCol = list(df.columns).index(v) - df.columns.values[iCol]=k + iCol = new_cols.index(v) + new_cols[iCol]=k ColNew.append(k) - df.columns = df.columns.values # Hack to ensure columns are updated + df.columns = new_cols if len(ColMapMiss)>0: print('[FAIL] The following columns were not found in the dataframe:',ColMapMiss)