Skip to content

Commit

Permalink
metadata and Matlab CI
Browse files Browse the repository at this point in the history
cleanup

cmake/meson template

meson
  • Loading branch information
scivision committed Jun 11, 2019
1 parent 9954d85 commit cb4c084
Show file tree
Hide file tree
Showing 17 changed files with 90 additions and 127 deletions.
2 changes: 1 addition & 1 deletion .appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ environment:
MINGW_DIR: C:\mingw-w64\x86_64-7.2.0-posix-seh-rt_v5-rev1\mingw64\bin
PY_DIR: C:\Python37-x64

clone_depth: 3
clone_depth: 25

build: off

Expand Down
2 changes: 0 additions & 2 deletions .codeclimate.yml

This file was deleted.

20 changes: 20 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[run]
cover_pylib = false
omit =
/home/travis/virtualenv/*
*/site-packages/*
*/bin/*

[report]
exclude_lines =
pragma: no cover
def __repr__
except RuntimeError
except NotImplementedError
except ImportError
except FileNotFoundError
except CalledProcessError
logging.warning
logging.error
logging.critical
if __name__ == .__main__.:
3 changes: 3 additions & 0 deletions .flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[flake8]
max-line-length = 132
exclude = .git,__pycache__,.eggs/,doc/,docs/,build/,dist/,archive/
22 changes: 11 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ group: travis_latest
dist: xenial

git:
depth: 3
depth: 25
quiet: true

python:
Expand All @@ -20,21 +20,21 @@ matrix:
- os: linux
python: 3.7
install: pip install -e .[tests,cov]
script:
script:
- flake8
- mypy . --ignore-missing-imports
- mypy .
after_success:
- pytest --cov --cov-config=setup.cfg
- pytest --cov
- coveralls
- os: osx
language: sh
before_install: brew install gcc
language: minimal
before_install: brew install gcc > /dev/null
install: pip3 install -e .[tests]
- os: windows
language: sh
before_install:
- choco install python3
- export PATH="/c/Python37:/c/Python37/Scripts:$PATH"
# - os: windows
# language: minimal
# before_install:
# - choco install python3
# - export PATH="/c/Python37:/c/Python37/Scripts:$PATH"


install: pip install -e .[tests]
Expand Down
9 changes: 3 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
cmake_minimum_required(VERSION 3.7)
if(NOT CMAKE_BUILD_TYPE)
set(CMAKE_BUILD_TYPE Release CACHE STRING "Debug or Release")
endif()
project(lowtran Fortran)
enable_testing()

include(cmake/compilers.cmake)

add_executable(testlowtran src/lowtran_driver.f90 src/lowtran7.f src/assert.f90)
if(f2008)
target_sources(testlowtran PRIVATE src/error2008.f90)
else()
target_sources(testlowtran PRIVATE src/error2003.f90)
endif()
target_link_libraries(testlowtran PRIVATE ${FLIBS})
target_compile_options(testlowtran PRIVATE ${FFLAGS})

add_test(NAME FortranObs2space COMMAND testlowtran obs2space)
Expand Down
File renamed without changes.
27 changes: 14 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@

# Lowtran in Python

LOWTRAN7 atmospheric absorption extinction model.
Updated by Michael Hirsch to be platform independent and easily accessible from Python ≥ 3.6 and
LOWTRAN7 atmospheric absorption extinction model.
Updated by Michael Hirsch to be platform independent and easily accessible from Python ≥ 3.6 and
[Matlab](#matlab).

The main LOWTRAN program has been made accessible from Python by using direct memory transfers instead of the cumbersome and error-prone process of writing/reading text files.
Expand Down Expand Up @@ -39,40 +39,41 @@ We use `f2py` (part of `numpy`) to seamlessly use Fortran libraries from Python

## Examples

In these examples, you can write to HDF5 with the `-o` option.
In these examples, you can write to HDF5 with the `-o` option.

We present examples of:

* ground-to-space transmittance:
* ground-to-space transmittance:
[TransmittanceGround2Space.py](./TransmittanceGround2Space.py)

![Lowtran Transmission](./doc/txgnd2space.png)
* sun-to-observer scattered radiance (why the sky is blue):
* sun-to-observer scattered radiance (why the sky is blue):
[ScatterRadiance.py](./ScatterRadiance.py)

![Lowtran Scatter Radiance](./gfx/whyskyisblue.png)
* sun-to-observer irradiance:
* sun-to-observer irradiance:
[SolarIrradiance.py](./SolarIrradiance.py)

![Lowtran Solar Irradiance](./gfx/irradiance.png)
* observer-to-observer solar single-scattering solar radiance (up-going) with custom Pressure, Temperature and partial pressure for 12 species:
* observer-to-observer solar single-scattering solar radiance (up-going) with custom Pressure, Temperature and partial pressure for 12 species:
[UserDataHorizontalRadiance.py](./UserDataHorizontalRadiance.py)
![Lowtran Solar Irradiance](./gfx/thermalradiance.png)
* observer-to-observer transmittance with custom Pressure, Temperature and partial pressure for 12 species:
* observer-to-observer transmittance with custom Pressure, Temperature and partial pressure for 12 species:
[UserDataHorizontalTransmittance.py](./UserDataHorizontalTransmittance.py)
* observer-to-observer transmittance:
[HorizontalTransmittance.py](./HorizontalTransmittance.py)

![Lowtran Horizontal Path transmittance](./gfx/horizcompare.png)

### Matlab
Matlab users can seamlessly access Python modules, as demonstrated in
[RunLowtran.m](./matlab/RunLowtran.m) and

Matlab users can seamlessly access Python modules, as demonstrated in
[RunLowtran.m](./matlab/RunLowtran.m) and
[lowtran_transmission.m](./matlab/lowtran_transmission.m).

Here's what's you'll need:
1. [Setup Python ↔ Matlab interface](https://www.scivision.co/matlab-python-user-module-import/).
1. [Setup Python ↔ Matlab interface](https://www.scivision.dev/matlab-python-user-module-import/).
2. Install Lowtran in Python as at the top of this Readme.
3. From Matlab, verify everything is working by from the `lowtran/` directory:
```matlab
Expand All @@ -82,7 +83,7 @@ Here's what's you'll need:
## Notes
LOWTRAN7
LOWTRAN7
[User manual](http://www.dtic.mil/dtic/tr/fulltext/u2/a206773.pdf)
Refer to this to understand what parameters are set to default.
Currently I don't have any aerosols enabled for example, though it's straightforward to add them into the code.
Expand All @@ -106,6 +107,6 @@ cmake --build .
ctest -V
```

should generate
should generate
[this text output](https://gist.github.com/drhirsch/89ef2060d8f15b0a60914d13a61e33ab).

16 changes: 1 addition & 15 deletions cmake/compilers.cmake
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
if(CMAKE_BUILD_TYPE STREQUAL Debug)
add_compile_options(-g -O0)
else()
add_compile_options(-O3)
endif()

if(CMAKE_Fortran_COMPILER_ID STREQUAL GNU)
list(APPEND FFLAGS -mtune=native)
Expand All @@ -14,14 +9,5 @@ elseif(CMAKE_Fortran_COMPILER_ID STREQUAL Intel)
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL PGI)

elseif(CMAKE_Fortran_COMPILER_ID STREQUAL Flang)
list(APPEND FFLAGS -Mallocatable=03)
list(APPEND FLIBS -static-flang-libs)
endif()

# ---

include(CheckFortranSourceCompiles)

check_fortran_source_compiles("program es; error stop; end" f2008
SRC_EXT f90)

endif()
6 changes: 6 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
project('lowtran', 'fortran', default_options : ['default_library=static'])

lowtran_exe = executable('testlowtran', 'src/lowtran_driver.f90', 'src/lowtran7.f', 'src/assert.f90')

test('Obs2space', lowtran_exe, args: 'obs2space')
test('SolarRadiance', lowtran_exe, args: 'solarrad')
6 changes: 6 additions & 0 deletions mypy.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[mypy]
ignore_missing_imports = True
strict_optional = False
allow_redefinition = True
show_error_context = False
show_column_numbers = True
42 changes: 13 additions & 29 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = 2.4.0
author = Michael Hirsch, Ph.D.
author_email = scivision@users.noreply.github.com
description = Model of Earth atmosphere absorption and transmission vs. wavelength and location.
url = https://github.com/scivision/lowtran
url = https://github.com/space-physics/lowtran
keywords =
mesosphere
stratosphere
Expand All @@ -17,8 +17,10 @@ classifiers =
Programming Language :: Fortran
Programming Language :: Python :: 3.6
Programming Language :: Python :: 3.7
Programming Language :: Python :: 3.8
Topic :: Scientific/Engineering :: Atmospheric Science
license_file = LICENSE
license_files =
LICENSE.txt
long_description = file: README.md
long_description_content_type = text/markdown

Expand All @@ -28,8 +30,16 @@ setup_requires =
setuptools >= 38.6
pip >= 10
twine >= 1.11
include_package_data = True
packages = find:
scripts =
HorizontalTransmittance.py
ThermalRadiance.py
UserHorizontalTransmittance.py
ScatterRadiance.py
TransmittanceGround2Space.py
Wavelength2LowtranWavenumber.py
SolarIrradiance.py
UserDataHorizontalRadiance.py
install_requires =
python-dateutil
numpy
Expand Down Expand Up @@ -57,29 +67,3 @@ console_scripts =
UserDataHorizontalRadiance = UserDataHorizontalRadiance:main
UserHorizontalTransmittance = UserHorizontalTransmittance:main
Wavelength2LowtranWavenumber = Wavelength2LowtranWavenumber:main

[flake8]
max-line-length = 132
exclude = .git,__pycache__,.eggs/,doc/,docs/,build/,dist/,archive/

[coverage:run]
cover_pylib = false
omit =
/home/travis/virtualenv/*
*/site-packages/*
*/bin/*

[coverage:report]
exclude_lines =
pragma: no cover
def __repr__
except RuntimeError
except NotImplementedError
except ImportError
except FileNotFoundError
except CalledProcessError
logging.warning
logging.error
logging.critical
if __name__ == .__main__.:

15 changes: 7 additions & 8 deletions src/assert.f90
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@ module assert
use, intrinsic:: iso_c_binding, only: sp=>c_float, dp=>c_double
use, intrinsic:: iso_fortran_env, only: stderr=>error_unit
use, intrinsic:: ieee_arithmetic
use error
implicit none

private

integer,parameter :: wp = sp
public :: wp,isclose, assert_isclose, errorstop

public :: wp,isclose, assert_isclose

contains

Expand Down Expand Up @@ -42,11 +41,11 @@ elemental logical function isclose(actual, desired, rtol, atol, equal_nan)
if (present(rtol)) r = rtol
if (present(atol)) a = atol
if (present(equal_nan)) n = equal_nan

!print*,r,a,n,actual,desired

!--- sanity check
if ((r < 0._wp).or.(a < 0._wp)) call errorstop
if ((r < 0._wp).or.(a < 0._wp)) error stop "impossible tolerance"
!--- simplest case -- too unlikely, especially for arrays?
!isclose = (actual == desired)
!if (isclose) return
Expand Down Expand Up @@ -79,10 +78,10 @@ impure elemental subroutine assert_isclose(actual, desired, rtol, atol, equal_na
real(wp), intent(in), optional :: rtol, atol
logical, intent(in), optional :: equal_nan
character(*), intent(in), optional :: err_msg

if (.not.isclose(actual,desired,rtol,atol,equal_nan)) then
write(stderr,*) merge(err_msg,'',present(err_msg)),': actual',actual,'desired',desired
call errorstop
error stop "values not within specified tolerances"
endif

end subroutine assert_isclose
Expand Down
15 changes: 0 additions & 15 deletions src/error2003.f90

This file was deleted.

15 changes: 0 additions & 15 deletions src/error2008.f90

This file was deleted.

6 changes: 0 additions & 6 deletions tests/test_lowtran.m
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
%% environment
assert(~verLessThan('matlab', '9.5'), 'Matlab >= R2018b required')
v = ver('matlab');
mv = v.Version;
pv = pyversion;
switch(mv)
case '9.5', assert(pv=="3.6", 'Matlab <-> Python version mismatch')
end

%% simple
cwd = fileparts(mfilename('fullpath'));
Expand Down
11 changes: 5 additions & 6 deletions tests/test_matlab.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,16 @@
from pathlib import Path
import subprocess
import pytest
import shutil

R = Path(__file__).parent
MATLAB = shutil.which('matlab')


@pytest.mark.skipif(not MATLAB, reason='Matlab not found')
def test_matlab_api():
try:
subprocess.check_call(['matlab', '-nojvm', '-r',
'r=runtests(); exit(any([r.Failed]))'],
cwd=R, timeout=60)
except FileNotFoundError as e:
pytest.skip(f'Matlab not available {e}')
subprocess.check_call(['matlab', '-batch', 'r=runtests(); exit(any([r.Failed]))'],
cwd=R, timeout=60)


if __name__ == '__main__':
Expand Down

0 comments on commit cb4c084

Please sign in to comment.