Spacecraft File
- class cosipy.spacecraftfile.SpacecraftFile(time, x_pointings=None, y_pointings=None, z_pointings=None, attitude=None, instrument='COSI', frame='galactic')[source]
- classmethod parse_from_file(file)[source]
Parses timestamps, axis positions from file and returns to __init__.
- Parameters:
file (str) – The file path of the pointings.
- Returns:
The SpacecraftFile object.
- Return type:
- get_time(time_array=None)[source]
Return the arrary pf pointing times as a astropy.Time object.
- Parameters:
time_array (numpy.ndarray, optional) – The time array (the default is None, which implies the time array will be taken from the instance).
- Returns:
The time stamps of the orientation.
- Return type:
- get_time_delta(time_array=None)[source]
Return an array of the time period between neighbouring time points.
- Parameters:
time_array (numpy.ndarray, optional) – The time delta array (the default is None, which implies the time array will be taken from the instance).
- Returns:
time_delta – The time difference between the neighbouring time stamps.
- Return type:
- interpolate_direction(trigger, idx, direction)[source]
Linearly interpolates position at a given time between two timestamps.
- Parameters:
trigger (astropy.time.Time) – The time of the event.
idx (int) – The closest index in the pointing to the trigger time.
direction (numpy.ndarray) – The pointing axis (x,z).
- Returns:
The interpolated positions.
- Return type:
- source_interval(start, stop)[source]
Returns the SpacecraftFile file class object for the source interval.
- Parameters:
start (astropy.time.Time) – The star time of the orientation period.
stop (astropy.time.Time) – The end time of the orientation period.
- Return type:
cosipy.spacecraft.SpacecraftFile
- get_attitude(x_pointings=None, y_pointings=None, z_pointings=None)[source]
Converts the x, y and z pointings to the attitude of the telescope.
- Parameters:
x_pointings (astropy.coordinates.SkyCoord, optional) – The pointings (galactic system) of the x axis of the local coordinate system attached to the spacecraft (the default is None, which implies that the x pointings will be taken from the instance).
y_pointings (astropy.coordinates.SkyCoord, optional) – The pointings (galactic system) of the y axis of the local coordinate system attached to the spacecraft (the default is None, which implies that the y pointings will be taken from the instance).
z_pointings (astropy.coordinates.SkyCoord, optional) – The pointings (galactic system) of the z axis of the local coordinate system attached to the spacecraft (the default is None, which implies that the z pointings will be taken from the instance).
- Returns:
The attitude of the spacecraft.
- Return type:
scoords.attitude.Attitude
- get_target_in_sc_frame(target_name, target_coord, attitude=None, quiet=False, save=False)[source]
Convert the x, y and z pointings of the spacescraft axes to the path of the source in the spacecraft frame. Specify the pointings of at least two axes.
- Parameters:
target_name (str) – The name of the target object.
target_coord (astropy.coordinates.SkyCoord) – The coordinates of the target object.
attitude (cosipy.coordinates.attitude.Attitude, optional) – The attitude of the spacecraft (the default is None, which implies the attitude will be taken from the instance).
quiet (bool, default=False) – Setting True to stop printing the messages.
save (bool, default=False) – Setting True to save the target coordinates in the spacecraft frame.
- Returns:
The target coordinates in the spacecraft frame.
- Return type:
- get_dwell_map(response, src_path=None, save=False)[source]
Generates the dwell time map for the source.
- Parameters:
response (str or pathlib.Path) – The path to the response file.
src_path (astropy.coordinates.SkyCoord, optional) – The movement of source in the detector frame (the default is None, which implies that the src_path will be read from the instance).
save (bool, default=False) – Set True to save the dwell time map.
- Returns:
The dwell time map.
- Return type:
- get_scatt_map(nside, scheme='ring', coordsys='galactic')[source]
Bin the spacecraft attitude history into a 4D histogram that contains the accumulated time the axes of the spacecraft where looking at a given direction.
- Parameters:
- Returns:
h_ori – The spacecraft attitude map.
- Return type:
- get_psr_rsp(response=None, dwell_map=None, dts=None)[source]
Generates the point source response based on the response file and dwell time map. dts is used to find the exposure time for this observation.
- Parameters:
response (str or pathlib.Path, optional) – The response for the observation (the defaul is None, which implies that the response will be read from the instance).
dwell_map (str, optional) – The time dwell map for the source, you can load saved dwell time map using this parameter if you’ve saved it before (the defaul is None, which implies that the dwell_map will be read from the instance).
dts (numpy.ndarray or str, optional) – The elapsed time for each pointing. It must has the same size as the pointings. If you have saved this array, you can load it using this parameter (the defaul is None, which implies that the dts will be read from the instance).
- Returns:
Ei_edges (numpy.ndarray) – The edges of the incident energy.
Ei_lo (numpy.ndarray) – The lower edges of the incident energy.
Ei_hi (numpy.ndarray) – The upper edges of the incident energy.
Em_edges (numpy.ndarray) – The edges of the measured energy.
Em_lo (numpy.ndarray) – The lower edges of the measured energy.
Em_hi (numpy.ndarray) – The upper edges of the measured energy.
areas (numpy.ndarray) – The effective area of each energy bin.
matrix (numpy.ndarray) – The energy dispersion matrix.
- get_arf(out_name=None)[source]
Converts the point source response to an arf file that can be read by XSPEC.
- Parameters:
out_name (str, optional) – The name of the arf file to save. (the default is None, which implies that the saving name will be the target name of the instance).
- get_rmf(out_name=None)[source]
Converts the point source response to an rmf file that can be read by XSPEC.
- Parameters:
out_name (str, optional) – The name of the arf file to save. (the default is None, which implies that the saving name will be the target name of the instance).
- get_pha(src_counts, errors, rmf_file=None, arf_file=None, bkg_file=None, exposure_time=None, dts=None, telescope='COSI', instrument='COSI')[source]
Generate the pha file that can be read by XSPEC. This file stores the counts info of the source.
- Parameters:
src_counts (numpy.ndarray) – The counts in each energy band. If you have src_counts with unit counts/kev/s, you must convert it to counts by multiplying it with exposure time and the energy band width.
errors (numpy.ndarray) – The error for counts. It has the same unit requirement as src_counts.
rmf_file (str, optional) – The rmf file name to be written into the pha file (the default is None, which implies that it uses the rmf file generate by function get_rmf)
arf_file (str, optional) – The arf file name to be written into the pha file (the default is None, which implies that it uses the arf file generate by function get_arf)
bkg_file (str, optional) – The background file name (the default is None, which implied the src_counts is source counts only).
exposure_time (float, optional) – The exposure time for this source observation (the default is None, which implied that the exposure time will be calculated by dts).
dts (numpy.ndarray, optional) – It’s used to calculate the exposure time. It has the same effect as exposure_time. If both exposure_time and dts are given, dts will write over the exposure_time (the default is None, which implies that the dts will be read from the instance).
telescope (str, optional) – The name of the telecope (the default is “COSI”).
instrument (str, optional) – The instrument name (the default is “COSI”).
- plot_arf(file_name=None, save_name=None, dpi=300)[source]
Read the arf fits file, plot and save it.
- Parameters:
file_name (str, optional) – The directory if the arf fits file (the default is None, which implies the file name will be read from the instance).
save_name (str, optional) – The name of the saved image of effective area (the default is None, which implies the file name will be read from the instance).
dpi (int, optional) – The dpi of the saved image (the default is 300).
- plot_rmf(file_name=None, save_name=None, dpi=300)[source]
Read the rmf fits file, plot and save it.
- Parameters:
file_name (str, optional) – The directory if the arf fits file (the default is None, which implies the file name will be read from the instance).
save_name (str, optional) – The name of the saved image of effective area (the default is None, which implies the file name will be read from the instance).
dpi (int, optional) – The dpi of the saved image (the default is 300).