Advertisement
Guest User

Untitled

a guest
Oct 21st, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.19 KB | None | 0 0
  1. from pylab import *
  2.  
  3. # A function for Mackenzie's model of speed of sound in water in m/s
  4. def mackenzie_sos(tempC,depthM,salinityPPT):
  5. sos = 1448.96 + 4.591*tempC - 5.304*(10**-2)*(tempC**2) + 2.374*(10**-4)*(tempC**3) + 1.34*(salinityPPT-35) + 1.63*(10**-2)*depthM + 1.675*(10**-7)*(depthM**2) - 1.025*(10**-2)*tempC*(salinityPPT-35) - 7.139*(10**-13)*tempC*(depthM**3)
  6. return (sos)
  7. # A function for the salinity of seawater in parts per thousand
  8. def sal_of_seawater(latitude):
  9. salinityPPT = (1/45)*latitude + 36
  10. return (salinityPPT)
  11. # A function for the temperature of seawater in degrees Celsius
  12. TempSurfaceZone = 24-(11/45)*latitude # Temperature in the surface zone
  13. def temp_of_seawater(TempSurfaceZone,depthM): # Temperature in the thermocline (dependent on the surface zone temp)
  14. tempC = ((2-TempSurfaceZone)/800)*depthM + (TempSurfaceZone-((2-TempSurfaceZone)/800)*200)
  15. return (tempC)
  16. # A function for the distance to an objected detected using echolocation
  17. def distance_to_object(ReturnTimeSec,sos):
  18. DistanceM = (ReturnTimeSec/2)*sos
  19. return (DistanceM)
  20.  
  21. # A welcome and prompt for patron to enter their preferred complexity for the program's info
  22. print("Welcome to the South Bank Science Museum interactive echolocation program!")
  23. patronType = float(input("Select which level of complexity you would like for information in the program. Enter 0 (simple), 1 (moderate), or 2 (complex): "))
  24.  
  25. # Separate welcome messages and an explanation of latitude for the 3 patron types
  26. if patronType == 1: # Seasoned patron
  27. print("Regular")
  28. print("Latitude is the angle based on the distance somewhere is from the Earth's equator.")
  29. elif patronType == 2: # Grizzled patron
  30. print("Expert")
  31. print("Latitude is the angle between a point on the Earth's surface and point on the surface at the equator. Latitude lines form concentric circles parallel to one another heading from the equator. A latitude in the northern hemisphere may be denoted by either 'N' or '+', and 'S' or '-' in the southern hemisphere.")
  32. else: # Rookie patron
  33. print("Rookie")
  34. print("Latitude is the angle for the distance someone is away from the ring around Earth's widest point called the 'equator'.")
  35.  
  36. # Use of the variable i so the patron has the option to loop back to input another latitude if they desire
  37. i = 1
  38. while i == 1:
  39. # Common info on latitude for the 3 patron types and a prompt to enter the latitude
  40. print("Latitude starts at 0° at the equator and increases going towards the north and south poles where it is 90°, with an 'N' for north and 'S' for south. For example, the latitude in Brisbane is 27.4698° S.")
  41. latitude = float(input("Enter a latitude to explore the sperm whale's echolocation (without the N or S): "))
  42. # Messages if the patron enters a latitude outside the bounds of [0, 90]
  43. if latitude < 0:
  44. print("Sorry, this latitude was below 0. Please enter a value between 0 and 90° to run the program.")
  45. elif latitude > 90:
  46. print("Sorry, this latitude was above 90. Please enter a value between 0 and 90° to run the program.")
  47. else:
  48. salinityPPT = sal_of_seawater(latitude)
  49. print("The salinity at",latitude,"degrees latitude is",salinityPPT,"parts per thousand.")
  50. # Graphing seawater temperature vs depth at the given latitude for the grizzled patron
  51. if patronType == 2:
  52. # Plotting surface zone temperature
  53. DepthSurfaceM = arange(0,201,200)
  54. ArraySurfaceZone = array([TempSurfaceZone, TempSurfaceZone])
  55. plot(DepthSurfaceM, ArraySurfaceZone, linewidth = 2, label="Surface Zone")
  56. # Plotting thermocline temperature
  57. DepthThermoclineM = array([200, 1000.])
  58. XD = (2-TempSurfaceZone)/800 # Expression repeated multiple times in the following equation, storing it in a variable makes the program more efficient
  59. TempThermocline = array([(XD*DepthThermoclineM[0] + TempSurfaceZone-XD*200), (XD*DepthThermoclineM[1] + TempSurfaceZone-XD*200)])
  60. plot(DepthThermoclineM, TempThermocline, linewidth = 2, label="Thermocline")
  61. # Plotting deep zone temperature
  62. DepthDeepM = arange(1000,2001,200)
  63. TempDeepZone = zeros(6)
  64. plot(DepthDeepM, TempDeepZone+2, linewidth = 2, label="Deep Zone")
  65. # Graph communication
  66. title("Temperature vs. Depth at "+str(latitude)+"° Latitude")
  67. xlabel("Depth (m)")
  68. ylabel("Temperature (degrees C)")
  69. grid(True)
  70. legend()
  71. show()
  72.  
  73. # Prompt patron to enter a depth
  74. depthM = float(input("Enter a depth in metres at which you would like to model sperm whale echolocation: "))
  75. # If the depth is in the surface zone
  76. if depthM >= 0 and depthM <= 200:
  77. tempC = TempSurfaceZone
  78. # If the depth is in the thermocline
  79. elif depthM > 200 and depthM < 1000:
  80. tempC = temp_of_seawater(TempSurfaceZone,depthM)
  81. # If the depth is in the deep zone
  82. else:
  83. tempC = 2
  84. # Calculating the speed of sound at patron's input latitude and depth
  85. sos = mackenzie_sos(tempC,depthM,salinityPPT)
  86.  
  87. # Speed of sound, salinity, depth, and temperature data
  88. print("The speed of sound underwater is",round(sos,2),"m/s at",latitude,"° latitude and",depthM,"m depth, where the water is",round(tempC,2),"°C and the salinity is",round(salinityPPT,2),"parts per thousand.")
  89.  
  90. # Separate explanations of return time for the 3 patron types
  91. if patronType == 1: # Seasoned patron
  92. print("Return time is how long the sperm whale waits between it emits a sonar signal and the signal returning.")
  93. elif patronType == 2: # Grizzled patron
  94. print("Return time is the duration of time from when the sperm whale emits its sonar which reflects off an object and returns and is detected by the whale's senses.")
  95. else: # Rookie patron
  96. print("Return time is how long the sperm whale waits after it sends out its sonar signal to when it returns and hears it.")
  97.  
  98. # A loop and conditional so if the patron enters a return time of an object over 50km away, they are told to try again
  99. DistanceM = 50001
  100. while DistanceM > 50000:
  101. ReturnTimeSec = float(input("Enter a return time in seconds (sonar travels very fast, so a small time such as under a 1 minute is ideal): "))
  102. DistanceM = distance_to_object(ReturnTimeSec,sos)
  103. if DistanceM > 50000:
  104. print("The underwater object is too far away!")
  105. else:
  106. print("The sperm whale sends out a sonar signal and hears it",ReturnTimeSec,"seconds later, which means it detects an underwater object",round(DistanceM,0),"m away.")
  107.  
  108. # i == 1 means the program loops back to where the patron can enter another latitude
  109. i = i + float(input("Would you like to explore sperm whale echolocation at another latitude? If YES, enter 0; if NO, enter any other number: "))
  110.  
  111. # Farewell message
  112. print("Thank you for using the South Bank Science Museum sperm whale echolocation program!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement