fcmaker package

Submodules

fcmaker.fcmaker module

fcmaker.fcmaker_instrument_dispatch module

fcmaker.fcmaker_instrument_dispatch.get_bk_image(inst)

Returns the default SkyView survey name for all supported instruments.

Parameters:inst – the instrument name
Returns:The survey name as a string
fcmaker.fcmaker_instrument_dispatch.get_chart_center(fc_params)

Defines the center of the right and left plots for different instruments.

Parameters:fc_params – the parameters of the finding charts (a dictionary)
Returns:a tuple with the chart center as a SkyCoord value.
Return type:(left_center, right_center)
fcmaker.fcmaker_instrument_dispatch.get_chart_radius(fc_params)

Defines the radius of the right and left plots for different instruments.

Parameters:fc_params – the parameters of the finding charts (a dictionary)
Returns:a tuple with the chart radius in arcsec.
Return type:(left_radius, right_radius)
fcmaker.fcmaker_instrument_dispatch.get_fields_dict(fc_params)

Returns the dictionnary of the field plotting parameters, given certain fc parameters.

Parameters:fc_params – the parameters of the finding chart (a dictionnary)
Returns:A dictionary of lists.
fcmaker.fcmaker_instrument_dispatch.get_localfcdata(inpars)

Extract the required info for creating a finding chart from the ob and templates obtained from a local parameter file.

Parameters:inpars – a dictionnary.
Returns:a dictionnary containing the OB parameters
fcmaker.fcmaker_instrument_dispatch.get_p2fcdata(obID, api)

Extract the required info for creating a finding chart from the ob and templates obtained via p2api.

Parameters:
  • obID – the OB Id, as an integer.
  • api – a p2api.ApiConnection() object
Returns:

a dictionnary containing the OB parameters

fcmaker.fcmaker_instrument_dispatch.plot_field(ax1, ax2, fc_params, field)

Triggers the plotting of a specific field.

Parameters:
  • ax1,ax2 – the left and right plots ‘axis’
  • fc_params – the dictionnary of parameters for the OB
  • field – the specific field list of parameters

fcmaker.fcmaker_metadata module

fcmaker.fcmaker_muse module

fcmaker.fcmaker_muse.get_fields_dict(fc_params)

Create a dictionnary with the basic info required to draw the fields, given certain OB parameters.

Parameters:fc_params – A dictionnary containing the MUSE OB parameters
Returns:A dictionary containing the plotting parameters for each field.
fcmaker.fcmaker_muse.get_localfcdata_muse(inpars)

Extracts all the important info to build a finding chart from a given MUSE OB defined locally.

Parameters:inpars – A dictionnary containing the OB parameters
Returns:A dictionnary containing the MUSE OB parameters
fcmaker.fcmaker_muse.get_p2fcdata_muse(ob, api)

Extracts all the important info to build a finding chart from a given MUSE OB from p2.

Parameters:
  • ob – an api.getOB() object
  • api – a p2api.ApiConnection() object
Returns:

A dictionnary containing the OB parameters

fcmaker.fcmaker_muse.get_polygon(central_coord, pa)

Given the central location and position of a field, build a polygon to feed to matplotlib down the line.

Parameters:
  • central_coord – an astropy.SkyCoord entry with the center of the MUSE field
  • pa – the position angle of the field (p2 convention)
Returns:

A list of 2-D coordinates for each corner of the field-of-view.

fcmaker.fcmaker_muse.plot_field(ax1, ax2, fc_params, field)

The specific MUSE function that draws a specific observation field.

Parameters:
  • ax1,ax2 – the left and right plots ‘axis’
  • fc_params – the dictionnary of parameters for the OB
  • field – the specific field list of parameters

fcmaker.fcmaker_plots module

fcmaker.fcmaker_plots.add_orient(ax, field_center, radius=<Quantity 540.0 arcsec>, arrow_width=<Quantity 120.0 arcsec>, usetex=True)

Plot some N-E orientation arrows

Rely on the show_arrow function from aplpy, which should be able to deal with any image orientation, even is North /= up.

Parameters:
  • ax – the aplpy ax instance to add the arrows to
  • field_center – a SkyCoord entry marking the central pointing of the chart
  • radius – the distance from the field_center to draw the arrows at, in arcsec.
  • arrow_width – the arrow size, in arcsec
  • usetex – whether a system LaTeX is used, or not
fcmaker.fcmaker_plots.get_bk_image(bk_image, fc_params)

A function that fetches the background image from the web, or locally if specified by the user.

Parameters:
  • bk_image – (string) defines whethe to use a local image (FITS filename) or a SkyView image (survey name).
  • fc_params – the parameters of the finding chart (a dictionnary)
Returns:

The absolute path of the background image (possibly after download), and the survey name.

Note

For local images, the code excpet them to be stored in fcm_m.data_loc folger.

fcmaker.fcmaker_plots.get_bk_image_lam(fn_bk_image, fc_params)

Reads the wavelength of the background image from the header. Assumes SkyView image.

Parameters:fn_bk_image – path to background image FITS file. fc_params: the parameters of the finding chart (a dictionnary)
Returns:The image wavelength range as a string.
fcmaker.fcmaker_plots.make_fc(fc_params, bk_image=None, bk_lam=None, do_pdf=True)

The finding chart master plotting function.

Parameters:
  • fc_params – a dictionnary containing the OB parameters
  • bk_image – the background image as string, either a SkyView entry, or local filename
  • bk_lam – the wavelength of the chart as a string
Returns:

The finding chart filename as a string

fcmaker.fcmaker_tools module

fcmaker.fcmaker_tools.blind_offset(coord_start, coord_end)

Compute the offsets between two astropy.sky_coordinate.SkyCoord positions. This function assumes that the sky is flat, and only really makes sense for positions within 15 arcmin.

Parameters:
  • coord_start – a SkyCoord object
  • coord_end – a SkyCoord object
Returns:

The offsets in arcsec

fcmaker.fcmaker_tools.crosshair(inner_r=1, pa=0)

The PATH of acrosshair, useful for indicating targets without crowding the field.

Parameters:
  • inner_r – the (relative) inner radius. Default=1
  • pa – the position anglem in degrees
Returns:

A mpl.path.Path() object.

fcmaker.fcmaker_tools.myrotmatrix(angle)

Defines a clockwise rotation matrix given a certain rotation angle. There is probably a smarter way to do this …

Parameters:angle – a rotation angle in degree
Returns:a 2D numpy array
fcmaker.fcmaker_tools.offset_coord(coord_start, delta_ra=<Quantity 0.0 arcsec>, delta_dec=<Quantity 0.0 arcsec>)

Compute a new SkyCoord entity given a starting location and offset. THis function assumes that the sky is flat!

Parameters:
  • coord_start – a SKyCoord object
  • delta_ra – an RA offset, in u.arcsec
  • delta_dec – an Dec offset, in u.arcsec
Returns:

a SkyCoord object

fcmaker.p2api module

class fcmaker.p2api.ApiConnection(environment, username, password, debug=False)

Bases: object

addFindingChart(obId, filename)

Attach a new finding chart in format image/jpeg. Up to 5 finding charts can be attached to a single OB. The maximum file size is 1MB (2^20 bytes).

The OB must have the latest ipVersion.

  • Visitor Mode: The OB must have status (P), (+), (A)borted or e(X)ecuted.
  • Service Mode: The OB must have status (-) or (P).

Example

api.addFindingChart(obId, filename)
createCB(containerId, name)

Example

cb, cbVersion = api.createCB(containerId, 'OliCB')
createConcatenation(containerId, name)

Example

con, conVersion = api.createConcatenation(containerId, 'OliConcatenation')
createFolder(containerId, name)

Example

fld, fldVersion = api.createFolder(containerId, 'OliFolder')
createGroup(containerId, name)

Example

grp, grpVersion = api.createGroup(containerId, 'OliGroup')
createItem(type, containerId, name)

Create a new OB, CB, Folder, Group, Concatenation or TimeLink at the end of the given container.

The initial values for the observing constraints of a new OB are those specified during phase 1, or the instrument defaults.

Visitor Mode: Groups, Concatenations and TimeLinks cannot be created.

Service Mode: Groups, Concatenations and TimeLinks cannot contain other containers, only OBs and CBs.

See also wrappers below to create specific items by name.

Example

ob, obVersion = api.createItem('OB', containerId, 'OliOB')
createOB(containerId, name)

Example

ob, obVersion = api.createOB(containerId, 'OliOB')
createTemplate(obId, name)

Attach a new template. An OB can have only one acquisition template. Attempting to add a second one will result in an error.

The OB must have the latest ipVersion.

  • Visitor Mode: The OB can be changed in any status.
  • Service Mode: The OB must have status (-) or (P).

Example

tpl, tplVersion = api.createTemplate(obId, 'UVES_blue_acq_slit')

Example

tl, tlVersion = api.createTimeLink(containerId, 'OliTimeLink')
delete(url, etag=None)
deleteEphemerisFile(obId, version)

Delete the ephemeris file of this OB.

Service Mode: The OB must have status (-) or (P).

Example

_, ephVersion = api.getEphemerisFile(obId, 'delete_me.txt')
api.deleteEphemerisFile(obId, ephVersion)
deleteFindingChart(obId, index)

Delete finding chart.

The finding chart at the given index is deleted. Finding charts with a higher index ‘slide down’, i.e. finding charts are always numbered consecutively starting with 1.

The OB must have the latest ipVersion.

  • Visitor Mode: The OB must have status (P), (+), (A)borted or e(X)ecuted.
  • Service Mode: The OB must have status (-) or (P).

Example

api.deleteFindingChart(obId, 1)
deleteOB(obId, version)

Delete existing OB or CB.

  • Visitor Mode: The OB must have never been executed.
  • Service Mode: The OB must have status (-), (P) or (D) and must have never been executed.

Example

ob, obVersion = api.getOB(obId)
api.deleteOB(ob, obVersion)
deleteTemplate(obId, templateId, version)

Delete existing template. [DFS-10901]

The OB must have the latest ipVersion.

  • Visitor Mode: The OB can be changed in any status.
  • Service Mode: The OB must have status (-) or (P).

Example

_, tplVersion = api.getTemplate(obId, templateId)
api.deleteTemplate(obId, templateId, tplVersion)
downloadBinaryFile(url, filename)
downloadTextFile(url, filename)
duplicateOB(obId, containerId=0)

Duplicate OB.

Create a new OB or CB identical to this one in the same or a different container. The new OB is appended at the end of the container. The destination may be in a different observing run.

The name of the new OB or CB is altered as follows:

if the name of the OB does not end with underscore ‘_’ followed by a sequence of digits, an underscore will be appended followed by a new sequence number otherwise, the sequence number will be replaced.

The new sequence number will start at 2 if there is no other OB with the same base name and having a sequence number. If there is such an OB, the new sequence number will be the highest sequence number of all such OBs + 1. If the name of the OB is too long to have a sequence number appended, it will be shortened to accomodate a 5-digit sequence number.

The new OB or CB will have a new obId, status ‘P’ and its exposure time and execution time will be set to zero. Its migrate flag will be recalculated with respect to the destination run. All other fields will be the same as in the original OB.

The new OB will have also:

  • identical absolute and sidereal time constraints
  • a copy of all templates attached (in order), with identical template parameters
  • the same finding charts attached (in order)
  • and the same ephemeris file attached

If no containerId is specified, the OB will be duplicated in its current container.

Example

duplicatedOB, duplicatedOBVersion = api.duplicateOB(obId)
duplicatedOB, duplicatedOBVersion = api.duplicateOB(obId, containerId)
get(url)
getAbsoluteTimeConstraints(obId)

Get list of absolute time constraints.

The list is sorted in ascending order by from. Date and time are in ISO-8601 format for the UTC timezone.

Example

absTCs, atcVersion = api.getAbsoluteTimeConstraints(obId)
getEphemerisFile(obId, filename)

Get the ephemeris file of this OB and save it into the given filename.

If the ephemeris file was never saved, or was deleted, an empty file is returned.

Example

_, ephVersion = api.getEphemerisFile(obId, 'ephem.txt')
getExecutionSequence(instrument)

Retrieve the personal execution sequence for an instrument.

Example

executionSequence, esVersion = api.getExecutionSequence('UVES')
getFindingChart(obId, index, filename)

Download finding chart.

Example

api.getFindingChart(obId, 1, 'fc1.jpg')
getFindingChartNames(obId)

Returns the list of names of the attached finding charts in the order of their index. If no finding charts are attached, an empty list will be returned.

Example

fcNames, _ = api.getFindingChartNames(obId)
getInstrumentConstraints(instrument, ipVersion)

Get all observing constraints that OBs using this instrument package must define.

The information returned is useful for building a user interface and also contains allowed values or ranges.

Example

insConstraints, _ = api.getInstrumentConstraints('UVES', '98.09')
getOB(obId)

Get existing OB or CB.

Example

ob, obVersion = api.getOB(obId)
getPhase1Targets(runId)

Retrieve the list of phase 1 targets.

Example

targets, _ = api.getPhase1Targets(runId)
getPrettyPrinter()

Return a pretty printer object that is configured to remove the unicode prefix

getReadme(runId)

Retrieve the ReadMe file.

Return the ReadMe file of this observing run. If the ReadMe file was never saved before, a template with default values (possibly empty values) is returned.

If the instrument package was updated since the ReadMe file was saved, the data returned will reflect the changes made to the instrument package. This may include new fields with (possibly empty) default values which may need to be changed by the application.

Example

readme, readmeVersion = api.getReadme(runId)
getReadmeSchema(runId)

Retrieve the schema definition for the ReadMe file of this observing run.

Example

readmeSchema, _ = api.getReadmeSchema(runId)
getRun(runId)

Get a single observing run.

Example

run, _ = api.getRun(runId)
getRuns()

Retrieve observing runs owned by or delegated to logged-in user.

Example

runs, _ = api.getRuns()
getSiderealTimeConstraints(obId)

Get list of sidereal time constraints. The list is sorted in ascending order by from.

Example

sidTCs, stcVersion = api.getSiderealTimeConstraints(obId)
getTemplate(obId, templateId)

Get existing template.

A parameter value may be null if there is no default value and a value was never set.

For parameters of type ‘paramfile’ or ‘file’ a string is returned. For a ‘paramfile’ this is the value of PAF.NAME in the PAF header; for a ‘file’ the first few characters are returned. File parameters are set with a separate call.

Example

tpl, tplVersion = api.getTemplate(obId, templateId)
getTemplateSignature(instrument, ipVersion, templateName)

Get a specific template signature.

Example

tplSignature, _ = api.getTemplateSignature('UVES', '98.08', 'UVES_blue_acq_slit')
getTemplateSignatures(instrument, ipVersion)

List all template signatures that can be attached to OBs using this instrument package.

Example

tplSignatures, _ = api.getTemplateSignatures('UVES', '98.09')
getTemplates(obId)

Get all attached templates.

Example

templates, templatesVersion = api.getTemplates(obId)
for t in templates:
   print ('template found:', t['templateName'])
moveCB(obId, containerId)

Move existing CB into destination container.

Todo

Remove list from JSON when DFS-12374 is implemented

Example

api.moveCB(obId, containerId)
moveOB(obId, containerId)

Move existing OB into destination container.

Todo

Remove list from JSON when DFS-12374 is implemented

Example

api.moveOB(obId, containerId)
post(url, data=None, etag=None)
put(url, data, etag=None)
request(method, url, data=None, etag=None)
reviseOB(obId, version)

Back to the drawing board.

Change the OB status back to ‘P’ or ‘-‘, i.e. mark it as not observable. This is the counterpart to verification with submission.

A visitor mode OB can be in any status. The status is changed to ‘P’. The OB will be removed from any visitor execution sequences because it is no longer in an observable status.

A service mode OB can only be revised in status ‘D’. The status is changed to ‘-‘.

This call invalidates the version of the OB.

Example

ob, obVersion = api.getOB(obId)
_, obVersion = api.reviseOB(obId, obVersion)
saveAbsoluteTimeConstraints(obId, timeConstraints, version)

Set list of absolute time constraints.

Date and time are in ISO-8601 format and must use UTC timezone. Time intervals must not overlap and from must be earlier than to.

  • Visitor Mode: The OB can have any status.
  • Service Mode: The OB must have status (-), (P), (D), (+), (A), or (M).

Example

absTCs, atcVersion = api.getAbsoluteTimeConstraints(obId)
api.saveAbsoluteTimeConstraints(obId,[
   {
      'from': '2017-09-01T00:00',
      'to': '2017-09-30T23:59'
   },
   {
      'from': '2017-11-01T00:00',
      'to': '2017-11-30T23:59'
   }
], atcVersion)
saveEphemerisFile(obId, filename, version)

Save the ephemeris file of this OB.

Example

_, ephVersion = api.getEphemerisFile(obId, 'delete_me.txt')
_, ephVersion = api.saveEphemerisFile(obId, 'ephem.txt', ephVersion)
saveExecutionSequence(instrument, executionSequence, version)

Change personal visitor execution sequence for an instrument.

The list should contain objects with an obId in the desired execution order and may also contain OBs from delegated observing runs. Only visitor mode OBs in status ‘+’, ‘A’, ‘X’ or ‘S’ can be included.

The obId is the only required field in each list member, but all fields sent by a GET request can be included unchanged.

Example

executionSequence, esVersion = api.getExecutionSequence('UVES')
executionSequence, esVersion = api.saveExecutionSequence('UVES',
       [{ 'obId': ob1 }, { 'obId': ob2 }], esVersion)
print('OBs in UVES execution sequence', ', '.join(str(e['obId']) for e in executionSequence))
saveOB(ob, version)

Update existing OB or CB.

The format of an OB is instrument-specific and differs for OBs and CBs. The instrument defines the applicable observingConstraints. A CB does not have a target. The properties itemType, obId, obStatus, ipVersion, exposureTime and executionTime cannot be changed. The OB must have the latest ipVersion.

  • Visitor Mode: The OB can be updated in any status.
  • Service Mode: The OB must have status (-) or (P).

Example

ob, obVersion = api.getOB(obId)
# modify some OB properties ...
ob['userPriority'] = 42
ob['target']['name']         = 'M 32 -- Interacting Galaxies'
ob['target']['ra']           = '00:42:41.825'
ob['target']['dec']          = '-60:51:54.610'
ob['constraints']['name']    = 'My hardest constraints ever'
ob['constraints']['airmass'] = 1.3
# save changes
ob, obVersion = api.saveOB(ob, obVersion)
saveReadme(runId, readme, version)

Update the ReadMe file.

Example

readme, readmeVersion = api.saveReadme(runId, readme, version)
saveSiderealTimeConstraints(obId, timeConstraints, version)

Set list of sidereal time constraints.

Time intervals must not overlap. A time interval ending at the starting time of another is considered an overlap; combine the intervals into a single one.

  • Visitor Mode: The OB can have any status.
  • Service Mode: The OB must have status (-) or (P).

Example

sidTCs, stcVersion = api.getSiderealTimeConstraints(obId)
api.saveSiderealTimeConstraints(obId,[
   {
      'from': '00:00',
      'to': '01:00'
   },
   {
      'from': '03:00',
      'to': '05:00'
   }
], stcVersion)
saveTemplate(obId, template, version)

Update existing template.

The templateId, templateName and type cannot be changed.

When GET returns a value of null, it can be changed to a proper value (or left at null). But a proper value cannot be unset to null.

File parameters must be set with a separate call; the string value returned from GET cannot be changed.

The OB must have the latest ipVersion.

  • Visitor Mode: The OB can be changed in any status.
  • Service Mode: The OB must have status (-) or (P).
saveTemplates(obId, templates, version)

Change order of attached templates.

The list must contain the same items as in the previous GET request. Only the order can be changed. Templates must be explicitly added with a POST request or deleted with a DELETE request. If there is an acquisition template, it must be the first in the list.

The OB must have the latest ipVersion.

  • Visitor Mode: The OB can be changed in any status.
  • Service Mode: The OB must have status (-) or (P).

Example

tpls, tplsVersion = api.getTemplates(obId)
# change order of tpls ...
tpls, tplsVersion = api.saveTemplates(obId, tpls, tplsVersion)
setTemplateParams(obId, template, params, version)

Helper call to make it easier to update template parameters. Uses saveTemplate() under the hood.

Example

tpl, tplVersion = api.createTemplate(obId, 'UVES_blue_acq_slit')
tpl, tplVersion  = api.setTemplateParams(obId, tpl, {
   'TEL.GS1.ALPHA': '11:22:33.000',
   'INS.COLL.NAID': 'COLL_SR+7',
   'INS.DPOL.MODE': 'ON'
}, tplVersion)
submitRun(runId)

Get a single observing run.

Example

api.submitRun(runId)
uploadFile(method, url, filename, contentType, etag=None)
verifyOB(obId, submit, version)

Verify OB and submit it for observation. If submit is false, an OB can be verified in any status. If submit is true, a service mode OB must be in status ‘P’ or ‘-‘ and a visitor mode OB must be in status ‘P’, ‘-‘, ‘C’, ‘D’, ‘F’, ‘K’, ‘M’, ‘R’ or ‘T’.

If the OB was created with an earlier instrument package, the response is 409 with a list of changes that a migration would perform.

The exposure time of the OB is recalculated.

If verification is successful and submit is true, the OB status is changed to ‘+’ for a visitor mode OB or to ‘D’ for a service mode OB.

Any change in the OB will invalidate the ETags of the OB or its templates and the item must be fetched again before the next change.

Example

ob, obVersion = api.getOB(obId)
response, _ = api.verifyOB(obId, True, obVersion)
if response['observable']:
   print('Your OB' , obId, ob['name'], 'is observable!')
else:
   print('OB', obId, 'is >>not observable<<. See messages below.')
   print(' ', '\n  '.join(response['messages']))
fcmaker.p2api.no_unicode(object, context, maxlevels, level)

change unicode u’foo’ to string ‘foo’ when pretty printing

Module contents