spacetelescope / mirage

This code can be used to generate simulated NIRCam, NIRISS, or FGS data
https://mirage-data-simulator.readthedocs.io/en/latest/
BSD 3-Clause "New" or "Revised" License
39 stars 40 forks source link

Adjust xml reader for APT file format changes #838

Open bhilbert4 opened 2 weeks ago

bhilbert4 commented 2 weeks ago

Looks like APT has updated the format of the xml for the AMI observing mode. This PR adjusts the mirage xml reader such that it can read the new version.

To Do: make this backwards compatible for those using an older version of APT?

dthatte commented 1 week ago

I tested this and it crashes with a new Traceback below-


AttributeError Traceback (most recent call last) Cell In[14], line 1 ----> 1 yam = yaml_generator.SimInput(input_xml=xml_name, pointing_file=pointing_name, 2 catalogs=catalogues, roll_angle=roll_angle, 3 dates=dates, reffile_defaults=reffile_defaults, 4 verbose=True, output_dir=odir, 5 simdata_output_dir=simdata_output_directory, 6 datatype=datatype)

File ~/anaconda3/envs/dusters09/lib/python3.11/site-packages/mirage/yaml/yaml_generator.py:344, in SimInput.init(self, input_xml, pointing_file, datatype, reffile_defaults, reffile_overrides, use_JWST_pipeline, catalogs, cosmic_rays, background, roll_angle, dates, observation_list_file, verbose, output_dir, simdata_output_dir, dateobs_for_background, segmap_flux_limit, segmap_flux_limit_units, add_ghosts, convolve_ghosts_with_psf, convolve_extended_with_psf, offline) 342 if self.observation_list_file is None: 343 self.observation_list_file = os.path.join(self.output_dir, 'observation_list.yaml') --> 344 self.apt_xml_dict, self.xml_skipped_observations = get_observation_dict(self.input_xml, self.observation_list_file, catalogs, 345 verbose=self.verbose, 346 parameter_overrides=parameter_overrides) 347 else: 348 self.logger.error('No input xml file provided. Observation dictionary not constructed.')

File ~/anaconda3/envs/dusters09/lib/python3.11/site-packages/mirage/yaml/generate_observationlist.py:502, in get_observation_dict(xml_file, yaml_file, catalogs, parameter_overrides, verbose) 499 # Read in filters from APT .xml file 500 readxml_obj = read_apt_xml.ReadAPTXML() --> 502 xml_dict = readxml_obj.read_xml(xml_file, verbose=verbose) 504 # if verbose: 505 #print('Summary of observation dictionary:') 506 #for key in xml_dict.keys(): 507 # print('{:<25}: number of elements is {:>5}'.format(key, len(xml_dict[key]))) 508 509 # create an expanded dictionary that contains lists of parameters expanded for dithers 510 xml_dict = expand_for_dithers(xml_dict, verbose=verbose)

File ~/anaconda3/envs/dusters09/lib/python3.11/site-packages/mirage/apt/read_apt_xml.py:409, in ReadAPTXML.read_xml(self, infile, verbose) 407 # NIRISS AMI 408 elif template_name == 'NirissAmi': --> 409 exposures_dictionary = self.read_niriss_ami_template(template, template_name, obs, 410 proposal_parameter_dictionary, 411 verbose=verbose) 413 # If template is WFSS 414 elif template_name == 'NircamWfss':

File ~/anaconda3/envs/dusters09/lib/python3.11/site-packages/mirage/apt/read_apt_xml.py:3300, in ReadAPTXML.read_niriss_ami_template(self, template, template_name, obs, proposal_param_dict, parallel, verbose) 3294 number_of_dithers = str(number_of_primary_dithers * number_of_subpixel_dithers) 3296 # Check if there is a direct image 3297 #direct_imaging = template.find(ns + 'DirectImaging').text 3298 3299 #if direct_imaging.upper() == 'TRUE': -> 3300 image_dithers = template.find(ns + 'ImageDithers').text
3301 # if image_dithers.upper() != 'NONE': 3302 # number_of_direct_dithers = int(image_dithers) 3303 # else: 3304 # number_of_direct_dithers = 1 3305 3306 # Get information about any TA exposures 3307 ta_targ = template.find(ns + 'AcqTarget').text

AttributeError: 'NoneType' object has no attribute 'text'

bhilbert4 commented 7 hours ago

This has been tested successfully by both Deepashri and myself, so this is ready for review @mfixstsci