<SYSTEM_TASK:>
Given the following text description, write Python code to implement the functionality described below step by step
<END_TASK>
<USER_TASK:>
Description:
 Contents
This notebook covers the basics of creating TransferFunction object, obtaining time and energy resolved responses, plotting them and using IO methods available. Finally, artificial responses are introduced which provide a way for quick testing.
Setup
Set up some useful libraries.
Step1:  Import relevant stingray libraries.
Step2:  Creating TransferFunction
A transfer function can be initialized by passing a 2-d array containing time across the first dimension and energy across the second. For example, if the 2-d array is defined by arr, then arr[1][5] defines a time of 5 units and energy of 1 unit.
For the purpose of this tutorial, we have stored a 2-d array in a text file named intensity.txt. The script to generate this file is explained in Data Preparation notebook.
Step3:  Initialize transfer function by passing the array defined above.
Step4:  By default, time and energy spacing across both axes are set to 1. However, they can be changed by supplying additional parameters dt and de.
Obtaining Time-Resolved Response
The 2-d transfer function can be converted into a time-resolved/energy-averaged response.
Step5:  This sets time parameter which can be accessed by transfer.time
Step6:  Additionally, energy interval over which to average, can be specified by specifying e0 and e1 parameters.
Obtaining Energy-Resolved Response
Energy-resolved/time-averaged response can be also be formed from 2-d transfer function.
Step7:  This sets energy parameter which can be accessed by transfer.energy
Step8:  Plotting Responses
TransferFunction() creates plots of time-resolved, energy-resolved and 2-d responses. These plots can be saved by setting save parameter.
Step9:  By enabling save=True parameter, the plots can be also saved.
IO
TransferFunction can be saved in pickle format and retrieved later.
Step10:  Saved files can be read using static read() method.
Step11:  Artificial Responses
For quick testing, two helper impulse response models are provided.
1- Simple IR
simple_ir() allows to define an impulse response of constant height. It takes in time resolution starting time, width and intensity as arguments.
Step12:  2- Relativistic IR
A more realistic impulse response mimicking black hole dynamics can be created using relativistic_ir(). Its arguments are
<ASSISTANT_TASK:>
Python Code:
import numpy as np
from matplotlib import pyplot as plt
%matplotlib inline
Explanation: Contents
This notebook covers the basics of creating TransferFunction object, obtaining time and energy resolved responses, plotting them and using IO methods available. Finally, artificial responses are introduced which provide a way for quick testing.
Setup
Set up some useful libraries.
End of explanation
from stingray.simulator.transfer import TransferFunction
from stingray.simulator.transfer import simple_ir, relativistic_ir
Explanation: Import relevant stingray libraries.
End of explanation
response = np.loadtxt('intensity.txt')
Explanation: Creating TransferFunction
A transfer function can be initialized by passing a 2-d array containing time across the first dimension and energy across the second. For example, if the 2-d array is defined by arr, then arr[1][5] defines a time of 5 units and energy of 1 unit.
For the purpose of this tutorial, we have stored a 2-d array in a text file named intensity.txt. The script to generate this file is explained in Data Preparation notebook.
End of explanation
transfer = TransferFunction(response)
transfer.data.shape
Explanation: Initialize transfer function by passing the array defined above.
End of explanation
transfer.time_response()
Explanation: By default, time and energy spacing across both axes are set to 1. However, they can be changed by supplying additional parameters dt and de.
Obtaining Time-Resolved Response
The 2-d transfer function can be converted into a time-resolved/energy-averaged response.
End of explanation
transfer.time[1:10]
Explanation: This sets time parameter which can be accessed by transfer.time
End of explanation
transfer.energy_response()
Explanation: Additionally, energy interval over which to average, can be specified by specifying e0 and e1 parameters.
Obtaining Energy-Resolved Response
Energy-resolved/time-averaged response can be also be formed from 2-d transfer function.
End of explanation
transfer.energy[1:10]
Explanation: This sets energy parameter which can be accessed by transfer.energy
End of explanation
transfer.plot(response='2d')
transfer.plot(response='time')
transfer.plot(response='energy')
Explanation: Plotting Responses
TransferFunction() creates plots of time-resolved, energy-resolved and 2-d responses. These plots can be saved by setting save parameter.
End of explanation
transfer.write('transfer.pickle')
Explanation: By enabling save=True parameter, the plots can be also saved.
IO
TransferFunction can be saved in pickle format and retrieved later.
End of explanation
transfer_new = TransferFunction.read('transfer.pickle')
transfer_new.time[1:10]
Explanation: Saved files can be read using static read() method.
End of explanation
s_ir = simple_ir(dt=0.125, start=10, width=5, intensity=0.1)
plt.plot(s_ir)
Explanation: Artificial Responses
For quick testing, two helper impulse response models are provided.
1- Simple IR
simple_ir() allows to define an impulse response of constant height. It takes in time resolution starting time, width and intensity as arguments.
End of explanation
r_ir = relativistic_ir(dt=0.125)
plt.plot(r_ir)
Explanation: 2- Relativistic IR
A more realistic impulse response mimicking black hole dynamics can be created using relativistic_ir(). Its arguments are: time_resolution, primary peak time, secondary peak time, end time, primary peak value, secondary peak value, rise slope and decay slope. These paramaters are set to appropriate values by default.
End of explanation
<END_TASK>