Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sybenzvi/enable ecsv #15

Merged
merged 8 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions BEMEWS_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
help='Maximum energy ax MeV')
p.add_argument('--accuracy', type=float,
help='Accuracy of Runge-Kutta solver')
p.add_argument('--output', action='store_true',
help='Output calculations to file(s)')
p.add_argument('--ecsvformat', action='store_true',
help='Output using astropy-compatible ECSV format')
p.add_argument('--stepcounterlimit', type=int,
help='Output every N steps through the Earth (higher = less output)')

Expand All @@ -57,9 +61,7 @@
for k in config.keys():
defaults.update(dict(config[k]))
settings = defaults
settings.update({k: v for k, v in args.items() if v is not None})

print(settings)
settings.update({k: v for k, v in args.items() if v is not None and v is not False})

# skycoordinates of neutrino source
source = SkyCoord.from_name(settings['source'])
Expand Down Expand Up @@ -103,8 +105,9 @@
# if set to True the BEMEWS module will output files in the 'out' directory
# The stepcounterlimit controls how often output is written. The larger the number, the less often it happens.
ID.outputflag = settings['output'] in ['True', 'true']
ID.ecsvformat = settings['ecsvformat'] if isinstance(settings['ecsvformat'], bool) else settings['ecsvformat'] in ['True', 'true']
ID.stepcounterlimit = int(settings['stepcounterlimit'])

if ID.outputflag:
os.makedirs('out', exist_ok=True)

Expand Down
1 change: 1 addition & 0 deletions config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,5 @@ Emin = 1
Emax = 60
accuracy = 1.01e-9
output = True
ecsvformat = False
stepcounterlimit = 1
27 changes: 14 additions & 13 deletions src/BEMEWS/_ext/BEMEWS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ PYBIND11_MODULE(_ext, m)
.def_readwrite("accuracy", &InputDataBEMEWS::accuracy)
.def_readwrite("stepcounterlimit", &InputDataBEMEWS::stepcounterlimit)
.def_readwrite("NE", &InputDataBEMEWS::NE)
.def_readwrite("ecsvformat", &InputDataBEMEWS::ecsvformat)
.def_readwrite("outputflag", &InputDataBEMEWS::outputflag)
;

Expand Down Expand Up @@ -162,7 +163,7 @@ vector<vector<vector<vector<double> > > > Run(InputDataBEMEWS ID)
ofstream fHvslambda; // a file for anything else
ofstream fSvsE;

if(ID.outputflag==true){ Initialize_Output(outputfilenamestem,fPvslambda,fHvslambda);}
if(ID.outputflag==true){ Initialize_Output(outputfilenamestem,fPvslambda,fHvslambda,ID);}

// *****************************************************
// *****************************************************
Expand Down Expand Up @@ -330,14 +331,14 @@ vector<vector<vector<vector<double> > > > Run(InputDataBEMEWS ID)
if(ID.outputflag==true){ output=true;}
if(output==true){
if(firsttime==true){
Output_Pvslambda(firsttime,lasttime,fPvslambda,lambdamin,Y,Scumulative);
Output_Hvslambda(firsttime,lasttime,fHvslambda,lambdamin,Y,Scumulative);
Output_Pvslambda(firsttime,lasttime,fPvslambda,lambdamin,Y,Scumulative,ID);
Output_Hvslambda(firsttime,lasttime,fHvslambda,lambdamin,Y,Scumulative,ID);
}

firsttime = false;

Output_Pvslambda(firsttime,lasttime,fPvslambda,lambdamin,Y,Scumulative);
Output_Hvslambda(firsttime,lasttime,fHvslambda,lambdamin,Y,Scumulative);
Output_Pvslambda(firsttime,lasttime,fPvslambda,lambdamin,Y,Scumulative,ID);
Output_Hvslambda(firsttime,lasttime,fHvslambda,lambdamin,Y,Scumulative,ID);

output = false;
}
Expand Down Expand Up @@ -454,9 +455,9 @@ vector<vector<vector<vector<double> > > > Run(InputDataBEMEWS ID)
if(output==true)
{ cout<<"\nOutput at\t"<<lambda<<flush;

Output_Pvslambda(firsttime,lasttime,fPvslambda,lambda,Y,Scumulative);
Output_Hvslambda(firsttime,lasttime,fHvslambda,lambda,Y,Scumulative);
//Output_PvsE(lasttime,fPvsE,outputfilenamestem,lambda,Y,Scumulative);
Output_Pvslambda(firsttime,lasttime,fPvslambda,lambda,Y,Scumulative,ID);
Output_Hvslambda(firsttime,lasttime,fHvslambda,lambda,Y,Scumulative,ID);
//Output_PvsE(lasttime,fPvsE,outputfilenamestem,lambda,Y,Scumulative,ID);

output=false;
}
Expand All @@ -477,14 +478,14 @@ vector<vector<vector<vector<double> > > > Run(InputDataBEMEWS ID)
else{ // output at the end of the code
if(ID.outputflag==true){ output = true;}
if(output==true){
Output_Pvslambda(firsttime,lasttime,fPvslambda,lambdamax,Y,Scumulative);
Output_Hvslambda(firsttime,lasttime,fHvslambda,lambdamax,Y,Scumulative);
Output_Pvslambda(firsttime,lasttime,fPvslambda,lambdamax,Y,Scumulative,ID);
Output_Hvslambda(firsttime,lasttime,fHvslambda,lambdamax,Y,Scumulative,ID);

lasttime = true;

Output_Pvslambda(firsttime,lasttime,fPvslambda,lambdamax,Y,Scumulative);
Output_Hvslambda(firsttime,lasttime,fHvslambda,lambdamax,Y,Scumulative);
Output_PvsE(lasttime,fPvsE,outputfilenamestem,lambdamax,Y,Scumulative);
Output_Pvslambda(firsttime,lasttime,fPvslambda,lambdamax,Y,Scumulative,ID);
Output_Hvslambda(firsttime,lasttime,fHvslambda,lambdamax,Y,Scumulative,ID);
Output_PvsE(lasttime,fPvsE,outputfilenamestem,lambdamax,Y,Scumulative,ID);

output = false;
}
Expand Down
1 change: 1 addition & 0 deletions src/BEMEWS/_ext/input_class.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ struct InputDataBEMEWS
double accuracy;
double stepcounterlimit; // how often it outputs data
bool outputflag; // whether the code outputs data as it does the integration
bool ecsvformat; // whether the output is in ECSV or tab-separated text files

InputDataBEMEWS(void) {;}
};
Expand Down
Loading