Skip to content

Commit 9638f33

Browse files
committed
Many minor code changes
1 parent 581ae67 commit 9638f33

25 files changed

+202
-182
lines changed

.github/workflows/run_tests.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,20 @@ jobs:
1818
python-version: ${{ matrix.python-version }}
1919
- name: Display Python version
2020
run: python -c "import sys; print(sys.version)"
21+
- name: Build dplpy
22+
run: |
23+
python -m pip install -U pip build
24+
python -m build
2125
- name: Install dependencies
2226
run: |
2327
python -m pip install --upgrade pip
2428
pip install -r ${{ matrix.python-version }}-requirements.txt
2529
pip install pytest pytest-cov
30+
pip install ruff
31+
- name: Lint with Ruff
32+
run: |
33+
ruff --output-format=github .
34+
continue-on-error: true
2635
- name: Run unit tests
2736
run: |
2837
pytest tests/unit --cov=dplpy

dplpy/autoreg.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ def autoreg(data: pd.Series, max_lag=5):
158158
# given an array containing the original data and the parameters for
159159
# the AR model
160160
def fitted_values(data_series, params):
161-
mean = np.mean(data_series)
162161
results = []
163162

164163
for i in range((len(params)-1), len(data_series)):

dplpy/chron.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ def plot_chron(years, depths, means, whitened_means):
167167
# create figure and axis objects with subplots()
168168
fig,ax = plt.subplots()
169169

170-
if whitened_means != None:
170+
if whitened_means is not None:
171171
y_val = whitened_means
172172
y_label = "Mean Res"
173173
else:

dplpy/create_json.py

Lines changed: 93 additions & 93 deletions
Original file line numberDiff line numberDiff line change
@@ -33,97 +33,97 @@
3333

3434
def create_json(input):
3535

36-
with open("input", "r" ) as rings:
37-
data= rings.read()
38-
lines = data.split("\n")
39-
print (lines[0-2])
40-
# read every single line
41-
for rows in lines:
42-
print (rows)
36+
with open("input", "r" ) as rings:
37+
data= rings.read()
38+
lines = data.split("\n")
39+
print (lines[0-2])
40+
# read every single line
41+
for rows in lines:
42+
print (rows)
43+
44+
# remove empty lines from the file.
45+
46+
# convert every element in each list to string- it is easier to manupilate the elements
47+
48+
for items in lines:
49+
str(items)
50+
51+
# State/province
52+
state_province = lines[1,3]
53+
54+
# country
55+
country= lines[0,2]
56+
57+
# species
58+
species = lines[1,4]
59+
60+
# species code
61+
species_code= lines[1,5]
62+
63+
# start year- start of collection
64+
start_date = int(lines[1,6])
65+
66+
# end year- completion year
67+
end_year = int(lines[1,7])
68+
69+
# latitude, longitude, elevation
70+
latitude = lines[2,4]
71+
longitude = lines[2,5]
72+
73+
# lead investigator
74+
lead_investigator= lines[2,2]
75+
76+
# site_id
77+
# Via indexing the first three digits of the site id are assigned to var named site_code and the rest to information.
78+
# Check if all the site codes are the same for the whole dataset
79+
for site_code in lines:
80+
current=0
81+
information=0
82+
site_id=0
83+
unit = 0
84+
while current >=0 and current<=len(lines)-1:
85+
if current <=3:
86+
site_code = lines[current,0,0]
87+
if current>=4 and current<=len(lines)-1:
88+
if lines[current,0,0] == lines[4,0,0]:
89+
site_id = lines[current,0,0]
90+
information = site_id[3::]
91+
site_id= site_code + information
92+
#data
93+
data=[]
94+
y=1
95+
past= y-1
96+
end=[current,-1]
97+
if site_id == lines[current,0] and start_date <= int(lines[current]):
98+
for points in lines[current,2:]:
99+
pts=[]
100+
pts.append(points)
101+
# End of data collection for that year
102+
if points== "999" or points== "-9999":
103+
pts[:-1]
104+
data.append(pts)
105+
pts=0
106+
unit = points
107+
else:
108+
current = current + 1
109+
pts=0
43110

44-
# remove empty lines from the file.
45-
46-
# convert every element in each list to string- it is easier to manupilate the elements
47-
48-
for items in lines:
49-
str(items)
50-
51-
# State/province
52-
state_province = lines[1,3]
53-
54-
# country
55-
country= lines[0,2]
56-
57-
# species
58-
species = lines[1,4]
59-
60-
# species code
61-
species_code= lines[1,5]
62-
63-
# start year- start of collection
64-
start_date = int(lines[1,6])
65-
66-
# end year- completion year
67-
end_year = int(lines[1,7])
68-
69-
# latitude, longitude, elevation
70-
latitude = lines[2,4]
71-
longitude = lines[2,5]
72-
73-
# lead investigator
74-
lead_investigator= lines[2,2]
75-
76-
# site_id
77-
# Via indexing the first three digits of the site id are assigned to var named site_code and the rest to information.
78-
# Check if all the site codes are the same for the whole dataset
79-
for site_code in lines:
80-
current=0
81-
information=0
82-
site_id=0
83-
unit = 0
84-
while current >=0 and current<=len(lines)-1:
85-
if current <=3:
86-
site_code = lines[current,0,0]
87-
if current>=4 and current<=len(lines)-1:
88-
if lines[current,0,0] == lines[4,0,0]:
89-
site_id = lines[current,0,0]
90-
information = site_id[3::]
91-
site_id= site_code + information
92-
#data
93-
data=[]
94-
y=1
95-
past= y-1
96-
end=[current,-1]
97-
if site_id == lines[current,0] and start_date <= int(lines[]):
98-
for points in lines[current,2:]:
99-
pts=[]
100-
pts.append(points)
101-
# End of data collection for that year
102-
if points== "999" or points== "-9999":
103-
pts[:-1]
104-
data.append(pts)
105-
pts=0
106-
unit = points
107-
else:
108-
current = current + 1
109-
pts=0
110-
111-
jsonfile = {}
112-
jsonfile["site_code"] = site_code
113-
jsonfile["site_name"] = site_id
114-
jsonfile["species_code"] = species_code
115-
jsonfile["species_name"] = species
116-
jsonfile["country"] = country
117-
jsonfile["state_province"] = state_province
118-
jsonfile["elevation"] = ""
119-
jsonfile["latitude"] = latitude
120-
jsonfile["longitude"] = longitude
121-
if unit == "999":
122-
jsonfile["unit"] = "0.01mm"
123-
elif unit == "-9999":
124-
jsonfile["unit"] = "0.001mm"
125-
else:
126-
print("ERROR - Stop code is not 999 or -9999. Cannot identify a unit.")
127-
exit
128-
jsonfile["lead_investigator"] = lead_investigator
129-
jsonfile["collection_date"] = ""
111+
jsonfile = {}
112+
jsonfile["site_code"] = site_code
113+
jsonfile["site_name"] = site_id
114+
jsonfile["species_code"] = species_code
115+
jsonfile["species_name"] = species
116+
jsonfile["country"] = country
117+
jsonfile["state_province"] = state_province
118+
jsonfile["elevation"] = ""
119+
jsonfile["latitude"] = latitude
120+
jsonfile["longitude"] = longitude
121+
if unit == "999":
122+
jsonfile["unit"] = "0.01mm"
123+
elif unit == "-9999":
124+
jsonfile["unit"] = "0.001mm"
125+
else:
126+
print("ERROR - Stop code is not 999 or -9999. Cannot identify a unit.")
127+
exit
128+
jsonfile["lead_investigator"] = lead_investigator
129+
jsonfile["collection_date"] = ""

dplpy/curvefit.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
# modified negative exponential, linear and horizontal.
3030

3131
import numpy as np
32-
import pandas as pd
3332
from scipy.optimize import curve_fit
3433

3534
# Modified hugershoff function

dplpy/detrend.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,9 @@
2828
# with spline(s) as the default, and then by calculating residuals or differences
2929
# compared to the original data (residuals by default).
3030

31-
from tkinter import Y
3231
import pandas as pd
3332
import matplotlib.pyplot as plt
3433
from smoothingspline import spline
35-
from autoreg import ar_func
3634
import curvefit
3735

3836
def detrend(data: pd.DataFrame | pd.Series, fit="spline", method="residual", plot=True, period=None):
@@ -141,7 +139,10 @@ def detrend_series(data: pd.Series, fit, method, plot, period=None):
141139

142140
plt.show()
143141

144-
return pd.Series(detrended_data, index=x, name=series_name)
142+
return pd.Series(detrended_data, index=pd.Index(data=x, name="Year"), name=series_name).combine(data, pick_first)
143+
144+
def pick_first(a, b):
145+
return a
145146

146147
# Detrends by finding ratio of original series data to curve data
147148
def residual(y, yi):

dplpy/dplpy.py

Lines changed: 14 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,17 @@
11
from __future__ import print_function
2+
from readers import readers
3+
from summary import summary
4+
from stats import stats
5+
from report import report
6+
from plot import plot
7+
from detrend import detrend
8+
from autoreg import ar_func, autoreg
9+
from chron import chron
10+
from chron_stabilized import chron_stabilized
11+
from xdate import xdate
12+
from series_corr import series_corr
13+
from writers import write
14+
215

316
__copyright__ = """
417
dplPy for tree ring width time series analyses
@@ -93,7 +106,7 @@ def readme():
93106
try:
94107
a = webbrowser.open("https://opendendro.org/dplpy-man/", new=2)
95108
print("Success: Check your web browser for a new tab")
96-
if a == False:
109+
if a is False:
97110
print("Your computer does not use a monitor, and cannot display the webpages")
98111
except Exception as e:
99112
print(e)
@@ -143,18 +156,6 @@ def readme_from_parser(args):
143156
#
144157
#dplpy_version()
145158

146-
from readers import readers
147-
from summary import summary
148-
from stats import stats
149-
from report import report
150-
from plot import plot
151-
from detrend import detrend
152-
from autoreg import ar_func, autoreg
153-
from chron import chron
154-
from chron_stabilized import chron_stabilized
155-
from xdate import xdate, xdate_plot
156-
from series_corr import series_corr
157-
from writers import write
158159

159160

160161
# set the definition for the Readers functions (from readers.py)
@@ -203,17 +204,6 @@ def chron_stabilized_from_parser(args):
203204
def write_from_parser(args):
204205
write(input=args.input)
205206

206-
def series_corr_from_parser(args):
207-
series_corr(input=args.input)
208-
209-
def series_corr_from_parser(args):
210-
series_corr(input=args.input)
211-
212-
def common_interval_from_parser(args):
213-
common_interval(input=args.input)
214-
215-
def rbar_from_parser(args):
216-
rbar(input=args.input)
217207
# creates whitespace
218208
print("")
219209

dplpy/rbar.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
# period of years, and calculating rbar constant for a dataset over this best
2929
# period of overlap
3030

31-
import pandas as pd
3231
import numpy as np
3332
from detrend import detrend
3433
from chron import chron

0 commit comments

Comments
 (0)