diff --git a/jarvis/analysis/solarefficiency/solar.py b/jarvis/analysis/solarefficiency/solar.py index 785f7447..c004eb08 100644 --- a/jarvis/analysis/solarefficiency/solar.py +++ b/jarvis/analysis/solarefficiency/solar.py @@ -4,15 +4,18 @@ Please find more detailsin: https://pubs.acs.org/doi/abs/10.1021/acs.chemmater.9b02166 """ + import numpy as np import os from scipy.interpolate import interp1d from numpy import interp import scipy.constants as constants + try: from scipy.integrate import simps -except: +except Exception: from scipy.integrate import simpson as simps + pass import matplotlib.pyplot as plt @@ -73,7 +76,7 @@ def calculate_SQ( # units of W/(m**3), different than solar_spectra_irradiance!!! (This # is intentional, it is for convenience) blackbody_irradiance = ( - 2.0 * h * c ** 2 / (solar_spectra_wavelength_meters ** 5) + 2.0 * h * c**2 / (solar_spectra_wavelength_meters**5) ) * ( 1.0 / ( @@ -113,7 +116,7 @@ def calculate_SQ( ) bandgap_blackbody = ( - (2.0 * h * c ** 2 / (bandgap_wavelength ** 5)) + (2.0 * h * c**2 / (bandgap_wavelength**5)) * ( 1.0 / ( @@ -277,7 +280,7 @@ def slme( # units of W/(m**3), different than solar_spectra_irradiance!!! (This # is intentional, it is for convenience) blackbody_irradiance = ( - 2.0 * h * c ** 2 / (solar_spectra_wavelength_meters ** 5) + 2.0 * h * c**2 / (solar_spectra_wavelength_meters**5) ) * ( 1.0 / ( @@ -302,7 +305,7 @@ def slme( # units of nm material_wavelength_for_absorbance_data = ( (c * h_e) / (material_energy_for_absorbance_data + 0.00000001) - ) * 10 ** 9 + ) * 10**9 # absorbance interpolation onto each solar spectrum wavelength diff --git a/jarvis/analysis/structure/spacegroup.py b/jarvis/analysis/structure/spacegroup.py index f797071c..dd6b9394 100644 --- a/jarvis/analysis/structure/spacegroup.py +++ b/jarvis/analysis/structure/spacegroup.py @@ -12,7 +12,7 @@ try: import spglib -except Exception as exp: +except Exception: # print(exp) pass # from numpy import gcd diff --git a/jarvis/core/utils.py b/jarvis/core/utils.py index 97d65e85..7588fb79 100644 --- a/jarvis/core/utils.py +++ b/jarvis/core/utils.py @@ -1,6 +1,7 @@ """Set of useful utility functions.""" from collections import OrderedDict +from collections import defaultdict from scipy import sparse from scipy.sparse.linalg import spsolve import random @@ -338,7 +339,7 @@ def cos_formula(a, b, c): def baseline_als(y, lam, p, niter=10): """ Adaptive Least Squares fitting for baseline correction - + Parameters: y: array_like Input signal @@ -348,32 +349,39 @@ def baseline_als(y, lam, p, niter=10): Asymmetry niter: int, optional Number of iterations - + Returns: array_like The estimated baseline """ L = len(y) - D = sparse.diags([1,-2,1],[0,-1,-2], shape=(L,L-2)) + D = sparse.diags([1, -2, 1], [0, -1, -2], shape=(L, L - 2)) w = np.ones(L) for i in range(niter): W = sparse.spdiags(w, 0, L, L) Z = W + lam * D.dot(D.transpose()) - z = spsolve(Z, w*y) - w = p * (y > z) + (1-p) * (y < z) + z = spsolve(Z, w * y) + w = p * (y > z) + (1 - p) * (y < z) return z - -def recast_array(x_original = [],y_original = [],x_new = np.arange(0, 90, 1),tol=0.1): - x_original=np.array(x_original) + + +def recast_array( + x_original=[], y_original=[], x_new=np.arange(0, 90, 1), tol=0.1 +): + x_original = np.array(x_original) # Initialize the new y array with NaNs or a default value y_new = np.full_like(x_new, 0, dtype=np.float64) # Fill the corresponding bins for x_val, y_val in zip(x_original, y_original): - closest_index = np.abs(x_new - x_val).argmin() # Find the closest x_new index + closest_index = np.abs( + x_new - x_val + ).argmin() # Find the closest x_new index y_new[closest_index] = y_val - #y_new[y_new