Skip to content

Instantly share code, notes, and snippets.

@zonca
Created April 19, 2019 00:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zonca/e15620ff5d26652bc201b180ec00cdce to your computer and use it in GitHub Desktop.
Save zonca/e15620ff5d26652bc201b180ec00cdce to your computer and use it in GitHub Desktop.
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"from astropy.io import fits\n",
"import numpy as np"
]
},
{
"cell_type": "code",
"execution_count": 30,
"metadata": {},
"outputs": [],
"source": [
"from jwst import datamodels"
]
},
{
"cell_type": "code",
"execution_count": 31,
"metadata": {},
"outputs": [],
"source": [
"f = datamodels.TMTRampModel()"
]
},
{
"cell_type": "code",
"execution_count": 35,
"metadata": {},
"outputs": [],
"source": [
"f.pixeldq = np.zeros((4096, 4096))"
]
},
{
"cell_type": "code",
"execution_count": 49,
"metadata": {},
"outputs": [],
"source": [
"f.meta.observation.time = \"10:00:00\"\n",
"f.meta.instrument.name = \"IRIS\"\n",
"f.meta.instrument.detector = \"IRIS1\"\n",
"f.meta.filter = \"K\"\n",
"f.meta.exposure_type = \"IRIS_IMAGE\"\n",
"f.meta.observation.date = \"01/01/2019\""
]
},
{
"cell_type": "code",
"execution_count": 50,
"metadata": {},
"outputs": [],
"source": [
"# flat-fielding also requires the subarray properties to be defined\n",
"f.meta.subarray.name = 'FULL'\n",
"f.meta.subarray.xsize = 4096\n",
"f.meta.subarray.xstart = 1\n",
"f.meta.subarray.ysize = 4096\n",
"f.meta.subarray.ystart = 1"
]
},
{
"cell_type": "code",
"execution_count": 51,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(array([ 0, 0, 0, 0, 0, 16777216,\n",
" 0, 0, 0, 0]),\n",
" array([-0.5, -0.4, -0.3, -0.2, -0.1, 0. , 0.1, 0.2, 0.3, 0.4, 0.5]))"
]
},
"execution_count": 51,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.histogram(f.pixeldq)"
]
},
{
"cell_type": "code",
"execution_count": 64,
"metadata": {},
"outputs": [],
"source": [
"f.data = np.zeros((1, 4, 4096, 4096))"
]
},
{
"cell_type": "code",
"execution_count": 65,
"metadata": {},
"outputs": [],
"source": [
"f.groupdq = np.zeros((1, 4, 4096, 4096))"
]
},
{
"cell_type": "code",
"execution_count": 71,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([[[[0, 0, 0, ..., 0, 0, 0],\n",
" [0, 0, 0, ..., 0, 0, 0],\n",
" [0, 0, 0, ..., 0, 0, 0],\n",
" ...,\n",
" [0, 0, 0, ..., 0, 0, 0],\n",
" [0, 0, 0, ..., 0, 0, 0],\n",
" [0, 0, 0, ..., 0, 0, 0]],\n",
"\n",
" [[0, 0, 0, ..., 0, 0, 0],\n",
" [0, 0, 0, ..., 0, 0, 0],\n",
" [0, 0, 0, ..., 0, 0, 0],\n",
" ...,\n",
" [0, 0, 0, ..., 0, 0, 0],\n",
" [0, 0, 0, ..., 0, 0, 0],\n",
" [0, 0, 0, ..., 0, 0, 0]],\n",
"\n",
" [[0, 0, 0, ..., 0, 0, 0],\n",
" [0, 0, 0, ..., 0, 0, 0],\n",
" [0, 0, 0, ..., 0, 0, 0],\n",
" ...,\n",
" [0, 0, 0, ..., 0, 0, 0],\n",
" [0, 0, 0, ..., 0, 0, 0],\n",
" [0, 0, 0, ..., 0, 0, 0]],\n",
"\n",
" [[0, 0, 0, ..., 0, 0, 0],\n",
" [0, 0, 0, ..., 0, 0, 0],\n",
" [0, 0, 0, ..., 0, 0, 0],\n",
" ...,\n",
" [0, 0, 0, ..., 0, 0, 0],\n",
" [0, 0, 0, ..., 0, 0, 0],\n",
" [0, 0, 0, ..., 0, 0, 0]]]], dtype=uint8)"
]
},
"execution_count": 71,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"f.groupdq"
]
},
{
"cell_type": "code",
"execution_count": 72,
"metadata": {},
"outputs": [],
"source": [
"filename = \"test_ramp.fits\"\n",
"f.write(filename)"
]
},
{
"cell_type": "code",
"execution_count": 73,
"metadata": {},
"outputs": [],
"source": [
"import jwst"
]
},
{
"cell_type": "code",
"execution_count": 74,
"metadata": {},
"outputs": [],
"source": [
"import os"
]
},
{
"cell_type": "code",
"execution_count": 75,
"metadata": {},
"outputs": [],
"source": [
"from pathlib import Path"
]
},
{
"cell_type": "code",
"execution_count": 76,
"metadata": {},
"outputs": [],
"source": [
"os.environ[\"CRDS_PATH\"]= str(Path.home() / \"crds_cache\")\n",
"os.environ[\"CRDS_CONTEXT\"]=\"tmt_0001.pmap\"\n",
"os.environ[\"CRDS_SERVER_URL\"]=\"https://crds-serverless-mode.stsci.edu\""
]
},
{
"cell_type": "code",
"execution_count": 77,
"metadata": {},
"outputs": [],
"source": [
"from iris_pipeline import dq_init"
]
},
{
"cell_type": "code",
"execution_count": 78,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"<TMTRampModel(1, 4, 4096, 4096) from test_ramp.fits>"
]
},
"execution_count": 78,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"datamodels.open(\"test_ramp.fits\")"
]
},
{
"cell_type": "code",
"execution_count": 79,
"metadata": {},
"outputs": [
{
"name": "stderr",
"output_type": "stream",
"text": [
"2019-04-18 17:28:44,121 - stpipe.DQInitStep - INFO - DQInitStep instance created.\n",
"2019-04-18 17:28:44,190 - stpipe.DQInitStep - INFO - Step DQInitStep running with args ('test_ramp.fits',).\n",
"2019-04-18 17:28:44,312 - stpipe.DQInitStep - INFO - Using MASK reference file /home/azonca/crds_cache/references/tmt/iris/tmt_iris_mask_0001.fits\n",
"2019-04-18 17:28:44,626 - stpipe.DQInitStep - INFO - Step DQInitStep done\n"
]
}
],
"source": [
"out = dq_init.DQInitStep.call(\"test_ramp.fits\")"
]
},
{
"cell_type": "code",
"execution_count": 80,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"(array([16777016, 0, 0, 0, 0, 100,\n",
" 0, 0, 0, 100]),\n",
" array([ 0. , 204.8, 409.6, 614.4, 819.2, 1024. , 1228.8, 1433.6,\n",
" 1638.4, 1843.2, 2048. ]))"
]
},
"execution_count": 80,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"np.histogram(out.pixeldq)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "jwst",
"language": "python",
"name": "jwst"
},
"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.6.7"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment