Skip to content

Commit

Permalink
ci => actions
Browse files Browse the repository at this point in the history
build on run

package robust: needed Manifest.in
  • Loading branch information
scivision committed Feb 28, 2020
1 parent 8be909b commit 88d22ff
Show file tree
Hide file tree
Showing 24 changed files with 468 additions and 379 deletions.
5 changes: 5 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[flake8]
max-line-length = 132
exclude = .git,__pycache__,.eggs/,doc/,docs/,build/,dist/,archive/
per-file-ignores =
__init__.py:F401
4 changes: 4 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# These are supported funding model platforms

github: [scivision]
ko_fi: scivision
43 changes: 43 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: ci

on: [push, pull_request]

jobs:

linux:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v1
with:
python-version: '3.x'
- run: pip install cmake
- run: sudo apt install -yq --no-install-recommends gfortran
- run: pip install .[tests,lint]
- run: flake8
- run: mypy .
- run: pytest
working-directory: tests

macos:
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v1
with:
python-version: '3.x'
- run: brew install gcc
- run: pip install .[tests]
- run: pytest
working-directory: tests

windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-python@v1
with:
python-version: '3.x'
- run: pip install .[tests]
- run: pytest
working-directory: tests
32 changes: 18 additions & 14 deletions GRwave.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,36 +2,40 @@
"""Simple groundwave example, assuming uniform ground parameters"""
from matplotlib.pyplot import figure, show
import grwave

try:
import seaborn as sns
sns.set_context('talk', 1.)

sns.set_context("talk", 1.0)
except ImportError:
pass


def main():
wls = {'freqMHz': 0.89,
'sigma': 2e-3,
'epslon': 4,
'dmax': 400,
'hrr': 3,
'htt': 100,
'dstep': 10,
'txwatt': 50e3, }
wls = {
"freqMHz": 0.89,
"sigma": 2e-3,
"epslon": 4,
"dmax": 400,
"hrr": 3,
"htt": 100,
"dstep": 10,
"txwatt": 50e3,
}

data = grwave.grwave(wls)
# %%
d_km = data.index.values.astype(float)

ax = figure().gca()
ax.plot(d_km, data['fs'].values)
ax.set_xlabel('distance [km]')
ax.set_ylabel('field strength mV/m')
ax.axhline(4, color='red', linestyle='--')
ax.plot(d_km, data["fs"].values)
ax.set_xlabel("distance [km]")
ax.set_ylabel("field strength mV/m")
ax.axhline(4, color="red", linestyle="--")
ax.grid(True)
# ax.set_ylim((0,25))
show()


if __name__ == '__main__':
if __name__ == "__main__":
main()
1 change: 1 addition & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
include grwave/src/CMakeLists.txt grwave/src/meson.build grwave/src/grwave.for
31 changes: 14 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,29 +1,26 @@
[![Travis-CI](https://travis-ci.org/scivision/grwave.svg?branch=master)](https://travis-ci.org/scivision/grwave)
[![Coverage](https://coveralls.io/repos/github/scivision/grwave/badge.svg?branch=master)](https://coveralls.io/github/scivision/grwave?branch=master)
[![Build status](https://ci.appveyor.com/api/projects/status/uu30h9akapgk9bc7?svg=true)](https://ci.appveyor.com/project/scivision/grwave)

# GRWave groundwave propagation

![ci](https://github.com/space-physics/grwave/workflows/ci/badge.svg)

Python for ITU P.368: Ground-wave propagation curves for frequencies between 10 kHz and 30 MHz.

[Original code](https://www.itu.int/en/ITU-R/study-groups/rsg3/Pages/iono-tropo-spheric.aspx)

More serious needs for LF propagation modeling should consider modern software like SPAWAR
More serious needs for LF propagation modeling should consider modern software like SPAWAR
[LWPC](https://www.ann-geophys.net/31/765/2013/angeo-31-765-2013.pdf)
since for communications circuits, signal strength is just one part of a complex system.
Other necessary dominant factors include:

* ITU-R [P.372](https://www.itu.int/rec/R-REC-P.372/en) Radio circuit noise
* ITU-R [F.1487](https://www.itu.int/rec/R-REC-F.1487-0-200005-I/en) Ionospheric circuit simultation. Even if you only want groundwave, the ionospheric path in general interferes with the groundwave path.


![image](data/fs.png)

## Install
This also compiles the Fortran code using `gfortran`:
## Install

python -m pip install -e .
```sh
pip install -e .
```

## Usage

Expand All @@ -36,9 +33,9 @@ parameters into GRWAVE from Python. No files are used, just
## Ground conductivity

Serious use of this would involve incremental runs with conductivity.
To start assume uniform ground conductivity for the
[United States](https://www.fcc.gov/media/radio/m3-ground-conductivity-map)
or
To start assume uniform ground conductivity for the
[United States](https://www.fcc.gov/media/radio/m3-ground-conductivity-map)
or
[world atlas](http://hamwaves.com/ground/en/index.html).

### Variables
Expand All @@ -52,7 +49,7 @@ ANS: [R] The refractivity of the troposphere at the surface of the earth in N-un
HSCALE:[R] The scale height of the troposphere in kilometres. Default HSCALE = 7.35.

IPOLRN:[I] A code number for the polarization. Default IPOLRN = 1.
* 1 vertical polarization
* 1 vertical polarization
* 2 horizontal polarization

FREQ: [R] The frequency in MHz. Default FREQ = 1.0.
Expand All @@ -67,9 +64,9 @@ DMAX: [R] The maximum range in kilometres. Default DMAX = 200.0.

DSTEP:[R] The range step. See LOGLIN for further explanation. Default DSTEP = 10.0.

LOGLIN:[I] If LOGLIN = 0 then DSTEP, the range step is added to the range in geometrical and extended flat earth calculation regions and subtracted in the residue series regions.
If LOGLIN = 1 then the new distance is computed by multiplying or dividing the previous distance by DSTEP. In this case, DSTEP is chosen to give a fixed number of points per logarithmic decade.
If N points per logarithmic decade are desired, DSTEP is equal to 10 to the power (1/N).
LOGLIN:[I] If LOGLIN = 0 then DSTEP, the range step is added to the range in geometrical and extended flat earth calculation regions and subtracted in the residue series regions.
If LOGLIN = 1 then the new distance is computed by multiplying or dividing the previous distance by DSTEP. In this case, DSTEP is chosen to give a fixed number of points per logarithmic decade.
If N points per logarithmic decade are desired, DSTEP is equal to 10 to the power (1/N).
Default LOGLIN = 0.

[Note: In the residue series region, the calculations begin at DMAX
Expand All @@ -81,7 +78,7 @@ region and 100 points in the flat earth region. These limits may be
expanded by compiling the source code after modification of the
appropriate dimension statements.]

IG: [I] If IG = -1 or 0, the field is calculated at long distances using the residue series formulation. If IG = 0 or 1, the field is calculated at short distances using the geometric optics or extended flat earth formulation.
IG: [I] If IG = -1 or 0, the field is calculated at long distances using the residue series formulation. If IG = 0 or 1, the field is calculated at short distances using the geometric optics or extended flat earth formulation.
Default IG = 0.

JHT: [I] A variable which determines which combination of receiver antenna heights (HR(LR) LR=1,JR) and transmitter heights
Expand Down
1 change: 0 additions & 1 deletion .appveyor.yml → archive/.appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,3 @@ install:
- sh: make

test_script: pytest -rsv

1 change: 0 additions & 1 deletion .travis.yml → archive/.travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,3 @@ after_success:
pytest --cov --cov-config=setup.cfg;
coveralls;
fi

2 changes: 1 addition & 1 deletion Makefile → archive/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

grwave.exe: src/grwave.for
$(FC) $^ -o $@

clean:
$(RM) grwave.exe
2 changes: 1 addition & 1 deletion grwave/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from .base import grwave # noqa: F401
from .base import grwave
34 changes: 25 additions & 9 deletions grwave/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,29 @@
import io
import pandas as pd
import numpy as np
import shutil
import typing as T

root = Path(__file__).parents[1]
R = Path(__file__).parent
src_dir = R / "src"
build_dir = R / "build"
TXW0 = 1e3 # ITU assumes 1kW power
CORR = 0.5

grwave_exe = shutil.which("grwave.bin", path=str(build_dir))
if not grwave_exe:
if shutil.which("cmake"):
subprocess.run(["cmake", "-S", str(src_dir), "-B", str(build_dir)])
subprocess.run(["cmake", "--build", str(build_dir)])
elif shutil.which("meson") and shutil.which("ninja"):
subprocess.run(["meson", str(src_dir), str(build_dir)])
subprocess.run(["ninja", "-C", str(build_dir)])
grwave_exe = shutil.which("grwave.bin", path=str(build_dir))
if not grwave_exe:
raise ImportError("need to compile grwave.bin")

def grwave(wls: dict) -> pd.DataFrame:

def grwave(wls: T.Dict[str, T.Any]) -> pd.DataFrame:

strin = (
f'freq {wls["freqMHz"]}\n'
Expand All @@ -19,17 +35,17 @@ def grwave(wls: dict) -> pd.DataFrame:
f'hrr {wls["hrr"]}\n'
f'htt {wls["htt"]}\n'
f'dstep {wls["dstep"]}\n'
'GO')
"GO"
)

out = subprocess.check_output('./grwave.exe', input=strin, universal_newlines=True, cwd=root)
out = subprocess.check_output([grwave_exe], input=strin, universal_newlines=True)
# %%
data = pd.read_csv(io.StringIO(out), sep=r'\s+', index_col=0,
skiprows=31, names=['fs', 'pathloss'])
data = pd.read_csv(io.StringIO(out), sep=r"\s+", index_col=0, skiprows=31, names=["fs", "pathloss"])

data.dropna(how='all', axis=0, inplace=True)
data = data[~data.index.duplicated(keep='last')]
data.dropna(how="all", axis=0, inplace=True)
data = data[~data.index.duplicated(keep="last")]
data.index = data.index.astype(float)

data['fs'] *= np.sqrt(wls['txwatt']/TXW0) * CORR
data["fs"] *= np.sqrt(wls["txwatt"] / TXW0) * CORR

return data
5 changes: 5 additions & 0 deletions grwave/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
cmake_minimum_required(VERSION 3.1)
project(GRwave Fortran)

add_executable(grwave.bin grwave.for)
target_compile_options(grwave.bin PRIVATE -w)
4 changes: 2 additions & 2 deletions src/ex.inp → grwave/src/ex.inp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/ Example input file
HTT 9
/ Example input file
HTT 9
HRR 2.5
IPOLRN 1
FREQ 6
Expand Down
17 changes: 8 additions & 9 deletions src/grwave.for → grwave/src/grwave.for
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ C* *
C***********************************************************************
C
C================================================================
C= MODIFIED FOR MICROSOFT FORTRAN VERSION 4.0 =
C= MODIFIED FOR MICROSOFT FORTRAN VERSION 4.0 =
C= FOR MS-DOS PERSONAL COMPUTERS =
C= July 1988/10DEC88-jfc =
C= CCIR United States Study Group 5 =
C= Dr. John F. Cavanagh =
C= Dr. John F. Cavanagh =
C= Ms. Sheila A. Thurston =
C= Naval Surface Warfare Center =
C= Code F405 =
Expand Down Expand Up @@ -245,7 +245,7 @@ C ((LT=LR,JR),LR=1,JR).
40 DM(LR,LT)=DMAX
IF(IDEBUG.GE.1)WRITE(6,10000)(HRR(LR),LR=1,JR)
10000 FORMAT('0TERMINAL HEIGHTS IN METRES'/' HRR=',7E15.7/(4X,7E15.7)
1 /' GRWAVE-242')
1 /' GRWAVE-242')
IF(IDEBUG.GE.1)WRITE(6,11000)(HTT(LT),LT=1,JT)
11000 FORMAT(' HTT=',7E15.7/(4X,7E15.7) /' GRWAVE-245,259')
C COMPUTE MODIFIED HEIGHTS USING EARTH FLATTENING TRANSFORMATION.
Expand Down Expand Up @@ -543,7 +543,7 @@ C IF(IDEBUG.EQ.2)PRINT*,'TERM',TERM,'H1(M)',H1(M) ,'TPOINT-524'
EPS=ABS2(TERM/H1(M))
IF(EPS.LT.1.D-11)RETURN
60 CONTINUE
IF(IDEBUG.GE.1)WRITE(6,2000)TERM,M,H1(M)
IF(IDEBUG.GE.1)WRITE(6,2000)TERM,M,H1(M)
2000 FORMAT(' TERM=(',E14.7,',',E14.7,') H1(',I1,')=(',E14.7
1,',',E14.7,')' ' TPOINT-528')

Expand Down Expand Up @@ -837,7 +837,7 @@ C
LOGICAL LARGE
COMPLEX*16 FAC,DP(4),XI,PSI0,Z0T(1),ZXI,Z0(1),ZPSI,PHINT,
1P0(9),H1(9),TERM,P,F,DF,AKI,XIT,PINT,PSIT,P0T,D1P,D2P,FID(9)
COMMON /BUGGER/N,IDEBUG,AK,AK2,AKI /PEES/P,DP /PEXCIT/P0,FID
COMMON /BUGGER/N,IDEBUG,AK,AK2,AKI /PEES/P,DP /PEXCIT/P0,FID
1/AIRYS/AS(10),ASD(10) /HCHITE/HCH(9)
EXTERNAL ZXI,ZPSI
C
Expand Down Expand Up @@ -1462,7 +1462,7 @@ C********************
IF(LT.LE.JT)GOTO 70
90 CONTINUE
IF(IDEBUG.LE.1)GOTO 110
C PRINT*,'RESIDH-1408'
C PRINT*,'RESIDH-1408'
DO 100 M3=1,3
M2=3*M3
M1=M2-2
Expand Down Expand Up @@ -1657,7 +1657,7 @@ C
IF(ZI.LT.0.0D0)W=2.0D0*CDEXP(-A2)-W
ELSE IF(CZ.EQ.0.0D0) THEN
W=(1.0D0,0.0D0)
ELSE
ELSE
TERM=(0.0D0,1.128379D0)*Z
SUM=TERM
W=SUM
Expand Down Expand Up @@ -1689,7 +1689,7 @@ C
3000 FORMAT(' NO CONVERGENCE IN W' ,' W(Z)-1603,1630')
40 IF(TYPE) THEN
W=CDEXP(-A2)*(1.0D0+W)
ELSE
ELSE
W=CDEXP(-A2)+W
ENDIF
ENDIF
Expand Down Expand Up @@ -2871,4 +2871,3 @@ C Stop on EOF or an unrecognised word *
GOTO 70

END SUBROUTINE RDDLST

Loading

0 comments on commit 88d22ff

Please sign in to comment.