Skip to content

Commit

Permalink
Merge pull request #220 from mgastner/fix-output-name
Browse files Browse the repository at this point in the history
Revise CSV naming convention, update README, and improve CMakeLists.txt compatibility
  • Loading branch information
adisidev authored Nov 29, 2024
2 parents 85068c7 + 736b57f commit ab4fdaf
Show file tree
Hide file tree
Showing 37 changed files with 79 additions and 26 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ jobs:
uses: actions/checkout@v4
with:
submodules: 'recursive'
fetch-depth: 0
fetch-depth: 1

- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DRELEASE_TAG=${{ needs.set-outputs.outputs.short_sha }}
Expand Down
13 changes: 12 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,18 @@
"variant": "cpp",
"__bit_reference": "cpp",
"__threading_support": "cpp",
"execution": "cpp"
"execution": "cpp",
"__locale": "cpp",
"__node_handle": "cpp",
"bitset": "cpp",
"clocale": "cpp",
"complex": "cpp",
"cstdarg": "cpp",
"locale": "cpp",
"mutex": "cpp",
"print": "cpp",
"queue": "cpp",
"stack": "cpp"
},
"files.exclude": {
"**/external": true
Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required(VERSION 3.25)
cmake_minimum_required(VERSION 3.22)

if(UNIX AND NOT APPLE)
set(CMAKE_CXX_COMPILER "g++-11")
Expand Down Expand Up @@ -70,7 +70,7 @@ target_link_libraries(cartogram
)

# ========== Installation ==========
install(TARGETS cartogram DESTINATION bin)
install(TARGETS cartogram DESTINATION /usr/local/bin)

# Enable CTest testing
enable_testing()
Expand Down
69 changes: 55 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@ Gastner MT, Seguy V, More P. _Fast flow-based algorithm for creating density-equ
Data produced by code in this repository are subject to the MIT license found [here](./LICENSE) and should cite the aforementioned paper by Gastner et al. (2018).

While cloning this repository, please ensure you use the `--recurse-submodules` flag like so:
-
git clone --recurse-submodules https://github.com/mgastner/cartogram-cpp.git

```shell script
git clone --recurse-submodules https://github.com/mgastner/cartogram-cpp.git
```

## Dependencies

Expand All @@ -24,49 +26,68 @@ Please note, we only support UNIX-based systems, and have only tested on macOS,

Install [homebrew](brew.sh) by running the following command:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
```shell script
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
```

#### Installing dependencies through Homebrew

Install pkg-config, boost, fftw, nlohmann-json, and cmake by running the following command:

brew install libomp pkg-config boost fftw nlohmann-json cmake cairo
```shell script
brew install libomp pkg-config boost fftw nlohmann-json cmake cairo
```

### Debian-based distributions (Ubuntu, Arch Linux etc.)

#### Installing relevant dependencies through apt:

Have a look through to apt-requirements.txt if you'd like to see what all will be installed. Then, run the following commands to install all dependencies through apt:

apt install -y g++-11 build-essential cmake libboost-all-dev nlohmann-json3-dev libomp-dev libfftw3-dev libcairo2-dev
```shell script
apt install -y g++-11 build-essential cmake libboost-all-dev nlohmann-json3-dev libomp-dev libfftw3-dev libcairo2-dev
```

### Installation

Go to the `cartogram-cpp` directory in your preferred terminal and execute the following commands.

cmake -B build
make -C build
sudo make install -C build
```shell script
cmake -B build
make -C build
sudo make install -C build
```

If your computer has multiple cores, you may use the `make` command with the `-j` flag to use all your cores, or `-j` followed by a number to use the specified number of cores (for example, `-j4` to use 4 cores). You may perform the entire installation at once with:

sudo cmake -B build && sudo make install -j -C build
```shell script
sudo cmake -B build && sudo make install -j -C build
```

Using lesser cores than you have is recommended so that your computer still has some headroom for other tasks. Thus, it may be a good idea for you to modify the above snippet, appending your preferred number of cores to `-j`.

#### Installing using VScode

If you are using VScode, you may also install the program by running the `CMake: Install` command from the command palette (accessible via `Ctrl/Command + Shift + P`). By default, VSCode builds the `DEBUG` version. If you would like to build the `RELEASE` version, you may change the build type in the `CMake: Select Variant` command. The `RELEASE` version will be much faster.

If you encounter any issues, please look at the troubleshooting section below, especially the last bullet point.

### Troubleshooting

- If compilation suddenly stopped working for you, you may remove the `build` directory with `rm -rf build` and run the installation commands again.
- If running `cmake -B build` gives you an error, it is likely that a dependency was not installed correctly. Rerun the appropriate commands above to install the required dependencies and try again.
- If you get an error which mentions permission issues, try running the command that gave you the error with `sudo` prefixed, as done with `sudo make install -C build` above.
- If `cmake` complains that it could not find a particular library, please try uninstalling it and installing it again. After reinstalling it, please also unlink it and link it with the `--force` flag.
- If you get errors related to CGAL, it's likely you have another version of CGAL installed on your computer that is getting chosen instead of the one contained as a submodule within this repository. It's also possible that when cloning this repository, the `--recurse-submodule` flag was missing. Try running `git submodule init` and `git submodule update` in the root directory of the repository.
- If VScode's `CMake: Install` does not work, make sure you own `/usr/local/bin` and the working directory. You may assign ownership to your account with `sudo chown -R $(whoami) .`, replacing `.` with the directory of choice.

### Usage

Run the following command (replace `your-geojson-file.geojson` file with your geographic data and `your-csv-file.csv` with your visual variables file, containing target areas for each geographic region):

cartogram your-geojson-file.geojson your-csv-file.csv
```shell script
cartogram your-geojson-file.geojson your-csv-file.csv
```

- The first argument's input is a GeoJSON or JSON file, in the standard GeoJSON format.
- The second argument's input is a `.csv` file with data about target areas.
Expand All @@ -89,27 +110,47 @@ The CSV file should be in the following format:
2. `"rgb(255, 0, 120)"` or `rgb(255 0 120)` or `"255, 0, 120"` or `255 0 120`: red, green and blue values out of 255.
3. `#e74c3c`: hex code of color, must start with `#`.

**You may find sample GeoJSON (containing geographic data) and CSV (containing information about target areas, colors and other visual variables) files in the `cartogram-cpp/sample_data` directory.**
You may find sample GeoJSON (containing geographic data) and CSV (containing information about target areas, colors and other visual variables) files in the `cartogram-cpp/sample_data` directory.

To test whether whether the program was installed successfully and is working fine, you may run the following command from the repository root:

```shell script
cartogram sample_data/world_by_country_since_2022/world_by_country_since_2022.geojson sample_data/world_by_country_since_2022/world_population_by_country_2010.csv --plot_polygons --world
```

You may inspect the resultant SVG to check if everything looks as expected.

### Contributing

Contributions are highly encouraged! Please feel free to take a stab at any at any of the open issues and send in a pull request. If you need help getting setup or more guidance contributing, please @ any of the main contributors (@adisidev, @nihalzp, @mgastner) under any of the open issues (or after creating your own issue), and we'll be happy to guide you!

Maintainers, please make sure to run the "Build and Release" workflow under GitHub Actions before approving the pull request. You may delete the newly created release before merging the pull-request. Another release should be automatically created after merging with main.

### Testing

If you'd like to contribute to the project, please run our tests after you make any changes.

To run the unit tests, execute the following command:

ctest --verbose
```shell script
ctest --verbose
```

To learn more about the tests, you may go to the `cartogram-cpp/tests` directory and read the `README.md` file.

Additionally, you may go to the `cartogram-cpp/tests` directory and run the following command:

bash stress_test.sh
```shell script
bash stress_test.sh
```

### Uninstallation

Go to the `cartogram-cpp` directory in your preferred terminal and execute the following command:

sudo make uninstall -C build
```shell script
sudo make uninstall -C build
```

Upon successful uninstallation, the following will be outputted:

Expand Down
2 changes: 1 addition & 1 deletion include/ft_real_2d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ class FTReal2d
double operator()(unsigned int, unsigned int) const;
};

#endif // FT_REAL_2D_HPP_
#endif // FT_REAL_2D_HPP_
10 changes: 5 additions & 5 deletions sample_data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,13 +68,13 @@ In each subdirectory, there should be:

The column header for the divisions (e.g. `shapeName`) must match a key in the
GeoJSON file.
The names of the divisions (e.g. Wallonia etc.) must match the corresponding values
The names of the divisions (e.g. Wallonia etc.) must match the corresponding values
in the GeoJSON.
There are additional examples available in the directory `sample_data`.

CSV file names should follow the pattern:

`(geographic_region)_(statistic)_(optional_unit)_(year[s]).csv`
`(geographic_region)_(statistic)_(optional_unit)_by_(division)_(year[s]).csv`

Years refer to the time applicable to the data, not the years when the data
were obtained.
Expand All @@ -83,9 +83,9 @@ In each subdirectory, there should be:

Examples:

* `world_population_2018.csv`
* `india_agricultural_production_in_inr_2012.csv`
* `germany_votes_for_green_party_2017.csv`
* `world_population_by_country_2018.csv`
* `india_agricultural_production_in_inr_by_state_2012.csv`
* `germany_votes_for_green_party_by_electoral_district_2017.csv`
- exactly one Markdown file with the name:

`(geographic_region)_by_(division)_(optional_descrip)_(year[s]).md`
Expand Down
1 change: 1 addition & 0 deletions src/cartogram_info/read_geojson.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,7 @@ void CartogramInfo::read_geojson(

// Write CSV
std::ofstream out_file_csv;
set_map_name(geometry_file_name);
const auto csv_name = map_name_ + ".csv";
out_file_csv.open(csv_name);
if (!out_file_csv) {
Expand Down
2 changes: 1 addition & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ int main(const int argc, const char *argv[])
CartogramInfo cart_info(world, visual_file_name);

// Determine name of input map based on the geo_file_name and store it
std::string map_name = cart_info.set_map_name(geo_file_name);
std::string map_name = cart_info.set_map_name(visual_file_name);
if (!make_csv) {

// Read visual variables (e.g., area and color) from CSV
Expand Down
2 changes: 1 addition & 1 deletion tests/stress_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ else
verbose=1
printf "\VERBOSE mode turned on.\n"
else
cli="$arg"
cli="$cli $arg"
fi
done
fi
Expand Down

0 comments on commit ab4fdaf

Please sign in to comment.