-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #62 from Pica4x6/traces_deletion
Traces + Bias improvements
- Loading branch information
Showing
18 changed files
with
142 additions
and
27,797 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import logging | ||
|
||
from astropy.io import fits | ||
|
||
from megaradrp.core import MegaraBaseRecipe | ||
from megaradrp.processing import OverscanCorrector, TrimImage | ||
from megaradrp.products import MasterBias | ||
|
||
from numina.array.combine import median as c_median | ||
from numina.core import Product, RecipeError | ||
from numina.core.requirements import ObservationResultRequirement | ||
from numina.flow import SerialFlow | ||
|
||
_logger = logging.getLogger('numina.recipes.megara') | ||
|
||
|
||
class BiasRecipe(MegaraBaseRecipe): | ||
'''Process BIAS images and create MASTER_BIAS.''' | ||
|
||
obresult = ObservationResultRequirement() | ||
biasframe = Product(MasterBias) | ||
|
||
def __init__(self): | ||
super(BiasRecipe, self).__init__(version="0.1.0") | ||
|
||
def run(self, rinput): | ||
return self.process(rinput.obresult) | ||
|
||
def process(self, obresult): | ||
_logger.info('starting bias reduction') | ||
|
||
if not obresult.images: | ||
raise RecipeError('Frame list is empty') | ||
|
||
cdata = [] | ||
o_c = OverscanCorrector() | ||
t_i = TrimImage() | ||
basicflow = SerialFlow([o_c, t_i]) | ||
|
||
try: | ||
for frame in obresult.images: | ||
hdulist = frame.open() | ||
hdulist = basicflow(hdulist) | ||
cdata.append(hdulist) | ||
|
||
_logger.info('stacking %d images using median', len(cdata)) | ||
|
||
data = c_median([d[0].data for d in cdata], dtype='float32') | ||
template_header = cdata[0][0].header | ||
hdu = fits.PrimaryHDU(data[0], header=template_header) | ||
finally: | ||
for hdulist in cdata: | ||
hdulist.close() | ||
|
||
hdr = hdu.header | ||
hdr = self.set_base_headers(hdr) | ||
hdr['IMGTYP'] = ('BIAS', 'Image type') | ||
hdr['NUMTYP'] = ('MASTER_BIAS', 'Data product type') | ||
hdr['CCDMEAN'] = data[0].mean() | ||
|
||
varhdu = fits.ImageHDU(data[1], name='VARIANCE') | ||
num = fits.ImageHDU(data[2], name='MAP') | ||
hdulist = fits.HDUList([hdu, varhdu, num]) | ||
_logger.info('bias reduction ended') | ||
|
||
result = self.create_result(biasframe=hdu) | ||
return result |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import os | ||
|
||
import pytest | ||
|
||
from numina.tests.testcache import download_cache | ||
|
||
from numina.core import import_object | ||
from numina.core.pipeline import DrpSystem | ||
from numina.core import ObservationResult | ||
from numina.core import DataFrame | ||
from megaradrp.recipes.calibration.bias import BiasRecipe | ||
from megaradrp.loader import megara_drp_load | ||
|
||
@pytest.mark.remote | ||
def test_bias(drpmocker): | ||
|
||
BASE_URL = 'http://guaix.fis.ucm.es/~spr/megara_test/BIAS/%s' | ||
images = ['e99d2937d2c29a27c0ba4eebfcf7918e', | ||
'e99d2937d2c29a27c0ba4eebfcf7918e', | ||
'e99d2937d2c29a27c0ba4eebfcf7918e'] | ||
|
||
fs = [download_cache(BASE_URL % i) for i in images] | ||
|
||
ob = ObservationResult() | ||
ob.instrument = 'MEGARA' | ||
ob.mode = 'bias_image' | ||
ob.frames = [DataFrame(filename=f.name) for f in fs] | ||
|
||
drpmocker.add_drp('MEGARA', megara_drp_load) | ||
|
||
# Here we could directly import the required pipeline, | ||
# but the idea is to test all the process | ||
insdrp = DrpSystem().query_by_name(ob.instrument) | ||
pipeline = insdrp.pipelines.get('default') | ||
recipe_fqn = pipeline.recipes.get(ob.mode) | ||
RecipeClass = import_object(recipe_fqn) | ||
|
||
assert RecipeClass is BiasRecipe | ||
|
||
# TODO: these should be created by a build_recipe_input method | ||
recipe = BiasRecipe() | ||
ri = recipe.create_input(obresult=ob) | ||
|
||
result = recipe.run(ri) | ||
# assert result.qc >= QC.UNKNOWN | ||
|
||
# Checks on the image | ||
hdulist = result.biasframe.open() | ||
assert len(hdulist) == 1 | ||
|
||
hdu = hdulist[0] | ||
assert hdu.shape == (4112, 4096) | ||
|
||
data = hdu.data | ||
mlevel = 0.0 | ||
|
||
block = data[1980:2020, 1980:2020] | ||
mblock = block.mean() | ||
sblock = block.std() | ||
|
||
assert abs(mblock - mlevel) < 5 * sblock | ||
|
||
# In the end, remove the files | ||
for f in fs: | ||
os.remove(f.name) |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.