Skip to content

Commit d5234ee

Browse files
authored
Merge pull request #160 from spacetelescope/dev
merge changes to Readme, local files and pandeia notebook
2 parents 1682e43 + 1410055 commit d5234ee

3 files changed

Lines changed: 84 additions & 31 deletions

File tree

README.md

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -10,33 +10,12 @@ Notebook tutorials are organized under the `content/notebooks/` directory. Each
1010

1111
Markdown documentation files are contained within the `markdown/` folder.
1212

13-
## Local Installation (Not Recommended)
13+
## Local Installation
1414

15-
The notebooks in this repository are designed to work on the Roman Research Nexus for the best user experience. Due to the size of Roman data, local use is not recommended for most users. However, we provide instructions for local installation below.
16-
17-
The notebooks contained in this repository can be run locally with the correct environment setup. It is recommended to create a new environment (e.g., with [mamba](https://mamba.readthedocs.io/en/latest/index.html)) to run the tutorials. For example:
18-
```
19-
mamba create -n roman-notebooks python ipython jupyterlab
20-
```
21-
22-
Each notebook folder includes a `requirements.txt` file with the necessary Python package versions listed. To install package dependencies from a `requirements.txt` file with `pip`, first navigate to a notebook folder and then use the following command:
23-
```
24-
pip install -r requirements.txt
25-
```
26-
27-
Several notebooks use packages that require supplementary data to be installed (e.g., `stpsf` for generating Roman Wide Field Instrument point spread functions). In those instances, a Python script is called at the beginning of the notebook to check for these data dependencies, download the appropriate data files if they are not found, and instruct you on how to set the correct environment variables.
28-
29-
Additionally, a correctly configured [Calibration Reference Data System](https://roman-crds.stsci.edu/static/users_guide/index.html) setup is required to simulate and/or calibrate Roman observations. Please set the environment variable below:
30-
```
31-
export CRDS_SERVER_URL = "https://roman-crds.stsci.edu"
32-
export CRDS_PATH = "/path/to/crds/cache/"
33-
```
34-
where `CRDS_PATH` points to your CRDS cache. If you do not have a cache already, the directory will be created the first time CRDS is used in the notebooks, but the path must still be set in advance.
35-
36-
Note that any embedded, relative links to markdown files and other notebook tutorials may not work if the repository is cloned and modified or if files are selectively installed.
15+
The notebooks in this repository are designed to work on the Roman Research Nexus for the best user experience. Due to the size of Roman data, local use is not recommended for most users. However, we provide instructions for local installation below. For detailed instructions refer to the [**Working Localy**](markdown/local-run.md) instructions.
3716

3817
## Get Support
3918

4019
Please refer to the [Roman Documentation (RDox)](https://roman-docs.stsci.edu) website for technical documentation about the Roman Space Telescope.
4120

42-
If you need assistance, please submit a ticket through the [Roman Help Desk](https://romanhelp.stsci.edu) portal. Once logged into the help desk, click on "Get Help with the Roman Space Telescope" and then select the "Roman Research Nexus" category and submit your ticket.
21+
If you need assistance, please submit a ticket through the [Roman Help Desk](https://romanhelp.stsci.edu) portal. Once logged into the help desk, click on "Get Help with the Roman Space Telescope" and then select the "Roman Research Nexus" category and submit your ticket.

markdown/local-run.md

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Some of these apply to all notebooks will other to a selected few.
55

66
## Setting up the environment for all notebooks
77

8-
Not every notebook in this repository uses the same dependencies. For reproducibility and to avoid conflicts, each notebook folder contains its own requirements.txt file listing only the packages required for that specific notebook.
8+
The notebooks were tested with Python 3.13, earlier and later versions might not have the desired results. Also note, not every notebook in this repository uses the same dependencies. For reproducibility and to avoid conflicts, each notebook folder contains its own requirements.txt file listing only the packages required for that specific notebook.
99

1010
The recommended steps:
1111

@@ -27,8 +27,8 @@ Navigate to the specific notebook folder and install the exact dependencies for
2727
Additionally, a correctly configured [Calibration Reference Data System](https://roman-crds.stsci.edu/static/users_guide/index.html) setup is required to simulate and/or calibrate Roman observations. Please set the environment variable below:
2828

2929
```
30-
export CRDS_SERVER_URL = "https://roman-crds.stsci.edu"
31-
export CRDS_PATH = "/path/to/crds/cache/"
30+
export CRDS_SERVER_URL="https://roman-crds.stsci.edu"
31+
export CRDS_PATH="/path/to/crds/cache/"
3232
```
3333

3434
where `CRDS_PATH` points to your CRDS cache. If you do not have a cache already, the directory will be created the first time CRDS is used in the notebooks, but the path must still be set in advance.
@@ -55,11 +55,15 @@ For example, for `STPSF` you need to define `STSPSF_PATH`.
5555

5656
In the commnad line or permanently in your shell profile (e.g., ~/.bashrc, ~/.zshrc):
5757

58-
export STSPSF_PATH="/your/preferred/path/to/stpsf_data"
58+
```
59+
export STSPSF_PATH="/your/preferred/path/to/stpsf_data"
60+
```
5961

6062
You can also add a cell in your notebook with the following code:
6163

62-
```os.environ['STSPSF_PATH'] = "/your/preferred/path/to/stpsf_data"```
64+
```
65+
os.environ['STSPSF_PATH'] = "/your/preferred/path/to/stpsf_data"
66+
```
6367

6468
this cell should be run before the first code cell in the notebook. This is in particular useful with you re-run your notebook and you did not set this environment variable in your shell profile.
6569

@@ -73,10 +77,14 @@ The other variables you might need to set are:
7377

7478
If you wish to re-download the data files, even after setting the environment variable, you can accomplish this in the command line with:
7579

76-
unset STSPSF_PATH
80+
```
81+
unset STSPSF_PATH
82+
```
7783

7884
for the `STSPSF_PATH` environment variable. Or in the notebook:
7985

80-
```os.environ.pop('STSPSF_PATH', None)```
86+
```
87+
os.environ.pop('STSPSF_PATH', None)
88+
```
8189

8290
Depending on which (if any) reference data are missing, this cell may take several minutes to execute.

notebooks/pandeia/pandeia.ipynb

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,72 @@
4747
"\n",
4848
"This notebook walks through brief examples of common use cases.\n",
4949
"\n",
50+
"The cell below will check to ensure ancillary reference files for `pandeia` package are installed. If not, it will download the ancillary reference files and install them under your home directory (i.e., `${HOME}/refdata/`).\n",
51+
"\n",
52+
"### Local Run Settings\n",
53+
"\n",
54+
"If you want to run the notebook in your local machine, refer to the information in [local installation](../../markdown/local-run.md) instructions before proceeding with the notebook. The instructions provide inportant information about setting up your environment, installing dependnecies, and adding to your working directory scripts to help with the reference data installation.\n",
55+
"\n",
56+
"Depending on which (if any) reference data are missing, this cell may take several minutes to execute.\n",
57+
"\n",
58+
"### On the Roman Research Nexus\n",
59+
"\n",
60+
"If you are working on the Nexus, then the ancillary reference data are pre-installed and this cell will execute instantly."
61+
]
62+
},
63+
{
64+
"cell_type": "code",
65+
"execution_count": null,
66+
"id": "2e7fbfae",
67+
"metadata": {},
68+
"outputs": [],
69+
"source": [
70+
"import os\n",
71+
"import sys\n",
72+
"import importlib.util\n",
73+
"\n",
74+
"try:\n",
75+
" import notebook_data_dependencies as ndd\n",
76+
" local = True\n",
77+
"except ImportError:\n",
78+
" local = False\n",
79+
"\n",
80+
"# If running locally Get the directory with the script\n",
81+
"if not local:\n",
82+
" notebook_dir = os.getcwd()\n",
83+
" shared_path = os.path.abspath(\n",
84+
" os.path.join(notebook_dir, '..', '..', 'shared', 'notebook_data_dependencies.py')\n",
85+
" )\n",
86+
"\n",
87+
" if os.path.exists(shared_path):\n",
88+
" print(f\"Loading notebook_data_dependencies from shared location: {shared_path}\")\n",
89+
" spec = importlib.util.spec_from_file_location(\"notebook_data_dependencies\", shared_path)\n",
90+
" ndd = importlib.util.module_from_spec(spec)\n",
91+
" sys.modules['notebook_data_dependencies'] = ndd # Optional: makes subsequent imports work\n",
92+
" spec.loader.exec_module(ndd)\n",
93+
" else:\n",
94+
" raise FileNotFoundError(f\"Local install script not found at {shared_path}\")\n",
95+
"\n",
96+
"if not local:\n",
97+
" print(\"Running local data dependency installation...\")\n",
98+
" result = ndd.install_files(packages=['pandeia'])\n",
99+
"\n",
100+
" # Update environment variables (if necessary) and print reference data paths\n",
101+
" print('Reference data paths set to:')\n",
102+
" for k, v in result.items():\n",
103+
" if not v['pre_installed']:\n",
104+
" os.environ[k] = v['path']\n",
105+
" print(f\"\\t{k} = {v['path']}\")\n",
106+
"\n",
107+
"else:\n",
108+
" print(\"Running on RNN — data already available, skipping local install.\")\n"
109+
]
110+
},
111+
{
112+
"cell_type": "markdown",
113+
"id": "b8e2590e",
114+
"metadata": {},
115+
"source": [
50116
"## Imports\n",
51117
"\n",
52118
"Besides the Pandeia-related imports, we will use `scipy.optimize.minimize_scalar` to help with optimizing signal-to-noise ratios (SNRs), `scipy.interpolate.interp1d` to calculate a desired target magnitude for a given observing setup and `numpy` to handle numerical computing."

0 commit comments

Comments
 (0)