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

Add argparse, deterministic precipitation, image input support for simulation.py #23

Open
wants to merge 25 commits into
base: master
Choose a base branch
from

Conversation

MightyBOBcnc
Copy link

  • Results from all scripts other than the machine learning scripts will go into an output subfolder to keep things tidy.
  • simulation.py's precipitation randomness has been replaced with seeded randomness in the two parts of the code that were using random precipitation. This makes the output of the simulation deterministic for the same given input seed or image. For now we're just using the current iteration # as the base for the seed and changing it on every iteration to keep things close to the way the previous randomness used to be.
  • fbm function also accepts a specific seed for user control of results.
  • Introduced argparse to all scripts other than the machine larning scripts to add some features and make things a bit more user-friendly. Run <script_name.py> -h for help on a particular .py file.
  • Not all scripts have all arguments but a short rundown is as follows (all arguments are optional except in make_grayscale_image.py and make_hillshaded_image.py):
    -h: Help
    -f: simulation.py can now take an input image as terrain source instead of generating a new fBm every time it runs. If a file is given as input then simulation.py will get its dimensions from the file. Requires a square image.
    -s: A positive integer. This is a seed for the randomness used in plain_old_fbm.py and simulation.py so we can have predictable, repeatable results.
    -o: User-defined name for the output file (without file extension, except in make_grayscale_image.py and make_hillshaded_image.py where user must type .png extension)
    --snapshot: Controls whether simulation.py will use snapshotting.
    --png: Automatically save out a grayscale and hillshaded png of the result to save some work.

Add an image_to_array function so we can run simulation.py from an input image instead of generating a new FBM every time we run simulation.py

I have not tested this for robustness and it will probably break if the image isn't an 8-bit grayscale (1 channel) image.
- Simulation takes an input image as terrain source instead of generating a new FBM every time it runs.  (This is probably fragile as I haven't tested with anything other than an 8-bit 1-channel grayscale png) Usage:  `python simulation.py <input_image.png>`
- Precipitation randomness has been replaced with seeded randomness in the two parts of the code that were using random precipitation.  This makes the output of the simulation deterministic for the same given input image.  For now we're just using the current iteration as the base for the seed and changing it on every iteration to keep things close to the way the previous randomness used to be.
- If enable_snapshotting is True, also save out the terrain source before running any iterations on it.
Fix a typo
- Allow user to control the seed used to generate fbm.
- Added argparse options (required moving a few things around)
- Argparse controls snapshotting now
- Also has an argument for saving out png files automatically so the user doesn't need to run make_grayscaleimage.py or make_hillshaded_image.py
- Added argparse options
- Add argparse options and ability to automatically save out png files.
- Add argparse options
- User control over fbm input seed
- Option to automatically save out png files
- Add argparse options
- Fixed a typo
- Result is saved into an output subfolder
- Add argparse options
- Fixed a typo
- Result is saved into an output subfolder
- Add argparse options and ability to save out png files automatically
- Update help text for --file argument
- Added conversion support for 16-bit grayscale images and RGB and RGBA images.  Tested with png, jpg, tga, and tiff images of various bit depths and with/without alpha channels and didn't run into issues but there are still a lot of untested combinations.  Still room for improvement but these should be the most common.
@dandrino
Copy link
Owner

This is a lot of good work, and I like the effort you put into it.

My personal preference for many of these scripts was that they be demos rather than utilities, since I wanted people to go in and change things to see what happened.

However, since I am no longer actively contributing to this project, and you have put in a lot of good effort, I would be willing to add a comment to the top of README.md pointing readers to your fork. Does that sound fine by you?

@MightyBOBcnc
Copy link
Author

Hmm, an interesting idea although I'm not sure how to "brand" a link to my fork.

I.E. I'm not really capable of doing major revisions or features related to the simulations as a responsible maintainer or anything like that. I'm still new to programming in general and these demos are using math that's above my head. (I don't remember a thing about imaginary numbers and I never made it as far as Fourier transforms in my schooling. [present-me wishes that past-me had taken calc and trig])

For an example of how I'm already kind of at my knowledge limits, I tried to get simulation.py to operate on a rectangular shape but couldn't figure out how to fix some roadblocks because numpy is like a magic black box to me and I'm not sure how to wrangle the arrays into the proper shape.
ValueError: operands could not be broadcast together with shapes (2,1024,512) (2,512,1024)

I also don't grok, for example, how you plotted the river network images when there doesn't appear to be code for that explicit purpose in the repo.

/images/poisson_disc_sampling.png
/images/delaunay_triangulation.png
/images/river_network_low_inertia.png
/images/river_network_high_inertia.png
/images/river_network_with_volume.png

I know the data is there in their own arrays of course (points, coords, upstream, downstream, volume) but mapping that onto an image eludes me.

So yeah in summation I'm not sure what the best way to frame a link to this fork would be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants