Skip to content

Commit

Permalink
Use a faster csv parser to parse the point sources
Browse files Browse the repository at this point in the history
  • Loading branch information
dirkvdb committed Aug 29, 2024
1 parent 84f7704 commit aed3204
Show file tree
Hide file tree
Showing 21 changed files with 252 additions and 111 deletions.
6 changes: 1 addition & 5 deletions bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,10 @@
"c:/DEV/bld" # avoid long path issues by using a short build path
)

overlay_ports = os.path.abspath(
os.path.join(os.path.dirname(__file__), "deps", "overlay-ports")
)

if args.clean:
vcpkg.clean(triplet=triplet)
else:
vcpkg.bootstrap(ports_dir=os.path.join(".", "deps"), triplet=triplet, build_root=build_root, install_root=install_root, overlay_ports=overlay_ports, clean_after_build=args.clean_after_build)
vcpkg.bootstrap(ports_dir=os.path.join(".", "deps"), triplet=triplet, build_root=build_root, install_root=install_root, clean_after_build=args.clean_after_build)
except KeyboardInterrupt:
print("\nInterrupted")
sys.exit(-1)
Expand Down
20 changes: 0 additions & 20 deletions deps/overlay-ports/fast-cpp-csv-parser/FindFastCppCsvParser.cmake

This file was deleted.

15 changes: 0 additions & 15 deletions deps/overlay-ports/fast-cpp-csv-parser/portfile.cmake

This file was deleted.

7 changes: 0 additions & 7 deletions deps/overlay-ports/fast-cpp-csv-parser/vcpkg.json

This file was deleted.

1 change: 1 addition & 0 deletions logic/configurationparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ namespace emap {

using namespace inf;
using namespace std::string_view_literals;
namespace gdal = inf::gdal;

static EmissionDestination emission_destination_from_string(std::string_view str)
{
Expand Down
1 change: 1 addition & 0 deletions logic/debugtools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ namespace emap {

using namespace inf;
using namespace std::string_literals;
namespace gdal = inf::gdal;

class VectorBuilder
{
Expand Down
1 change: 1 addition & 0 deletions logic/emissioninventory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ namespace emap {

using namespace inf;
using namespace date::literals;
namespace gdal = inf::gdal;

static fs::path throw_if_not_exists(const fs::path& path)
{
Expand Down
4 changes: 1 addition & 3 deletions logic/emissionscollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ void EmissionsCollector::add_emissions(const CountryCellCoverage& countryInfo, c
}

for (auto& entry : pointEmissions) {
if (entry.value().amount() > 0.0) {
_outputBuilder->add_point_output_entry(entry);
}
_outputBuilder->add_point_output_entry(entry);
}

if (diffuseEmissions.empty() && !pointEmissions.empty()) {
Expand Down
1 change: 1 addition & 0 deletions logic/gridprocessing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ namespace emap {

using namespace inf;
using namespace std::string_literals;
namespace gdal = inf::gdal;

gdal::VectorDataSet transform_vector(const fs::path& vectorPath, const GeoMetadata& destMeta)
{
Expand Down
38 changes: 38 additions & 0 deletions logic/include/emap/emissioninventory.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "emap/emissions.h"
#include "infra/math.h"

namespace emap {

Expand Down Expand Up @@ -223,6 +224,26 @@ class EmissionCollection
throw inf::RuntimeError("No emission found with id: {}", id);
}

const TEmission& emission_with_id_at_coordinate(const EmissionIdentifier& id, Coordinate coord) const
{
auto iter = std::find_if(_emissions.begin(), _emissions.end(), [&id, &coord](const TEmission& em) {
if (em.id() == id) {
if (auto coordOpt = em.coordinate(); coordOpt.has_value()) {
return inf::math::approx_equal(coord.x, coordOpt->x, 1e-4) &&
inf::math::approx_equal(coord.y, coordOpt->y, 1e-4);
}
}

return false;
});

if (iter == _emissions.end()) {
throw inf::RuntimeError("No emission found with id: {} at coordinate {}", id, coord);
}

return *iter;
}

std::optional<TEmission> try_emission_with_id(const EmissionIdentifier& id) const noexcept
{
auto emissionIter = find_sorted(id);
Expand All @@ -243,6 +264,23 @@ class EmissionCollection
return result;
}

std::vector<TEmission> emissions_with_id_at_coordinate(const EmissionIdentifier& id, Coordinate coord) const
{
std::vector<TEmission> result;
std::copy_if(_emissions.begin(), _emissions.end(), std::back_inserter(result), [&id, &coord](const TEmission& em) {
if (em.id() == id) {
if (auto coordOpt = em.coordinate(); coordOpt.has_value()) {
return inf::math::approx_equal(coord.x, coordOpt->x, 1e-4) &&
inf::math::approx_equal(coord.y, coordOpt->y, 1e-4);
}
}

return false;
});

return result;
}

size_t empty() const noexcept
{
return _emissions.empty();
Expand Down
Loading

0 comments on commit aed3204

Please sign in to comment.