Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions fast-magephem-service/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ core.*
*~
*.csv
*.err
*.so
*.o
python/irene/c/*.so
python/irene/c/common_include
python/irene/c/lib
python/irene/c/models_include
python/irene/lib
.dockerconfigjson
40 changes: 26 additions & 14 deletions fast-magephem-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,24 +1,36 @@
#FROM e3-devops.aero.org/ssdhas/python:3.9.13-buster
FROM python:3.9.13-buster
FROM python:3.9.17-slim-bookworm

WORKDIR /app

#Removing warning in Jenkins about apt-util not being installed, causing containerization to hang
ENV DEBIAN_FRONTEND noninteractive
ENV DEBCONF_NOWARNINGS="yes"

RUN apt-get update && apt-get install -y\
build-essential \
cmake \
gfortran \
libboost-all-dev \
libopenmpi-dev \
googletest \
libhdf5-dev \
libxerces-c-dev \
&& rm -rf /var/lib/apt/lists/*

COPY requirements.txt .

RUN pip install --no-cache-dir --upgrade pip setuptools \
&& pip install --no-cache-dir -r requirements.txt \
&& pip uninstall -y Flask \
&& pip install Flask==2.2.3

COPY python /app/python
COPY python/lib /usr/local/lib64/
COPY test /app/test
COPY requirements.txt .

RUN ln -s /usr/lib/x86_64-linux-gnu/hdf5/serial/libhdf5.so /usr/lib/x86_64-linux-gnu/libhdf5.so.103

#RUN DOW=$(date +%a) \
RUN apt-get update \
&& apt-get install -y build-essential \
&& apt-get install -y libhdf5-dev \
&& apt-get install -y libxerces-c-dev \
&& pip3 install --upgrade pip setuptools \
&& pip3 install -r requirements.txt \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& ln -s /usr/lib/x86_64-linux-gnu/hdf5/serial/libhdf5.so /usr/lib/x86_64-linux-gnu/libhdf5.so.103
# Run pytest tests
RUN pytest /app/test

# Run app.py
CMD ["python", "/app/python/app.py"]
3 changes: 1 addition & 2 deletions fast-magephem-service/python/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
update to python 3.7+ to get fromisoformat
replace strptime call
modify OpenAPI YAML file to note time format S(.mmmuuu) instead of S.mmm(uuu)
add magephem service for OPQ
add magephem service for IGRF, T89
add magephem service for T89 (when IRENE C++ code supports it)
"""

import sys
Expand Down
50 changes: 38 additions & 12 deletions fast-magephem-service/python/fast-magephem.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ paths:
Supports GDZ, GEO, GSM, GSE, SM, GEI, MAG, SPH.<br>
Provide input system (fromSys) and list of dates (dates),
list of 3-D locations (xIN), and requested output system (outSys).<br>
Supports up to 100,000 dates/locations <br>
Returns same list of dates (dates) and list of 3-D locations (xOUT) in output system.<br>
dates and xIN lists must have same length. xOUT will have that length as well.<br>
- GDZ - geodetic as alt (km), latitude (deg), longitude (deg).
Expand Down Expand Up @@ -67,6 +68,8 @@ paths:
xIN:
allOf:
- $ref: '#/components/schemas/CoordinateList3D'
minItems: 0
maxItems: 100000
description: "list of input 3-D coordinate sets in fromSys (nested list)"
responses:
'200':
Expand All @@ -83,14 +86,16 @@ paths:
xOUT:
allOf:
- $ref: '#/components/schemas/CoordinateList3D'
minItems: 0
maxItems: 100000
description: "list of 3-D coordinate sets in toSys (nested list)"
'405':
description: Invalid input
/magephem:
post:
tags:
- magephem
summary: Translate from one 3-D frame to another
summary: Compute magnetic ephemeris
description: |
compute magnetic ephemeris / coordinates for a list of times and locations<br>

Expand All @@ -112,6 +117,7 @@ paths:
time x 3, or time x direciton x 3
- kext - external field model 'opq' or 'igrf' (=none)
- outputs - list of coordinates to output (I,Bm,K,Phi,hmin,L,Blocal,MLT,Bmin,BminX,BminY,BminZ)<br>
Supports up to 100,000 dates/locations, and up to 25 pitch angles/dirs <br>
At most one of alpha, dirs is allowed. if neither alpha or dirs is provided, assumes alpha=90


Expand Down Expand Up @@ -147,6 +153,8 @@ paths:
X:
allOf:
- $ref: '#/components/schemas/CoordinateList3D'
minItems: 0
maxItems: 100000
description: "list of input 3-D coordinate sets (nested list)"
sys:
allOf:
Expand All @@ -164,21 +172,37 @@ paths:
description: scalar input pitch angle
- type: array
example: [10.0,45.0,90.0]
minItems: 0
maxItems: 25
description: "static list of input pitch angles"
items:
$ref: '#/components/schemas/PitchAngle'
- type: array
example: [[10.0,45.0,90.0],[20.0,55.0,95.0]]
minItems: 0
maxItems: 100000
description: "time-varying list of lists input pitch angles"
items:
oneOf:
- $ref: '#/components/schemas/PitchAngle'
- type: array
items:
$ref: '#/components/schemas/PitchAngle'
description: "list of input pitch angles"
type: array
minItems: 0
maxItems: 25
items:
$ref: '#/components/schemas/PitchAngle'
dirs:
oneOf:
- allOf:
- $ref: '#/components/schemas/CoordinateList3D'
description: "list of input 3-D coordinate sets (nested list)"
minItems: 0
maxItems: 25
description: "list of static input 3-D coordinate sets (nested list)"
- type: array
minItems: 0
maxItems: 100000
items:
$ref: '#/components/schemas/CoordinateList3D'
allOf:
- $ref: '#/components/schemas/CoordinateList3D'
minItems: 0
maxItems: 25
description: "list of lists of input 3-D coordinate sets (nested nested list)"
outputs:
type: array
Expand Down Expand Up @@ -286,6 +310,8 @@ components:
DateList:
# supply "description" via {allOf : [ $ref : #/components/schemas/DateList],description:...}
type: array
minItems: 0
maxItems: 100000
items:
type: string
format: date-time
Expand All @@ -296,10 +322,10 @@ components:
example: [[ 100.0, 45.0, -73.0],[ 100.1, 45.2, -73.5]]
items:
type: array
minItems: 3
maxItems: 3
items:
format: number
minLength: 3
maxLength: 3
example: 100.0
PitchAngle:
type: number
Expand All @@ -317,4 +343,4 @@ components:
type: number
default: -1.0E+30



2 changes: 1 addition & 1 deletion fast-magephem-service/python/irene/fast_invariants.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
assert _slash == '/', "non-linux systems not supported yet"
_flyin_path = os.path.dirname(os.path.abspath(__file__))
_NN_files = { # file names by [kext][coord] w/o the final .mat, also w/o _Kp# for t89
'opq':{'Phi':'fastPhi_net','hmin':'fast_him_net'},
'opq':{'Phi':'fastPhi_net','hmin':'fast_hmin_net'},
'igrf':{'Phi':'fastPhi_net_igrf','hmin':'fast_hmin_net_igrf'},
}
_NNs = {key:{} for key in _NN_files} # nets themselves
Expand Down
Binary file removed fast-magephem-service/python/irene/lib.zip
Binary file not shown.
Binary file not shown.
Binary file removed fast-magephem-service/python/lib.zip
Binary file not shown.
Binary file added fast-magephem-service/python/lib/libAbMatrix.so
Binary file not shown.
Binary file added fast-magephem-service/python/lib/libCTimeValue.so
Binary file not shown.
Binary file not shown.
Binary file added fast-magephem-service/python/lib/libFloatMath.so
Binary file not shown.
Binary file not shown.
Binary file added fast-magephem-service/python/lib/libThreading.so
Binary file not shown.
Binary file added fast-magephem-service/python/lib/libTimeConv_c.so
Binary file not shown.
Binary file not shown.
Binary file added fast-magephem-service/python/lib/libVectorOps.so
Binary file not shown.
Binary file not shown.
Binary file added fast-magephem-service/python/lib/libadiabat.so
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added fast-magephem-service/python/lib/libcammice.so
Binary file not shown.
Binary file added fast-magephem-service/python/lib/libcmagfield.so
Binary file not shown.
Binary file not shown.
Binary file added fast-magephem-service/python/lib/libdosemodel.so
Binary file not shown.
Binary file not shown.
Binary file added fast-magephem-service/python/lib/libfileio.so
Binary file not shown.
Binary file added fast-magephem-service/python/lib/libfio.so
Binary file not shown.
Binary file added fast-magephem-service/python/lib/libinputproc.so
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added fast-magephem-service/python/lib/libmag_util.so
Binary file not shown.
Binary file added fast-magephem-service/python/lib/liborbitprop.so
Binary file not shown.
Binary file added fast-magephem-service/python/lib/libradenv.so
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added fast-magephem-service/python/lib/libtaskproc.so
Binary file not shown.
4 changes: 3 additions & 1 deletion fast-magephem-service/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,6 @@ connexion[swagger-ui]==2.14.1
numpy==1.22.4
h5py==3.7.0
scipy==1.9.3
flask==2.2.5
pytest==7.4.0
xlsxwriter==3.1.2
matplotlib==3.7.1
16 changes: 11 additions & 5 deletions fast-magephem-service/test/ssdhas_shared/python/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@

import numpy as np
import datetime as dt
from pytest import approx

def recursive_equals(a,b,path='/'):
if isinstance(a,np.ndarray):
assert isinstance(b,np.ndarray), '%s are not both numpy ndarrays ' % path
assert len(a.dtype) == len(b.dtype), '%s have different dtype structure' % path
if len(a.dtype) == 0: # simple array
assert np.array_equal(a,b,equal_nan=np.issubdtype(a.dtype,float)), 'arrays %s are not equal ' % path
assert np.all_close(a,b,equal_nan=np.issubdtype(a.dtype,float)), 'arrays %s are not equal ' % path
return True
else: # structured array
assert a.dtype.names != b.dtype.names, 'structured arrays %s have different keys ' % path
for key in a.dtype.names:
assert np.array_equal(a[key],b[key],equal_nan=np.issubdtype(a[key].dtype,float)),'arrays %s/%s are not equal' % (path,key)
assert np.all_close(a[key],b[key],equal_nan=np.issubdtype(a[key].dtype,float)),'arrays %s/%s are not equal' % (path,key)
return True

if isinstance(a,dict):
Expand All @@ -42,9 +43,14 @@ def recursive_equals(a,b,path='/'):
assert np.issubdtype(type(b),base),'%s are not both %s' % (path,base.__name__)
assert np.isscalar(a), 'a is not scalar %s' % path
assert np.isscalar(b), 'b is not scalar %s' % path
if base == float:
assert (np.isnan(a) == np.isnan(b)), 'Only one is NaN at %s' % (path)
assert a==b, 'a != b at %s' % path
if base == float: # special case, handling nan and approximately equal
if np.isnan(a):
assert np.isnan(b), 'a is nan, b is not at %s' % (path)
else:
assert not np.isnan(b), 'b is nan, a is not at %s' % (path)
assert a==approx(b), 'a != b at %s' % path
else: # all other classes require exact equals
assert a==b, 'a != b at %s' % path
return True

assert False, 'Unable to compare %s types %s and %s' % (path,type(a),type(b))
Expand Down