Package: mmtapi
MMT APIThis repository is designed to facilitate submitting a rapid Target of Opprotunity (ToO) observation to Binospec at theMMTwith the goal to enable same-night spectroscopy of interesting transients. Here we will provide examples to install and upload targets.InstallTo get the repository (in a bash/unix terminal)pip3installmmtapiUsing the API WrapperHere we describe the process to POST, GET, UPDATE, and DELETE a MMT Target. TheTargetclass also contains anapiclass that calls each of the API methods. This class contains the request information for each request method so that it can debugged in the command line.importmmtapi.mmtapiasmmtapitarget=mmtapi.Target(token=API_TOKEN,...)#once a request is madetarget.**action()#post, delete, update... etc#the request response can be viewed bytarget.request#which contains all of the expected request response information:#   target.request.content#   target.request.text#   target.request.status_code#   etcCreating a TargetTo create a target there are a lot of required fields and conditional parameters based on the observation type. To begin with the metadata for the target itself:objectid: This is the name of the target. The requirements for this field is that it contains no special characters and spaces. It must also be greater than 2 characters and less than 50 characters.ra: Right Ascension of the target. Required format to be:dd:dd:dd.ddec: Declination of the target. Required format to be:[+/-]dd:dd:dd.dmagnitude: Magnitude of the target. Must be afloatepoch: The epoch of the target. Defaults to 2000.0The target exposure information is based on the the fieldobservationtype:Forobservationtype:imaging:filter: Must beg,r,i, orzmaskid: can be110or a predefined mask set up prior to target requestexposuretime: The observation exposure time in secondsForobservationtype:longslit:grating: Valid options are270,600, and1000centralwavelength: Depending on the chosengrating:Forgrating=270, valid options are between5501-7838Forgrating=600, valid options are between5146-8783Forgrating=1000, valid options are between4108-4683,5181-7273,7363-7967,8153-8772or8897-9279slitwidth: valid options areLongslit0_75,Longslit1,Longslit1_25,Longslit1_5,Longslit5filter: valid options areLP3800orLP3500. Defaults toLP3800maskid: Can be a predefined mask, or there are commonmaskids depending on the chosen slitwidth:ForLongslit0_75: id113ForLongslit1: id111ForLongslit1_25: id131ForLongslit1_5: id114ForLongslit5: id112Other observation metadata:pa: The parralactic angle. Defaults to 0pm_raandpm_dec: Proper motion of of the RA and DEC parameters. Defaults to 0.0 respectivelynumberexposures: Number of exposures. Defaults to 1visits: Visits. Defaults to 1priority: Ranks for all targets in the users catalog. Valid options are 1,2,3 where 1 is the highest priority. Defaults to 3photometric: Valid options are 0 for non-photometric conditions or 1 for photometric conditions. Defaults to 0targetofopportunity: Valid options are 0 for non ToO or 1 for requesting a ToO.All metadata will be validated upon initialization. Once the target object has been validated as True, it can be posted to the MMT schedule.importmmtapi.mmtapiasmmtapi#example for imaging target payload:payload={'objectid':'TARGETNAME','ra':'12:34:56.78','dec':'+87:65:43:21','magnitude':21,'epoch':2000,'filter':g,'maskid':110,'exposuretime':400,'visits':1,'numberexposures':2,'priority':1}#example payload for longslit target payloadpayload={'objectid':'Targetname','ra':'12:34:56.78','dec':'+87:65:43:21','magnitude':21,'epoch':2000,'grating':1000,'centralwavelength':7380,'slitwidth':'Longslit1_25',`maskid`:131,`filter`:'LP380''visits':1,'numberexposures':2,'priority':1,'targetofopportunity':1}#this will create the target along with validating the payload information. It will inform the user of any errors or warnings associated with the metadatatarget=mmtapi.Target(token=API_TOKEN,verbose=True,payload=payload)#this will send the information to the scheduler if it is a valid targettarget.post()Getting Target InformationTo get Target Information the only parameters to be passed into the Target class initation are thetokenandtargetid. This will populate the Target with all of the MMT Target's keywords. If the request is successful, print out all of the target information with the.dump()method.importmmtapi.mmtapiasmmtapitarget=mmtapi.Target(token=API_TOKEN,verbose=True,payload={'targetid':TARGETID})target.dump()Uploading a Finder ImageOnce a target is either created, or retrieved with the API GET method, a finder image can be uploaded. If an finder image already exists, this will overwrite it. All that is needed the pathway to the finder image.target.upload_finder(finder_path=PATH_TO_IMAGE)Downloading a completed observationtarget.download_exposures()Updating Target InformationOnce a target is created, or retrieved with the API GET method, its meta-data can be updated. All that is required is passing in the valid keyword arguments and their respective values. The updated information will be validated before being submitted to the API.#the kwargs can be defined as: KEY_WORD1=VAlUE1, KEY_WORD2=VALUE2... etctarget.update(KEY_WORD1=VAlUE1,KEY_WORD2=VALUE2...etc)Valid MMT TargetKEY_WORD's:['id','ra','objectid','observationtype','moon','seeing','photometric','priority','dec','ra_decimal','dec_decimal','pm_ra','pm_dec','magnitude','exposuretime','numberexposures','visits','onevisitpernight','filter','grism','grating','centralwavelength','readtab','gain','dithersize','epoch','submitted','modified','notes','pa','maskid','slitwidth','slitwidthproperty','iscomplete','disabled','notify','locked','findingchartfilename','instrumentid','targetofopportunity','reduced','exposuretimeremaining','totallength','totallengthformatted','exposuretimeremainingformatted','exposuretimecompleted','percentcompleted','offsetstars','details','mask']Deleting a TargetOnce a target is created or retireved with the API GET method, it can be deleted from the Observatory scheduler.target.delete()Other API EndpointsMMT InstrumentHere we describe the API endpoint to get the current instruments in the most recent published schedule. When instantiating a Target through this API it will validate whether or not the Binospec instrument is on the telescope. It can also be used to see what instruments are currently on, or when an instrument will be on the telescope.This function takes can take in two parameters:dateinstrumentidif you don't pass any params into the function it will just find the current instruments on the telescope usingdatetime.datetime.now()fromdatetimeimportdatetime,timedeltaapi=mmtapi.api()current_instruments=api.get_instruments()#you can look into the future to see what instruments will be available:future_instruments=api.get_instruments(date=datetime.datetime.now()+timedelta(months=1))#you can look through the entire published schedule to see when a certain instrument will be on the telescope (Binospec = 16)my_instrument=api.get_instruments(instrumentid=16)This function returns a list of dictionary elements with the values for:instrumentid- ID for the instrumentname-  the name of the queue runstart- start dateend- end date