Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sourcery refactored main branch #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Conversation

sourcery-ai[bot]
Copy link

@sourcery-ai sourcery-ai bot commented Nov 1, 2022

Branch main refactored by Sourcery.

If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.

See our documentation here.

Run Sourcery locally

Reduce the feedback loop during development by using the Sourcery editor plugin:

Review changes via command line

To manually merge these changes, make sure you're on the main branch, then run:

git fetch origin sourcery/main
git merge --ff-only FETCH_HEAD
git reset HEAD^

Help us improve this pull request!

Comment on lines -71 to +74

code = GrayCode(bitsSymb)
a = list(code.generate_gray())

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function GrayMapping refactored with the following changes:

Comment on lines -124 to +127

hdDecision_vec = np.vectorize(hdDecision, excluded = [1])
index_list = hdDecision_vec(symb, const[:,0])
demod_bits = dec2bitarray(index_list, int(np.log2(M)))

return demod_bits

hdDecision_vec = np.vectorize(hdDecision, excluded = [1])
index_list = hdDecision_vec(symb, const[:,0])
return dec2bitarray(index_list, int(np.log2(M)))
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function demodulateGray refactored with the following changes:

Comment on lines -161 to +159

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 161-320 refactored with the following changes:

Comment on lines -148 to +152
σ = np.sqrt(σ2_s)
σ = np.sqrt(σ2_s)
Is = normal(μ, σ, Namostras)

# plotas as primeiras 1000 amostras
plt.plot(Is[0:1000],linewidth = 0.8);
plt.plot(Is[:1000], linewidth = 0.8);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lines 148-152 refactored with the following changes:

Ao = Ai*np.cos(0.5/Vπ*(u+Vb)*π)

return Ao
return Ai*np.cos(0.5/Vπ*(u+Vb)*π)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function mzm refactored with the following changes:

Comment on lines -221 to +215
def dbp(Ei, Fs, Ltotal, Lspan, hz=0.5, alpha=0.2, gamma=1.3, D=16, Fc=193.1e12):
def dbp(Ei, Fs, Ltotal, Lspan, hz=0.5, alpha=0.2, gamma=1.3, D=16, Fc=193.1e12):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function dbp refactored with the following changes:

Ao = Ai*np.cos(0.5/Vπ*(u+Vb)*π)

return Ao
return Ai*np.cos(0.5/Vπ*(u+Vb)*π)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function mzm refactored with the following changes:

Ao = mzm(Ai/np.sqrt(2), Vπ, u.real, VbI) + 1j*mzm(Ai/np.sqrt(2), Vπ, u.imag, VbQ)

return Ao
return mzm(Ai / np.sqrt(2), Vπ, u.real, VbI) + 1j * mzm(
Ai / np.sqrt(2), Vπ, u.imag, VbQ
)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function iqm refactored with the following changes:

Comment on lines -106 to +114

# optical hybrid transfer matrix
T = np.array([[ 1/2, 1j/2, 1j/2, -1/2],
[ 1j/2, -1/2, 1/2, 1j/2],
[ 1j/2, 1/2, -1j/2, -1/2],
[-1/2, 1j/2, -1/2, 1j/2]])

Ei = np.array([E1, np.zeros((E1.size,)),
np.zeros((E1.size,)), E2])

Eo = T@Ei

return Eo

return T@Ei
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function hybrid_2x4_90deg refactored with the following changes:

Comment on lines -166 to +162
def ssfm(Ei, Fs, paramCh):
def ssfm(Ei, Fs, paramCh):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function ssfm refactored with the following changes:

Comment on lines -254 to +250
def manakov_ssf(Ei, Fs, paramCh):
def manakov_ssf(Ei, Fs, paramCh):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function manakov_ssf refactored with the following changes:

Comment on lines -359 to +360
σ2 = 2*np.pi*lw*Ts
σ2 = 2*np.pi*lw*Ts
phi = np.zeros(Nsamples)
for ind in range(0, Nsamples-1):

for ind in range(Nsamples-1):
phi[ind+1] = phi[ind] + normal(0, np.sqrt(σ2))

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function phaseNoise refactored with the following changes:

Comment on lines -40 to +74

# transmitter parameters
Ts = 1/param.Rs # symbol period [s]
Fa = 1/(Ts/param.SpS) # sampling frequency [samples/s]
Ta = 1/Fa # sampling period [s]

# central frequencies of the WDM channels
freqGrid = np.arange(-np.floor(param.Nch/2), np.floor(param.Nch/2)+1,1)*param.freqSpac

if (param.Nch % 2) == 0:
freqGrid += param.freqSpac/2

# IQM parameters
Ai = 1
Vπ = 2
Vb = -Vπ
Pch = 10**(param.Pch_dBm/10)*1e-3 # optical signal power per WDM channel

π = np.pi

t = np.arange(0, int(((param.Nbits)/np.log2(param.M))*param.SpS))

# allocate array
sigTxWDM = np.zeros((len(t), param.Nmodes), dtype='complex')
symbTxWDM = np.zeros((int(len(t)/param.SpS), param.Nmodes, param.Nch), dtype='complex')

symbTxWDM = np.zeros(
(len(t) // param.SpS, param.Nmodes, param.Nch), dtype='complex'
)


Psig = 0
for indMode in range(0, param.Nmodes):

for indMode in range(param.Nmodes):
print('Mode #%d'%(indMode))
for indCh in range(0, param.Nch):

for indCh in range(param.Nch):
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function simpleWDMTx refactored with the following changes:

y = sig[0:Nsamples].real
y = sig[:Nsamples].real
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function eyediagram refactored with the following changes:

@sourcery-ai
Copy link
Author

sourcery-ai bot commented Nov 1, 2022

Sourcery Code Quality Report

❌  Merging this PR will decrease code quality in the affected files by 0.19%.

Quality metrics Before After Change
Complexity 3.15 ⭐ 3.15 ⭐ 0.00
Method Length 196.89 😞 196.27 😞 -0.62 👍
Working memory 19.48 ⛔ 19.56 ⛔ 0.08 👎
Quality 43.92% 😞 43.73% 😞 -0.19% 👎
Other metrics Before After Change
Lines 2553 2538 -15
Changed files Quality Before Quality After Quality Change
jupyter notebooks/CommpyTest_BERvsEbN0_wPulseShaping.py 45.28% 😞 45.06% 😞 -0.22% 👎
jupyter notebooks/Sistemas coerentes.py 40.85% 😞 40.72% 😞 -0.13% 👎
jupyter notebooks/Split-Step Fourier Method (SSFM).py 45.48% 😞 45.48% 😞 0.00%
jupyter notebooks/utils/dsp.py 53.40% 🙂 53.32% 🙂 -0.08% 👎
jupyter notebooks/utils/models.py 46.30% 😞 45.71% 😞 -0.59% 👎
jupyter notebooks/utils/tx.py 27.46% 😞 27.47% 😞 0.01% 👍
jupyter notebooks/utils/.ipynb_checkpoints/dsp-checkpoint.py 62.84% 🙂 62.88% 🙂 0.04% 👍

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Working Memory Quality Recommendation
jupyter notebooks/utils/tx.py simpleWDMTx 8 ⭐ 535 ⛔ 26 ⛔ 27.47% 😞 Try splitting into smaller methods. Extract out complex expressions
jupyter notebooks/utils/dsp.py eyediagram 12 🙂 309 ⛔ 19 ⛔ 29.80% 😞 Try splitting into smaller methods. Extract out complex expressions
jupyter notebooks/utils/models.py manakov_ssf 7 ⭐ 531 ⛔ 22 ⛔ 29.84% 😞 Try splitting into smaller methods. Extract out complex expressions
jupyter notebooks/Sistemas coerentes.py simpleWDMTx 8 ⭐ 425 ⛔ 21 ⛔ 30.06% 😞 Try splitting into smaller methods. Extract out complex expressions
jupyter notebooks/utils/models.py ssfm 7 ⭐ 387 ⛔ 19 ⛔ 32.72% 😞 Try splitting into smaller methods. Extract out complex expressions

Legend and Explanation

The emojis denote the absolute quality of the code:

  • ⭐ excellent
  • 🙂 good
  • 😞 poor
  • ⛔ very poor

The 👍 and 👎 indicate whether the quality has improved or gotten worse with this pull request.


Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Help us improve this quality report!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

0 participants