Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 30fcb0362d06ceedf46abeee729b9398d5d186b4
Author: Michael Hirsch, Ph.D <scivision@users.noreply.github.com>
Date:   Mon Aug 13 18:50:14 2018 -0400

    allow user to specify wavelength step (short, long, step)

commit 4f0b26421207acaa2d09fcd61d357a765a124532
Author: Michael Hirsch, Ph.D <scivision@users.noreply.github.com>
Date:   Mon Aug 13 18:07:30 2018 -0400

    cleanup

commit c45c10e76206efade9c0e03543a73aa06601e113
Author: Michael Hirsch, Ph.D <scivision@users.noreply.github.com>
Date:   Mon Aug 13 18:03:57 2018 -0400

    modularize
  • Loading branch information
scivision committed Aug 13, 2018
1 parent be68ef9 commit 92c683e
Show file tree
Hide file tree
Showing 24 changed files with 355 additions and 299 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ script:

after_success:
- if [[ $TRAVIS_PYTHON_VERSION == 3.6* ]]; then
pytest --cov;
pytest --cov --cov-config=setup.cfg;
coveralls;
fi

8 changes: 4 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ endif()


# --- assert lib
add_library(assert assert.f90)
add_library(assert src/assert.f90)
target_compile_options(assert PRIVATE ${FFLAGS})

set(okcomp GNU Intel)
if(CMAKE_Fortran_COMPILER_ID IN_LIST okcomp)
target_sources(assert PRIVATE error2008.f90)
target_sources(assert PRIVATE src/error2008.f90)
else() # non-Fortran 2008 compilers
target_sources(assert PRIVATE error2003.f90)
target_sources(assert PRIVATE src/error2003.f90)
endif()
# ---
add_executable(testlowtran reference/lowtran_driver.f90 lowtran7.f)
add_executable(testlowtran reference/lowtran_driver.f90 src/lowtran7.f)
target_link_libraries(testlowtran PRIVATE assert)
target_compile_options(testlowtran PRIVATE ${FFLAGS})

Expand Down
8 changes: 6 additions & 2 deletions HorizontalTransmittance.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,17 @@ def main():
p.add_argument('-z', '--obsalt', help='altitude of bother observers on horizontal path [km]', type=float, default=0.3)
p.add_argument('-r', '--range_km', help='range between observers on horizontal path [km]', type=float, default=1.0)
p.add_argument('-a', '--zenang', help='zenith angle [deg] can be single value or list of values', type=float, default=0.)
p.add_argument('-w', '--wavelen', help='wavelength range nm (start,stop)', type=float, nargs=2, default=(200, 30000))
p.add_argument('-s', '--short', help='shortest wavelength nm ', type=float, default=200)
p.add_argument('-l', '--long', help='longest wavelength nm ', type=float, default=30000)
p.add_argument('-step', help='wavelength step size cm^-1', type=float, default=20)
P = p.parse_args()

c1 = {'zmdl': P.obsalt,
'h1': P.obsalt,
'range_km': P.range_km,
'wlnmlim': P.wavelen,
'wlshort': P.short,
'wllong': P.long,
'wlstep': P.step,
}

TR = lowtran.horiztrans(c1).squeeze()
Expand Down
36 changes: 20 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,11 @@

# Lowtran in Python

LOWTRAN7 atmospheric absorption extinction model. Updated by Michael
Hirsch to be platform independent and easily accessible from Python.
LOWTRAN7 atmospheric absorption extinction model.
Updated by Michael Hirsch to be platform independent and easily accessible from Python.

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. xarray.Dataset high-performance
N-D array data is passed out, with all appropriate metadata.
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.
`xarray.Dataset` high-performance, simple N-D array data is passed out, with appropriate metadata.


## Gallery
Expand All @@ -26,7 +24,9 @@ See below for how to make these examples.

## Install

1. You need a Fortran compiler. If you don't have one, here is how to install Gfortran:
1. A Fortran compiler such as `gfortran` is needed.
We use `f2py` (part of `numpy`) to seamlessly use the Fortran Lowtran library from Python.
If you don't have one, here is how to install Gfortran:

* Linux: `apt install gfortran`
* Mac: `brew install gcc`
Expand Down Expand Up @@ -78,21 +78,25 @@ Right now a lot of configuration features aren't implemented, please request tho
### Fortran (optional)
This is not necessary for normal users:
```sh
cd bin
cmake ..
cmake --build .
ctest -V
```
cd bin
cmake ..
make
make test
should generate [this text output](https://gist.github.com/drhirsch/89ef2060d8f15b0a60914d13a61e33ab).
should generate
[this text output](https://gist.github.com/drhirsch/89ef2060d8f15b0a60914d13a61e33ab).
### Windows f2py
(this is handled automatically by `setup.py`, noted here for debugging)
Yes, even though you're [using a 64-bit compiler](https://scivision.co/f2py-running-fortran-code-in-python-on-windows/):

f2py --compiler=mingw32 -m lowtran7 -c lowtran7.f
Yes, even though you're
[using a 64-bit compiler](https://scivision.co/f2py-running-fortran-code-in-python-on-windows/):
```sh
f2py --compiler=mingw32 -m lowtran7 -c lowtran7.f
```

Tested on Windows with
[MinGW](https://sourceforge.net/projects/mingw-w64/).
Expand Down
10 changes: 7 additions & 3 deletions ScatterRadiance.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from matplotlib.pyplot import show
try:
import seaborn as sns
sns.set_context('talk', font_scale=1.5)
sns.set_context('talk')
except ImportError:
pass
from argparse import ArgumentParser
Expand All @@ -27,7 +27,9 @@ def main():
p = ArgumentParser(description='Lowtran 7 interface')
p.add_argument('-z', '--obsalt', help='altitude of observer [km]', type=float, default=0.)
p.add_argument('-a', '--zenang', help='Observer zenith angle [deg] ', nargs='+', type=float, default=[0., 60, 80])
p.add_argument('-w', '--wavelen', help='wavelength range nm (start,stop)', type=float, nargs=2, default=(300, 1000))
p.add_argument('-s', '--short', help='shortest wavelength nm ', type=float, default=400)
p.add_argument('-l', '--long', help='longest wavelength nm ', type=float, default=700)
p.add_argument('-step', help='wavelength step size cm^-1', type=float, default=20)
p.add_argument('-o', '--outfn', help='NetCDF4 file to write')
p.add_argument('--model', help='0-6, see Card1 "model" reference. 5=subarctic winter', type=int, default=5)

Expand All @@ -36,7 +38,9 @@ def main():
c1 = {'model': P.model,
'h1': P.obsalt, # of observer
'angle': P.zenang, # of observer
'wlnmlim': P.wavelen,
'wlshort': P.short,
'wllong': P.long,
'wlstep': P.step,
}
# %%
TR = lowtran.scatter(c1)
Expand Down
8 changes: 6 additions & 2 deletions SolarIrradiance.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,18 @@ def main():
p = ArgumentParser(description='Lowtran 7 interface')
p.add_argument('-z', '--obsalt', help='altitude of observer [km]', type=float, default=0.)
p.add_argument('-a', '--zenang', help='zenith angle [deg] of sun or moon', nargs='+', type=float, default=[0, 60, 80])
p.add_argument('-w', '--wavelen', help='wavelength range nm (start,stop)', type=float, nargs=2, default=(200, 25000))
p.add_argument('-s', '--short', help='shortest wavelength nm ', type=float, default=200)
p.add_argument('-l', '--long', help='longest wavelength nm ', type=float, default=30000)
p.add_argument('-step', help='wavelength step size cm^-1', type=float, default=20)
p.add_argument('--model', help='0-6, see Card1 "model" reference. 5=subarctic winter', type=int, default=5)
P = p.parse_args()

c1 = {'model': P.model,
'h1': P.obsalt,
'angle': P.zenang, # zenith angle of sun or moon
'wlnmlim': P.wavelen,
'wlshort': P.short,
'wllong': P.long,
'wlstep': P.step,
}

irr = lowtran.irradiance(c1)
Expand Down
8 changes: 6 additions & 2 deletions ThermalRadiance.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ def main():
p = ArgumentParser(description='Lowtran 7 interface')
p.add_argument('-z', '--obsalt', help='altitude of observer [km]', type=float, default=0.)
p.add_argument('-a', '--zenang', help='Observer zenith angle [deg] ', nargs='+', type=float, default=[0., 60, 80])
p.add_argument('-w', '--wavelen', help='wavelength range nm (start,stop)', type=float, nargs=2, default=(200, 30000))
p.add_argument('-s', '--short', help='shortest wavelength nm ', type=float, default=200)
p.add_argument('-l', '--long', help='longest wavelength nm ', type=float, default=30000)
p.add_argument('-step', help='wavelength step size cm^-1', type=float, default=20)
p.add_argument('-o', '--outfn', help='HDF5 file to write')
p.add_argument('--model', help='0-6, see Card1 "model" reference. 5=subarctic winter', type=int, default=5)

Expand All @@ -32,7 +34,9 @@ def main():
c1 = {'model': P.model,
'h1': P.obsalt, # of observer
'angle': P.zenang, # of observer
'wlnmlim': P.wavelen,
'wlshort': P.short,
'wllong': P.long,
'wlstep': P.step,
}

TR = lowtran.radiance(c1)
Expand Down
8 changes: 6 additions & 2 deletions TransmittanceGround2Space.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,18 @@ def main():
p = ArgumentParser(description='Lowtran 7 interface')
p.add_argument('-z', '--obsalt', help='altitude of observer [km]', type=float, default=0.)
p.add_argument('-a', '--zenang', help='observer zenith angle [deg]', type=float, nargs='+', default=[0, 60, 80])
p.add_argument('-w', '--wavelen', help='wavelength range nm (start,stop)', type=float, nargs=2, default=(200, 30000))
p.add_argument('-s', '--short', help='shortest wavelength nm ', type=float, default=200)
p.add_argument('-l', '--long', help='longest wavelength cm^-1 ', type=float, default=30000)
p.add_argument('-step', help='wavelength step size cm^-1', type=float, default=20)
p.add_argument('--model', help='0-6, see Card1 "model" reference. 5=subarctic winter', type=int, default=5)
P = p.parse_args()

c1 = {'model': P.model,
'h1': P.obsalt,
'angle': P.zenang,
'wlnmlim': P.wavelen,
'wlshort': P.short,
'wllong': P.long,
'wlstep': P.step,
}

TR = lowtran.transmittance(c1)
Expand Down
8 changes: 6 additions & 2 deletions UserDataHorizontalRadiance.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,19 @@ def main():
p.add_argument(
'ptfn', help='csv file with time,relative humidity [%],ambient temperature [K], total pressure (millibar)', nargs='?')
p.add_argument('-z', '--obsalt', help='altitude of observer [km]', type=float, default=0.05)
p.add_argument('-w', '--wavelen', help='wavelength range nm (start,stop)', type=float, nargs=2, default=(200, 30000))
p.add_argument('-s', '--short', help='shortest wavelength nm ', type=float, default=200)
p.add_argument('-l', '--long', help='longest wavelength nm ', type=float, default=30000)
p.add_argument('-step', help='wavelength step size cm^-1', type=float, default=20)
p.add_argument('-o', '--outfn', help='HDF5 file to write')
P = p.parse_args()

# %% low-level Lowtran configuration for this scenario, don't change
c1 = {'range_km': P.obsalt,
'zmdl': P.obsalt,
'h1': P.obsalt,
'wlnmlim': P.wavelen,
'wlshort': P.short,
'wllong': P.long,
'wlstep': P.step,
}

TR = lowtran.horizrad(P.ptfn, P.outfn, c1)
Expand Down
8 changes: 6 additions & 2 deletions UserHorizontalTransmittance.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,17 @@ def main():
p.add_argument('-z', '--obsalt', help='altitude of bother observers on horizontal path [km]', type=float, default=0.3)
p.add_argument('-r', '--range_km', help='range between observers on horizontal path [km]', type=float, default=1.0)
p.add_argument('-a', '--zenang', help='zenith angle [deg] can be single value or list of values', type=float, default=0.)
p.add_argument('-w', '--wavelen', help='wavelength range nm (start,stop)', type=float, nargs=2, default=(200, 30000))
p.add_argument('-s', '--short', help='shortest wavelength nm ', type=float, default=200)
p.add_argument('-l', '--long', help='longest wavelength nm ', type=float, default=30000)
p.add_argument('-step', help='wavelength step size cm^-1', type=float, default=20)
P = p.parse_args()

c1 = {'zmdl': P.obsalt,
'h1': P.obsalt,
'range_km': P.range_km,
'wlnmlim': P.wavelen,
'wlshort': P.short,
'wllong': P.long,
'wlstep': P.step,
}

atmos = {'p': 949., 't': 283.8, 'wmol': [93.96, 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.]}
Expand Down
7 changes: 5 additions & 2 deletions Wavelength2LowtranWavenumber.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,13 @@

def main():
p = ArgumentParser()
p.add_argument('wlnm', help='wavelength [nm]', nargs='+', type=float)
p.add_argument('-s', '--short', help='shortest wavelength nm ', type=float, default=200)
p.add_argument('-l', '--long', help='longest wavelength nm ', type=float, default=30000)
p.add_argument('-step', help='wavelength step size cm^-1', type=float, default=20)
P = p.parse_args()

print(nm2lt7(P.wlnm)[0])
w = nm2lt7(P.short, P.long, P.step)
print(f'{w[0]:.2f} cm^-1 to {w[1]:.2f} cm^-1, comprising {w[2]} wavelength steps')


if __name__ == '__main__':
Expand Down
Loading

0 comments on commit 92c683e

Please sign in to comment.