Skip to content

Commit

Permalink
Merge pull request #52 from /issues/51/codequality
Browse files Browse the repository at this point in the history
Improve code quality
  • Loading branch information
JulienPeloton authored Jan 26, 2021
2 parents ec064cd + 35a7263 commit 1fe483a
Show file tree
Hide file tree
Showing 11 changed files with 2,971 additions and 1,962 deletions.
25 changes: 25 additions & 0 deletions .github/workflows/lint-s4cmb.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: PEP8

on: [push, pull_request]

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
python-version: [3.6]

steps:
- uses: actions/checkout@v2
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v2
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8
- name: Analysing the code with flake8
run: |
flake8 s4cmb/*.py --count --show-source --statistics --max-line-length 86 --doctests --ignore=E741,W605
45 changes: 33 additions & 12 deletions s4cmb/celestial_body_trajectories.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,19 @@
from datetime import datetime, date, time, timedelta
import numpy as np

class celestial_trajectory():

class celestial_trajectory:
"""Predict the trajectory of a body (Sun, Moon, ...) """
def __init__(self, body, lon_observer, lat_observer, elevation_observer,
year, tz_offset=0.):

def __init__(
self,
body,
lon_observer,
lat_observer,
elevation_observer,
year,
tz_offset=0.0,
):
"""
Parameters
----------
Expand All @@ -38,8 +47,20 @@ def __init__(self, body, lon_observer, lat_observer, elevation_observer,
self.year = year
self.tz_offset = tz_offset

self.months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
self.months = [
"Jan",
"Feb",
"Mar",
"Apr",
"May",
"Jun",
"Jul",
"Aug",
"Sep",
"Oct",
"Nov",
"Dec",
]

self.altaz = []
self.radec = []
Expand All @@ -52,7 +73,7 @@ def initialise_observer(self):
"""
Set the Longitute and Latitude of the Observer.
"""
## Define the observer
# Define the observer
self.ob = ephem.Observer()
self.ob.lat, self.ob.lon = self.lat_observer, self.lon_observer
self.ob.elevation = self.elevation_observer
Expand Down Expand Up @@ -141,20 +162,19 @@ def traj_of_body_oneday(self, date):
WTF?
"""
## Update the date
date = datetime.combine(date, time(12)) - timedelta(
hours=self.tz_offset)
# Update the date
date = datetime.combine(date, time(12)) - timedelta(hours=self.tz_offset)
self.ob.date = date

## Alt/Az
# Alt/Az
ALTAZ = self.alt_az(date)
self.altaz.append(ALTAZ)

## RA/Dec
# RA/Dec
RADEC = self.radec_of(ALTAZ)
self.radec.append(RADEC)

## Theta/Phi
# Theta/Phi
THETAPHI = self.radec2thetaphi(RADEC)
self.thetaphi.append(THETAPHI)

Expand Down Expand Up @@ -188,4 +208,5 @@ def traj_of_body_oneyear(self):

if __name__ == "__main__":
import doctest

doctest.testmod()
18 changes: 11 additions & 7 deletions s4cmb/config_s4cmb.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import importlib
import numpy as np


def compare_version_number(version, threshold):
"""
Compare two version numbers.
Expand All @@ -36,12 +37,12 @@ def compare_version_number(version, threshold):
True
"""
## If the two versions are equal
# If the two versions are equal
if version == threshold:
return True

version_numbers = version.split('.')
threshold_numbers = threshold.split('.')
version_numbers = version.split(".")
threshold_numbers = threshold.split(".")
for v, t in zip(version_numbers, threshold_numbers):
v = int(v)
t = int(t)
Expand All @@ -53,6 +54,7 @@ def compare_version_number(version, threshold):
return False
return True


def import_string_as_module(fn_full):
"""
Import module from its name given as a string.
Expand All @@ -76,16 +78,18 @@ def import_string_as_module(fn_full):
True
"""
## Import parameters from the user parameter file
fn_short = os.path.basename(fn_full).split('.py')[0]
sys.path.insert(0, os.path.realpath(
os.path.join(os.getcwd(), os.path.dirname(fn_full))))
# Import parameters from the user parameter file
fn_short = os.path.basename(fn_full).split(".py")[0]
sys.path.insert(
0, os.path.realpath(os.path.join(os.getcwd(), os.path.dirname(fn_full)))
)
params = importlib.import_module(fn_short)
return params


if __name__ == "__main__":
import doctest

if np.__version__ >= "1.14.0":
np.set_printoptions(legacy="1.13")
doctest.testmod()
Loading

0 comments on commit 1fe483a

Please sign in to comment.