Skip to content

Commit

Permalink
Update setting of notebook's env. variables for CRDS (#262)
Browse files Browse the repository at this point in the history
* update crds config to match jwst-pipeline-notebooks

* move crds import to be after setting of env variables

* update set server condition

* move crds config to right below imports
  • Loading branch information
gibsongreen authored Nov 13, 2024
1 parent 4f7c223 commit 8e4eade
Showing 1 changed file with 45 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,55 @@
"import requests\n",
"from scipy.stats import sigmaclip\n",
"\n",
"from crds import client\n",
"import grismconf\n",
"from jwst.assign_wcs import AssignWcsStep\n",
"from jwst.flatfield import FlatFieldStep\n",
"from jwst.photom import PhotomStep"
]
},
{
"cell_type": "markdown",
"id": "d6b0fc4b",
"metadata": {},
"source": [
"## Set CRDS Path and Server"
]
},
{
"cell_type": "markdown",
"id": "bb09075d-b0ba-4bee-b6c5-a2f27b767b6a",
"metadata": {},
"source": [
"Before running the pipeline steps, we need to ensure our our CRDS environment is configured. This includes defining a CRDS cache directory in which to keep the reference files that will be used by the calibration pipeline.\n",
"\n",
"If the root directory for the local CRDS cache has not already been set, it will be created in the home directory."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "0ab935ab-a215-4fe3-8aad-b3dae5a017bb",
"metadata": {},
"outputs": [],
"source": [
"# Check whether the local CRDS cache directory has been set.\n",
"# If not, set it to the user home directory\n",
"if (os.getenv('CRDS_PATH') is None):\n",
" os.environ['CRDS_PATH'] = os.path.join(os.path.expanduser('~'), 'crds')\n",
"# Check whether the CRDS server URL has been set. If not, set it.\n",
"if (os.getenv('CRDS_SERVER_URL') is None):\n",
" os.environ['CRDS_SERVER_URL'] = 'https://jwst-crds.stsci.edu'\n",
"\n",
"# Echo CRDS path and context in use\n",
"print('CRDS local filepath:', os.environ['CRDS_PATH'])\n",
"print('CRDS file server:', os.environ['CRDS_SERVER_URL'])\n",
"\n",
"# import crds after setting up the required environment variables\n",
"from crds import client\n",
"if client.get_crds_server() != os.environ['CRDS_SERVER_URL']:\n",
" client.set_crds_server('https://jwst-crds.stsci.edu')"
]
},
{
"cell_type": "markdown",
"id": "117e4ec7-610c-4d11-82f4-756971dc23e0",
Expand Down Expand Up @@ -199,7 +241,7 @@
"id": "41068262-9a54-46c5-a9d2-ca2217ad1fee",
"metadata": {},
"source": [
"## Download Data and Ensure CRDS Configuration"
"## Download Data"
]
},
{
Expand All @@ -224,28 +266,6 @@
"get_jwst_file(wfss_file)"
]
},
{
"cell_type": "markdown",
"id": "faa27c94",
"metadata": {},
"source": [
"If CRDS is not configured, set the CRDS server URL and define a local cache path \n",
"to ensure the pipeline steps can access reference files as needed."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "af7a4057",
"metadata": {},
"outputs": [],
"source": [
"if os.environ.get(\"CRDS_PATH\") is None:\n",
" client.set_crds_server('https://jwst-crds.stsci.edu')\n",
" os.environ[\"CRDS_SERVER_URL\"] = \"https://jwst-crds.stsci.edu\"\n",
" os.environ[\"CRDS_PATH\"] = \"\""
]
},
{
"cell_type": "markdown",
"id": "ab5f3c78-258f-49c4-99c4-87e26f0972cf",
Expand Down Expand Up @@ -1138,7 +1158,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.10"
"version": "3.12.7"
}
},
"nbformat": 4,
Expand Down

0 comments on commit 8e4eade

Please sign in to comment.