PyESPER 1.0.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,105 @@
1
+ def process_netresults(Equations, code={}, df={}, EstAtl={}, EstOther={}):
2
+
3
+ """
4
+ Regional smoothing and processing net outputs
5
+
6
+ Inputs:
7
+ Equations: List of equations to use
8
+ code: Dictionary of input for each equation-variable scenario
9
+ df: Dictionary of coordinates and boolean indicators for regions
10
+ EstAtl: Dictionary of estimates for the Atlantic and Arctic
11
+ for each combination
12
+ EstOther: Dictionary of estimates for not Atlantic and Arctic,
13
+ for each combination
14
+
15
+ Output:
16
+ Estimate: Dictionary of estimates for each combination
17
+ """
18
+
19
+ import numpy as np
20
+
21
+ # Function to provide the mean of values when needed
22
+ def process_estimates(estimates):
23
+ keys = list(estimates.keys())
24
+ values = list(estimates.values())
25
+ result = {}
26
+ for i, key in enumerate(keys):
27
+ result[key] = [np.mean(values[i][v]) for v in range(len(values[0]))]
28
+ return result
29
+
30
+ Esta = process_estimates(EstAtl)
31
+ Esto = process_estimates(EstOther)
32
+
33
+ # Processing regionally in the Atlantic and Bering
34
+ EstA, EstB, EB2, ESat, ESat2, ESaf, Estimate = {}, {}, {}, {}, {}, {}, {}
35
+
36
+ for i in code:
37
+ code[i]["AAInds"] = df["AAInds"]
38
+ code[i]["BeringInds"] = df["BeringInds"]
39
+ code[i]["SAtlInds"] = df["SAtlInds"]
40
+ code[i]["SoAfrInds"] = df["SoAfrInds"]
41
+
42
+ for codename, codedata in code.items():
43
+ # Defining empty lists for data from each regions
44
+ Estatl, Estb, eb2, Estsat, esafr = [], [], [], [], []
45
+ aainds, beringinds, satlinds, latitude, safrinds = (
46
+ codedata[key] for key in ["AAInds", "BeringInds", "SAtlInds", "Latitude", "SoAfrInds"]
47
+ )
48
+ Estatl = [Esta[codename][i] if aa_ind else Esto[codename][i] for i, aa_ind in enumerate(aainds)]
49
+
50
+ # Smoothing for the Atlantic
51
+ for lenatl in range(0, len(Estatl)):
52
+ repeated_values = (latitude[lenatl]-62.5)/7.5
53
+ B = np.tile(repeated_values, (1, len(Equations)))
54
+ C = Esta[codename][lenatl]
55
+ B1 = C * B
56
+ repeated_values2 = (70-latitude[lenatl])/7.5
57
+ D = np.tile(repeated_values2, (1, len(Equations)))
58
+ E = Esto[codename][lenatl]
59
+ B2 = E * D
60
+ Estb.append(B1[0][0] + B2[0][0])
61
+
62
+ eb2 = [Estb[j] if b_ind else Estatl[j] for j, b_ind in enumerate(beringinds)]
63
+ # Smoothing for the Bering
64
+ for n in range(0, len(satlinds)):
65
+ repeated_values = (latitude[n]+44)/10
66
+ F1 = Esta[codename][n]
67
+ F = np.tile(repeated_values, (1, len(Equations)))
68
+ G1 = F1 * F
69
+ repeated_values2 = (-34-latitude[n])/10
70
+ H1 = Esto[codename][n]
71
+ H = np.tile(repeated_values2, (1, len(Equations)))
72
+ G2 = H1 * H
73
+ Estsat.append(G1[0][0] + G2[0][0])
74
+
75
+ EstA[codename], EstB[codename], EB2[codename], ESat[codename] = Estatl, Estb, eb2, Estsat
76
+
77
+ # Regional processing for S. Atlantic
78
+ ESat2[codename] = [
79
+ ESat[codename][i] if satlinds[i] == "True" else EB2[codename][i]
80
+ for i in range(len(satlinds))
81
+ ]
82
+
83
+ # Regional processing for S. Africa
84
+ for s in range(0, len(safrinds)):
85
+ repeated_values = (27-df["Lon"][s])/8
86
+ F1 = ESat2[codename][s]
87
+ F = np.tile(repeated_values, (1, len(Equations)))
88
+ G1 = F1*F
89
+ repeated_values2 = (df["Lon"][s]-19)/8
90
+ H1 = Esto[codename][s]
91
+ H = np.tile(repeated_values2, (1, len(Equations)))
92
+ G2 = H1 * H
93
+ esafr.append(G1[0][0] + G2[0][0])
94
+
95
+ ESaf[codename] = esafr
96
+
97
+ Estimate[codename] = [
98
+ ESaf[codename][i] if safrinds[i] == "True" else ESat2[codename][i]
99
+ for i in range(len(safrinds))
100
+ ]
101
+
102
+ # Bookkeeping blanks back to NaN as needed
103
+ Estimate = {k: ('NaN' if v == '' else v) for k, v in Estimate.items()}
104
+
105
+ return Estimate
PyESPER/run_nets.py ADDED
@@ -0,0 +1,85 @@
1
+ def run_nets(DesiredVariables, Equations, code={}):
2
+
3
+ """
4
+ Running neural nets
5
+
6
+ Inputs:
7
+ DesiredVariables: List of variables for estimates
8
+ Equations: List of desired equations
9
+ code: Dictionary of preprocessed measurements
10
+
11
+ Outputs:
12
+ EstAtl: Dictionary of estimates for the Atlantic and Arctic
13
+ Oceans
14
+ EstOther: Dictionary of estimates for not Altnatic/Arctic
15
+ """
16
+
17
+ import importlib
18
+ import numpy as np
19
+
20
+ # Predefining dictionaries to populate
21
+ EstAtl, EstOther = {}, {}
22
+ P, Sd, Td, Ad, Bd, Cd = {}, {}, {}, {}, {}, {}
23
+
24
+ # Calculating inputs for nets and formatting them
25
+ for name, value in code.items():
26
+ cosd = np.cos(np.deg2rad(value["Longitude"] - 20)).tolist()
27
+ sind = np.sin(np.deg2rad(value["Longitude"] - 20)).tolist()
28
+ lat, depth = value["Latitude"].tolist(), value["Depth"].tolist()
29
+ # Convert columns to lists of floats
30
+ Sd[name] = value["S"].astype(float).tolist()
31
+ Td[name] = value["T"].astype(float).tolist()
32
+ Ad[name] = value["A"].astype(float).tolist()
33
+ Bd[name] = value["B"].astype(float).tolist()
34
+ Cd[name] = value["C"].astype(float).tolist()
35
+
36
+ # Define a mapping from equations to the list of variables
37
+ equation_map = {
38
+ 1: ["Sd", "Td", "Ad", "Bd", "Cd"],
39
+ 2: ["Sd", "Td", "Ad", "Cd"],
40
+ 3: ["Sd", "Td", "Bd", "Cd"],
41
+ 4: ["Sd", "Td", "Cd"],
42
+ 5: ["Sd", "Td", "Ad", "Bd"],
43
+ 6: ["Sd", "Td", "Ad"],
44
+ 7: ["Sd", "Td", "Bd"],
45
+ 8: ["Sd", "Td"],
46
+ 9: ["Sd", "Ad", "Bd", "Cd"],
47
+ 10: ["Sd", "Ad", "Cd"],
48
+ 11: ["Sd", "Bd", "Cd"],
49
+ 12: ["Sd", "Cd"],
50
+ 13: ["Sd", "Ad", "Bd"],
51
+ 14: ["Sd", "Ad"],
52
+ 15: ["Sd", "Bd"],
53
+ 16: ["Sd"]
54
+ }
55
+
56
+ # Create the correct vector for each equation case
57
+ for e in Equations:
58
+ for v in DesiredVariables:
59
+ name = v + str(e)
60
+ # Get the corresponding variables for the equation
61
+ variables = [locals()[var][name] for var in equation_map[e]]
62
+ P[name] = [[[cosd, sind, lat, depth] + variables]]
63
+ netstimateAtl, netstimateOther = [], []
64
+ for n in range(1, 5):
65
+ fOName = f"NeuralNetworks.ESPER_{v}_{e}_Other_{n}"
66
+ fAName = f"NeuralNetworks.ESPER_{v}_{e}_Atl_{n}"
67
+ moda = importlib.import_module(fAName)
68
+ modo = importlib.import_module(fOName)
69
+ from importlib import reload
70
+ reload(moda)
71
+ reload(modo)
72
+ # Running the nets
73
+ netstimateAtl.append(moda.PyESPER_NN(P[name]))
74
+ netstimateOther.append(modo.PyESPER_NN(P[name]))
75
+
76
+ # Process estimates for Atlantic and Other regions
77
+ EstAtlL = [[netstimateAtl[na][0][eatl] for na in range(4)] for eatl in range(len(netstimateAtl[0][0]))]
78
+ EstOtherL = [[netstimateOther[no][0][eoth] for no in range(4)] for eoth in range(len(netstimateOther[0][0]))]
79
+
80
+ # Store the result
81
+ EstAtl[name] = EstAtlL
82
+ EstOther[name] = EstOtherL
83
+
84
+ return EstAtl, EstOther
85
+
@@ -0,0 +1,43 @@
1
+ def simplecantestimatelr(EstDates, longitude, latitude, depth):
2
+
3
+ """
4
+ Simple estimate of contribution of anthropogenic carbon to pH and DIC estimates.
5
+
6
+ Inputs:
7
+ EstDates: List of dates for which estimates will be made
8
+ longitude:
9
+
10
+ Ouptuts:
11
+ CantMeas: List of anthropogenic carbon estimates
12
+ Cant2002: List of anthropogenic carbon estimates for 2002
13
+ """
14
+
15
+ import numpy as np
16
+ import pandas as pd
17
+ from scipy.interpolate import griddata
18
+
19
+ # Load interpolation points and values
20
+ CantIntPoints = pd.read_csv('SimpleCantEstimateLR_full.csv')
21
+ pointsi = (
22
+ CantIntPoints['Int_long'] * 0.25,
23
+ CantIntPoints['Int_lat'],
24
+ CantIntPoints['Int_depth'] * 0.025,
25
+ )
26
+ values = CantIntPoints['values']
27
+
28
+ # Scale input coordinates
29
+ pointso = (
30
+ np.array(longitude) * 0.25,
31
+ np.array(latitude),
32
+ np.array(depth) * 0.025,
33
+ )
34
+
35
+ # Interpolate and compute Cant2002
36
+ Cant2002 = griddata(pointsi, values, pointso, method='linear')
37
+
38
+ # Adjust for estimation dates
39
+ EstDates = np.asarray(EstDates)
40
+ CantMeas = Cant2002 * np.exp(0.018989 * (EstDates - 2002))
41
+
42
+ return CantMeas, Cant2002
43
+
@@ -0,0 +1,48 @@
1
+ def temperature_define(
2
+ DesiredVariables,
3
+ PredictorMeasurements,
4
+ InputAll,
5
+ **kwargs
6
+ ):
7
+
8
+ """
9
+ A small function to define temperature as needed and adjust
10
+ InputAll and PredictorMeasurements acccordingly.
11
+
12
+ Inputs:
13
+ DesiredVariables: List of desired output variables
14
+ PredictorMeasurements: Dictionary of user input measurements for predictors
15
+ InputAll: Dictionary of pre-adjusted and combined input and defined data
16
+ **kwargs: Please see README for more information
17
+
18
+ Ouputs:
19
+ PredictorMeasurements: Dictionary of user input measurements, adjusted for temperature
20
+ as needed
21
+ InputAll: Combined and processed necessary data to run the LIR, adjusted now for
22
+ temperature as needed
23
+ """
24
+
25
+ import numpy as np
26
+
27
+ n = max(len(v) for v in PredictorMeasurements.values()) # Recalculating number of required estimates
28
+
29
+ # Printing a custom warning if temperature is absent but needed
30
+ if "EstDates" in kwargs and "pH" in DesiredVariables:
31
+ if "temperature" not in PredictorMeasurements:
32
+ print(
33
+ "Warning: Carbonate system calculations will be used to adjust the pH, but no temperature is"
34
+ "specified so 10 C will be assumed. If this is a poor estimate for your region, consider supplying"
35
+ "your own value in the PredictorMeasurements input."
36
+ )
37
+ # Assuming temperature is 10 C if not defined
38
+ Temperature = np.full(n, 10)
39
+ else:
40
+ # Reading in temperature if defined
41
+ Temperature = np.array(InputAll["Temperature"])
42
+
43
+ # Adjusting dictionaries for the updated temperature definition
44
+ PredictorMeasurements["temperature"] = Temperature
45
+ InputAll["temperature"] = Temperature
46
+
47
+ return PredictorMeasurements, InputAll
48
+
@@ -0,0 +1,16 @@
1
+ Metadata-Version: 2.4
2
+ Name: PyESPER
3
+ Version: 1.0.0
4
+ Summary: Python version of ESPERv1
5
+ Author: LMD
6
+ Author-email: lmdias@uw.edu
7
+ Requires-Dist: numpy
8
+ Requires-Dist: seawater
9
+ Requires-Dist: scipy
10
+ Requires-Dist: matplotlib
11
+ Requires-Dist: PyCO2SYS
12
+ Requires-Dist: pandas
13
+ Dynamic: author
14
+ Dynamic: author-email
15
+ Dynamic: requires-dist
16
+ Dynamic: summary
@@ -0,0 +1,33 @@
1
+ PyESPER/__init__.py,sha256=YnGqTco75ge10rdvEZXdS_zKR3yzSg6a1eVtD2BYqSs,1140
2
+ PyESPER/adjust_pH_DIC.py,sha256=k5VVI-QxOF2ySQjevvph8V769QoJ-gXo7RwpS8whLv8,3278
3
+ PyESPER/coefs_AAinds.py,sha256=ay8VWvd2ijYl4Z8w6PJqrNqz2V_BxBLzFJAgLMFHLXM,2091
4
+ PyESPER/defaults.py,sha256=-8oX8Zc43ga74DZDgR3isOcBDpeVP_wLHQILfCtQTio,3141
5
+ PyESPER/define_polygons.py,sha256=c3DbtwrdF5HhZ3WAqp76h3Xt22sRitZ-HkP7iT6QsuQ,2798
6
+ PyESPER/emlr_estimate.py,sha256=ZErziQzl1oVoYXMr0Q7JZ5ruYy1kLq4TBjVBhSElfd0,6177
7
+ PyESPER/emlr_nn.py,sha256=o2tDMXMKyDTvIBjvw4UBQKJQZU-POet1uobcXYcCGhw,1583
8
+ PyESPER/errors.py,sha256=ApDeJOdXyDNMj2dgcL1JI6QLuXD7AYfWntHe1lM5qTA,2486
9
+ PyESPER/fetch_data.py,sha256=GpLRRCzBboZ8h61ZE7kE-SFSBjk-xc0YbLipxyvDQ_A,1698
10
+ PyESPER/fetch_polys_NN.py,sha256=qJMCAjBsWI0_xq72cs_BXCKRYvmFoWn0BXJkj9O3Gd8,413
11
+ PyESPER/final_formatting.py,sha256=kcpttKqMUo4bruGiWGhqO_iZFpNVvGuj-4WNOUYaV_Y,828
12
+ PyESPER/input_AAinds.py,sha256=I_drT8gQPd4U_iTR2s4KZNNqM-dSNo-7d7-Y8Nom1DM,4721
13
+ PyESPER/inputdata_organize.py,sha256=F41OHSD7TeA9PYNx44O9Tt1F2gH0OyZ4NFL_zjAZCNs,1734
14
+ PyESPER/interpolate.py,sha256=yL-4ePBQRbujq6aSeudlh65ArFsu5SxfuiGFtBRajLg,2283
15
+ PyESPER/iterations.py,sha256=UgInZxYIZEjlbLhhDCxHAAqu492wyjLOV4RQN7wHhz0,11016
16
+ PyESPER/lir.py,sha256=uKOMCMZeeKu69mO0Cj4m8ctz7U5BhzmxGUctwtryIpI,5966
17
+ PyESPER/lir_uncertainties.py,sha256=PbedM_F-G1vQa1kdx9B6LdnYQ1NZV5vxZxRqItiyacI,4212
18
+ PyESPER/mixed.py,sha256=TO1VVF0nBBAYzLuSwqVL4s7-5RN0gq_NUH9W_T2cUzY,1877
19
+ PyESPER/nn.py,sha256=tJX2ziBe2zg7uqHD6w0trdkpwl6UnJ2_EFV48ZWKqlI,4244
20
+ PyESPER/organize_data.py,sha256=40rBZT7PUWXnO2PzhniOjzGgYT5rRxzr3RNAN4OgqEE,15422
21
+ PyESPER/organize_nn_output.py,sha256=j2gZyrDOUq3x7RU9G3XyVhYNrsrJctU3EFvJBOh33OE,8754
22
+ PyESPER/pH_DIC_nn_adjustment.py,sha256=hE6tcW0ma-5MChycWC0I1wArmgg7ccOHTgaqBhKy6V4,8346
23
+ PyESPER/pH_adjcalc.py,sha256=hj-dm4RAQFChzK0OS2tmVmkr3B_c5kb60EVSuNakQQw,1392
24
+ PyESPER/pH_adjustment.py,sha256=JattOCeBY5lle0KXYOlVI4IXuAeU9EqKelscMKxWYbQ,7806
25
+ PyESPER/process_netresults.py,sha256=8azrlkL8UrXmIBgQusXnQjaCNRAOkk1g92HfuvW9H28,4064
26
+ PyESPER/run_nets.py,sha256=vD-cnIe0gmOkLwun1dI6o3Ima7WoLDdmxg1ns7rwP00,3221
27
+ PyESPER/simplecantestimatelr.py,sha256=tKLbP8INYYgngfqHSOL_nhqYFXVIAi4BG4HGBpDArp0,1202
28
+ PyESPER/temperature_define.py,sha256=d6iEVwtvDLPNPQKWN4e-pWmI4E8i10aTVnQDQiann4A,1879
29
+ pyesper-1.0.0.dist-info/METADATA,sha256=lmdWzuq2oSR5yj7QKnovay4B6QVCGfVAjs3_7D1S-XI,342
30
+ pyesper-1.0.0.dist-info/WHEEL,sha256=lTU6B6eIfYoiQJTZNc-fyaR6BpL6ehTzU3xGYxn2n8k,91
31
+ pyesper-1.0.0.dist-info/entry_points.txt,sha256=HUU4cSedQ0gjEPqylS2XRZyJYlfQorLWqz7Giyj-H20,74
32
+ pyesper-1.0.0.dist-info/top_level.txt,sha256=TlLY5TlArHVpCWb0rItFEzqlQtDSwpNU-Aq1NcZeUMI,8
33
+ pyesper-1.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (78.1.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,4 @@
1
+ [console_scripts]
2
+ lir = PyESPER:lir
3
+ mixed = PyESPER:mixed
4
+ nn = PyESPER:nn
@@ -0,0 +1 @@
1
+ PyESPER