Package: kamodo
KamodoKamodo originated as a CCMC tool for access, interpolation, and visualization of space weather models and data in python.
Kamodo allows model developers to represent simulation results as mathematical functions which may be manipulated directly by end users.
This general approach allows observational data to be represented functionally, through the use of interpolators.
Kamodo handles unit conversion transparently and supports interactive science discovery in a low coding environment through jupyter notebooks.
These features allow Kamodo to be used in other fields of study and as a teaching tool for working with real world physical data.This repository hosts the core Kamodo libraries under a permissiveNASA open source license.
The core library supports function registration, composition, unit conversion, automated plotting, LaTeX I/O, and remote procedure call (RPC) interfaces.Space weather simulation readers are implemented as subclasses of the Kamodo base class and are developed and maintained by the Community Coordinated Modeling Center, located at NASA Goddard Space Flight Center. CCMC's Kamodo readers may be found herehttps://ccmc.gsfc.nasa.gov/Kamodo/UsageSuppose we have a vector field defined by a function of positions in the x-y plane:fromkamodoimportkamodofyimportnumpyasnpx=np.linspace(-np.pi,np.pi,25)y=np.linspace(-np.pi,np.pi,30)xx,yy=np.meshgrid(x,y)points=np.array(list(zip(xx.ravel(),yy.ravel())))@kamodofy(units='km/s')deffvec(rvec=points):ux=np.sin(rvec[:,0])uy=np.cos(rvec[:,1])returnnp.vstack((ux,uy)).TThe @kamodofy decorator lets us register this field with units to enable unit-conversion downstream:fromkamodoimportKamodokamodo=Kamodo(fvec=fvec)kamodoWhen run in a jupyter notebook, the above kamodo object will render as a set of equations:$$\vec{f}{\left (\vec{r} \right )} [km/s] = \lambda{\left (\vec{r} \right )}$$We can now evaluate our function using dot notation:kamodo.fvec(np.array([[-1,1]]))array([[-0.84147098,  0.54030231]])We can perform unit conversion by function composition:kamodo['gvec[m/s]']='fvec'kamodo automatically generates the appropriate multiplicative factors:
$$\vec{g}{\left (\vec{r} \right )} [m/s] = 1000 \vec{f}{\left (\vec{r} \right )}$$
we can verify these results through evaluationkamodo.gvec(np.array([[-1,1]]))array([[-841.47098481,  540.30230587]])Kamodo also generates quick-look graphics via function inspection.importplotly.ioaspiofig=kamodo.plot('fvec')pio.write_image(fig,'images/fig2d-usage.svg')Head over to theIntroductionpage for more details.Getting startedKamodo may be installed from pippip install kamodoKamodo is now maintained by Ensemble Government Services. To get the latest version, install from the Ensemble git repo:pip install git+https://github.com/EnsembleGovServices/kamodo-core.gitKamodo EnvironmentWe strongly recommend using the conda environment system to avoid library conflicts with your host machine's python.Download and install miniconda fromhere. The advantage to using miniconda is that each new environment includes the bare-minimum for a project. This allows you to keep many different projects on a single work station.Create Kamodo environmentCreate a new environment for kamodoconda create -n kamodo python=3.7conda activate kamodo(kamodo)pip install kamodo!!! note
The leading (kamodo) in your prompt indicates that you have activated thekamodoenvironment.
From here on, anything you install will be isolated to thekamodoenvironment.Loading example notebooksIf you want to run any of the notebooks in docs, you will need to installjupyter:(kamodo)conda install jupyterNavigate to the top-level of the kamodo repo, then point jupyter todocs/notebooks:(kamodo) jupyter notebook docs/notebooksThis should open a browser window that will allow you to load any of the example notebooks.RequirementsThe following (minimum) requirements are obtained by runningpip install kamododecorator>=4.4.2numpyscipysympy==1.5.1pandasplotlypytesthydra-core==0.11.3Flask==1.1.2flask-corsflask-restful==0.3.8antlr4-python3-runtime==4.7python-forgerequestsincrementalpycapnppyOpenSSLThe antlr package may be necessary for rendering latex in a notebookcondainstallantlr-python-runtimePlotly-orca may be needed for proper image exportcondainstall-cplotlyplotly-orca(forwritingimages)!!! note
plotly version in fluxTest SuiteKamodo's unit tests are run withpytest. To install pytest with code coveragepython-mpipinstallflake8pytest
pipinstallpytest-covThen, from the base of the git repo:pytest--covkamodo.kamodo--covkamodo.util--covplottingkamodo/test_plotting.pykamodo/test_kamodo.pykamodo/test_utils.pyThis will generate a test report and coverage of thekamodomodule.To run RPC tests, you must first generate a self-signed certificate.pythonkamodo/rpc/gen_self_signed_cert.pycertfile# certfile.key and certfile.cert will be placed in your local directorypytestkamodo/rpc/test_rpc_threaded.py