Git Product home page Git Product logo

pygrife's Introduction

PyGriFE

Documentation Status

A package to aid in the forced extraction of pre-processed grism data. The full documentation can be found at https://pygrife.readthedocs.io, with a brief summary below.

Installation

In all cases, it is strongly recommended to install PyGriFE into a new virtual environment, to minimise dependency conflicts (see Requirements).

Building from source

To clone the latest GitHub repository, use this command:

git clone https://github.com/PJ-Watson/PyGriFE.git

To build and install PyGriFE, run (from the root of the source tree):

pip install .

Alternatively, if grizli and sep are not already installed in the environment, they can be installed by running:

pip install .[grizli,sep]

Necessary Files

PyGriFE is designed to work with pre-processed grism data, specifically the output from grizli. If you do not have the following files, PyGriFe will not run:

  • "*GrismFLT.fits" and "*GrismFLT.pkl" files, containing the grism exposures, contamination models, blotted segmentation maps, and direct images.
  • The (un-blotted) segmentation map, used to derive the contamination models ( e.g. "nis-wfss-ir_seg.fits" ).
  • The direct images used to create the reference catalogue ( e.g. "nis-wfss-ir_drz_sci.fits", "nis-wfss-{f}_drz_sci.fits" for filters f).

Example

First, begin by importing the main class.

from pygrife import GrismExtractor

To instantiate the GrismExtractor object, we need to supply the root_name of the processed files, their current location (see Necessary Files), and the output directory. PyGriFE copies the relevant files to the output directory, to preserve the originals and prevent any unexpected modifications.

ge = GrismExtractor(
    field_root="nis-wfss",
    in_dir="probably/called/Prep",
    out_dir="use/a/new/name/for/this",
)

Next, we need to load the original segmentation map.

ge.load_orig_seg_map(
    "/path/to/nis-wfss-ir_seg.fits",
)

We can now begin modifying the segmentation map to our liking. ge.seg_map is a 2D numpy array, and can be modified using any relevant operation. Several convenience methods are also built into GrismExtractor, such as the ability to read in a regions file written by DS9.

new_id = ge.add_reg_obj(
    reg_path="/some/path/to/targets_ds9_A2744_03.reg",
)

Alternatively, we could extract an object within a particular radius of a point (with many different ways to express this; see the documentation for further details).

import numpy as np
import astropy.units as u

new_ids = np.append(
    new_id,
    ge.add_circ_obj(
        ra=3.61066,
        dec=-30.39560,
        unit="deg",
        radius=3*u.arcsec,
    ),
)

Now we've modified the segmentation map, we need to regenerate the object catalogue, and load the processed grism data.

ge.regen_multiband_catalogue()
ge.load_grism_files(cpu_count=6)

Any objects can then be extracted, by supplying an array of IDs, and specifying the redshift range to search through.

ge.extract_spectra(
    new_ids,
    z_range=[0.25,0.35],
)

If the sources are in a heavily contaminated part of the field, the contamination model can be refined using the best-fit spectra, and the process repeated.

ge.refine_contam_model_with_fits(
    fit_files=[ge.out_dir / f"{ge.field_root}_{o_id:0>5}.full.fits" for o_id in new_ids],
)
ge.extract_spectra(
    new_ids,
    z_range=[0.25,0.35],
)

Running the GUI

PyGriFE also includes a graphical interface, to view and modify the segmentation map. This feature is under active development, but can be run after installing the optional dependencies (see below for more details):

pip install .[GUI]

The GUI itself can be used by running the following:

from pygrife.GUI import run_GUI

run_GUI()

Note that even when feature complete, at least one thread will be dedicated to running the GUI, and so the method detailed above in Example will be slightly more performant.

Requirements

PyGriFE currently has the following requirements:

Grizli

To extract objects, a working installation of grizli is required. PyGriFE modifies some of the grizli class methods in order to extract arbitrary regions, and cannot be guaranteed to work with every version (if PyGriFE encounters any compatibility problems, please raise an issue here, rather than bothering the grizli developers). The current tested version is grizli==1.11.

SEP

Both PyGriFE and grizli rely on SEP, the Python implementation of Source Extractor (Bertin & Arnouts 1996). Unfortunately, since the original repository no longer appears to be maintained, it is necessary to install the fork maintained at PJ-Watson/sep. This includes the functionality necessary to rebuild a catalogue from an existing segmentation map.

GUI

To run the GUI, the following packages are also required:

PyGriFE has been tested with Python 3.10, and is developed primarily on Python 3.11.

pygrife's People

Contributors

pj-watson avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.