Trinity-SpaceData / conjunction /nasa_cara /DistributedMatlab /CollisionConsequence /CollisionConsequenceFigures.m
Download conjunction/nasa_cara/DistributedMatlab/CollisionConsequence/CollisionConsequenceFigures.m from STAR-future/Trinity-SpaceData: direct link, hf CLI and curl.
- Browser
- Download file 16 kB
-
https://huggingface.co/datasets/STAR-future/Trinity-SpaceData/resolve/main/conjunction/nasa_cara/DistributedMatlab/CollisionConsequence/CollisionConsequenceFigures.m
- Command line
-
hf download hf://datasets/STAR-future/Trinity-SpaceData/conjunction/nasa_cara/DistributedMatlab/CollisionConsequence/CollisionConsequenceFigures.m
-
curl -L -o CollisionConsequenceFigures.m https://huggingface.co/datasets/STAR-future/Trinity-SpaceData/resolve/main/conjunction/nasa_cara/DistributedMatlab/CollisionConsequence/CollisionConsequenceFigures.m
16 kB
| function [Status] = CollisionConsequenceFigures(PrimaryMass,VRel,OutputFolder,OutputID,Catastrophic,NumOfPieces,massVec) | |
| % | |
| % CollisionConsequenceFigures - Generates Figures for representing the | |
| % collision consequence numbers including the number of pieces | |
| % distribution and secondary object mass distribution. The secondary object | |
| % mass distribution can only be generated if a non-empty massVec is passed | |
| % in. | |
| % | |
| % Note: The graph for non-catastrophic collisions will only be generated if | |
| % more than 5% of "Catastrophic" array indicates non-catastrophic | |
| % collisions. Likewise, the graph for a catastrophic collisions will | |
| % only be generated if more than 5% of the "Catastrophic" array | |
| % indicates catastrophic collisions. | |
| % | |
| % Syntax: [Status] = CollisionConsequenceFigures(PrimaryMass,VRel,OutputFolder,OutputID,Catastrophic,NumOfPieces,massVec) | |
| % | |
| % Inputs: | |
| % PrimaryMass - 1X1 Mass of Primary Object (kg) | |
| % VRel - 1x1, 3X1, or 1X3 vector of the relative velocity | |
| % between the primary and secondary objects (m/s) | |
| % OutputFolder - String location of output file directory folder where | |
| % figures will be saved (optional) | |
| % - If no output location specified, figures will not | |
| % be saved but will remain on screen | |
| % - If output location specified, figures will be | |
| % saved and then automatically closed | |
| % OutputID - String for output figure ID (optional) used to | |
| % identify specific event | |
| % Catastrophic - [n x 1] logical array indicating whether the | |
| % sampled collision is catastrophic (comes from | |
| % CollisionConsequenceNumPieces.m outputs where "n" | |
| % corresponds to the size of the SecondaryMass array) | |
| % NumOfPieces - [n x 1] array of the number of pieces | |
| % expected to be generated from a collision for each | |
| % sample (comes from CollisionConsequenceNumPieces.m | |
| % outputs where "n" corresponds to the size of the | |
| % SecondaryMass array) | |
| % massVec - [m x 1] array of the secondary object mass | |
| % estimates for each individual sample (comes from | |
| % EstimatedObjectMassQuantiles.m outputs where "m" | |
| % corresponds to the NumOfSamples input parameter) | |
| % | |
| % Outputs: | |
| % Status - Success Status of operation | |
| % 1 - Figures generated Successfully | |
| % 0 - Error Encountered | |
| % | |
| % Example/Validation Cases: | |
| % | |
| % Example 1: Generating graphs for expected number of pieces when | |
| % non-catastrophic and catastrophic collisions occur | |
| % | |
| % % Calculate the number of pieces generated by various secondary mass | |
| % % values and whether or not the number of pieces is characterized as | |
| % % catastrophic | |
| % PrimaryMass = 2000; | |
| % VRel = 10000; | |
| % SecondaryMass = logspace(-2,3,1000); % 1000 evenly spaced masses (in log space) from 0.01 kg to 1000 kg | |
| % [Catastrophic,NumOfPieces] = CollisionConsequenceNumPieces(PrimaryMass,VRel,SecondaryMass); | |
| % % Display the distribution of catastrophic vs. non-catastrophic | |
| % % collisions based on the primary mass, relative velocity, and | |
| % % values calculated in the previous step | |
| % CollisionConsequenceFigures(PrimaryMass, VRel, [], [], Catastrophic, NumOfPieces, []); | |
| % | |
| % Example 2: Generating graphs for expected number of pieces when | |
| % non-catastrophic and catastrophic collisions occur, in | |
| % addition generate a graph of the mass distribution | |
| % (requires knowledge of the object's RCS, drag coefficient, | |
| % drag coefficient variance, ballistic coefficient, and | |
| % ballistic coefficient variance) | |
| % | |
| % % First step: | |
| % % Calculate the number of pieces generated by various secondary mass | |
| % % values and whether or not the number of pieces is characterized as | |
| % % catastrophic | |
| % PrimaryMass = 2000; | |
| % VRel = 10000; | |
| % SecondaryMass = logspace(-2,3,1000); % 1000 evenly spaced masses (in log space) from 0.01 kg to 1000 kg | |
| % [Catastrophic,NumOfPieces] = CollisionConsequenceNumPieces(PrimaryMass,VRel,SecondaryMass); | |
| % | |
| % % Second step: | |
| % % Generate a sample distribution of masses for an unknown secondary | |
| % % based on the RCS, drag coefficient & variance, and ballistic | |
| % % coefficient & variance for the secondary object | |
| % Accuracy = 0.05; % Relative 5% tolerance for well defined quantiles | |
| % RCSdB = -21.52; | |
| % RCS = 10^(RCSdB/10); | |
| % Cd = 2.1; | |
| % CdVar = (0.05*Cd)^2; | |
| % B = 0.059683; | |
| % BVar = 0.0143760217028217*B^2; | |
| % QuantileVector = [.5 .75 .95 .99 0.999 0.9999]; | |
| % NumOfSamples = 100000; | |
| % [massVec,QuantileArray] = EstimateObjectMassQuantiles(RCS,B,BVar,Cd,CdVar,QuantileVector,NumOfSamples); | |
| % | |
| % % Display the distribution of catastrophic vs. non-catastrophic | |
| % % collisions based on the primary mass, relative velocity, and | |
| % % values calculated in the first step. In addition, display the | |
| % % distribution of secondary masses based on the values from the | |
| % % second step. | |
| % CollisionConsequenceFigures(PrimaryMass, VRel, [], [], Catastrophic, NumOfPieces, massVec); | |
| % | |
| % Other m-files required: None | |
| % | |
| % Subfunctions: None | |
| % MAT-files required: None | |
| % | |
| % See also: none | |
| % | |
| % May 2018; Last revision: Feb 2024 | |
| % | |
| % ----------------- BEGIN CODE ----------------- | |
| try | |
| %% Set Constants | |
| CatastrophicThreshold = 40000; % Threshold for Catastrophic Collision (Joules/kg) | |
| CatastrophicThresholdMass = CatastrophicThreshold*2*PrimaryMass/norm(VRel)^2; | |
| if sum(Catastrophic)/length(Catastrophic)*100 > 0.005 | |
| CollisionProbabilityText = num2str(sum(Catastrophic)/length(Catastrophic)*100,'%.2f'); | |
| else | |
| CollisionProbabilityText = '<0.005'; | |
| end | |
| if ~isempty(OutputFolder) | |
| CloseFigures = 1; % Toggle Variable for whether to close figures after generation and saving | |
| else | |
| CloseFigures = 0; | |
| end | |
| %% Close Existing Collision Consequence figure windows if open | |
| try | |
| close('Secondary Mass Distribution') | |
| catch | |
| end | |
| try | |
| close('Non-Catastrophic Debris Piece Distribution') | |
| catch | |
| end | |
| try | |
| close('Catastrophic Debris Piece Distribution') | |
| catch | |
| end | |
| %% Generate Number of Pieces Distribution Plots for Non-Catastrophic Collisions | |
| CDFcounts = [0:100/length(NumOfPieces):100]; | |
| % Only generate figure if Non-Catastrophic Collision Probability above 5% | |
| if (1-sum(Catastrophic)/length(Catastrophic))*100 > 5 | |
| idx = find(~Catastrophic); | |
| ExpectedNumberofPieces = round(10^mean(log10(NumOfPieces(idx)))); | |
| h= figure('Position',[75 75 550 700],... | |
| 'Name','Non-Catastrophic Debris Piece Distribution'); | |
| % generate Histogram of distribution | |
| subplot(2,1,1); | |
| % define bin edges expecting to represet a chi square distribution | |
| edges = [0:median(NumOfPieces(idx))/4:median(NumOfPieces(idx))*6]; | |
| histogram(NumOfPieces(idx),edges) | |
| title({'Expected Number of Debris Pieces Generated'; 'If a Non-Catastrophic Collision Occurs'}) | |
| xlabel('Number of Pieces') | |
| ylabel({'Incidence Count ';['(' num2str(length(NumOfPieces),'%.0f') ' Total Trials)']}) | |
| box on | |
| grid on | |
| % Add Text Indicating probability of Catastrophic Collision | |
| yl = ylim; | |
| xl = xlim; | |
| text(xl(2)*0.98,yl(2)*0.97,... | |
| {[CollisionProbabilityText '% Chance of Catastrophic Collision']; | |
| [num2str(ExpectedNumberofPieces,'%.0f') ' Expected Debris Pieces ']; | |
| '(Non-Catastrophic Collision)'},... | |
| 'HorizontalAlignment','right',... | |
| 'VerticalAlignment','top',... | |
| 'EdgeColor','k',... | |
| 'BackgroundColor',[1 1 1]) | |
| % Generate CDF of distribution | |
| subplot(2,1,2); | |
| hold on | |
| % Plot CDF | |
| plot([0 reshape(sort(NumOfPieces(idx),'ascend'),1,length(NumOfPieces(idx))) xl(2)],... | |
| [CDFcounts(1:length(idx)+1) CDFcounts(length(idx)+1)],... | |
| 'LineWidth',2,... | |
| 'Color','b') | |
| hold off | |
| title({'Cumulative Distribution Function of';'Expected Non-Catastrophic Debris Pieces'}) | |
| xlabel('Number of Pieces') | |
| ylabel({'Cumulative Percentage'}) | |
| box on | |
| grid on | |
| xlim(xl); | |
| ylim([0 100]); | |
| if ~isempty(OutputFolder) | |
| % Save Figures | |
| saveas(h,fullfile(OutputFolder,[OutputID '_CollisionConsequence_NonCatastrophicDebrisPieces.fig'])); | |
| saveas(h,fullfile(OutputFolder,[OutputID '_CollisionConsequence_NonCatastrophicDebrisPieces.png'])); | |
| end | |
| if CloseFigures | |
| close(h) | |
| end | |
| end | |
| %% Generate Number of Pieces Distribution Plots for Catastrophic Collisions | |
| % Only generate figure if Catastrophic Collision Probability above 5% | |
| if sum(Catastrophic)/length(Catastrophic)*100 > 5 | |
| h= figure('Position',[75 75 550 700],... | |
| 'Name','Catastrophic Debris Piece Distribution'); | |
| idx = find(Catastrophic); | |
| ExpectedNumberofPieces = round(10^mean(log10(NumOfPieces(idx)))); | |
| % generate Histogram of distribution | |
| subplot(2,1,1); | |
| % define bin edges expecting to represet a chi square distribution | |
| edges = [min(NumOfPieces(idx)):(median(NumOfPieces(idx))-min(NumOfPieces(idx)))/4:median(NumOfPieces(idx))+(median(NumOfPieces(idx))-min(NumOfPieces(idx)))*6]; | |
| histogram(NumOfPieces(idx),edges) | |
| title({'Expected Number of Debris Pieces Generated'; 'If a Catastrophic Collision Occurs'}) | |
| xlabel('Number of Pieces') | |
| ylabel({'Incidence Count ';['(' num2str(length(NumOfPieces),'%.0f') ' Total Trials)']}) | |
| box on | |
| grid on | |
| % Add Text Indicating probability of Catastrophic Collision | |
| yl = ylim; | |
| xl = xlim; | |
| text(xl(1)+(xl(2)-xl(1))*0.98,yl(2)*0.97,... | |
| {[CollisionProbabilityText '% Chance of Catastrophic Collision']; | |
| [num2str(ExpectedNumberofPieces,'%.0f') ' Expected Debris Pieces ']; | |
| '(Catastrophic Collision)'},... | |
| 'HorizontalAlignment','right',... | |
| 'VerticalAlignment','top',... | |
| 'EdgeColor','k',... | |
| 'BackgroundColor',[1 1 1]) | |
| % Generate CDF of distribution | |
| subplot(2,1,2); | |
| hold on | |
| % Plot CDF | |
| plot([xl(1) reshape(sort(NumOfPieces(idx),'ascend'),1,length(NumOfPieces(idx)))],... | |
| [CDFcounts(length(NumOfPieces)-length(idx)+2) CDFcounts(length(NumOfPieces)-length(idx)+2:end)],... | |
| 'LineWidth',2,... | |
| 'Color','b') | |
| hold off | |
| title({'Cumulative Distribution Function of';'Expected Catastrophic Debris Pieces'}) | |
| xlabel('Number of Pieces') | |
| ylabel({'Cumulative Percentage'}) | |
| box on | |
| grid on | |
| xlim(xl); | |
| ylim([0 100]); | |
| if ~isempty(OutputFolder) | |
| % Save Figures | |
| saveas(h,fullfile(OutputFolder,[OutputID '_CollisionConsequence_CatastrophicDebrisPieces.fig'])); | |
| saveas(h,fullfile(OutputFolder,[OutputID '_CollisionConsequence_CatastrophicDebrisPieces.png'])); | |
| end | |
| if CloseFigures | |
| close(h) | |
| end | |
| end | |
| %% Generate Secondary Object Mass Distribution Plots | |
| if ~isempty(massVec) | |
| g= figure('Position',[75 75 550 700],... | |
| 'Name','Secondary Mass Distribution'); | |
| % generate Histogram of distribution | |
| subplot(2,1,1); | |
| % define bin edges expecting to represet a chi square distribution | |
| edges = [0:median(massVec)/4:median(massVec)*6]; | |
| histogram(massVec,edges) | |
| title({'Predicted Secondary Object Mass Distribution'}) | |
| xlabel('Secondary Mass (kg)') | |
| ylabel({'Incidence Count ';['(' num2str(length(massVec),'%.0f') ' Total Trials)']}) | |
| box on | |
| grid on | |
| % Add Text Indicating probability of Catastrophic Collision | |
| yl = ylim; | |
| xl = xlim; | |
| text(xl(2)*0.98,yl(2)*0.97,... | |
| [CollisionProbabilityText '% Chance of Catastrophic Collision'],... | |
| 'HorizontalAlignment','right',... | |
| 'VerticalAlignment','top',... | |
| 'EdgeColor','k',... | |
| 'BackgroundColor',[1 1 1]) | |
| % Generate CDF of distribution | |
| subplot(2,1,2); | |
| hold on | |
| % Plot CDF | |
| plot([0 reshape(sort(massVec,'ascend'),1,length(massVec))],... | |
| [0:100/length(massVec):100],... | |
| 'LineWidth',2,... | |
| 'Color','b') | |
| % Add Catastrophic Collision Threshold | |
| if CatastrophicThresholdMass < xl(2) | |
| plot([CatastrophicThresholdMass CatastrophicThresholdMass],... | |
| [0 100],... | |
| 'LineWidth',2,... | |
| 'Color','r') | |
| legend('CDF','Catastrophic Collision Threshold') | |
| else | |
| text(xl(2)*0.98,3,... | |
| {'Catastrophic Collision Threshold'; | |
| ['(40,000 J/kg): ' num2str(CatastrophicThresholdMass,'%0.2f') ' kg']},... | |
| 'HorizontalAlignment','right',... | |
| 'VerticalAlignment','bottom',... | |
| 'EdgeColor','k',... | |
| 'BackgroundColor',[1 1 1]) | |
| end | |
| hold off | |
| title({'Cumulative Distribution Function of';'Secondary Object Mass'}) | |
| xlabel('Secondary Mass (kg)') | |
| ylabel({'Cumulative Percentage'}) | |
| box on | |
| grid on | |
| xlim(xl); | |
| ylim([0 100]); | |
| if ~isempty(OutputFolder) | |
| % Save Figures | |
| saveas(g,fullfile(OutputFolder,[OutputID '_CollisionConsequence_SecondaryMass.fig'])); | |
| saveas(g,fullfile(OutputFolder,[OutputID '_CollisionConsequence_SecondaryMass.png'])); | |
| end | |
| if CloseFigures | |
| close(g) | |
| end | |
| end | |
| Status = 1; | |
| catch | |
| %% Close Existing Collision Consequence figure windows if open | |
| try | |
| close('Secondary Mass Distribution') | |
| catch | |
| end | |
| try | |
| close('Non-Catastrophic Debris Piece Distribution') | |
| catch | |
| end | |
| try | |
| close('Catastrophic Debris Piece Distribution') | |
| catch | |
| end | |
| warning('An Error occured attempting to generate collision consequence plots') | |
| Status = 0; | |
| return | |
| end | |
| % ----------------- END OF CODE ------------------ | |
| % | |
| % Please record any changes to the software in the change history | |
| % shown below: | |
| % | |
| % ----------------- CHANGE HISTORY ------------------ | |
| % Developer | Date | Description | |
| % --------------------------------------------------- | |
| % T. Lechtenberg | 05-22-2018 | Initial Development | |
| % L. Baars | 02-14-2024 | Added extra documentation for using this | |
| % function. In addition, made the massVec | |
| % array optional so that the other two graphs | |
| % can be generated if this data is not | |
| % available. | |
| % |