Skip to content

Commit

Permalink
Flux recipes (#840)
Browse files Browse the repository at this point in the history
  • Loading branch information
riclarsson authored Oct 16, 2024
2 parents bdb9916 + 8181701 commit fb0c77f
Show file tree
Hide file tree
Showing 38 changed files with 1,593 additions and 500 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ jobs:
if: matrix.doc == 'yes'
shell: bash -l {0}
run: |
python3 -m pip install build/python
cmake --build build -j${{ matrix.jbuild }} --target apidoc pyarts_docs
tar -zcf doxygen.tar.gz build/doc/doxygen/html
tar -zcf sphinx.tar.gz build/python/doc/build
Expand Down
53 changes: 22 additions & 31 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -467,43 +467,34 @@ endif (TEST_JOBS)
########### Path to arts-xml-data ##########
if (ARTS_XML_DATA_PATH)
get_filename_component (ARTS_XML_DATA_DIR "${ARTS_XML_DATA_PATH}" ABSOLUTE)
else (ARTS_XML_DATA_PATH)
if (NOT IS_DIRECTORY "${ARTS_XML_DATA_DIR}")
message(FATAL_ERROR "ARTS_XML_DATA_PATH is not a valid directory: ${ARTS_XML_DATA_PATH}")
endif()
else ()
get_filename_component (ARTS_XML_DATA_DIR "${CMAKE_SOURCE_DIR}/../arts-xml-data" ABSOLUTE)
endif (ARTS_XML_DATA_PATH)

if (NOT IS_DIRECTORY "${ARTS_XML_DATA_DIR}")
message(WARNING "Cannot determine location of arts-xml-data!
Depending tests will be disabled.
Please specify arts-xml-data location with
cmake -DARTS_XML_DATA_PATH=PATH_TO_ARTS_XML_DATA ..")
unset (ARTS_XML_DATA_DIR)
else (NOT IS_DIRECTORY "${ARTS_XML_DATA_DIR}")
message(STATUS "Found arts-xml-data in ${ARTS_XML_DATA_DIR}")
endif (NOT IS_DIRECTORY "${ARTS_XML_DATA_DIR}")
if (NOT IS_DIRECTORY "${ARTS_XML_DATA_DIR}")
set (ARTS_XML_DATA_DIR "${ARTS_BINARY_DIR}/tests/testdata/arts-xml-data")
message (STATUS "Did not find arts-xml-data, will be partially downloaded to ${ARTS_XML_DATA_DIR}")
else()
message(STATUS "Found arts-xml-data in ${ARTS_XML_DATA_DIR}")
endif()
endif ()

########### Path to arts-cat-data ##########
if (ARTS_CAT_DATA_PATH)
get_filename_component (ARTS_CAT_DATA_DIR "${ARTS_CAT_DATA_PATH}" ABSOLUTE)
else (ARTS_CAT_DATA_PATH)
if (NOT IS_DIRECTORY "${ARTS_CAT_DATA_DIR}")
message(FATAL_ERROR "ARTS_CAT_DATA_PATH is not a valid directory: ${ARTS_XML_DATA_PATH}")
endif()
else ()
get_filename_component (ARTS_CAT_DATA_DIR "${CMAKE_SOURCE_DIR}/../arts-cat-data" ABSOLUTE)
endif (ARTS_CAT_DATA_PATH)

if (NOT IS_DIRECTORY "${ARTS_CAT_DATA_DIR}")
message(WARNING "Cannot determine location of arts-cat-data!
Depending tests will be disabled.
Please specify arts-cat-data location with
cmake -DARTS_CAT_DATA_PATH=PATH_TO_ARTS_CAT_DATA ..")
unset (ARTS_CAT_DATA_DIR)
else (NOT IS_DIRECTORY "${ARTS_CAT_DATA_DIR}")
message(STATUS "Found arts-cat-data in ${ARTS_CAT_DATA_DIR}")
endif (NOT IS_DIRECTORY "${ARTS_CAT_DATA_DIR}")

if (WIN)
string(JOIN ";" ARTS_DATA_DIR ${ARTS_XML_DATA_DIR} ${ARTS_CAT_DATA_DIR})
else()
string(JOIN ":" ARTS_DATA_DIR ${ARTS_XML_DATA_DIR} ${ARTS_CAT_DATA_DIR})
endif()

if (NOT IS_DIRECTORY "${ARTS_CAT_DATA_DIR}")
set (ARTS_CAT_DATA_DIR "${ARTS_BINARY_DIR}/tests/testdata/arts-cat-data")
message (STATUS "Did not find arts-cat-data, will be partially downloaded to ${ARTS_CAT_DATA_DIR}")
else()
message(STATUS "Found arts-cat-data in ${ARTS_CAT_DATA_DIR}")
endif()
endif ()

########### Path to partition functions data ##########
if (ARTS_PARTFUN_DATA_PATH)
Expand Down
42 changes: 5 additions & 37 deletions cmake/modules/ArtsTestcases.cmake
Original file line number Diff line number Diff line change
@@ -1,25 +1,4 @@
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(DELIM "\;")
else()
set(DELIM ":")
endif()

macro (ARTS_TEST_RUN_EXE TESTNAME EXE)
if (ARTS_DATA_DIR)
string(APPEND CPP_TEST_INCLUDE_PATH "${DELIM}${ARTS_DATA_DIR}")
endif()

if (ARTS_XML_DATA_DIR)
string(APPEND CPP_TEST_INCLUDE_PATH ";ARTS_XML_DATA_DIR=${ARTS_XML_DATA_DIR}")
else()
string(APPEND CPP_TEST_INCLUDE_PATH ";ARTS_XML_DATA_DIR=${ARTS_BINARY_DIR}/tests/testdata/arts-xml-data")
endif()

if (ARTS_CAT_DATA_DIR)
string(APPEND CPP_TEST_INCLUDE_PATH ";ARTS_CAT_DATA_DIR=${ARTS_CAT_DATA_DIR}")
else()
string(APPEND CPP_TEST_INCLUDE_PATH ";ARTS_CAT_DATA_DIR=${ARTS_BINARY_DIR}/tests/testdata/arts-cat-data")
endif()

set(TESTNAME_LONG cpp.${TESTNAME})

Expand All @@ -29,27 +8,16 @@ macro (ARTS_TEST_RUN_EXE TESTNAME EXE)
)
set_tests_properties(
${TESTNAME_LONG} PROPERTIES
ENVIRONMENT "ARTS_HEADLESS=1;ARTS_INCLUDE_PATH=${CPP_TEST_INCLUDE_PATH}"
ENVIRONMENT "ARTS_HEADLESS=1;ARTS_XML_DATA_DIR=${ARTS_XML_DATA_DIR}"
)
endmacro()

macro (ARTS_TEST_RUN_PYFILE TESTNAME PYFILE)
if (ARTS_DATA_DIR)
string(APPEND PYARTS_TEST_INCLUDE_PATH "${DELIM}${ARTS_DATA_DIR}")
endif()

if (ARTS_XML_DATA_DIR)
string(APPEND PYARTS_TEST_INCLUDE_PATH ";ARTS_XML_DATA_DIR=${ARTS_XML_DATA_DIR}")
if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
set(DELIM "\;")
else()
string(APPEND PYARTS_TEST_INCLUDE_PATH ";ARTS_XML_DATA_DIR=${ARTS_BINARY_DIR}/tests/testdata/arts-xml-data")
set(DELIM ":")
endif()

if (ARTS_CAT_DATA_DIR)
string(APPEND PYARTS_TEST_INCLUDE_PATH ";ARTS_CAT_DATA_DIR=${ARTS_CAT_DATA_DIR}")
else()
string(APPEND PYARTS_TEST_INCLUDE_PATH ";ARTS_CAT_DATA_DIR=${ARTS_BINARY_DIR}/tests/testdata/arts-cat-data")
endif()

string(REGEX REPLACE "/" "." TESTNAME_LONG ${PYFILE})
string(REGEX REPLACE ".py$" "" TESTNAME_LONG ${TESTNAME_LONG})
set(TESTNAME_LONG pyarts.${TESTNAME}.${TESTNAME_LONG})
Expand All @@ -62,7 +30,7 @@ macro (ARTS_TEST_RUN_PYFILE TESTNAME PYFILE)
)
set_tests_properties(
${TESTNAME_LONG} PROPERTIES
ENVIRONMENT "PYTHONPATH=${ARTS_BINARY_DIR}/python/src;ARTS_HEADLESS=1;ARTS_INCLUDE_PATH=${CMAKE_CURRENT_SOURCE_DIR}/${CFILESUBDIR}${DELIM}${PYARTS_TEST_INCLUDE_PATH}"
ENVIRONMENT "PYTHONPATH=${ARTS_BINARY_DIR}/python/src;ARTS_HEADLESS=1;ARTS_XML_DATA_DIR=${CMAKE_CURRENT_SOURCE_DIR}/${CFILESUBDIR}${DELIM}${ARTS_XML_DATA_DIR};ARTS_CAT_DATA_DIR=${ARTS_CAT_DATA_DIR}"
DEPENDS python_tests
)
endmacro()
Expand Down
142 changes: 142 additions & 0 deletions examples/recipes/AtmosphericFlux/atmospheric_flux.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "42082fbc",
"metadata": {},
"source": [
"# Atmospheric flux operator"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "a3eae4ea-0aca-4502-9043-54e2ca6fcab9",
"metadata": {},
"outputs": [],
"source": [
"import pyarts\n",
"import numpy as np\n",
"import matplotlib.pyplot as plt"
]
},
{
"cell_type": "markdown",
"id": "952fa30f-9620-493b-9a69-7ea46d0ae9b7",
"metadata": {},
"source": [
"## Initialize the operator\n",
"\n",
"See [AtmosphericFlux](pyarts.recipe.rst#pyarts.recipe.AtmosphericFlux)."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b1943594-5e27-4c9c-831c-c575bbc08c6c",
"metadata": {},
"outputs": [],
"source": [
"fop = pyarts.recipe.AtmosphericFlux()"
]
},
{
"cell_type": "markdown",
"id": "df821a5e-11df-4000-a66f-b19ce8a431d1",
"metadata": {},
"source": [
"## Get the atmosphere (optional)\n",
"The atmosphere is the full atmospheric field of ARTS as a dictionary,\n",
"which is likely more than you wish to change. You may change only part\n",
"of the atmosphere by simply creating a dictionary that only contains the\n",
"fields that you want to change."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "79c18bda-7f10-42cb-87b0-ba636cef37f9",
"metadata": {},
"outputs": [],
"source": [
"atm = fop.get_atmosphere()"
]
},
{
"cell_type": "markdown",
"id": "da679d8d-8eef-4437-b299-7c85487df39a",
"metadata": {},
"source": [
"## Get the profile flux for the given `atm`\n",
"Passing `atm` is optional, if not passed the operator will use the current atmosphere,\n",
"which is the atmosphere that was set with the last call to `__call__`, or the constructor\n",
"default if no call to `__call__` has been made."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "ebf13038-90c1-44dc-93ad-63d4d3da105b",
"metadata": {},
"outputs": [],
"source": [
"solar, thermal, altitude = fop(atmospheric_profile=atm)"
]
},
{
"cell_type": "markdown",
"id": "25eafbd8",
"metadata": {},
"source": [
"## Plot"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b998604b-98aa-4f46-bf78-288d65ffb78e",
"metadata": {},
"outputs": [],
"source": [
"plt.figure(1, figsize=(8, 6))\n",
"plt.clf()\n",
"plt.subplot(121)\n",
"plt.plot(solar.up, altitude/1e3)\n",
"plt.plot(solar.down, altitude/1e3)\n",
"plt.legend([\"up\", \"down\"])\n",
"plt.ylabel(\"Altitude [km]\")\n",
"plt.xlabel(\"Flux [W / m$^2$]\")\n",
"plt.title(\"Solar flux\")\n",
"\n",
"plt.subplot(122)\n",
"plt.plot(thermal.up, altitude/1e3)\n",
"plt.plot(thermal.down, altitude/1e3)\n",
"plt.legend([\"up\", \"down\"])\n",
"plt.ylabel(\"Altitude [km]\")\n",
"plt.xlabel(\"Flux [W / m$^2$]\")\n",
"plt.title(\"Thermal flux\")"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.12.6"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
4 changes: 0 additions & 4 deletions examples/recipes/FastFlux1D.py

This file was deleted.

43 changes: 0 additions & 43 deletions examples/recipes/SingleSpeciesAbsorption.py

This file was deleted.

Loading

0 comments on commit fb0c77f

Please sign in to comment.