Skip to content

Instantly share code, notes, and snippets.

View nden's full-sized avatar

Nadia Dencheva nden

  • Space Telescope Science Institute
View GitHub Profile
@nden
nden / shared_models.asdf
Created September 13, 2022 21:35
ASDF Shared Models
#ASDF 1.0.0
#ASDF_STANDARD 1.5.0
%YAML 1.1
%TAG ! tag:stsci.edu:asdf/
--- !core/asdf-1.1.0
asdf_library: !core/software-1.0.0 {author: The ASDF Developers, homepage: 'http://github.com/asdf-format/asdf',
name: asdf, version: 2.11.1}
history:
extensions:
- !core/extension_metadata-1.0.0
@nden
nden / roman_imaging_wcs.asdf
Created September 13, 2022 21:13
GWCS in ASDF example
#ASDF 1.0.0
#ASDF_STANDARD 1.5.0
%YAML 1.1
%TAG ! tag:stsci.edu:asdf/
--- !core/asdf-1.1.0
asdf_library: !core/software-1.0.0 {author: The ASDF Developers, homepage: 'http://github.com/asdf-format/asdf',
name: asdf, version: 2.11.1}
history:
extensions:
- !core/extension_metadata-1.0.0
@nden
nden / Example_writing_to_fits.py
Last active April 29, 2020 20:42
ASDF transform examples
>>> from astropy.io import fits
>>> from asdf import fits_embed
>>> hdul = fits.open("example_imaging.fits")
>>> hdul.info()
Filename: example_imaging.fits
No. Name Ver Type Cards Dimensions Format
0 PRIMARY 1 PrimaryHDU 775 ()
1 SCI 1 ImageHDU 71 (600, 550) float32
>>> tree = {"sci": hdul[1].data,
... "wcs": wcsobj}
@nden
nden / example_docstrings.py
Last active October 10, 2018 09:49
example docstrings
"""This is the docstring for the example.py module. Modules names should
have short, all-lowercase names. The module name may have underscores if
this improves readability.
Every module should have a docstring at the very top of the file. The
module's docstring may extend over multiple lines. If your docstring does
extend over multiple lines, the closing three quotation marks must be on
a line by itself, preferably preceded by a blank line.
"""
import os # standard library imports first
@nden
nden / modeling_model_sets.py
Created February 7, 2018 16:32
How model sets work
from astropy.modeling.models import *
import numpy as np
from astropy.modeling.fitting import *
# How to create a multiset model
# There are two arguments that control this - `n_models` and `model_set_axis`.
# The trick with model_sets is that input arguments and model parameters need
# to broadcast appropriately.
x = np.arange(4)
@nden
nden / gist:40247cb41318902adf91a89de3b516b7
Last active February 19, 2018 22:03
Rules for units in modeling
Current definitions:
input_units_strict
# If set to True, values that are passed in compatible units will be converted to
# the exact units specified in input_units.
input_units_equivalencies
# This can be set to a dictionary that maps the input names to a list of equivalencies, for example:
@nden
nden / image_wcs.py
Last active November 30, 2017 18:55
Imaging WCS
import numpy as np
from astropy import wcs
from gwcs import wcs as gw
from astropy.modeling.models import Shift, Scale, AffineTransformation2D, RotateNative2Celestial, Pix2Sky_TAN
crpix1 = 512.5
crpix2 = 512.5
cdelt1 = 2.402792
cdelt2 = 2.402792
ctype1 = 'RA---TAN'
@nden
nden / memory_comparison.md
Last active November 28, 2017 14:20
memory_comparison_modeling

Script for memory profiling astropy.modeling

from astropy.modeling.models import Mapping, Tabular1D
from astropy.modeling.functional_models import Shift, Scale
from astropy.modeling.polynomial import Polynomial2D
import gc
from memory_profiler import profile
import numpy as np
@nden
nden / par_models.py
Created August 8, 2017 13:16
parameters can be models
from astropy.modeling.core import Model
from astropy.modeling.models import Polynomial2D, Polynomial1D
from astropy.modeling.parameters import Parameter
class MyModel(Model):
inputs = ('x', 'y', 't')
outputs = ('z',)
@nden
nden / hst_wcs.py
Created July 26, 2016 17:15
simulating HST WCS
# Simulate WFC3 WCS
import numpy as np
from astropy.io import fits
from stwcs import updatewcs
primary_header_kw = {'PA_V3': 81.872513, 'instrume': 'WFC3', 'detector': 'IR',
'idctab': 'w3m18525i_idc.fits', 'filter': 'F160W',
'telescop': 'HST', 'date-obs': '2009-08-07'}
sci_header_kw = {'CRPIX1': 562, 'CRPIX2': 562,