Optimising drawing graphs from a model: code architecture












-1














OK, I have a question about how to lay out code efficiently.



I have a model written in python which generates results which I use to produce graphs in matplotlib. As written, the model is contained within a single file, and I have 15 other run-files, which call on it with complicated configurations and produce graphs. It takes a while to go through and run each of these run-files, but since they all use substantially different settings for the model, I need to have complicated setup files anyway, and it all works.



I have the output set up for figures which could go in an academic paper. I have now realised that I am going to need each of these figures again in other formats - one for presentations (low dpi, medium size, different font) and one for a poster (high dpi, much bigger, different font again.)



This means I could potentially have 45 odd files to wade through every time I want to make a change to my model. I also would have to cut and paste a lot of boilerplate matplotlib code with minor alterations (each run-file would become 3 different files - one for each graph).



Can anybody explain to me how (and if) I could speed things up? At the moment, I think it's taking me much longer than it should.



As I see it there are 3 main options:




  1. Set up 3 run-files for each actual model run (so duplicate a fair amount, and run the model a lot more than I need) but I can then tweak everything independently (but risk missing something important).

  2. Add another layer - so save the results as .csv or equivalent and then read them into the files for producing graphs. This means more files, but I only have to run the model once per 3 graphs (which might save some time).

  3. Keep the graph and model parameter files integrated, but add another file which sets up graphing templates, so every time I run the file it spits out 3 graphs) It might speed things up a bit, and will certainly keep the number of files down, but they will get very big (and probably much more complicated).

  4. Something else..


Can anybody point me to a resource or provide me with some advice on how best to handle this?



Thanks!










share|improve this question



























    -1














    OK, I have a question about how to lay out code efficiently.



    I have a model written in python which generates results which I use to produce graphs in matplotlib. As written, the model is contained within a single file, and I have 15 other run-files, which call on it with complicated configurations and produce graphs. It takes a while to go through and run each of these run-files, but since they all use substantially different settings for the model, I need to have complicated setup files anyway, and it all works.



    I have the output set up for figures which could go in an academic paper. I have now realised that I am going to need each of these figures again in other formats - one for presentations (low dpi, medium size, different font) and one for a poster (high dpi, much bigger, different font again.)



    This means I could potentially have 45 odd files to wade through every time I want to make a change to my model. I also would have to cut and paste a lot of boilerplate matplotlib code with minor alterations (each run-file would become 3 different files - one for each graph).



    Can anybody explain to me how (and if) I could speed things up? At the moment, I think it's taking me much longer than it should.



    As I see it there are 3 main options:




    1. Set up 3 run-files for each actual model run (so duplicate a fair amount, and run the model a lot more than I need) but I can then tweak everything independently (but risk missing something important).

    2. Add another layer - so save the results as .csv or equivalent and then read them into the files for producing graphs. This means more files, but I only have to run the model once per 3 graphs (which might save some time).

    3. Keep the graph and model parameter files integrated, but add another file which sets up graphing templates, so every time I run the file it spits out 3 graphs) It might speed things up a bit, and will certainly keep the number of files down, but they will get very big (and probably much more complicated).

    4. Something else..


    Can anybody point me to a resource or provide me with some advice on how best to handle this?



    Thanks!










    share|improve this question

























      -1












      -1








      -1







      OK, I have a question about how to lay out code efficiently.



      I have a model written in python which generates results which I use to produce graphs in matplotlib. As written, the model is contained within a single file, and I have 15 other run-files, which call on it with complicated configurations and produce graphs. It takes a while to go through and run each of these run-files, but since they all use substantially different settings for the model, I need to have complicated setup files anyway, and it all works.



      I have the output set up for figures which could go in an academic paper. I have now realised that I am going to need each of these figures again in other formats - one for presentations (low dpi, medium size, different font) and one for a poster (high dpi, much bigger, different font again.)



      This means I could potentially have 45 odd files to wade through every time I want to make a change to my model. I also would have to cut and paste a lot of boilerplate matplotlib code with minor alterations (each run-file would become 3 different files - one for each graph).



      Can anybody explain to me how (and if) I could speed things up? At the moment, I think it's taking me much longer than it should.



      As I see it there are 3 main options:




      1. Set up 3 run-files for each actual model run (so duplicate a fair amount, and run the model a lot more than I need) but I can then tweak everything independently (but risk missing something important).

      2. Add another layer - so save the results as .csv or equivalent and then read them into the files for producing graphs. This means more files, but I only have to run the model once per 3 graphs (which might save some time).

      3. Keep the graph and model parameter files integrated, but add another file which sets up graphing templates, so every time I run the file it spits out 3 graphs) It might speed things up a bit, and will certainly keep the number of files down, but they will get very big (and probably much more complicated).

      4. Something else..


      Can anybody point me to a resource or provide me with some advice on how best to handle this?



      Thanks!










      share|improve this question













      OK, I have a question about how to lay out code efficiently.



      I have a model written in python which generates results which I use to produce graphs in matplotlib. As written, the model is contained within a single file, and I have 15 other run-files, which call on it with complicated configurations and produce graphs. It takes a while to go through and run each of these run-files, but since they all use substantially different settings for the model, I need to have complicated setup files anyway, and it all works.



      I have the output set up for figures which could go in an academic paper. I have now realised that I am going to need each of these figures again in other formats - one for presentations (low dpi, medium size, different font) and one for a poster (high dpi, much bigger, different font again.)



      This means I could potentially have 45 odd files to wade through every time I want to make a change to my model. I also would have to cut and paste a lot of boilerplate matplotlib code with minor alterations (each run-file would become 3 different files - one for each graph).



      Can anybody explain to me how (and if) I could speed things up? At the moment, I think it's taking me much longer than it should.



      As I see it there are 3 main options:




      1. Set up 3 run-files for each actual model run (so duplicate a fair amount, and run the model a lot more than I need) but I can then tweak everything independently (but risk missing something important).

      2. Add another layer - so save the results as .csv or equivalent and then read them into the files for producing graphs. This means more files, but I only have to run the model once per 3 graphs (which might save some time).

      3. Keep the graph and model parameter files integrated, but add another file which sets up graphing templates, so every time I run the file it spits out 3 graphs) It might speed things up a bit, and will certainly keep the number of files down, but they will get very big (and probably much more complicated).

      4. Something else..


      Can anybody point me to a resource or provide me with some advice on how best to handle this?



      Thanks!







      python matplotlib architecture






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 20 '18 at 14:29









      WillWill

      9910




      9910
























          1 Answer
          1






          active

          oldest

          votes


















          1














          I think you are close to find what you want.



          If calculations take some time, store results in files to process later without recalculation.



          The most important: separate code from configuration, instead of copy pasting variations of such mixture.



          If the model takes parameters, define a model class. Maybe instantiate the model only once, but the model knows how to load_config, read_input_data and run. Model also does write_results. That way you can loop a sequence of load_config, read_data, write_results for every config and maybe input data.



          Write the config files by hand with ini format for example and use the confiparser module to load them.



          Do something similar for your Graph class. Put the template definition in configuration files, including output format, sizes fonts, and so on.



          In the end you will be able to "manage" the intended workflow with a single script that uses this facilites. Maybe store groups of related configuration files, output templates and input data together, one group per folder for each modelling session.






          share|improve this answer





















          • Thanks, I know it's a fairly woolly question, but the general shape of the thing was really confusing me.
            – Will
            Nov 27 '18 at 8:27











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53395228%2foptimising-drawing-graphs-from-a-model-code-architecture%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          I think you are close to find what you want.



          If calculations take some time, store results in files to process later without recalculation.



          The most important: separate code from configuration, instead of copy pasting variations of such mixture.



          If the model takes parameters, define a model class. Maybe instantiate the model only once, but the model knows how to load_config, read_input_data and run. Model also does write_results. That way you can loop a sequence of load_config, read_data, write_results for every config and maybe input data.



          Write the config files by hand with ini format for example and use the confiparser module to load them.



          Do something similar for your Graph class. Put the template definition in configuration files, including output format, sizes fonts, and so on.



          In the end you will be able to "manage" the intended workflow with a single script that uses this facilites. Maybe store groups of related configuration files, output templates and input data together, one group per folder for each modelling session.






          share|improve this answer





















          • Thanks, I know it's a fairly woolly question, but the general shape of the thing was really confusing me.
            – Will
            Nov 27 '18 at 8:27
















          1














          I think you are close to find what you want.



          If calculations take some time, store results in files to process later without recalculation.



          The most important: separate code from configuration, instead of copy pasting variations of such mixture.



          If the model takes parameters, define a model class. Maybe instantiate the model only once, but the model knows how to load_config, read_input_data and run. Model also does write_results. That way you can loop a sequence of load_config, read_data, write_results for every config and maybe input data.



          Write the config files by hand with ini format for example and use the confiparser module to load them.



          Do something similar for your Graph class. Put the template definition in configuration files, including output format, sizes fonts, and so on.



          In the end you will be able to "manage" the intended workflow with a single script that uses this facilites. Maybe store groups of related configuration files, output templates and input data together, one group per folder for each modelling session.






          share|improve this answer





















          • Thanks, I know it's a fairly woolly question, but the general shape of the thing was really confusing me.
            – Will
            Nov 27 '18 at 8:27














          1












          1








          1






          I think you are close to find what you want.



          If calculations take some time, store results in files to process later without recalculation.



          The most important: separate code from configuration, instead of copy pasting variations of such mixture.



          If the model takes parameters, define a model class. Maybe instantiate the model only once, but the model knows how to load_config, read_input_data and run. Model also does write_results. That way you can loop a sequence of load_config, read_data, write_results for every config and maybe input data.



          Write the config files by hand with ini format for example and use the confiparser module to load them.



          Do something similar for your Graph class. Put the template definition in configuration files, including output format, sizes fonts, and so on.



          In the end you will be able to "manage" the intended workflow with a single script that uses this facilites. Maybe store groups of related configuration files, output templates and input data together, one group per folder for each modelling session.






          share|improve this answer












          I think you are close to find what you want.



          If calculations take some time, store results in files to process later without recalculation.



          The most important: separate code from configuration, instead of copy pasting variations of such mixture.



          If the model takes parameters, define a model class. Maybe instantiate the model only once, but the model knows how to load_config, read_input_data and run. Model also does write_results. That way you can loop a sequence of load_config, read_data, write_results for every config and maybe input data.



          Write the config files by hand with ini format for example and use the confiparser module to load them.



          Do something similar for your Graph class. Put the template definition in configuration files, including output format, sizes fonts, and so on.



          In the end you will be able to "manage" the intended workflow with a single script that uses this facilites. Maybe store groups of related configuration files, output templates and input data together, one group per folder for each modelling session.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 21 '18 at 15:47









          progmaticoprogmatico

          1,8401512




          1,8401512












          • Thanks, I know it's a fairly woolly question, but the general shape of the thing was really confusing me.
            – Will
            Nov 27 '18 at 8:27


















          • Thanks, I know it's a fairly woolly question, but the general shape of the thing was really confusing me.
            – Will
            Nov 27 '18 at 8:27
















          Thanks, I know it's a fairly woolly question, but the general shape of the thing was really confusing me.
          – Will
          Nov 27 '18 at 8:27




          Thanks, I know it's a fairly woolly question, but the general shape of the thing was really confusing me.
          – Will
          Nov 27 '18 at 8:27


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53395228%2foptimising-drawing-graphs-from-a-model-code-architecture%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

          Alcedinidae

          Origin of the phrase “under your belt”?