This commit is contained in:
James Powell
2017-09-30 12:20:03 -04:00
parent 24f3e135ad
commit 7ee1ad2a92
5 changed files with 0 additions and 263 deletions

View File

@@ -43,7 +43,6 @@ clean-pyc: ## remove Python file artifacts
find . -name '__pycache__' -exec rm -fr {} +
clean-test: ## remove test and coverage artifacts
rm -fr .tox/
rm -f .coverage
rm -fr htmlcov/
@@ -52,10 +51,6 @@ lint: ## check style with flake8
test: ## run tests quickly with the default Python
py.test
test-all: ## run tests on every Python version with tox
tox
coverage: ## check code coverage quickly with the default Python
coverage run --source gnpy -m pytest

View File

@@ -1,84 +0,0 @@
import os
import gnpy as gn
import numpy as np
import matplotlib.pyplot as plt
import time
def main_ole():
# String indicating the folder in which outputs will be saved
string_date_time = time.strftime("%Y-%m-%d") + '_' + time.strftime("%H-%M-%S")
output_path = './output/' + string_date_time + '/'
# Creates the directory if it doesn't exist
if not os.path.isdir(output_path):
os.makedirs(output_path)
from configuration.fiber_parameters import fibers
from configuration.general_parameters import sys_param, control_param
from configuration.link_description import link
from input.spectrum_in import spectrum
# adapt the laser position to the grid
if len(spectrum['laser_position']) < sys_param['ns']:
n = sys_param['ns'] - len(spectrum['laser_position'])
missing_zeros = [0 for _ in range(n)]
spectrum['laser_position'] += missing_zeros
elif len(spectrum['laser_position']) > sys_param['ns']:
print('Error: the spectrum definition requires a larger number of slots ns in the spectrum grid')
delta_f = 6.25E-3
f_0 = sys_param['f0']
f_cent = f_0 + ((sys_param['ns'] // 2.0) * delta_f)
n_ch = spectrum['laser_position'].count(1)
# Get comb parameters
f_ch = np.zeros(n_ch)
count = 0
for index, bool_laser in enumerate(spectrum['laser_position']):
if bool_laser:
f_ch[count] = delta_f * index + (f_0 - f_cent)
count += 1
t = time.time()
# It runs the OLE
osnr_nl_db, osnr_lin_db = gn.ole(spectrum, link, fibers, sys_param, control_param, output_path=output_path)
print('Elapsed: %s' % (time.time() - t))
# Compute the raised cosine comb
power, rs, roll_off, p_ase, p_nli, n_ch = gn.get_spectrum_param(spectrum)
f1_array = np.linspace(np.amin(f_ch), np.amax(f_ch), 1e3)
gtx = gn.raised_cosine_comb(f1_array, rs, roll_off, f_ch, power)
gtx = gtx + 10 ** -6 # To avoid log10 issues.
# OSNR at in the central channel
ind_c = n_ch // 2
osnr_lin_central_db = osnr_lin_db[ind_c]
osnr_nl_central_db = osnr_nl_db[ind_c]
print('The linear OSNR in the central channel is: ' + str(osnr_lin_central_db) + ' dB')
print('The non linear OSNR in the central channel is: ' + str(osnr_nl_central_db) + ' dB')
# Plot the results
plt.figure(1)
plt.plot(f1_array, 10 * np.log10(gtx), '-b', label='WDM comb PSD [dB(W/THz)]')
plt.plot(f_ch, 10 * np.log10(p_nli), 'ro', label='NLI [dBw]')
plt.plot(f_ch, 10 * np.log10(p_ase), 'g+', label='ASE noise [dBw]')
plt.ylabel('')
plt.xlabel('f [THz]')
plt.legend(loc='upper right')
plt.grid()
plt.draw()
plt.figure(2)
plt.plot(f_ch, osnr_nl_db, 'ro', label='non-linear OSNR')
plt.plot(f_ch, osnr_lin_db, 'g+', label='linear OSNR')
plt.ylabel('OSNR [dB]')
plt.xlabel('f [THz]')
plt.legend(loc='lower left')
plt.grid()
plt.show()
if __name__ == '__main__':
main_ole()

View File

@@ -1,17 +0,0 @@
# -*- coding: utf-8 -*-
"""Console script for gnpy."""
import click
@click.command()
def main(args=None):
"""Console script for gnpy."""
click.echo("Replace this message by putting your code into "
"gnpy.cli.main")
click.echo("See click documentation at http://click.pocoo.org/")
if __name__ == "__main__":
main()

30
tox.ini
View File

@@ -1,30 +0,0 @@
[tox]
envlist = py26, py27, py33, py34, py35, flake8
[travis]
python =
3.5: py35
3.4: py34
3.3: py33
2.7: py27
2.6: py26
[testenv:flake8]
basepython=python
deps=flake8
commands=flake8 gnpy
[testenv]
setenv =
PYTHONPATH = {toxinidir}
deps =
-r{toxinidir}/requirements_dev.txt
commands =
pip install -U pip
py.test --basetemp={envtmpdir}
; If you want to make tox run the tests with the same versions, create a
; requirements.txt with the pinned versions and uncomment the following lines:
; deps =
; -r{toxinidir}/requirements.txt

View File

@@ -1,127 +0,0 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Update encrypted deploy password in Travis config file."""
from __future__ import print_function
import base64
import json
import os
from getpass import getpass
import yaml
from cryptography.hazmat.primitives.serialization import load_pem_public_key
from cryptography.hazmat.backends import default_backend
from cryptography.hazmat.primitives.asymmetric.padding import PKCS1v15
try:
from urllib import urlopen
except ImportError:
from urllib.request import urlopen
GITHUB_REPO = '<TBD>/gnpy'
TRAVIS_CONFIG_FILE = os.path.join(
os.path.dirname(os.path.abspath(__file__)), '.travis.yml')
def load_key(pubkey):
"""Load public RSA key.
Work around keys with incorrect header/footer format.
Read more about RSA encryption with cryptography:
https://cryptography.io/latest/hazmat/primitives/asymmetric/rsa/
"""
try:
return load_pem_public_key(pubkey.encode(), default_backend())
except ValueError:
# workaround for https://github.com/travis-ci/travis-api/issues/196
pubkey = pubkey.replace('BEGIN RSA', 'BEGIN').replace('END RSA', 'END')
return load_pem_public_key(pubkey.encode(), default_backend())
def encrypt(pubkey, password):
"""Encrypt password using given RSA public key and encode it with base64.
The encrypted password can only be decrypted by someone with the
private key (in this case, only Travis).
"""
key = load_key(pubkey)
encrypted_password = key.encrypt(password, PKCS1v15())
return base64.b64encode(encrypted_password)
def fetch_public_key(repo):
"""Download RSA public key Travis will use for this repo.
Travis API docs: http://docs.travis-ci.com/api/#repository-keys
"""
keyurl = 'https://api.travis-ci.org/repos/{0}/key'.format(repo)
data = json.loads(urlopen(keyurl).read().decode())
if 'key' not in data:
errmsg = "Could not find public key for repo: {}.\n".format(repo)
errmsg += "Have you already added your GitHub repo to Travis?"
raise ValueError(errmsg)
return data['key']
def prepend_line(filepath, line):
"""Rewrite a file adding a line to its beginning."""
with open(filepath) as f:
lines = f.readlines()
lines.insert(0, line)
with open(filepath, 'w') as f:
f.writelines(lines)
def load_yaml_config(filepath):
"""Load yaml config file at the given path."""
with open(filepath) as f:
return yaml.load(f)
def save_yaml_config(filepath, config):
"""Save yaml config file at the given path."""
with open(filepath, 'w') as f:
yaml.dump(config, f, default_flow_style=False)
def update_travis_deploy_password(encrypted_password):
"""Put `encrypted_password` into the deploy section of .travis.yml."""
config = load_yaml_config(TRAVIS_CONFIG_FILE)
config['deploy']['password'] = dict(secure=encrypted_password)
save_yaml_config(TRAVIS_CONFIG_FILE, config)
line = ('# This file was autogenerated and will overwrite'
' each time you run travis_pypi_setup.py\n')
prepend_line(TRAVIS_CONFIG_FILE, line)
def main(args):
"""Add a PyPI password to .travis.yml so that Travis can deploy to PyPI.
Fetch the Travis public key for the repo, and encrypt the PyPI password
with it before adding, so that only Travis can decrypt and use the PyPI
password.
"""
public_key = fetch_public_key(args.repo)
password = args.password or getpass('PyPI password: ')
update_travis_deploy_password(encrypt(public_key, password.encode()))
print("Wrote encrypted password to .travis.yml -- you're ready to deploy")
if '__main__' == __name__:
import argparse
parser = argparse.ArgumentParser(description=__doc__)
parser.add_argument('--repo', default=GITHUB_REPO,
help='GitHub repo (default: %s)' % GITHUB_REPO)
parser.add_argument('--password',
help='PyPI password (will prompt if not provided)')
args = parser.parse_args()
main(args)