def main(): parser = argparse.ArgumentParser(description='Convert Xija JSON model spec' ' to Python') parser.add_argument('model_spec', type=str, help='Input Xija model spec file name') parser.add_argument('--force', action='store_true', help='Overwrite existing outfile') parser.add_argument('--outfile', type=str, help='Output Python file (default=<model_spec>.py)') args = parser.parse_args() infile = args.model_spec outfile = args.outfile if outfile is None: if infile.endswith('.json'): outfile = infile[:-5] + '.py' else: outfile = infile + '.py' if os.path.exists(outfile) and not args.force: print('Error: {} exists. Use --force to overwrite.'.format(outfile)) sys.exit(1) model = xija.XijaModel(model_spec=infile) model.write(outfile) print('Wrote', outfile)
def _get_model_for_dP_pitches(solar_class, msid, dP_pitches, dPs): model = xija.XijaModel(msid, start='2021:001', stop='2021:005') model.add(xija.Node, msid) model.add(xija.Pitch) model.add(xija.Eclipse) model.add(xija.SimZ) model.add(xija.Roll) model.add(xija.DetectorHousingHeater) model.add(solar_class, P_pitches=[45, 90, 135, 180], dP_pitches=dP_pitches, Ps=[0.0, 1.0, 1.0, 0.0], dPs=dPs, ampl=0.0, eclipse_comp='eclipse', epoch='2020:001', node=msid, pitch_comp='pitch', ) model.add(xija.HeatSink, T=-20.0, node=msid, tau=30.0, ) model.add(xija.StepFunctionPower, P=0.1, id='_1iru', node=msid, time='2021:003' ) return model
def _compute_model(self, name, tstart, tstop, dt, T_init, evolve_method=None, rk4=None): if name == "fptemp_11": name = "fptemp" model = xija.XijaModel(name, start=tstart, stop=tstop, dt=dt, model_spec=self.model_spec, evolve_method=evolve_method, rk4=rk4) model.comp[name].set_data(T_init) for t in ["dea0", "dpa0"]: if t in model.comp: model.comp[t].set_data(T_init) model.make() model.calc() return model
# Licensed under a 3-clause BSD style license - see LICENSE.rst """ Example with a single node (ACA CCD temperature) with solar heating (2 bins). """ import xija name = __file__[:-3] model = xija.XijaModel(name, start='2015:001', stop='2015:050') model.add(xija.Node, 'aacccdpt') model.add(xija.Pitch) model.add(xija.Eclipse) model.add(xija.SolarHeat, node='aacccdpt', pitch_comp='pitch', eclipse_comp='eclipse', P_pitches=[45, 180], Ps=[0.0, 0.0], ampl=0.0, epoch='2010:001', ) model.write('{}.json'.format(name))
# Licensed under a 3-clause BSD style license - see LICENSE.rst import numpy as np import matplotlib.pyplot as plt import xija from Chandra.Time import DateTime from kadi import events start = '2014:200' stop = '2015:150' model = xija.XijaModel('acisfp', model_spec='acisfp_dh_spec.json', start=start, stop=stop) model.make() shcb = model.comp['solarheat__1cbat'] fptemp = model.comp['fptemp'] dh = model.comp['dh_heater'] # Calculate model with best fit dh_heater bias model.calc() dt_best = (fptemp.dvals - fptemp.mvals) # Force bias to 0 shcb.dh_heater_bias = 0.0 model.calc() dt_zero = (fptemp.dvals - fptemp.mvals) science_times = (~events.rad_zones(pad=3600)).intervals(start, stop)
import sys import xija model = xija.XijaModel('4hfspat', start='2017:301:00:01:50.816', stop='2021:039:23:53:18.816', dt=328.0, evolve_method=1, rk4=0) model.add( xija.Node, '4hfspat', ) model.add( xija.Delay, '4hfspat', delay=0, ) model.add(xija.Pitch, ) model.add(xija.Eclipse, ) model.add( xija.SolarHeat, P_pitches=[45, 70, 90, 115, 140, 160, 180], Ps=[0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], ampl=0.0, eclipse_comp='eclipse', epoch='2021:001', node='4hfspat', pitch_comp='pitch', )
# Licensed under a 3-clause BSD style license - see LICENSE.rst import sys import xija model = xija.XijaModel(u'example4', start='2014:205:12:10:16.816', stop='2015:240:11:43:44.816', dt=328.0) model.add(xija.Node, u'aacccdpt', ) model.add(xija.Pitch, ) model.add(xija.Eclipse, ) model.add(xija.Node, u'aca0', sigma=100000.0, ) model.add(xija.SolarHeat, u'aca0', u'pitch', u'eclipse', [45, 70, 90, 115, 140, 180], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0], epoch=u'2015:040', ampl=0.0, ) model.add(xija.HeatSink, u'aca0', tau=30.0,
def __init__(self, modelobject, days=180, stop=None, start=None, set_data_exprs=None, set_data=None, inherit_from=None, keep_epoch=False, quiet=False, name=None, snapshotfile=None): """Initialize XijaFit class. :param filename: Full path of file containing parameters to import :param days: Number of days of data to use to fit the model :param stop: Stop date for model fit duration :param set_data_exprs: Iterable of initial data values in the format: '<comp_name>=<value>' :param set_data: Dictionary of initialization parameters in one of the following formats: {<comp_name>: <value>} or {<comp_name>: {'times':<times>, 'data':<value>}} :param inherit_from: Full path of file containing parameters to inherit :param keep_epoch: Maintain epoch in SolarHeat models (default=recenter on fit interval) :param quiet: Suppress screen output ;param snapshotfile: json file containing fit snapshots """ self.fit_logger = logging.getLogger('fit') self.fit_logger.setLevel(logging.INFO) self.sherpa_logger = logging.getLogger('sherpa') self.sherpa_logger.setLevel(logging.INFO) self.log_capture_string = io.StringIO() ch = logging.StreamHandler(self.log_capture_string) ch.setLevel(logging.INFO) formatter = logging.Formatter( '[%(levelname)s] (%(processName)-10s) %(message)s') ch.setFormatter(formatter) self.fit_logger.addHandler(ch) self.sherpa_log_capture_string = io.StringIO() sch = logging.StreamHandler(self.sherpa_log_capture_string) sch.setLevel(logging.INFO) sformatter = logging.Formatter( '[%(levelname)s] (%(processName)-10s) %(message)s') sch.setFormatter(sformatter) self.sherpa_logger.addHandler(sch) # Set initial times. if stop and not start: self.start = DateTime(DateTime(stop).secs - days * 86400).date[:8] self.stop = stop elif start and not stop: self.start = start self.stop = DateTime(DateTime(stop).secs + days * 86400).date[:8] elif start and stop: self.start = start self.stop = stop self.days = np.floor( (DateTime(stop).secs - DateTime(start).secs) / (3600. * 24.)) else: self.start = DateTime(DateTime().secs - 3600 * 24 * 192).date self.stop = DateTime(DateTime().secs - 3600 * 24 * 10).date # Initialize Xija model object. self.model = xija.XijaModel(name or 'xijamodel', self.start, self.stop, model_spec=modelobject) self.model_spec = self.model.model_spec if name: self.model_spec['name'] = name self.set_data_exprs = set_data_exprs if self.set_data_exprs: self.set_init_data(set_data_exprs) if set_data: for key, value in set_data.items(): if isinstance(value, dict): self.model.comp[key].set_data(value['data'], value['times']) else: self.model.comp[key].set_data(value) # "make" model. self.model.make() # Load parameter values from inherited model file where parameter names match. if inherit_from: self.inherit_param_from(inherit_from) # Set epoch self.keep_epoch = keep_epoch if not self.keep_epoch: self.set_epoch() if snapshotfile: self.snapshots = json.load(open(snapshotfile, 'r')) else: self.snapshots = [] self.save_snapshot()
This shows necessary inputs and runs without using the eng archive. The model prediction is completely wrong because all values are set to a constant in this example instead of the correct time-varying values. """ import xija import Ska.engarchive.fetch_eng as fetch_eng from Ska.Matplotlib import plot_cxctime start = '2012:001' stop = '2012:005' model = xija.XijaModel('psmc', model_spec='psmc_spec.json', start=start, stop=stop) ## PREDICTED COMPONENTS # Use MSID values from telemetry to initialize if available model.comp['1pdeaat'].set_data(20.0) model.comp['pin1at'].set_data(20.0) ## INPUT DATA COMPONENTS # These initializations are used needed for predicting into the future. # For analyzing back-orbit data, do not set any of these and let xija # grab the right values from telemetry. # All the usual values here
def _compute_acis_model(self, name, tstart, tstop, states, dt, T_init, no_eclipse=False, evolve_method=None, rk4=None): import re from acis_thermal_check import calc_pitch_roll pattern = re.compile("q[1-4]") check_obj = getattr(self.model_check, model_classes[self.sname])() if name == "fptemp_11": name = "fptemp" model = xija.XijaModel(name, start=tstart, stop=tstop, dt=dt, model_spec=self.model_spec, rk4=rk4, evolve_method=evolve_method) ephem = self._get_ephemeris(model.tstart, model.tstop, model.times) if states is None: state_times = model.times state_names = ["ccd_count", "fep_count", "vid_board", "clocking", "pitch", "roll"] if 'aoattqt1' in model.comp: state_names += ["q1", "q2", "q3", "q4"] states = {} for n in state_names: nstate = n ncomp = n if pattern.match(n): ncomp = f'aoattqt{n[-1]}' elif name == "roll": nstate = "off_nom_roll" states[nstate] = np.array(model.comp[ncomp].dvals) else: if isinstance(states, np.ndarray): state_names = states.dtype.names else: state_names = list(states.keys()) state_times = np.array([states["tstart"], states["tstop"]]) model.comp['sim_z'].set_data(np.array(states['simpos']), state_times) if 'pitch' in state_names: model.comp['pitch'].set_data(np.array(states['pitch']), state_times) else: pitch, roll = calc_pitch_roll(model.times, ephem, states) model.comp['pitch'].set_data(pitch, model.times) model.comp['roll'].set_data(roll, model.times) for st in ('ccd_count', 'fep_count', 'vid_board', 'clocking'): model.comp[st].set_data(np.array(states[st]), state_times) if 'dh_heater' in model.comp: dhh = states["dh_heater"] if "dh_heater" in state_names else 0 model.comp['dh_heater'].set_data(dhh, state_times) if "off_nom_roll" in state_names: roll = np.array(states["off_nom_roll"]) model.comp["roll"].set_data(roll, state_times) if 'dpa_power' in model.comp: # This is just a hack, we're not # really setting the power to zero. model.comp['dpa_power'].set_data(0.0) model.comp[name].set_data(T_init) if no_eclipse: model.comp["eclipse"].set_data(False) check_obj._calc_model_supp(model, state_times, states, ephem, None) if self.name == "fptemp_11" and self.no_earth_heat: model.comp["earthheat__fptemp"].k = 0.0 model.make() model.calc() return model