Open adadams opened 3 years ago
I added three functions a while ago to Planet*.cpp. The code is short enough to show right here:
// ada: Additional function to return the contribution function of the opacity, here called "taulayer".
vector<vector<double > > Planet::getContribution()
{
vector<vector<double> > contribution(wavens.size(),vector<double>(nlayer,0));
for(int i=0; i<wavens.size(); i++){
for(int j=0; j<nlayer; j++){
contribution[i][j] = taulayer[i][j]*blayer[i][j] / exp(tauprof[i][j]);
}
}
return contribution;
}
// ada: Additional function to return the cloud optical depth.
vector<vector<double > > Planet::getCloudTau()
{
return cloudtauprof;
}
// ada: Additional function to return the gas optical depth.
vector<vector<double > > Planet::getGasTau()
{
return gastauprof;
}
I added these to the wrapper files as well. Then, the easiest way to mock this up was to make a copy of Apollo.py, "Apollo.getContribution.py", that simply takes the part through "get_Spectrum" then adds these calls to the new C++ functions:
# ada: Adding a call to getContribution, which returns "taulayer" from the C++ side.
contribution = planet.getContribution()
cloudtau = planet.getCloudTau()
gastau = planet.getGasTau()
# print("The shape of the contribution array is {}".format(np.shape(contribution)))
# with open(name+"_contribution.txt", "wb") as contribution_file:
# np.savetxt(contribution_file, contribution)
nlayers = np.shape(contribution)[-1] + 1
logPs = (minP-6.0) + (maxP-minP)*np.arange(nlayers)/(nlayers-1)
mean_logPs = (logPs[:-1]+logPs[1:])/2.
contribution_df = pd.DataFrame(data=contribution,
index=specwave,
columns=mean_logPs)
contribution_df.to_csv(name+"_contribution.txt")
cloudtau_df = pd.DataFrame(data=cloudtau,
index=specwave,
columns=mean_logPs)
cloudtau_df.to_csv(name+"_cloudtau.txt")
gastau_df = pd.DataFrame(data=gastau,
index=specwave,
columns=mean_logPs)
gastau_df.to_csv(name+"_gastau.txt")
I have an alpha-level version set up for v0.10.4.1, but it shouldn't be too difficult to port into the latest version!