Notebook
connection = engine.connect()def Sal_PSU_to_SA(S,press,lon,lat): SA=gsw.SA_from_SP(S,press,lon,lat) if SA>=40: print('Err: SA=',SA,', None entered') SA=None elif SA<0: SA=None print('Err: SA=',SA,', None entered') return(SA) def T_to_CT(SA,T,press): CT=gsw.CT_from_t(SA,T,press) if CT>=40: print('Err: CT=',CT,', None entered') CT=None elif CT<-5: CT=None print('Err: CT=',CT,', None entered') return(CT) def p_to_Z(press,lat): Z=-1.0*gsw.z_from_p(press,lat) return(Z) connection.connection.create_function("Sal_PSU_to_SA_DB",4,Sal_PSU_to_SA) connection.connection.create_function("T_to_CT_DB",3,T_to_CT) connection.connection.create_function("p_to_Z_DB",2,p_to_Z)connection.execute("""UPDATE CalcsTBL SET Temperature_CT = T_to_CT_DB(CalcsTBL.Salinity_SA,ObsTBL.Temperature,ObsTBL.Pressure), Temperature_Primary_CT = T_to_CT_DB(CalcsTBL.Salinity_T0_C0_SA,ObsTBL.Temperature,ObsTBL.Pressure), Temperature_Secondary_CT = T_to_CT_DB(CalcsTBL.Salinity_T1_C1_SA,ObsTBL.Temperature,ObsTBL.Pressure), FROM ((CalcsTBL INNER JOIN ObsTBL ON CalcsTBL.ObsID = ObsTBL.ID) INNER JOIN StationTBL ON CalcsTBL.StationID = StationTBL.ID)""")test=connection.execute("""SELECT T_to_CT_DB( CASE WHEN CalcsTBL.Salinity_T1_C1_SA IS NOT NULL THEN CalcsTBL.Salinity_T1_C1_SA WHEN CalcsTBL.Salinity_T0_C0_SA IS NOT NULL THEN CalcsTBL.Salinity_T0_C0_SA WHEN CalcsTBL.Salinity_SA IS NOT NULL THEN CalcsTBL.Salinity_SA ELSE NULL END,ObsTBL.Temperature,ObsTBL.Pressure) as T1, T_to_CT_DB( CASE WHEN CalcsTBL.Salinity_T1_C1_SA IS NOT NULL THEN CalcsTBL.Salinity_T1_C1_SA WHEN CalcsTBL.Salinity_T0_C0_SA IS NOT NULL THEN CalcsTBL.Salinity_T0_C0_SA WHEN CalcsTBL.Salinity_SA IS NOT NULL THEN CalcsTBL.Salinity_SA ELSE NULL END,ObsTBL.Temperature,ObsTBL.Pressure) as T2, T_to_CT_DB( CASE WHEN CalcsTBL.Salinity_T1_C1_SA IS NOT NULL THEN CalcsTBL.Salinity_T1_C1_SA WHEN CalcsTBL.Salinity_T0_C0_SA IS NOT NULL THEN CalcsTBL.Salinity_T0_C0_SA WHEN CalcsTBL.Salinity_SA IS NOT NULL THEN CalcsTBL.Salinity_SA ELSE NULL END,ObsTBL.Temperature,ObsTBL.Pressure) as T3 FROM CalcsTBL INNER JOIN ObsTBL ON CalcsTBL.ObsID = ObsTBL.ID INNER JOIN StationTBL ON CalcsTBL.StationID = StationTBL.ID;""") ii=0 for row in test: ii=ii+1 if (ii>100)&(ii<120): print(row)