[CXC logo]
Skip to the navigation links
Last modified: 23 July 2013

URL: http://cxc.harvard.edu/iris/sedlib/userGuide.html

SEDLib

User's Guide

Here we provide some simple code segments illustrating some usage scenarios for the SEDLib package.

Format conversion

The simple conversion of an IVOA Compliant SED File from VOTable to FITS format.
  
     Sed sed = null;
  
     // Load input file in VOTable format.
     try{
         sed = Sed.read( infile, SedFormat.VOT );
     }
     catch ( SedException e ){
        throw e;
     }
  
     // Write file in FITS format.
     try{
         sed.write( outfile, SedFormat.FITS );
     }
     catch ( SedException e ){
        throw e;
     }
  
  

Create and populate a Segment

This example illustrates the process for creating a new Segment and populating various elements of the object hierarchy.
     double[] specdata = new double[nvals];
     double[] fluxdata = new double[nvals];
   
     double[] loerrors = new double[nvals];
     double[] hierrors = new double[nvals];

     Double upperError = 0.;
     Double lowerError = 0.;

     // Instantiate a new Segment object
     segment = new Segment();
   
     // Create Target object and set the name.
     // NOTE: All 'create' methods in SEDLib will return an existing object
     //       or instantiate a new one if needed. 
     segment.createTarget().createName().setValue("MyObject");
   
     // Assign values to specific metadata elements.
     // Create any missing intermediate classes along the way.
     segment.createChar().createFluxAxis().createAccuracy().createStatErrHigh().setUnit("Jy");
     segment.createChar().createFluxAxis().createAccuracy().createStatErrHigh().setUcd("stat.error;phot.flux.density;em.freq");
     segment.createChar().createFluxAxis().createAccuracy().createStatErrHigh().setValue(upperError);

     segment.createChar().createFluxAxis().createAccuracy().createStatErrLow().setUnit("Jy");
     segment.createChar().createFluxAxis().createAccuracy().createStatErrLow().setUcd("stat.error;phot.flux.density;em.freq");
     segment.createChar().createFluxAxis().createAccuracy().createStatErrLow().setValue(lowerError);
   
     // Set data arrays to the Segment.
     // Shortcut methods are provided for the most commonly used columns.
     segment.setFluxAxisValues(fluxdata);
     segment.setSpectralAxisValues(specdata);
   
     // Set error data to the Segment.
     // Using the generic method for assigning values to Data elements.
     segment.setDataValues(loerrors, Utypes.SEG_DATA_FLUXAXIS_ACC_STATERRLOW);
     segment.setDataValues(hierrors, Utypes.SEG_DATA_FLUXAXIS_ACC_STATERRHIGH);
   
     // Add the new segment to an SED
     try 
     {
       sed.addSegment(segments);
     }
     catch (SedInconsistentException ex) 
     {
        System.err.println("ERROR: segments are inconsistent: "+ ex.getMessage());
        exit();
     }

  

Metadata access

This example illustrates the process extracting metadata information from an SED Segment.
     String target;
     String resolution;
     double ra;
     double dec;

     // Extract the Segment of interest from the SED.
     Segment segment = sed.getSegment(segmentIndex); 

     // For metadata which is part of the SED class hierarchy are stored as
     // parameter attributes in the containing objects.  Travel the object tree 
     // and extract the value, use the getCastValue() method to return the 
     // stored String as a native datatype.

     // Extract Target name
     TextParam p = segment.getTarget().getName();
     if ( p != null) {
       target = p.getValue();
     }

     // Each attribute has an 'isSet' method which may be used to help avoid 
     // null pointer issues.
     
     // Extract Target position
     if (segment.getTarget().isSetPos()) {
       DoubleParam[] posValue = segment.getTarget().getPos().getValue();
       ra  = (Double) posValue[0].getCastValue();
       dec = (Double) posValue[1].getCastValue(); 
     }

     // Extract Spectral Axis Resolution
     if (segment.getChar().getSpectralAxis().isSetResolution()) {
       resolution = segment.getChar().getSpectralAxis().getResolution().getValue();
     }

  

Data access

This example illustrates the process extracting data from an SED Segment.

     // Extract the Segment of interest from the SED.
     Segment segment = sed.getSegment(segmentIndex); 
     
     // Get data arrays from the Segment.
     // Shortcut methods are provided for the most commonly used columns.
     double[] wave = segment.getSpectralAxisValues(); 
     double[] flux = segment.getFluxAxisValues(); 

     // Get other data from the Segment.
     // Using the generic method for accessing values from Data columns.
     double[] error = null;
     try {
       error = (double[]) segment.getDataValues(Utypes.SEG_DATA_FLUXAXIS_ACC_STATERR);
     }
     catch (SedInconsistentException ex) 
     {
       System.err.println(ex.toString());
     } 

     // Information about the data column are stored in the DataInfo class associated
     // with each column.
     String wavename = segment.getDataInfo(Utypes.SEG_DATA_FLUXAXIS_ACC_STATERR).getName(); 
     

  

Last modified: 23 July 2013
[CXC logo] [Smithsonian Institute]
[VAO] [NED] [STScI]
[NSF] [NASA] AUI AURA
Copyright 2011-2014 VAO, LCC
Copyright 2015 Smithsonian Astrophysical Observatory