astwro.pydaophot Module

See also

astwro.pydaophot

Runner classes

Daophot and Allstar are wrappers of daophot and allstar tools.

class astwro.pydaophot.Daophot(dir=None, image=None, daophotopt=None, options=None, batch=False)[source]

daophot runner

Object of this class maintains single process of daophot and it’s working directory.

Methods of this class corresponds to daophot’s commands, each of those methods returns result object providing access to daophot screen output as well as easy access to files generated by daophot command.

Instance attributes:

Variables:
  • daophotopt (str) – daophotopt.opt file to be copied
  • OPtion_result (DPOP_OPtion) – results of command OPtion or initial options reported by daophot
  • ATtach_result (DPOP_ATtach) – results of command ATtach
  • SKy_result (DpOp_SKy) – results of command SKy
  • FInd_result (DpOp_FInd) – results of command FInd
  • PHotometry_result (DpOp_PHotometry) – results of command PHotometry
  • PIck_result (DpOp_PIck) – results of command PIck
  • PSf_result (DpOp_PSf) – results of command PSf
  • SOrt_result (DpOp_SOrt) – results of command SOrt (not implemented)
  • SUbstar_result (DpOp_SUbstar) – results of command SUbstar
  • image (str) – image which will be automatically ATTACHed before every run
  • options

    options which will be automatically added as OPTION command before every run, can be either:

    dictionary:
    >>> dp = Daophot()
    >>> dp.options = {'GAIN': 9, 'FI': '6.0'}
    
    iterable of tuples:
    >>> dp.options = [('GA', 9.0), ('FITTING RADIUS', '6.0')]
    
    filename string of daophot.opt-formatted file:
    >>> dp.options = 'config/pydaophot.opt'
    
Parameters:
  • dir (str) – pathname or TmpDir object - working directory for daophot, if None temp dir will be used and deleted on Daophot.close()
  • image (str) – if provided this file will be automatically attached (AT) as first daophot command setting image property has same effect
  • daophotopt (str) – daophot.opt file, if None build in default file will be used, can be added later by Runner.copy_to_runner_dir(file, ‘daophot.opt’)
  • options (list or str) – if provided OPTION command will be automatically attached setting options property has same effect; list of tuples or dict. Do not set WATCH PROGRESS to sth else than -2
  • batch (bool) – whether Daophot have to work in batch mode.
dir

Runner’s directory, object of astwro.utils.TmpDir, call Daophot.dir.path for string path to directory

set_options(options, value=None)[source]

Set option(s) before run.

Options can be either:

dictionary:
dp.set_options({'GAIN': 9, 'FI': '6.0'})
iterable of tuples:
dp.set_options([('GA', 9.0), ('FITTING RADIUS', '6.0')])
option key, followed by value in ‘value’ parameter:
dp.set_options('GA', 9.0)
filename string of allstar.opt-formatted file (file will be symlinked as allstar.opt):
dp.set_options('opts/newallstar.opt')

Warning

Do not set WATCH PROGRESS to something else than -2

Parameters:
  • options – described above
  • value – value if options is just single key
Returns:

results object also accessible as Daophot.OPtion_result property

Return type:

DPOP_OPtion

ATtach(image_file)[source]

Add daophot ATTACH command to execution queue. Available only in “batch” mode.

If image_file parameter is provided in constructor or by set_image method, ATtach is enqueued automatically (preferred method until multiple ATTACH commands needed in “batch” mode).

Parameters:image_file (str) – image to attach file will be symlinked to work dir as "i.fits", if None, i.fits (file or symlink) is expected in working dir
Returns:results object also accessible as ATtach_result property
Return type:DPOP_ATtach
OPtions(options, value=None)[source]

Adds daophot OPTION command to execution queue. Available only in “batch” mode.

Use set_options() for options which are set after daophot process start

Parameter options can be either:
dictionary:
>>> dp = Daophot(mode = "batch")
>>> dp.OPtions({'GAIN': 9, 'FI': '6.0'})
iterable of tuples:
>>> dp.OPtions([('GA', 9.0), ('FITTING RADIUS', '6.0')])
option key, followed by value in ‘value’ parameter:
>>> dp.OPtions('GA', 9.0)
filename string of daophot.opt-formatted file:
>>> dp.OPtions('config/pydaophot.opt')
Parameters:
  • options – described above
  • value – value if options is just single key
Returns:

results object also accessible as Daophot.OPtion_result property

Return type:

DPOP_OPtion

SKy()[source]

Runs (or adds to execution queue in batch mode) daophot SKY command.

Returns:results object also accessible as Daophot.SKy_result property
Return type:DpOp_SKy
FInd(frames_av=1, frames_sum=1, starlist_file='i.coo')[source]

Runs (or adds to execution queue in batch mode) daophot FIND command.

Parameters:
  • frames_av (int) – averaged frames in image, default: 1
  • frames_sum (int) – summed frames in image, default: 1
  • starlist_file (str) – output coo file, default: "i.coo"
Returns:

results object also accessible as Daophot.FInd_result property

Return type:

DpOp_FInd

PHotometry(photoopt=None, IS=0, OS=0, apertures=None, stars='i.coo', photometry_file='i.ap')[source]

Runs (or adds to execution queue in batch mode) daophot PHOTOMETRY command.

Either photoopt or IS, OS and apertures have to be set. eg.: IS=35, OS=50, apertures=[8]

Parameters:
  • photoopt (str) – photo.opt file to be used, default: None (provide IS, OS and apertures)
  • IS (float) – inner sky radius, overwrites photoopt file value IS
  • OS (float) – outer sky radius, overwrites photoopt file value OS
  • apertures (list) – apertures radius, up to 12, overwrites photoopt file values A1, A2, …
  • stars (str or StarList) – input list of stars, default: "i.coo"
  • photometry_file (str) – output magnitudes file
Returns:

results object also accessible as Daophot.PHotometry_result property

Return type:

DpOp_PHotometry

See also

NEda()

PIck(number_of_stars_to_pick=50, faintest_mag=20.0, photometry='i.ap', picked_stars_file='i.lst')[source]

Runs (or adds to execution queue in batch mode) daophot PICK command.

Parameters:
  • int – number_of_stars_to_pick
  • faintest_mag (float) – instrumental magnitude for the faintest star considered to be picked
  • photometry (str or StarList) – input magnitudes file or StarList, usually from aperture photometry done by PHotometry().
  • picked_stars_file (str) – output list of picked stars, default: i.lst
Returns:

results object also accessible as :var:`Daophot.PIck_result` property

Return type:

DpOp_PIck

PSf(photometry='i.ap', psf_stars='i.lst', psf_file='i.psf')[source]

Runs (or adds to execution queue in batch mode) daophot PHOTOMETRY command.

Parameters:
  • or sl.StarList photometry (str) – input magnitudes file or Starlist, e.g. from aperture photometry by PHotometry().
  • or sl.StarList psf_stars (str) – input list of PSF stars, default: i.coo
  • psf_file (str) – output PSF file, default: i.psf
Returns:

results object also accessible as Daophot.PSf_result property

Return type:

DpOp_PSf

SOrt(file, by, decreasing=None)[source]

Adds daophot SORT command to execution stack. NOT IMPLEMENTED sorry

Use sorting capabilities of StarList and StarList.renumber() :param str file: fname.COO_FILE etc… any fname.*_FILE to sort :param by: 1-based column number, negative for descending order - daophot standard, or

one of ‘id’, ‘x’, ‘y’, ‘mag’
Parameters:decreasing (bool) – in not None, forces sort order
Returns:results object, also accessible as Daophot.SOrt_result property
Return type:DpOp_Sort
SUbstar(subtract, leave_in=None, subtracted_image='is.fits', psf_file='i.psf')[source]

Adds daophot SUBSTAR command to execution stack.

Parameters:
  • subtract – relative to work dir pathname of stars to subtract file
  • leave_in – relative to work dir pathname of stars to be kept file (default: None)
  • psf_file – relative to work dir pathname of file with PSF (default i.psf)
  • subtracted_image – relative to work dir pathname of output fits file (default is.fits)
Returns:

results object, also accessible as Daophot.SUbstar_result property

GRoup(photometry='i.ap', psf_file='i.psf', critical_overlap=0.1, groups_file='i.grp')[source]

Runs (or adds to execution queue in batch mode) daophot GROUP command to execution stack.

Parameters:
  • photometry (str,StarList) – stars to be grouped
  • psf_file (str) – file with PSF
  • critical_overlap (float) – relative to work dir pathname of file with PSF
  • groups_file (str) – output gouped stars file
Returns:

results object, also accessible as GRoup_result property

NEda(photoopt=None, IS=0, OS=0, apertures=None, psf_file='i.psf', psf_photometry='i.als', stars_id='i.als', neda_photometry_file='i.nap')[source]

Runs (or adds to execution queue in batch mode) daophot NEDA command.

Performing aperture photometry with neighbours SPF profiles subtraction. Either :param photoopt or :param photo_is, :param OS and :param photo_ap have to be set. :param [str] photoopt: photo.opt file to be used, default: none

(provide :param photo_is, :param OS and :param photo_ap)
Parameters:
  • IS (float) – inner sky radius, overwrites :param photoopt file value IS
  • OS (float) – outer sky radius, overwrites :param photoopt file value OS
  • apertures ([list]) – apertures radius, up to 12, overwrites photoopt file values A1, A2, …
  • psf_file (str) – file with PSF for profile subtraction
  • sl.StarList] psf_photometry ([str,) – stars with PSF photometry for profile subtraction, default: i.als
  • sl.StarList] stars_id ([str,) – input list of stars to be measured, default: i.als
  • neda_photometry_file (str) – output neda aperture photometry file
Returns:

results object, also accessible as NEda_result property

Return type:

DpOp_NEda

exception ExitError(message, runner, code)

Exceptions raised when underlying process returns error code on exit

exception NoFileError(message, runner, filename)
exception RunnerException(message, runner)

Exceptions raised by Runner and subclasses

exception RunnerTypeError
exception RunnerValueError
absolute_path(path)

Returns absolute path for filepath parameter, if :arg:path contain filename only, runner dir is added

apertures_file_create(apertures, IS, OS)

Creates photo.opt in daophot working dir from list :param list apertures: list of apertures A1,A2… e.g. [6.0,8.0,12.0] :param float IS: inner radius of sky annulus :param float OS: outer radius of sky annulus :rtype: None

apertures_file_pull(dst_path='.')

Extracts current aperture file photo.opt from working dir. :param dst_path: destination :rtype: None

apertures_file_push(src_path)

Copies aperture file photo.opt into working dir. File will be used by daophot :param str src_path: patch to src file :rtype: None

clone()

Clones runner

If runner directory was provided in constructor, clone will share the same dir, else, if runner directory is temp dir created implicitly by runner, clone will create it’s own one, and content of runner directory will be copied from source to clone.

close()

Cleans things up.

copy_from_runner_dir(filename, dest='./')

Copies file: filename from runner dir. Overwrites existing file.

copy_to_runner_dir(source, filename=None)

Copies source file to runner dir under name filename or the same as original if filename is None. Overwrites existing file.

exists_in_runner_dir(filename)

Checks for filename existence in runner dir

static expand_path(path)

Expand user ~ directory and finds absolute path.

file_from_runner_dir(filename)

Simply adds runner dir path into filename

has_finished_run()

Returns True if process has finished and output is available

Returns:bool
is_ready_to_run()

Returns True if there are some commands waiting for run but process was not started yet

Returns:bool

Creates symlink in dest of file from runner dir. dest can be either file path for new symlink or directory. In second case name of symlink will be filename. Overwrites existing file.

Creates symlink in runner dir under name filename or the same as original if filename is None. Overwrites existing link. :param source: file patch :param link_filename: worker dir link name, default: same as filename part of source

mode

Either “normal” or “batch”. In batch mode, commands are not executed but collected on execution queue, then run together, in single process, one by one, triggered by run() method

read_starlist(filepath, **kwargs)

Returns StarList object with stars extracted from daophot files :param [str] filepath: source file for starlist, if filename without path is provided, runner directory is assumed. :param kwargs: additional parameters for extra processing in subclasses e.g. add_psf_errors=True :rtype: starlist.StarList

rm_from_runner_dir(filename)

Removes (if exists) file filename from runner dir

run(wait=True)

Execute commands queue.

In the “normal” mode there is no need to call run(), because all commands are executed immediately. In “batch” mode, commands execution is queued and postponed until run()

Parameters:wait (bool) – If false, run() exits without waiting for finishing commands executions (asynchronous processing). Call wait_for_results() before accessing results.
Returns:None
running

Whether if runner is running

True If executable was started in async mode run(wait=False), and no output collected yet.

Note

Even if executable has finished, output will not be collected and running will return True until user asks for results or call wait_for_results()

Returns:bool
wait_for_results()

In the “batch” mode, waits for commands completion if run(wait=False) was called

write_starlist(stars, filename=None, dao_file_type=None)

Writes StarList object to file in runner directory :param sl.StarList stars: star list to be written :param filename: name of file in runner directory, default: random name with extension ‘.stars’ :return name of file in runner directory

class astwro.pydaophot.Allstar(dir=None, image=None, allstaropt=None, options=None, batch=False)[source]

daophot runner

Object of this class maintains single process of allstar and it’s working directory.

Instance attributes: :var str allstaropt: allstar.opt file to be copied into runner dir :var DPOP_OPtion OPtion_result: initial options reported by allstar :var DPOP_ATtach ATtach_result: results of command ATtach :var str image: image which will be automatically used if not provided in ALlstars command :var dict options: options which will be automatically set as OPTION command before every run,

can be either:
dictionary:
>>> dp = Allstar()
>>> dp.options = {'PROFILE ERROR': 5, 'FI': '6.0'}
iterable of tuples:
>>> dp.options = [('PR', 5.0), ('FITTING RADIUS', 6.0)]
Parameters:
  • dir ([str]) – pathname or TmpDir object - working directory for daophot, if None temp dir will be used and deleted on Allstar.close()
  • image ([str]) – if provided this file will be used if not provided in ALlstars command setting image property has same effect
  • allstaropt ([str]) – allstar.opt file, if None build in default file will be used, can be added later by Runner.copy_to_runner_dir(file, ‘allstar.opt’)
  • options ([list,dict]) – if provided options will be set on beginning of each process list of tuples or dict
  • batch (bool) – whether Allstar have to work in batch mode.
set_options(options, value=None)[source]

set option(s) before run.

Options can be either:

dictionary: dp.OPtion({‘GAIN’: 9, ‘FI’: ‘6.0’}) iterable of tuples: dp.OPtion([(‘GA’, 9.0), (‘FITTING RADIUS’, ‘6.0’)]) option key, followed by value in ‘value’ parameter:

dp.OPtion(‘GA’, 9.0)
filename string of allstar.opt-formatted file (file will be symlinked as allstar.opt):
dp.OPtion(‘opts/newallstar.opt’)

Once set, options will stay set in next runs, set option to None to unset

ALlstar(image_file=None, psf_file='i.psf', stars='i.ap', profile_photometry_file='i.als', subtracted_image_file=None)[source]

Runs (or adds to execution queue in batch mode) daophot PICK command. :param [str] image_file: input image filepath, if None, one set in constructor or ‘i.fits’ will be used :param str psf_file: input file with psf from daophot PSF command :param str stars: input magnitudes file, e.g. from aperture photometry done by Daophot.PHotometry(). :param str profile_photometry_file: output file with aperture photometry results, default: i.als :param str subtracted_image_file: output file with subtracted FITS image, default: do not generate image :return: results object also accessible as :var:`Allstar.ALlstars_result` property :rtype: AsOp_result

exception ExitError(message, runner, code)

Exceptions raised when underlying process returns error code on exit

exception NoFileError(message, runner, filename)
exception RunnerException(message, runner)

Exceptions raised by Runner and subclasses

exception RunnerTypeError
exception RunnerValueError
absolute_path(path)

Returns absolute path for filepath parameter, if :arg:path contain filename only, runner dir is added

apertures_file_create(apertures, IS, OS)

Creates photo.opt in daophot working dir from list :param list apertures: list of apertures A1,A2… e.g. [6.0,8.0,12.0] :param float IS: inner radius of sky annulus :param float OS: outer radius of sky annulus :rtype: None

apertures_file_pull(dst_path='.')

Extracts current aperture file photo.opt from working dir. :param dst_path: destination :rtype: None

apertures_file_push(src_path)

Copies aperture file photo.opt into working dir. File will be used by daophot :param str src_path: patch to src file :rtype: None

clone()

Clones runner

If runner directory was provided in constructor, clone will share the same dir, else, if runner directory is temp dir created implicitly by runner, clone will create it’s own one, and content of runner directory will be copied from source to clone.

close()

Cleans things up.

copy_from_runner_dir(filename, dest='./')

Copies file: filename from runner dir. Overwrites existing file.

copy_to_runner_dir(source, filename=None)

Copies source file to runner dir under name filename or the same as original if filename is None. Overwrites existing file.

exists_in_runner_dir(filename)

Checks for filename existence in runner dir

static expand_path(path)

Expand user ~ directory and finds absolute path.

file_from_runner_dir(filename)

Simply adds runner dir path into filename

has_finished_run()

Returns True if process has finished and output is available

Returns:bool
is_ready_to_run()

Returns True if there are some commands waiting for run but process was not started yet

Returns:bool

Creates symlink in dest of file from runner dir. dest can be either file path for new symlink or directory. In second case name of symlink will be filename. Overwrites existing file.

Creates symlink in runner dir under name filename or the same as original if filename is None. Overwrites existing link. :param source: file patch :param link_filename: worker dir link name, default: same as filename part of source

mode

Either “normal” or “batch”. In batch mode, commands are not executed but collected on execution queue, then run together, in single process, one by one, triggered by run() method

read_starlist(filepath, **kwargs)

Returns StarList object with stars extracted from daophot files :param [str] filepath: source file for starlist, if filename without path is provided, runner directory is assumed. :param kwargs: additional parameters for extra processing in subclasses e.g. add_psf_errors=True :rtype: starlist.StarList

rm_from_runner_dir(filename)

Removes (if exists) file filename from runner dir

run(wait=True)

Execute commands queue.

In the “normal” mode there is no need to call run(), because all commands are executed immediately. In “batch” mode, commands execution is queued and postponed until run()

Parameters:wait (bool) – If false, run() exits without waiting for finishing commands executions (asynchronous processing). Call wait_for_results() before accessing results.
Returns:None
running

Whether if runner is running

True If executable was started in async mode run(wait=False), and no output collected yet.

Note

Even if executable has finished, output will not be collected and running will return True until user asks for results or call wait_for_results()

Returns:bool
wait_for_results()

In the “batch” mode, waits for commands completion if run(wait=False) was called

write_starlist(stars, filename=None, dao_file_type=None)

Writes StarList object to file in runner directory :param sl.StarList stars: star list to be written :param filename: name of file in runner directory, default: random name with extension ‘.stars’ :return name of file in runner directory

Command Results

Results of daophot and allstar commands execution are available as Output Providers objects

class astwro.pydaophot.OutputProviders.DPOP_ATtach(prev_in_chain=None)[source]

Results of ATTACH daophot command

picture_size

tuple with (x,y) size of pic returned by ‘ATTACH’

raise_if_error()[source]

Should raise exception if not properly processed: - command did not run - buffer analysis indicates error - no output value found… User can call it to check if command was successful To be overridden

class astwro.pydaophot.OutputProviders.DPOP_OPtion(prev_in_chain=None)[source]

Results of OPTION daophot command, or initial daophot options

options

Dictionary of options: XX: ‘nnn.dd’ keys are two letter option names values are strings

get_option(key)[source]

single option

raise_if_error()[source]

Should raise exception if not properly processed: - command did not run - buffer analysis indicates error - no output value found… User can call it to check if command was successful To be overridden

class astwro.pydaophot.OutputProviders.DpOp_SKy(prev_in_chain=None)[source]

Results of SKY daophot command

sky

Sky estimation

skydev

Standart deviation of :var sky

mean

Mean of image

median

Median of image

pixels

Number of analyzed pixels

class astwro.pydaophot.OutputProviders.DpOp_FInd(prev_in_chain=None, starlist_file=None)[source]

Results of FIND daophot command (extends SKY)

starlist_file = None

Patch to output file with found stars

found_starlist

StarList with found stars

err

Error estimation

stars

Number of found stars

class astwro.pydaophot.OutputProviders.DpOp_PHotometry(prev_in_chain=None, photometry_file=None)[source]

Results of PHOTOMETRY daophot command

photometry_file = None

Patch to output file with aperture photometry

photometry_starlist

StarList with photometry

Return type:astwro.starlist.StarList
class astwro.pydaophot.OutputProviders.DpOp_PIck(prev_in_chain=None, picked_stars_file=None)[source]

Results of PICK daophot command

picked_stars_file = None

Patch to output file with picked stars

stars

Number of picked stars

picked_starlist

StarList with picked stars

class astwro.pydaophot.OutputProviders.DpOp_PSf(prev_in_chain=None, psf_file=None, nei_file=None, err_file=None)[source]

Results of PSF daophot command

psf_file = None

Patch to output file with PSF function

nei_file = None

Patch to output neighbours file

err_file = None

Patch to output errors file

nei_starlist

StarList with neighbours stars

converged

False if daophot PSF routine does not produced result, e.g. ‘Failed to converge’

errors

StarList (pandas.DataFrame) of PSF stars with errors and flags (‘?’, ‘*’ or ‘ ‘)

This information is identical to i.err file, but obtained directly from daophot output

chi

Chi error estimation

hwhm_xy

tuple (x,y) of halfwidth’s of PSF function

raise_if_error()[source]

Should raise exception if not properly processed: - command did not run - buffer analysis indicates error - no output value found… User can call it to check if command was successful To be overridden

class astwro.pydaophot.OutputProviders.DpOp_SUbstar(prev_in_chain=None, subtracted_image_file=None)[source]

Results of SUBSTAR daophot command

subtracted_image_file = None

Patch to output fits image

class astwro.pydaophot.OutputProviders.DpOp_GRoup(prev_in_chain=None, groups_file=None)[source]

Results of GROUP daophot command

groups_file = None

Patch to output file with groups

groups_histogram

List of tuples: (size_of_group, number_of_groups)

stars

Number of grouped stars reported by daophot GROUP command

groups

Number of groups