.. -*- coding: utf-8 -*- .. _LDAC_advanced: ========================================= LDAC - Advanced Catalogue Manipulations ========================================= .. note:: The concrete examples on this page use the LDAC catalogues `D1_r_sex.cat <../_static/D1_r_sex.cat>`_ and `D1_i_sex.cat <../_static/D1_i_sex.cat>`_. A tar archive with the complete set of LDAC Tools example files is `here <../_static/LDAC_Tools_Examples.tgz>`_ Filtering Objects from an LDAC Table ==================================== The command :command:`ldacfilter` allows the selection of a subset of objects within an LDAC table: :: user$ ldacdesc -i D1_r_sex.cat . ****** Table #3 . Number of elements:.....100 user$ ldacfilter > SYNTAX: ldacfilter -i Input_catalog [-o Output_catalog] -c [ -m maskname ] [options] Options are: -t [defaulted to OBJECTS] user$ ldacfilter -i D1_r_sex.cat -o filt.cat -t LDAC_OBJECTS -c "(MAG_APER(2)<26);" user$ ldacdesc -i filt.cat . ****** Table #3 . Number of elements:.....49 user$ ldacfilter -i D1_r_sex.cat -o filt.cat -t LDAC_OBJECTS \ -c "((MAG_AUTO<26)AND(X_IMAGE<2000))AND(Y_IMAGE<15);" .. _ldacfilter_cond: .. note:: #. The condition parsing string always needs to be protected from the shell by embedding it into double quotes! Inside the quotes, it needs to be embedded into a pair of parentheses and it needs to finish with a semicolon! (e.g. '-c **"(**\MAG_AUTO<26\ **);"**\') #. It is only possible to connect **TWO** conditions with *AND* or *OR*. If more than two conditions are necessary we need to collect them with an appropriate amount of parentheses! Hence, use '-c "(**(**\(A)AND(B)\ **)**\AND(C));"' instead of '-c "((A)AND(B)AND(C));"' #. It is not possible to put constraints on keys with :ref:`keytype string `. Calculating new Quantities ========================== To calculate new object quantities we use the command :command:`ldaccalc`: :: user$ ldaccalc > SYNTAX: ldaccalc -i Input_catalog [-o Output_catalog] -c -n -k . . user$ ldaccalc -i D1_r_sex.cat -o calc.cat -t LDAC_OBJECTS \ -c "(FLUX_RADIUS*0.186);" -n FLUX_RADIUS_WORLD "Flux Radius in arcsec" -k FLOAT \ -c "((A_IMAGE+B_IMAGE)/2);" -n A_B_MEAN "Mean of object ellipse axes" -k FLOAT user$ ldacdesc -i calc.cat -t LDAC_OBJECTS . . ****** Key #25 Key name:...............FLUX_RADIUS_WORLD Key comment:............Flux Radius in arcsec Key type:...............Float Key dimension:..........0 ****** Key #26 Key name:...............A_B_MEAN Key comment:............Mean of object ellipse axes Key type:...............Float Key dimension:..........0 .. note:: #. Currently, :command:`ldaccalc` does not treat correctly calculations with :ref:`vector keys ` #. For the condition string of :command:`ldaccalc` the same restrictions as for that of :ref:`ldacfilter ` apply! #. Possible :ref:`types ` for the new key(s) () are: SHORT, LONG, FLOAT, DOUBLE #. :command:`ldaccalc` knows the mathematical functions *+*, *-*, \*, */*, *abs*, *cos*, *exp*, *int*, *log*, *sin*, *sqrt* Transferring keys from one catalogue to another =============================================== Often, we transfer parts of an LDAC table to an ASCII file and process it with another program that creates new columns of data. We would like to include these new columns into the initial catalogue. The main ingredient for this and similar tasks is the :command:`ldacjoinkey` command (besides :command:`ldactoasc` and :command:`asctoldac`). In the following example the two catalogues `D1_r_sex.cat <../_static/D1_r_sex.cat>`_ and `D1_i_sex.cat <../_static/D1_i_sex.cat>`_ were created with `SExtractor`_ in the *Dual-Image* mode. They contain information from two different filters of exactly the same objects. We create **ONE** catalogue that contains the essential information from both catalogues: :: user$ ldacrenkey -i D1_r_sex.cat -o tmp_r.cat -t LDAC_OBJECTS \ -k MAG_APER MAG_APER_r MAG_ISO MAG_ISO_r # rename MAG_APER to MAG_APER_r etc. user$ ldacrenkey -i D1_i_sex.cat -o tmp_i.cat -t LDAC_OBJECTS \ -k MAG_APER MAG_APER_i MAG_ISO MAG_ISO_i user$ ldacjoinkey > SYNTAX: ldacjoinkey -i Catalog [-o Output_catalog] -p Proto_Catalog [-t Table_name] -k Key_name [Key_name ...] [options] user$ ldacjoinkey -i tmp_r.cat -o D1_ir_sex.cat -t LDAC_OBJECTS -p tmp_i.cat \ -k MAG_APER_i MAG_ISO_i user$ ldactoasc -i D1_ir_sex.cat -t LDAC_OBJECTS -k MAG_ISO_r MAG_ISO_i # 1 MAG_ISO_r Isophotal magnitude [mag] # 2 MAG_ISO_i Isophotal magnitude [mag] 27.4693 26.9716 28.3986 28.3386 29.0798 28.6733 27.3656 26.4385 . . Making Scatter Plots of LDAC keys ================================= The `Python`_ script `ldacplot.py <../_static/ldacplot.py>`_ (based on the Python modules `ldac.py <../_static/ldac.py>`_, `argparse.py <../_static/argparse.py>`_, `pyfits`_, `matplotlib`_) allows us to generate scatter plots of LDAC keys: :: user$ ldacplot.py -h usage: ldacplot.py [-h] -i INPUT_FILE -t TABLE -k KEYS KEYS [-c [CONDITION [CONDITION ...]]] [-ti TITLE] [-o OUTPUT_FILE] [-l LIMITS LIMITS LIMITS LIMITS] [-s MARKER_STYLE] [-m MARKER_SIZE] optional arguments: -h, --help show this help message and exit -i INPUT_FILE, --input_file INPUT_FILE input file name -t TABLE, --table TABLE . . user$ ldacplot.py -i D1_r_sex.cat -o magplot.png -t LDAC_OBJECTS \ -k MAG_AUTO 'MAG_APER(4)' \ -c MAG_AUTO 10.0 30.0 "MAG_APER(4)" 10.0 30.0 -m 10 \ -ti "Magnitude Comparison" Saving plot to magplot.png .. image:: ../_images/magplot.png :scale: 80% :align: center :alt: difference of AUTO and APERTURE magnitudes Other Tools =========== The meaning of several other, important LDAC tools is selfexplaining or can easily be extracted from the program help message: +--------------------------+-------------------------------------------------------------+ | Tool | Task | +==========================+=============================================================+ | :command:`ldacaddmask` | mark objects lying within saoimage/`ds9`_ region files | +--------------------------+-------------------------------------------------------------+ | :command:`ldacaddtab` | transfer an entire LDAC table from one catalogue to another | +--------------------------+-------------------------------------------------------------+ | :command:`ldacdelkey` | delete an LDAC key in an LDAC table | +--------------------------+-------------------------------------------------------------+ | :command:`ldacdeltab` | delete an LDAC table | +--------------------------+-------------------------------------------------------------+ | :command:`ldacrenkey` | rename an LDAC key within a table | +--------------------------+-------------------------------------------------------------+ | :command:`ldacrentab` | rename an LDAC table | +--------------------------+-------------------------------------------------------------+ | :command:`ldacstats` | obtain basic statistics on an LDAC key | +--------------------------+-------------------------------------------------------------+ | :command:`ldactoskycat` | create an ASCII table to overlay objects in `Skycat`_ | +--------------------------+-------------------------------------------------------------+ .. include:: links.txt