Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- # Filename: metal_albedo_analysis_tool.py
- # Version: 1.0.0
- # Author: Jeoi Reqi
- """
- Description:
- - This script provides a comprehensive suite of tools for analyzing metal properties, focusing on albedo and index of refraction (IOR).
- - Albedo refers to the proportion of incident light that is reflected by a surface, making it a crucial factor in determining the visual appearance of metals.
- - Index of refraction (IOR) quantifies how light bends as it passes through a material, influencing its optical properties such as reflection and refraction.
- - By leveraging the provided functionalities, users can explore and understand the albedo characteristics of various metals.
- - Users can also compare the metal IOR values to gain insights into their optical behaviors.
- - This script also outputs the difference in value of the compared metal IOR to the terminal.
- Requirements:
- - Python 3.x
- - Matplotlib library for data visualization
- Functions:
- - visualize_metal_colors():
- Visualizes metal colors by plotting their albedo.
- - display_metal_data():
- Displays the available metal data as a numbered list.
- - calculate_albedo():
- Calculates the albedo of a specific metal selected by the user.
- - compare_ior(metal1, metal2):
- Compares the index of refraction between two metals selected by the user.
- Usage:
- - Run the script in a Python environment.
- - Follow the on-screen menu options to choose between different functionalities.
- - Enter the appropriate input as prompted to perform desired actions.
- Example Output:
- :: MENU OPTIONS ::
- 1. Visualize Metal Colors
- 2. Calculate Albedo
- 3. Compare Index of Refraction
- 0. Exit
- Enter your choice (1-3) or type '0' to exit: 3
- Metal data:
- 1. Silver
- 2. Gold
- 3. Copper
- 4. Aluminium
- 5. Chromium
- 6. Lead
- 7. Platinum
- 8. Titanium
- 9. Tungsten
- 10. Iron
- 11. Vanadium
- 12. Zinc
- 13. Nickel
- 14. Mercury
- 15. Cobalt
- Enter the number of the first metal: 7
- Enter the number of the second metal: 12
- Platinum has a higher Index of Refraction (1.0240) than Zinc (1.0110).
- The difference is 0.0130.
- Additional Notes:
- - Metal data includes information such as RGB values and index of refraction.
- - The script utilizes Matplotlib for data visualization.
- - Users can interactively explore metal properties and compare them using this tool.
- """
- import matplotlib.pyplot as plt
- # Metal data
- metal_data = {
- "Silver": {"Red_ACEScg": 0.758765, "Green_ACEScg": 0.755048, "Blue_ACEScg": 0.752412, "IOR": 1.082},
- "Gold": {"Red_ACEScg": 0.659051, "Green_ACEScg": 0.458738, "Blue_ACEScg": 0.123940, "IOR": 1.35002},
- "Copper": {"Red_ACEScg": 0.614256, "Green_ACEScg": 0.298303, "Blue_ACEScg": 0.213841, "IOR": 1.21901},
- "Aluminium": {"Red_ACEScg": 0.618401, "Green_ACEScg": 0.672947, "Blue_ACEScg": 0.682368, "IOR": 1.002},
- "Chromium": {"Red_ACEScg": 0.140349, "Green_ACEScg": 0.140349, "Blue_ACEScg": 0.140349, "IOR": 1.03},
- "Lead": {"Red_ACEScg": 0.264084, "Green_ACEScg": 0.265443, "Blue_ACEScg": 0.277903, "IOR": 1.016},
- "Platinum": {"Red_ACEScg": 0.654022, "Green_ACEScg": 0.616726, "Blue_ACEScg": 0.377176, "IOR": 1.024},
- "Titanium": {"Red_ACEScg": 0.699456, "Green_ACEScg": 0.637539, "Blue_ACEScg": 0.297492, "IOR": 1.086},
- "Tungsten": {"Red_ACEScg": 0.505142, "Green_ACEScg": 0.283667, "Blue_ACEScg": 0.179808, "IOR": 1.007},
- "Iron": {"Red_ACEScg": 0.456733, "Green_ACEScg": 0.434045, "Blue_ACEScg": 0.262660, "IOR": 1.006},
- "Vanadium": {"Red_ACEScg": 0.644844, "Green_ACEScg": 0.523107, "Blue_ACEScg": 0.196363, "IOR": 1.034},
- "Zinc": {"Red_ACEScg": 0.423637, "Green_ACEScg": 0.418052, "Blue_ACEScg": 0.409058, "IOR": 1.011},
- "Nickel": {"Red_ACEScg": 0.457723, "Green_ACEScg": 0.399388, "Blue_ACEScg": 0.169834, "IOR": 1.016},
- "Mercury": {"Red_ACEScg": 0.167639, "Green_ACEScg": 0.167639, "Blue_ACEScg": 0.167639, "IOR": 1.013},
- "Cobalt": {"Red_ACEScg": 0.071277, "Green_ACEScg": 0.045923, "Blue_ACEScg": 0.015718, "IOR": 1.031},
- }
- # Function to visualize metal colors
- def visualize_metal_colors():
- """
- Visualizes metal colors by plotting their albedo.
- """
- # Initialize empty lists to store metal names and their respective albedo values
- color_values = [] # List to store albedo values
- metal_names = [] # List to store metal names
- # Iterate through the metal_data dictionary to extract metal names and albedo values
- for metal_name, metal_data_single in metal_data.items(): # Change variable name here
- metal_names.append(metal_name) # Append the metal name to the metal_names list
- # Calculate the average albedo by summing up the RGB values and dividing by 3
- albedo = (metal_data_single["Red_ACEScg"] + metal_data_single["Green_ACEScg"] + metal_data_single["Blue_ACEScg"]) / 3
- color_values.append(albedo) # Append the calculated albedo to the color_values list
- # Plotting the metal albedo values as a horizontal bar chart
- plt.figure(figsize=(10, 6)) # Set the figure size
- plt.title('Metal Albedo') # Set the title of the plot
- plt.barh(metal_names, color_values, color='steelblue') # Create a horizontal bar chart
- plt.xlabel('Albedo') # Set the label for the x-axis
- plt.ylabel('Metal') # Set the label for the y-axis
- plt.grid(axis='x') # Add gridlines along the x-axis
- plt.show() # Display the plot
- # Function to display metal data as a numbered list
- def display_metal_data():
- """
- Displays the metal data as a numbered list.
- """
- print("\nMetal data:")
- # Step 1: Iterate through metal_data dictionary and enumerate items
- for index, (metal_name, _) in enumerate(metal_data.items(), start=1):
- metal_index = f"{index:2}" # Pad single digits with a space
- # Step 2: Print metal index and name
- print(f"{metal_index}. {metal_name}")
- # Function to calculate the albedo of a specific metal
- def calculate_albedo():
- """
- Calculates the albedo of a specific metal selected by the user.
- """
- display_metal_data() # Step 1: Display the list of metals
- metal_index_str = input("\nEnter the number of the metal: ")
- try:
- metal_index = int(metal_index_str)
- if 1 <= metal_index <= len(metal_data):
- metal_name = list(metal_data.keys())[metal_index - 1]
- metal_single = metal_data[metal_name]
- # Step 2: Calculate the albedo using RGB values
- albedo = (metal_single["Red_ACEScg"] + metal_single["Green_ACEScg"] + metal_single["Blue_ACEScg"]) / 3
- print(f"\nThe albedo of {metal_name} is: {albedo:.4f}")
- else:
- print("\nInvalid metal number!")
- except ValueError:
- print("\nInvalid input! Please enter a valid number.")
- # Function to compare the index of refraction between two metals
- def compare_ior(metal1_str, metal2_str):
- """
- Compares the Index of Refraction between two metals selected by the user.
- """
- try:
- metal1_index = int(metal1_str)
- metal2_index = int(metal2_str)
- if 1 <= metal1_index <= len(metal_data) and 1 <= metal2_index <= len(metal_data):
- metal1_name = list(metal_data.keys())[metal1_index - 1]
- metal2_name = list(metal_data.keys())[metal2_index - 1]
- metal1_data = metal_data[metal1_name]
- metal2_data = metal_data[metal2_name]
- if metal1_data["IOR"] > metal2_data["IOR"]:
- # Step 1: Print comparison result if metal1's IOR is higher
- print(f"\n{metal1_name} has a higher Index of Refraction ({metal1_data['IOR']:.4f}) than {metal2_name} ({metal2_data['IOR']:.4f}).")
- print(f"The difference is {metal1_data['IOR'] - metal2_data['IOR']:.4f}.")
- elif metal1_data["IOR"] < metal2_data["IOR"]:
- # Step 2: Print comparison result if metal2's IOR is higher
- print(f"\n{metal2_name} has a higher Index of Refraction ({metal2_data['IOR']:.4f}) than {metal1_name} ({metal1_data['IOR']:.4f}).")
- print(f"The difference is {metal2_data['IOR'] - metal1_data['IOR']:.4f}.")
- else:
- # Step 3: Print if both metals have equal IOR
- print(f"\nThe Index of Refraction of {metal1_name} ({metal1_data['IOR']:.4f}) and {metal2_name} ({metal2_data['IOR']:.4f}) are equal.")
- else:
- print("\nInvalid metal numbers!")
- except ValueError:
- print("\nInvalid input! Please enter valid numbers.")
- print() # Add a blank line for clarity
- # Menu-driven interface
- while True:
- print("\n:: MENU OPTIONS ::\n")
- print("1. Visualize Metal Colors")
- print("2. Calculate Albedo")
- print("3. Compare Index of Refraction")
- print("0. Exit")
- choice = input("\nEnter your choice (1-3) or type '0' to exit: ")
- if choice == '1':
- # Print the full metal data to the terminal in a formatted manner
- print("\nMetal Data:")
- for metal, data in metal_data.items():
- rgb_values = ', '.join([f"{color[0]}={value:.6f}" for color, value in data.items() if color != 'IOR'])
- print(f"{metal}: R={data['Red_ACEScg']:.6f}, G={data['Green_ACEScg']:.6f}, B={data['Blue_ACEScg']:.6f} IOR: {data['IOR']:.4f}")
- visualize_metal_colors()
- elif choice == '2':
- calculate_albedo()
- elif choice == '3':
- display_metal_data()
- metal1 = input("\nEnter the number of the first metal: ")
- metal2 = input("\nEnter the number of the second metal: ")
- compare_ior(metal1, metal2)
- elif choice == '0':
- print("\nExiting program... GoodBye!\n")
- break # Exit the program immediately
- else:
- print("\nInvalid choice! Please enter a valid option.\n")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement